From 2066e38998475d147ac8c3670d5a0a1cef6ee07b Mon Sep 17 00:00:00 2001 From: yashodha Date: Tue, 18 Feb 2014 17:41:52 +0530 Subject: [PATCH] HR-231 : support for Report menu items based on grouping --- CRM/Report/Page/InstanceList.php | 22 +++++++++++++++++++--- CRM/Report/Page/TemplateList.php | 19 ++++++++++++++----- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/CRM/Report/Page/InstanceList.php b/CRM/Report/Page/InstanceList.php index 6b586cc22d..24de971795 100644 --- a/CRM/Report/Page/InstanceList.php +++ b/CRM/Report/Page/InstanceList.php @@ -57,6 +57,13 @@ class CRM_Report_Page_InstanceList extends CRM_Core_Page { **/ protected $_compID = NULL; + /** + * ID of grouping if report list is filtered + * + * @var int + **/ + protected $_grouping = NULL; + /** * ID of parent report template if list is filtered by template * @@ -102,10 +109,17 @@ class CRM_Report_Page_InstanceList extends CRM_Core_Page { } } } + elseif ($this->grouping) { + $report .= " AND v.grouping = '{$this->grouping}' "; + } $sql = " - SELECT inst.id, inst.title, inst.report_id, inst.description, v.label, - ifnull( SUBSTRING(comp.name, 5), 'Contact' ) as compName + SELECT inst.id, inst.title, inst.report_id, inst.description, v.label, v.grouping, + CASE + WHEN comp.name IS NOT NULL THEN SUBSTRING(comp.name, 5) + WHEN v.grouping IS NOT NULL THEN v.grouping + ELSE 'Contact' + END as compName FROM civicrm_option_group g LEFT JOIN civicrm_option_value v ON v.option_group_id = g.id AND @@ -133,7 +147,7 @@ class CRM_Report_Page_InstanceList extends CRM_Core_Page { } $enabled = in_array("Civi{$dao->compName}", $config->enableComponents); - if ($dao->compName == 'Contact') { + if ($dao->compName == 'Contact' || $dao->compName == $dao->grouping) { $enabled = TRUE; } //filter report listings by permissions @@ -171,6 +185,8 @@ class CRM_Report_Page_InstanceList extends CRM_Core_Page { //Filters by source report template or by component $this->ovID = CRM_Utils_Request::retrieve('ovid', 'Positive', $this); $this->compID = CRM_Utils_Request::retrieve('compid', 'Positive', $this); + $this->grouping = CRM_Utils_Request::retrieve('grp', 'String', $this); + $rows = $this->info(); $this->assign('list', $rows); diff --git a/CRM/Report/Page/TemplateList.php b/CRM/Report/Page/TemplateList.php index e654d820f3..f71e1e982e 100644 --- a/CRM/Report/Page/TemplateList.php +++ b/CRM/Report/Page/TemplateList.php @@ -39,7 +39,7 @@ */ class CRM_Report_Page_TemplateList extends CRM_Core_Page { - public static function &info($compID = NULL) { + public static function &info($compID = NULL, $grouping = NULL) { $all = CRM_Utils_Request::retrieve('all', 'Boolean', CRM_Core_DAO::$_nullObject, FALSE, NULL, 'GET' ); @@ -52,10 +52,18 @@ class CRM_Report_Page_TemplateList extends CRM_Core_Page { $compClause = " AND v.component_id = {$compID} "; } } - + elseif ($grouping) { + $compClause = " AND v.grouping = '{$grouping}' "; + } $sql = " SELECT v.id, v.value, v.label, v.description, v.component_id, - inst.id as instance_id, ifnull( SUBSTRING(comp.name, 5), 'Contact' ) as component_name + CASE + WHEN comp.name IS NOT NULL THEN SUBSTRING(comp.name, 5) + WHEN v.grouping IS NOT NULL THEN v.grouping + ELSE 'Contact' + END as component_name, + v.grouping, + inst.id as instance_id FROM civicrm_option_value v INNER JOIN civicrm_option_group g ON (v.option_group_id = g.id AND g.name = 'report_template') @@ -74,7 +82,7 @@ LEFT JOIN civicrm_component comp $rows = array(); $config = CRM_Core_Config::singleton(); while ($dao->fetch()) { - if ($dao->component_name != 'Contact' && + if ($dao->component_name != 'Contact' && $dao->component_name != $dao->grouping && !in_array("Civi{$dao->component_name}", $config->enableComponents) ) { continue; @@ -99,7 +107,8 @@ LEFT JOIN civicrm_component comp */ function run() { $compID = CRM_Utils_Request::retrieve('compid', 'Positive', $this); - $rows = self::info($compID); + $grouping = CRM_Utils_Request::retrieve('grp', 'String', $this); + $rows = self::info($compID, $grouping); $this->assign('list', $rows); return parent::run(); -- 2.25.1