Commit | Line | Data |
---|---|---|
7f254ad8 AE |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.6 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright CiviCRM LLC (c) 2004-2015 | | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
31 | * @copyright CiviCRM LLC (c) 2004-2015 | |
32 | * $Id$ | |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * Page for displaying list of Reprot templates available | |
38 | */ | |
39 | class CRM_Report_Page_TemplateList extends CRM_Core_Page { | |
40 | ||
41 | /** | |
42 | * @param int $compID | |
43 | * @param null $grouping | |
44 | * | |
45 | * @return array | |
46 | */ | |
47 | public static function &info($compID = NULL, $grouping = NULL) { | |
48 | $all = CRM_Utils_Request::retrieve('all', 'Boolean', CRM_Core_DAO::$_nullObject, | |
49 | FALSE, NULL, 'GET' | |
50 | ); | |
51 | ||
52 | $compClause = ''; | |
53 | if ($compID) { | |
54 | if ($compID == 99) { | |
55 | $compClause = " AND v.component_id IS NULL "; | |
56 | } | |
57 | else { | |
58 | $compClause = " AND v.component_id = {$compID} "; | |
59 | } | |
60 | } | |
61 | elseif ($grouping) { | |
62 | $compClause = " AND v.grouping = '{$grouping}' "; | |
63 | } | |
64 | $sql = " | |
65 | SELECT v.id, v.value, v.label, v.description, v.component_id, | |
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 | |
73 | FROM civicrm_option_value v | |
74 | INNER JOIN civicrm_option_group g | |
75 | ON (v.option_group_id = g.id AND g.name = 'report_template') | |
76 | LEFT JOIN civicrm_report_instance inst | |
77 | ON v.value = inst.report_id | |
78 | LEFT JOIN civicrm_component comp | |
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()) { | |
91 | if ($dao->component_name != 'Contact' && $dao->component_name != $dao->grouping && | |
92 | !in_array("Civi{$dao->component_name}", $config->enableComponents) | |
93 | ) { | |
94 | continue; | |
95 | } | |
96 | $rows[$dao->component_name][$dao->value]['title'] = ts($dao->label); | |
97 | $rows[$dao->component_name][$dao->value]['description'] = ts($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 | public function run() { | |
115 | $compID = CRM_Utils_Request::retrieve('compid', 'Positive', $this); | |
116 | $grouping = CRM_Utils_Request::retrieve('grp', 'String', $this); | |
117 | $rows = self::info($compID, $grouping); | |
118 | $this->assign('list', $rows); | |
119 | ||
120 | return parent::run(); | |
121 | } | |
122 | ||
123 | } |