Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | |
3 | /* | |
4 | +--------------------------------------------------------------------+ | |
06b69b18 | 5 | | CiviCRM version 4.5 | |
6a488035 | 6 | +--------------------------------------------------------------------+ |
06b69b18 | 7 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
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 | |
06b69b18 | 32 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
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 | ||
74cf4551 EM |
42 | /** |
43 | * @param null $compID | |
44 | * @param null $grouping | |
45 | * | |
46 | * @return array | |
47 | */ | |
2066e389 | 48 | public static function &info($compID = NULL, $grouping = NULL) { |
6a488035 TO |
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) { | |
2f4c2f5d | 56 | $compClause = " AND v.component_id IS NULL "; |
6a488035 | 57 | } else { |
2f4c2f5d | 58 | $compClause = " AND v.component_id = {$compID} "; |
6a488035 TO |
59 | } |
60 | } | |
2066e389 | 61 | elseif ($grouping) { |
62 | $compClause = " AND v.grouping = '{$grouping}' "; | |
63 | } | |
6a488035 | 64 | $sql = " |
2f4c2f5d | 65 | SELECT v.id, v.value, v.label, v.description, v.component_id, |
2066e389 | 66 | CASE |
67 | WHEN comp.name IS NOT NULL THEN SUBSTRING(comp.name, 5) | |
68 | WHEN v.grouping IS NOT NULL THEN v.grouping | |
69 | ELSE 'Contact' | |
70 | END as component_name, | |
71 | v.grouping, | |
72 | inst.id as instance_id | |
6a488035 | 73 | FROM civicrm_option_value v |
2f4c2f5d | 74 | INNER JOIN civicrm_option_group g |
6a488035 | 75 | ON (v.option_group_id = g.id AND g.name = 'report_template') |
2f4c2f5d | 76 | LEFT JOIN civicrm_report_instance inst |
6a488035 | 77 | ON v.value = inst.report_id |
2f4c2f5d | 78 | LEFT JOIN civicrm_component comp |
6a488035 TO |
79 | ON v.component_id = comp.id |
80 | "; | |
81 | ||
82 | if (!$all) { | |
83 | $sql .= " WHERE v.is_active = 1 {$compClause}"; | |
84 | } | |
85 | $sql .= " ORDER BY v.weight "; | |
86 | ||
87 | $dao = CRM_Core_DAO::executeQuery($sql); | |
88 | $rows = array(); | |
89 | $config = CRM_Core_Config::singleton(); | |
90 | while ($dao->fetch()) { | |
2066e389 | 91 | if ($dao->component_name != 'Contact' && $dao->component_name != $dao->grouping && |
6a488035 TO |
92 | !in_array("Civi{$dao->component_name}", $config->enableComponents) |
93 | ) { | |
94 | continue; | |
95 | } | |
96 | $rows[$dao->component_name][$dao->value]['title'] = $dao->label; | |
97 | $rows[$dao->component_name][$dao->value]['description'] = $dao->description; | |
98 | $rows[$dao->component_name][$dao->value]['url'] = CRM_Utils_System::url('civicrm/report/' . trim($dao->value, '/'), 'reset=1'); | |
99 | if ($dao->instance_id) { | |
100 | $rows[$dao->component_name][$dao->value]['instanceUrl'] = CRM_Utils_System::url('civicrm/report/list', | |
101 | "reset=1&ovid={$dao->id}" | |
102 | ); | |
103 | } | |
104 | } | |
105 | ||
106 | return $rows; | |
107 | } | |
108 | ||
109 | /** | |
110 | * run this page (figure out the action needed and perform it). | |
111 | * | |
112 | * @return void | |
113 | */ | |
114 | function run() { | |
115 | $compID = CRM_Utils_Request::retrieve('compid', 'Positive', $this); | |
2066e389 | 116 | $grouping = CRM_Utils_Request::retrieve('grp', 'String', $this); |
117 | $rows = self::info($compID, $grouping); | |
6a488035 TO |
118 | $this->assign('list', $rows); |
119 | ||
120 | return parent::run(); | |
121 | } | |
122 | } | |
123 |