Hello,
i’ve successfully overwrite a dropdown definition in order to populate its options with data retrieve from database, here is the code:
custom/Extension/modules/Cases/Ext/Vardefs/_dropdown_db.php
$dictionary['Case']['fields']['dropdown_db_c'] = array (
'name' => 'dropdown_db_c',
'vname' => 'LBL_DROPDOWN_DB',
'function' => array(
'name' => 'getDropdown',
),
'type' => 'enum',
'len' => '100',
'comment' => 'Test created by Me',
);
Then the called php function is:
custom/Extension/application/Ext/Utils/getDropdown.php
function getDropdown(){
static $getDropdown = null;
if(!$getDropdown){
global $db;
$query = "SELECT DISTINCT name, value FROM cdz_dropdown where deleted = 0 order by name asc";
$result = $db->query($query, false);
$getDropdown = array();
$getDropdown[''] = '';
while (($row = $db->fetchByAssoc($result)) != null) {
$getDropdown[$row['name']] = $row['value'];
}
}
return $getDropdown;
}
Which is working like a charm.
Now i would pass a parameters in order to be more elastic like this:
custom/Extension/modules/Cases/Ext/Vardefs/_dropdown_db.php
$dictionary['Case']['fields']['dropdown_db_c'] = array (
'name' => 'dropdown_db_c',
'vname' => 'LBL_DROPDOWN_DB',
'function' => array(
'name' => 'getDropdown',
'params' => array (
0 => 'Context1'
),
),
'type' => 'enum',
'len' => '100',
'comment' => 'Test created by Me',
);
and then the function:
custom/Extension/application/Ext/Utils/getDropdown.php
function getDropdown($dropdown_context){
static $getDropdown = null;
if(!$getDropdown){
global $db;
$query = "SELECT DISTINCT name, value FROM cdz_dropdown where deleted = 0 AND context = '" . $dropdown_context . "'order by name asc";
$result = $db->query($query, false);
$getDropdown = array();
$getDropdown[''] = '';
while (($row = $db->fetchByAssoc($result)) != null) {
$getDropdown[$row['name']] = $row['value'];
}
}
return $getDropdown;
}
But this doesn’t work because the first time it pass the param string(when you are in ListView) then the second time the entire Object(In Detail or EditView)
The error is:
PHP Recoverable fatal error: Object of class aCase could not be converted to string in /var/www/html/SuiteCRM-7.10.29/custom/application/Ext/Utils/custom_utils.ext.php
Does anyone already tried this way, or can suggest a best way to do it.
I think it could be the rigth way because working with display() function in view seems to be less solid.
Many Thanks for every reply.
Regards