Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | ||
18 | /** | |
9be11d83 | 19 | * Page for displaying list of Report templates available. |
6a488035 TO |
20 | */ |
21 | class CRM_Report_Page_TemplateList extends CRM_Core_Page { | |
22 | ||
74cf4551 | 23 | /** |
100fef9d | 24 | * @param int $compID |
5e21e0f3 | 25 | * @param string|null $grouping |
74cf4551 EM |
26 | * |
27 | * @return array | |
28 | */ | |
2066e389 | 29 | public static function &info($compID = NULL, $grouping = NULL) { |
6a488035 TO |
30 | $all = CRM_Utils_Request::retrieve('all', 'Boolean', CRM_Core_DAO::$_nullObject, |
31 | FALSE, NULL, 'GET' | |
32 | ); | |
33 | ||
34 | $compClause = ''; | |
35 | if ($compID) { | |
36 | if ($compID == 99) { | |
2f4c2f5d | 37 | $compClause = " AND v.component_id IS NULL "; |
0db6c3e1 TO |
38 | } |
39 | else { | |
2f4c2f5d | 40 | $compClause = " AND v.component_id = {$compID} "; |
6a488035 TO |
41 | } |
42 | } | |
2066e389 | 43 | elseif ($grouping) { |
44 | $compClause = " AND v.grouping = '{$grouping}' "; | |
45 | } | |
6a488035 | 46 | $sql = " |
2f4c2f5d | 47 | SELECT v.id, v.value, v.label, v.description, v.component_id, |
2066e389 | 48 | CASE |
49 | WHEN comp.name IS NOT NULL THEN SUBSTRING(comp.name, 5) | |
50 | WHEN v.grouping IS NOT NULL THEN v.grouping | |
51 | ELSE 'Contact' | |
52 | END as component_name, | |
53 | v.grouping, | |
54 | inst.id as instance_id | |
6a488035 | 55 | FROM civicrm_option_value v |
2f4c2f5d | 56 | INNER JOIN civicrm_option_group g |
6a488035 | 57 | ON (v.option_group_id = g.id AND g.name = 'report_template') |
2f4c2f5d | 58 | LEFT JOIN civicrm_report_instance inst |
6a488035 | 59 | ON v.value = inst.report_id |
2f4c2f5d | 60 | LEFT JOIN civicrm_component comp |
6a488035 TO |
61 | ON v.component_id = comp.id |
62 | "; | |
63 | ||
64 | if (!$all) { | |
65 | $sql .= " WHERE v.is_active = 1 {$compClause}"; | |
66 | } | |
67 | $sql .= " ORDER BY v.weight "; | |
68 | ||
353ffa53 | 69 | $dao = CRM_Core_DAO::executeQuery($sql); |
be2fb01f | 70 | $rows = []; |
6a488035 | 71 | while ($dao->fetch()) { |
2066e389 | 72 | if ($dao->component_name != 'Contact' && $dao->component_name != $dao->grouping && |
e46f73c7 | 73 | !CRM_Core_Component::isEnabled("Civi{$dao->component_name}") |
6a488035 TO |
74 | ) { |
75 | continue; | |
76 | } | |
bc3364a9 ML |
77 | $rows[$dao->component_name][$dao->value]['title'] = ts($dao->label); |
78 | $rows[$dao->component_name][$dao->value]['description'] = ts($dao->description); | |
6a488035 | 79 | $rows[$dao->component_name][$dao->value]['url'] = CRM_Utils_System::url('civicrm/report/' . trim($dao->value, '/'), 'reset=1'); |
62ec4c67 EM |
80 | $rows[$dao->component_name][$dao->value]['instanceUrl'] = $dao->instance_id ? CRM_Utils_System::url( |
81 | 'civicrm/report/list', | |
82 | "reset=1&ovid=$dao->id" | |
83 | ) : ''; | |
6a488035 TO |
84 | } |
85 | ||
86 | return $rows; | |
87 | } | |
88 | ||
89 | /** | |
100fef9d | 90 | * Run this page (figure out the action needed and perform it). |
6a488035 | 91 | */ |
00be9182 | 92 | public function run() { |
6a488035 | 93 | $compID = CRM_Utils_Request::retrieve('compid', 'Positive', $this); |
2066e389 | 94 | $grouping = CRM_Utils_Request::retrieve('grp', 'String', $this); |
95 | $rows = self::info($compID, $grouping); | |
6a488035 TO |
96 | $this->assign('list', $rows); |
97 | ||
98 | return parent::run(); | |
99 | } | |
96025800 | 100 | |
6a488035 | 101 | } |