Merge pull request #4627 from colemanw/docblocks
[civicrm-core.git] / CRM / Report / Page / TemplateList.php
index e654d820f3763a45241de8ecc8780bc2fe95fa55..2eac142299809878cec3567b534633dc8425817c 100644 (file)
@@ -2,9 +2,9 @@
 
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.4                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -29,7 +29,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
  * $Id$
  *
  */
  */
 class CRM_Report_Page_TemplateList extends CRM_Core_Page {
 
-  public static function &info($compID = NULL) {
+  /**
+   * @param null $compID
+   * @param null $grouping
+   *
+   * @return array
+   */
+  public static function &info($compID = NULL, $grouping = NULL) {
     $all = CRM_Utils_Request::retrieve('all', 'Boolean', CRM_Core_DAO::$_nullObject,
       FALSE, NULL, 'GET'
     );
@@ -52,10 +58,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 +88,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 +113,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();