CRM-12490 - order-by fatal error fix
[civicrm-core.git] / CRM / Report / Page / TemplateList.php
CommitLineData
6a488035 1<?php
6a488035
TO
2
3/*
4 +--------------------------------------------------------------------+
232624b1 5 | CiviCRM version 4.4 |
6a488035
TO
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 */
40class CRM_Report_Page_TemplateList extends CRM_Core_Page {
41
42 public static function &info($compID = 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) {
2f4c2f5d 50 $compClause = " AND v.component_id IS NULL ";
6a488035 51 } else {
2f4c2f5d 52 $compClause = " AND v.component_id = {$compID} ";
6a488035
TO
53 }
54 }
55
56 $sql = "
2f4c2f5d 57SELECT v.id, v.value, v.label, v.description, v.component_id,
58 inst.id as instance_id, ifnull( SUBSTRING(comp.name, 5), 'Contact' ) as component_name
6a488035 59FROM civicrm_option_value v
2f4c2f5d 60INNER JOIN civicrm_option_group g
6a488035 61 ON (v.option_group_id = g.id AND g.name = 'report_template')
2f4c2f5d 62LEFT JOIN civicrm_report_instance inst
6a488035 63 ON v.value = inst.report_id
2f4c2f5d 64LEFT JOIN civicrm_component comp
6a488035
TO
65 ON v.component_id = comp.id
66";
67
68 if (!$all) {
69 $sql .= " WHERE v.is_active = 1 {$compClause}";
70 }
71 $sql .= " ORDER BY v.weight ";
72
73 $dao = CRM_Core_DAO::executeQuery($sql);
74 $rows = array();
75 $config = CRM_Core_Config::singleton();
76 while ($dao->fetch()) {
77 if ($dao->component_name != 'Contact' &&
78 !in_array("Civi{$dao->component_name}", $config->enableComponents)
79 ) {
80 continue;
81 }
82 $rows[$dao->component_name][$dao->value]['title'] = $dao->label;
83 $rows[$dao->component_name][$dao->value]['description'] = $dao->description;
84 $rows[$dao->component_name][$dao->value]['url'] = CRM_Utils_System::url('civicrm/report/' . trim($dao->value, '/'), 'reset=1');
85 if ($dao->instance_id) {
86 $rows[$dao->component_name][$dao->value]['instanceUrl'] = CRM_Utils_System::url('civicrm/report/list',
87 "reset=1&ovid={$dao->id}"
88 );
89 }
90 }
91
92 return $rows;
93 }
94
95 /**
96 * run this page (figure out the action needed and perform it).
97 *
98 * @return void
99 */
100 function run() {
101 $compID = CRM_Utils_Request::retrieve('compid', 'Positive', $this);
102 $rows = self::info($compID);
103 $this->assign('list', $rows);
104
105 return parent::run();
106 }
107}
108