How are enum fields with a function as data provider defined in fields_meta_data? - sugarcrm

So i have a custom enum which has a function as data provider:
$dictionary['Opportunity']['fields']['custom_enum_c'] = array(
'labelValue' => 'Enum',
'name' => 'custom_enum_c',
'inline_edit' => '1',
'vname' => 'LBL_CUSTOM_ENUM',
'type' => 'enum',
'function' => 'getAccounts',
'len' => '255',
'comment' => 'Enum',
'default_value' => '',
);
How is this field saved in fields_meta_data? Specifically where is the function saved in the fields_meta_data table? In one of the ext fields?
Thanks in advance!

As you can see that there is no option in studio to enter "function" there. You can only set it via code. Either by creating new field in custom/Extension/modules//Ext/Vardef OR you can override exciting one as well. Let me know if you face any issue while exploring it.

Related

How can I create custom file upload field in opportunities

I'm working with sugar 8.3. I'm trying to create custom field for upload documents.
I have create vardef file, but when I click on save record, file uploaded properly but not display in record.
custom/Extension/modules/Opportunities/Ext/Vardefs/custom_upload.php
<?php
$GLOBALS['dictionary']['Opportunity']['fields']['filename'] = array (
'name' => 'filename',
'vname' => 'LBL_FILENAME',
'type' => 'file',
'dbType' => 'varchar',
'len' => '255',
'reportable' => true,
'comment' => 'File name associated with the note (attachment)',
'importable' => false,
'source' => 'non-db',
'docUrl' => 'doc_url',
);
$GLOBALS['dictionary']['Opportunity']['fields']['file_mime_type'] = array(
'name' => 'file_mime_type',
'vname' => 'LBL_FILE_MIME_TYPE',
'type' => 'varchar',
'len' => '100',
'comment' => 'Attachment MIME type',
'importable' => false,
'source' => 'non-db',
);
$GLOBALS['dictionary']['Opportunity']['fields']['file_url'] = array (
'name'=>'file_url',
'vname' => 'LBL_FILE_URL',
'type'=>'varchar',
'source'=>'non-db',
'reportable'=>false,
'comment' => 'Path to file (can be URL)',
'importable' => false,
);
Before save attachment screenshot
After save attachment screenshot
The whole scenario is not very clear from the code you have provided, i think that you should remove 'source'=>'non-db', attribute from these fields so that they get saved in database.
Don't forget to perform Repair and execute queries that gets generated in result of repair so that Sugar create appropriate fields in opportunities table for saving you uploaded file data.

how can I add a dependant custom field through the manifest.php

I am currently adding a web hook and want to add some fields programmatically through the manifest.php.
I have found the relevent information to add fields as below:
'custom_fields' => array (
array (
'name' => 'text_c',
'label' => 'LBL_TEXT_C',
'type' => 'varchar',
'max_size' => 255,
'require_option' => 'optional',
'default_value' => '',
'ext1' => '',
'ext2' => '',
'ext3' => '',
'audited' => 1,
'module' => 'Accounts'
)
);
the issue is that I cant seem to find how to make the fields dependant i.e. they will only be visible if another field contains a specific value.
any help would be greatly appreciated
In the definition array you would need to add the dependency attribute like so :
'custom_fields' => array (
array (
'name' => 'text_c',
'label' => 'LBL_TEXT_C',
'type' => 'varchar',
'max_size' => 255,
'require_option' => 'optional',
'default_value' => '',
'ext1' => '',
'ext2' => '',
'ext3' => '',
'audited' => 1,
'module' => 'Accounts'
'dependency' => 'equal($other_field,"other field value")'
)
);
This would replicate setting the dependency option in Studio.
The dependency formula
'equal($other_field,"other field value")'
Means show this field when the another field other_field equals the string "other field value"

zend addElements form onchange select

I try to add dinamically a form input Elemnt on onchange of select element.
I have this code:
$this->addElement('select', 'nationality', array(
'multiOptions' => array('CH' => 'Choose','IT' => 'Italy', 'other' => 'Other'),
'required' => true,
'label' => 'Nation',
'filters' => array('StringTrim'),
'onChange' => '???'
));
I try to paste my new element instead "???"
$this->addElement('select', 'nationality', array(
'multiOptions' => array('CH' => 'Choose','IT' => 'Italy', 'other' => 'Other'),
'required' => true,
'label' => 'Nation',
'filters' => array('StringTrim'),
'onChange' => '$this->addElement(
'text', 'codice_fiscale', array(
'required' => true,
'label' => 'Codice fiscale',
'required' => true
))'
));
I know is not correct, but I dont' found any documentation about it.
How can I add an element onchange select value?
Thanks in advance
I would approach the problem in a different way, if it's possible for you:
javascript functions to call on the onChange. It would be syntax correct (and, as you said, what you wrote is not correct, it's going to be printed out entirely on the onChange attribute, not interpreted through php).
so, i would write
'onChange' => 'addElement()'
and then declare the javascript function which handles new elements. Or, you can prepare the elements before (if you have a fixed number), and show / hide them. It may be convenient if you don't have much elements, but if they're too many, just add through javascript the needed one.
PseudoCode Javascript
function addElement()
{
// add your element here, or show / hide it
}
As far as I saw from my experience and similar cases
(Zend_form_element_select onchange in zend framework,
Zend Form: onchange select load another view content)
you won't escape from Javascript if you want to handle the "onChange"

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.

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

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.