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