mirror of
https://github.com/SuiteCRM/SuiteCRM-Core.git
synced 2025-09-02 08:09:19 +08:00
Fix subpanel insights to support function query
This commit is contained in:
parent
d2882d22e7
commit
8f278ee7fe
2 changed files with 53 additions and 11 deletions
|
@ -78,10 +78,16 @@ class SubpanelDefault extends SubpanelDataQueryHandler implements StatisticsProv
|
|||
return $this->getErrorResponse(self::KEY);
|
||||
}
|
||||
|
||||
$parts = $queries[0];
|
||||
$parts['select'] = 'SELECT COUNT(*) as value';
|
||||
if (!empty($queries['isDatasourceFunction'])) {
|
||||
$dbQuery = $queries['isDatasourceFunction']['countQuery'];
|
||||
|
||||
} else {
|
||||
$parts = $queries[0];
|
||||
$parts['select'] = 'SELECT COUNT(*) as value';
|
||||
|
||||
$dbQuery = $this->joinQueryParts($parts);
|
||||
}
|
||||
|
||||
$dbQuery = $this->joinQueryParts($parts);
|
||||
$result = $this->fetchRow($dbQuery);
|
||||
$statistic = $this->buildSingleValueResponse(self::KEY, 'int', $result);
|
||||
|
||||
|
|
|
@ -38,26 +38,62 @@ class SubpanelCustomQueryPort
|
|||
/* @noinspection PhpIncludeInspection */
|
||||
require_once 'include/SubPanel/SubPanelDefinitions.php';
|
||||
|
||||
$queries = [];
|
||||
|
||||
$spd = new SubPanelDefinitions($bean);
|
||||
$subpanel_def = $spd->load_subpanel($subpanel);
|
||||
|
||||
$subpanel_list = [];
|
||||
if (method_exists($subpanel_def, 'isCollection')) {
|
||||
if ($subpanel_def->isCollection()) {
|
||||
if ($subpanel_def->load_sub_subpanels() === false) {
|
||||
$subpanel_list = [];
|
||||
|
||||
if (method_exists($subpanel_def, 'isDatasourceFunction')
|
||||
&& $subpanel_def->isDatasourceFunction()) {
|
||||
|
||||
$shortcut_function_name = $subpanel_def->get_data_source_name();
|
||||
$parameters = $subpanel_def->get_function_parameters();
|
||||
if (!empty($parameters)) {
|
||||
//if the import file function is set, then import the file to call the custom function from
|
||||
if (is_array($parameters) && isset($parameters['import_function_file'])) {
|
||||
//this call may happen multiple times, so only require if function does not exist
|
||||
if (!function_exists($shortcut_function_name)) {
|
||||
require_once($parameters['import_function_file']);
|
||||
}
|
||||
//call function from required file
|
||||
$func_query = $shortcut_function_name($parameters);
|
||||
} else {
|
||||
//call function from parent bean
|
||||
$func_query = $bean->$shortcut_function_name($parameters);
|
||||
}
|
||||
} else {
|
||||
$subpanel_list = $subpanel_def->sub_subpanels;
|
||||
$func_query = $bean->$shortcut_function_name();
|
||||
}
|
||||
|
||||
$countAlias = 'value';
|
||||
$countQuery = $bean->create_list_count_query($func_query, $countAlias);
|
||||
|
||||
$queries['isDatasourceFunction'] = [
|
||||
'query' => $func_query,
|
||||
'countQuery' => $countQuery
|
||||
];
|
||||
|
||||
} else {
|
||||
$subpanel_list[] = $subpanel_def;
|
||||
$subpanel_list = [];
|
||||
if ($subpanel_def->isCollection()) {
|
||||
if ($subpanel_def->load_sub_subpanels() === false) {
|
||||
$subpanel_list = [];
|
||||
} else {
|
||||
$subpanel_list = $subpanel_def->sub_subpanels;
|
||||
}
|
||||
} else {
|
||||
$subpanel_list[] = $subpanel_def;
|
||||
}
|
||||
|
||||
$queries = SugarBean::getUnionRelatedListQueries($subpanel_list, $subpanel_def, $bean, '');
|
||||
}
|
||||
} else {
|
||||
$GLOBALS['log']->fatal('Subpanel definition should be an aSubPanel');
|
||||
}
|
||||
|
||||
|
||||
return SugarBean::getUnionRelatedListQueries($subpanel_list, $subpanel_def, $bean, '');
|
||||
return $queries;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue