What is the right way to insert a line of code into a moodle module? - moodle

I have a the need to add a single line of code to locallib.php in the \mod\lti directory . ('custom_user' => $USER->username,)
$requestparams = array(
'resource_link_id' => $instance->id,
'resource_link_title' => $instance->name,
'resource_link_description' => $instance->intro,
'user_id' => $USER->id,
'roles' => $role,
'context_id' => $course->id,
'context_label' => $course->shortname,
'context_title' => $course->fullname,
'launch_presentation_locale' => current_language()
);
$requestparams = array(
'resource_link_id' => $instance->id,
'resource_link_title' => $instance->name,
'resource_link_description' => $instance->intro,
'user_id' => $USER->id,
'custom_user' => $USER->username,
'roles' => $role,
'context_id' => $course->id,
'context_label' => $course->shortname,
'context_title' => $course->fullname,
'launch_presentation_locale' => current_language()
);
Is there a right way to do this? Looking at plugins, it seems that they are for adding whole new functions, not just patching individual existing code.

Just having a look at the module - haven't come across it before.
There are custom parameters but they look like literal values.
I would say its okay to put that code in. Although I would probably add // CUSTOM before and after the mod.

Related

TYPO3 list module: custom records not showing

I am using TYPO3 7.6.11.
I wrote an provider extension to add some ts-code, templates, and viewhelpers.
After that, I wanted to add a custom data record (to use in the Backend).
I added the table in the ext_tables.sql.
I have a TCA-config under /[extension]/Configuration/TCA/tablename.php
I added
TYPO3\CMS\Core\Utility\ExtensionManagementUtility::allowTableOnStandardPages('tablename');
TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToInsertRecords('tablename');
to my ext_tables.php
Did I miss something?
I get a new record type under "System Records" in the List Module. I can add such an record, and the TCA-config seems to work fine for the record form.
But after saving, I have no record in the list view. The DB is looking fine. The record is saved correctly in my new table. What am I doing wrong?
Thanks
Edit:
crtl:
'ctrl' => array (
'title' => 'LLL:EXT:svkcore/Resources/Private/Language/locallang.xlf:records.title',
'label' => 'title',
'label_alt' => '',
'label_alt_force' => TRUE,
'default_sortby' => 'ORDER BY datetime DESC',
'prependAtCopy' => 'LLL:EXT:lang/locallang_general.php:LGL.prependAtCopy',
'versioningWS' => TRUE,
'versioning_followPages' => TRUE,
'origUid' => 't3_origuid',
'shadowColumnsForNewPlaceholders' => 'sys_language_uid,l18n_parent,starttime,endtime,fe_group',
'dividers2tabs' => TRUE,
'useColumnsForDefaultValues' => 'type',
'transOrigPointerField' => 'l18n_parent',
'transOrigDiffSourceField' => 'l18n_diffsource',
'languageField' => 'sys_language_uid',
'crdate' => 'crdate',
'tstamp' => 'tstamp',
'delete' => 'deleted',
'type' => 'type',
'cruser_id' => 'cruser_id',
'editlock' => 'editlock',
'enablecolumns' => array (
'disabled' => 'hidden',
'starttime' => 'starttime',
'endtime' => 'endtime',
'fe_group' => 'fe_group',
),
'typeicon_column' => 'type',
'typeicons' => array (
'1' => 'EXT:svkcore/res/gfx/svkcore_inturl.gif',
'2' => 'EXT:svkcore/res/gfx/svkcore_exturl.gif',
),
'thumbnail' => 'image',
'iconfile' => 'EXT:svkcore/res/gfx/ext_icon.gif',
'searchFields' => 'uid,title,short,bodytext'),
'interface' => Array (
'showRecordFieldList' => 'title,hidden,datetime_start,starttime,archivedate,category,short,image,record_files'
),
Since Typo3 7 it is possible to mask the list-view. This is configured via PageTSConfig, have a look at your info-Module (select the correct page in the page tree) and check the TSConfig there.
The configuration can be found in the following path:
mod.web_list.allowedNewTables
Check in ext_tables.php if you have everything needed for your new table : Typoscript inclusion, language file, exemple :
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile($_EXTKEY, 'Configuration/TypoScript', 'My TS configuration');
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addLLrefForTCAdescr('tx_myext_domain_model_mytable', 'EXT:my_ext/Resources/Private/Language/locallang_csh_tx_myext_domain_model_mytable.xlf');
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::allowTableOnStandardPages('tx_myext_domain_model_mytable');
Are you sure the new records are stored in the current page : have a look at the TS "persistence.storagePid".
You can check in the database wich pid is used for your new records.
Regards,
Florian

wordpress WP Query and Custom Field filtering

I've encoutered problem with filtering pages to display in WP query.
I use Codex WP query reference for custom fields with ACF (Advanced Custom Fields plugin - but it doesn't matter, couse it works same as WP custom field) parameters to filter pages.
In "Multiple Custom Field Handling" paragraph, Codex got an example with 2 conditions. We can use OR or AND relation. I works for both until you have 3rd condition (array).
They use example:
'relation' => 'OR',
array(
'key' => 'color',
'value' => 'blue',
'compare' => 'NOT LIKE'
),
array(
'key' => 'price',
'value' => array( 20, 100 ),
'type' => 'numeric',
'compare' => 'BETWEEN'
)
It has only 2 arrays. When I put 3rd, nothing shows. In debug mode I can see an error:
WordPress database error: [Lost connection to MySQL server during query]
When I use AND it works, but I got to use OR. Unfortunately it makes MySQL disconnect.
I've tryed asking phpMySQL for same query WP does. It couses problem - phpMyAdmin says same:
Lost connection
Any Idea?
Maybe I should try different aproach for filtering? (maybe I should use taxonomy?)
Here is code I use:
$query_array = array('relation' => 'OR');
array_push($query_array,
array(
'key' => 'filter1',
'value' => 'value1',
'compare' => 'LIKE'
),
array(
'key' => 'filter1',
'value' => 'value2',
'compare' => 'LIKE'
),
array(
'key' => 'filter1',
'value' => 'value3',
'compare' => 'LIKE'
)
);
$args = array(
'order' => $order_array,
'meta_key' => $meta_key,
'orderby' => $orderby,
'post_type' => 'page',
'paged' => $paged,
'post__in' => $postIDs,
'posts_per_page' => 12,
'paged' => get_query_var('paged'),
'meta_query' => $query_array
);
query_posts($args);
?>
(variables for $args are set of course)
I don't know why I can't use
'compare' => '='
but probably it is why I can't use:
$query_array = array('relation' => 'OR');
array_push($query_array,
array(
'key' => 'filter1',
'value' => array('value1', 'value2', 'value3'),
'compare' => 'IN'
)
);
Just wanted to say that your comment helped me; I'd been butting my head against a very similar problem for a while. I'm using ACF too, and using it to attach items of one post type to another custom post type was easy - for instance, to Attach Person_1 and Person_3 to "Project_A".
This made it easy to list out which users were attached to specific projects. But when it came to do the same in reverse - to show which projects were attached to which users - it became a massive headache.
I finally figured it out, in part thanks to your comment - I'll post my solution here in case someone else comes along with the same problem:
$args = array(
'numberposts' => -1,
'post_type' => 'project',
'meta_query' => array(
'relation' => 'IN',
array(
'key' => 'people',
'value' => ';s:1:"' . $person->ID . '";',
'compare' => 'LIKE'
)
)
);
In short: because the ACF values in repeater fields et cetera are serialized, the compare keyword has to be "LIKE", and I added some context to the value to eliminate false returns - just searching for an ID like "1" would match a lot of the (wrong) posts, but the ";s1;" part ensures that the given value is at index 1, which in my case is the correct index.
So it would need tweaking from case to case. Inspecting what you're trying to match up with var_dumping "get_post_meta($post->ID, 'people')" is helpful for getting the value correct.

Zend Framework 2 invalidate translator cache

I have this code:
'translator' => array(
...
'cache' => array(
'adapter' => array(
'name' => 'Filesystem',
'options' => array(
'cache_dir' => __DIR__ . '/../../../data/cache',
'ttl' => '3600'
)
),
'plugins' => array(
array(
'name' => 'serializer',
'options' => array()
),
'exception_handler' => array(
'throw_exceptions' => true
)
)
)
The question is, how do I invalidate it not by TTL?
For example, I KNOW when the translation was changed so I want to invalidate in on demand but I have not found a way to do it.
The translator component does not utilize the TaggableInterface so you have to know the cacheId which the translator generates to clear the item from you storage adapter. You can use the following code to simply generate the same id and remove the item. Call this from your service or some event listener.
$translator = $sm->get('McvTranslator');
$textDomain = 'default';
$locale = 'en';
$cacheId = 'Zend_I18n_Translator_Messages_' . md5($textDomain . $locale);
$translator->getCache()->removeItem($cacheId);
I think you could set Ttl = 0 (always), and when the cache (file) is not valid anymore -- delete it.
Another way to do it:
Find a point in your code where you call addTranslation.
For example:
$translate = Zend_Registry::get('Zend_Translate');
$translate->addTranslation(array(
'content' => "$dir/$locale.mo",
'locale' => $locale
));
Change the addTranslation function to add reload => true , like this:
$translate->addTranslation(array(
'content' => "$dir/$locale.mo",
'locale' => $locale,
'reload' => true
));
Refresh your page.
Voila.
Remeber to remove reload after that, otherwise you will have no cache.

need to query MongoDB using php

I need to query mongodb with something like this:
("something" < X OR "something" = "nll")
AND
("someother">X OR "someother"= "nll") AND z=$z AND s=1
I've tried a few things, but can't get it to work, this is what I've tried:
find(
array(
'$or'=>array(array("something"=>array("$le",$X)),array("something"=>"nll")),
'$or'=>array(array("someother"=>array("$ge",$X)),array("someother"=>"nll"))
))
But that's getting me the OR overwritten, so I'm lost on that...
After diggin a bit more, I assembled this code that seems to be what I need, but doesn't work either:
find( array('$and'=>array( array( '$or' => array( array("something"=>array('$gte'=>$X)),array("something"=>"nll"))), array('$or' => array( array("someother"=>array('$lte'=>$X)),array("someother"=>"nll")))),"Z"=>$z, "s"=>"1");
But this doesn't work as it returns zero results and I know for sure that there are more than 2 items that match on the db. (100% certain)
$range = array('$and' => array(
array('$or' => array(
array("something" => array( "$lte" => $X)),
array("something" => "null")),
array('$or' => array(
array("someother" => array("$gte" => $X)),
array("someother" => "null"))
));

Insert email when creating account with rest api

I am faced with a Sugar 6.3 CE installation, trying to create new accounts through rest api.
I am still on the learning curve for a lot of the innards of the CRM, and cannot figure out how to have the email inserted whith the rest of the account info upon creation with a REST call.
I have tried many different field values, and after catching that $email1 was used in some snippet examples I saw on the sugarCRM site. I have not found other mentions in the forums or in the docs yet.
The $parameters array used to configure the usual rest call to create an account in php with REST api looks like this and works fine, except for the $email1:
$parameters = array(
'session' => $session,
'module' => 'Contacts',
'name_value_list' => array(
array('name' => 'first_name', 'value' =>
utf8_encode($contacts["Name"])),
array('name' => 'last_name', 'value' =>
utf8_encode($contacts["GivenName"])),
array('name' => 'phone_work', 'value' =>
utf8_encode($row->PrimaryPhoneAreaCode . ' ' . $row->PrimaryPhone)),
array('name' => 'phone_fax', 'value' =>
utf8_encode($row->PrimaryFaxAreaCode . ' ' . $row->PrimaryFaxNumber)),
array('name' => 'title', 'value' =>
utf8_encode($contacts["Title"])),
/*
* PROBLEM HERE!
*/
array('name' => 'email1', 'value' =>
utf8_encode($row->PrimaryEmail)),
array('name' => 'primary_address_street', 'value' =>
utf8_encode($row->Address1) . ' ' .
utf8_encode($row->Address2)),
array('name' => 'language', 'value' =>
utf8_encode($row->Language)),
array('name' => 'assigned_user_id', 'value' =>
get_rep_id($row->Salesperson1Name, $sugarlink)),
)
);
I would be curious, if someone has the trick. I tried to find to field for emails but it seems to be in separate tables. Any help / tips appreciated.
If you are using REST API the email1 will work for both set en get methods (just tested it).
Did not used the SOAP API as in your example, and suggest to migrate all to REST according to SugarCRM recommendations.
You must add the email into emailadress database first, create contact and set a relationship between both ;-)
$set_entry_parametersEADDR = array(
"session" => $session_id,
//The name of the module from which to retrieve records.
"module_name" => "EmailAddresses",
//Record attributes
"name_value_list" => array(
array('name' => 'email_address', 'value' => $email),
array('name' => 'email_address_caps', 'value' => strtoupper($email)),
array('name' => 'invalid_email' , 'value' => 0),
array('name' => 'opt_out', 'value' => 0),
array('name' => 'date_created' , 'value' => date('Y-m-d H:i:s')),
array('name' => 'date_modified', 'value' => date('Y-m-d H:i:s')),
array('name' => 'deleted' , 'value' => 0),
),
);
$set_entry_resultEmailsAdd = call("set_entry", $set_entry_parametersEADDR, $url);
print_r($set_entry_resultEmailsAdd);
$Email_id = $set_entry_resultEmailsAdd->id;
$set_entry_parameters_contact = array(
//session id
"session" => $session_id,
//The name of the module from which to retrieve records.
"module_name" => "Contacts",
//Record attributes
"name_value_list" => array(
//to update a record, you will nee to pass in a record id as commented below
//array("name" => "id", "value" => "9b170af9-3080-e22b-fbc1-4fea74def88f"),
array("name" => "first_name", "value" => $prof["Prenom"]),
array("name" => "last_name", "value" => $prof["Nom"]),
array("name" => "login_c", "value" => $prof["Login"]),
//array("name" => "email1", "value" => $email),
array("name" => "fonction_c", "value" => "prof")
),
);
$set_entry_result_contact = call("set_entry", $set_entry_parameters_contact, $url);
print_r($set_entry_result_contact);
$contact_id = $set_entry_result_contact->id;
$set_relationship_parameters_email = array(
'session' => $session_id,
'module_name' => 'Contacts',
'module_id' => $contact_id,
'link_field_name' => 'email_addresses',
'related_ids' => $Email_id,
);
$set_relationship_result_email = call("set_relationship", $set_relationship_parameters_email, $url);
print_r($set_relationship_result_email);
Currently I think that not works with REST api but works with SOAP API. Could you try to use email1_set_in_workflow key instead of email1?
It's not a very good solution but perhaps that could unlock you pending a better way to do that in future release