Merge pull request #16264 from MegaphoneJon/soft-credit-hooks
[civicrm-core.git] / CRM / Report / Page / TemplateList.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * Page for displaying list of Report templates available.
20 */
21 class CRM_Report_Page_TemplateList extends CRM_Core_Page {
22
23 /**
24 * @param int $compID
25 * @param null $grouping
26 *
27 * @return array
28 */
29 public static function &info($compID = NULL, $grouping = NULL) {
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) {
37 $compClause = " AND v.component_id IS NULL ";
38 }
39 else {
40 $compClause = " AND v.component_id = {$compID} ";
41 }
42 }
43 elseif ($grouping) {
44 $compClause = " AND v.grouping = '{$grouping}' ";
45 }
46 $sql = "
47 SELECT v.id, v.value, v.label, v.description, v.component_id,
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
55 FROM civicrm_option_value v
56 INNER JOIN civicrm_option_group g
57 ON (v.option_group_id = g.id AND g.name = 'report_template')
58 LEFT JOIN civicrm_report_instance inst
59 ON v.value = inst.report_id
60 LEFT JOIN civicrm_component comp
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
69 $dao = CRM_Core_DAO::executeQuery($sql);
70 $rows = [];
71 $config = CRM_Core_Config::singleton();
72 while ($dao->fetch()) {
73 if ($dao->component_name != 'Contact' && $dao->component_name != $dao->grouping &&
74 !in_array("Civi{$dao->component_name}", $config->enableComponents)
75 ) {
76 continue;
77 }
78 $rows[$dao->component_name][$dao->value]['title'] = ts($dao->label);
79 $rows[$dao->component_name][$dao->value]['description'] = ts($dao->description);
80 $rows[$dao->component_name][$dao->value]['url'] = CRM_Utils_System::url('civicrm/report/' . trim($dao->value, '/'), 'reset=1');
81 if ($dao->instance_id) {
82 $rows[$dao->component_name][$dao->value]['instanceUrl'] = CRM_Utils_System::url('civicrm/report/list',
83 "reset=1&ovid={$dao->id}"
84 );
85 }
86 }
87
88 return $rows;
89 }
90
91 /**
92 * Run this page (figure out the action needed and perform it).
93 */
94 public function run() {
95 $compID = CRM_Utils_Request::retrieve('compid', 'Positive', $this);
96 $grouping = CRM_Utils_Request::retrieve('grp', 'String', $this);
97 $rows = self::info($compID, $grouping);
98 $this->assign('list', $rows);
99
100 return parent::run();
101 }
102
103 }