Merge pull request #4865 from eileenmcnaughton/my-first-factory
[civicrm-core.git] / CRM / Report / Page / TemplateList.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.6 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2014 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
10 | |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
19 | |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
27 */
28
29 /**
30 *
31 * @package CRM
32 * @copyright CiviCRM LLC (c) 2004-2014
33 * $Id$
34 *
35 */
36
37 /**
38 * Page for displaying list of Reprot templates available
39 */
40 class CRM_Report_Page_TemplateList extends CRM_Core_Page {
41
42 /**
43 * @param int $compID
44 * @param null $grouping
45 *
46 * @return array
47 */
48 public static function &info($compID = NULL, $grouping = NULL) {
49 $all = CRM_Utils_Request::retrieve('all', 'Boolean', CRM_Core_DAO::$_nullObject,
50 FALSE, NULL, 'GET'
51 );
52
53 $compClause = '';
54 if ($compID) {
55 if ($compID == 99) {
56 $compClause = " AND v.component_id IS NULL ";
57 }
58 else {
59 $compClause = " AND v.component_id = {$compID} ";
60 }
61 }
62 elseif ($grouping) {
63 $compClause = " AND v.grouping = '{$grouping}' ";
64 }
65 $sql = "
66 SELECT v.id, v.value, v.label, v.description, v.component_id,
67 CASE
68 WHEN comp.name IS NOT NULL THEN SUBSTRING(comp.name, 5)
69 WHEN v.grouping IS NOT NULL THEN v.grouping
70 ELSE 'Contact'
71 END as component_name,
72 v.grouping,
73 inst.id as instance_id
74 FROM civicrm_option_value v
75 INNER JOIN civicrm_option_group g
76 ON (v.option_group_id = g.id AND g.name = 'report_template')
77 LEFT JOIN civicrm_report_instance inst
78 ON v.value = inst.report_id
79 LEFT JOIN civicrm_component comp
80 ON v.component_id = comp.id
81 ";
82
83 if (!$all) {
84 $sql .= " WHERE v.is_active = 1 {$compClause}";
85 }
86 $sql .= " ORDER BY v.weight ";
87
88 $dao = CRM_Core_DAO::executeQuery($sql);
89 $rows = array();
90 $config = CRM_Core_Config::singleton();
91 while ($dao->fetch()) {
92 if ($dao->component_name != 'Contact' && $dao->component_name != $dao->grouping &&
93 !in_array("Civi{$dao->component_name}", $config->enableComponents)
94 ) {
95 continue;
96 }
97 $rows[$dao->component_name][$dao->value]['title'] = $dao->label;
98 $rows[$dao->component_name][$dao->value]['description'] = $dao->description;
99 $rows[$dao->component_name][$dao->value]['url'] = CRM_Utils_System::url('civicrm/report/' . trim($dao->value, '/'), 'reset=1');
100 if ($dao->instance_id) {
101 $rows[$dao->component_name][$dao->value]['instanceUrl'] = CRM_Utils_System::url('civicrm/report/list',
102 "reset=1&ovid={$dao->id}"
103 );
104 }
105 }
106
107 return $rows;
108 }
109
110 /**
111 * Run this page (figure out the action needed and perform it).
112 *
113 * @return void
114 */
115 public function run() {
116 $compID = CRM_Utils_Request::retrieve('compid', 'Positive', $this);
117 $grouping = CRM_Utils_Request::retrieve('grp', 'String', $this);
118 $rows = self::info($compID, $grouping);
119 $this->assign('list', $rows);
120
121 return parent::run();
122 }
123 }