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