Fix subpanel insights to support function query

This commit is contained in:
p.kumar 2021-08-22 05:31:03 +05:30 committed by Dillon-Brown
parent d2882d22e7
commit 8f278ee7fe
2 changed files with 53 additions and 11 deletions

View file

@ -78,10 +78,16 @@ class SubpanelDefault extends SubpanelDataQueryHandler implements StatisticsProv
return $this->getErrorResponse(self::KEY);
}
if (!empty($queries['isDatasourceFunction'])) {
$dbQuery = $queries['isDatasourceFunction']['countQuery'];
} else {
$parts = $queries[0];
$parts['select'] = 'SELECT COUNT(*) as value';
$dbQuery = $this->joinQueryParts($parts);
}
$result = $this->fetchRow($dbQuery);
$statistic = $this->buildSingleValueResponse(self::KEY, 'int', $result);

View file

@ -38,11 +38,45 @@ 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 (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 {
$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 = [];
if ($subpanel_def->isCollection()) {
if ($subpanel_def->load_sub_subpanels() === false) {
$subpanel_list = [];
@ -52,12 +86,14 @@ class SubpanelCustomQueryPort
} 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;
}
/**