Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * This class stores logic for managing CiviCRM extensions. | |
30 | * | |
31 | * @package CRM | |
06b69b18 | 32 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
33 | * $Id$ |
34 | * | |
35 | */ | |
36 | class CRM_Extension_Manager_Report extends CRM_Extension_Manager_Base { | |
37 | ||
38 | /** | |
6a488035 | 39 | */ |
7da04cde | 40 | const REPORT_GROUP_NAME = 'report_template'; |
6a488035 | 41 | |
e0ef6999 | 42 | /** |
e0ef6999 | 43 | */ |
6a488035 TO |
44 | public function __construct() { |
45 | parent::__construct(TRUE); | |
46 | $this->groupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', | |
47 | self::REPORT_GROUP_NAME, 'id', 'name' | |
48 | ); | |
49 | } | |
50 | ||
e0ef6999 EM |
51 | /** |
52 | * @param CRM_Extension_Info $info | |
53 | * | |
54 | * @throws Exception | |
55 | */ | |
6a488035 TO |
56 | public function onPreInstall(CRM_Extension_Info $info) { |
57 | $customReports = $this->getCustomReportsByName(); | |
58 | if (array_key_exists($info->key, $customReports)) { | |
59 | CRM_Core_Error::fatal('This report is already registered.'); | |
60 | } | |
61 | ||
62 | if ($info->typeInfo['component'] === 'Contact') { | |
63 | $compId = 'null'; | |
64 | } | |
65 | else { | |
66 | $comp = CRM_Core_Component::get($info->typeInfo['component']); | |
67 | $compId = $comp->componentID; | |
68 | } | |
69 | if (empty($compId)) { | |
70 | CRM_Core_Error::fatal("Component for which you're trying to install the extension (" . $info->typeInfo['component'] . ") is currently disabled."); | |
71 | } | |
72 | $weight = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', | |
73 | array('option_group_id' => $this->groupId) | |
74 | ); | |
75 | $ids = array(); | |
76 | $params = array( | |
77 | 'label' => $info->label . ' (' . $info->key . ')', | |
78 | 'value' => $info->typeInfo['reportUrl'], | |
79 | 'name' => $info->key, | |
80 | 'weight' => $weight, | |
81 | 'description' => $info->label . ' (' . $info->key . ')', | |
82 | 'component_id' => $compId, | |
83 | 'option_group_id' => $this->groupId, | |
84 | 'is_active' => 1, | |
85 | ); | |
86 | ||
87 | $optionValue = CRM_Core_BAO_OptionValue::add($params, $ids); | |
88 | } | |
89 | ||
e0ef6999 EM |
90 | /** |
91 | * @param CRM_Extension_Info $info | |
92 | * | |
93 | * @return bool | |
94 | */ | |
6a488035 TO |
95 | public function onPreUninstall(CRM_Extension_Info $info) { |
96 | ||
97 | // if( !array_key_exists( $info->key, $this->customReports ) ) { | |
98 | // CRM_Core_Error::fatal( 'This report is not registered.' ); | |
99 | // } | |
100 | ||
101 | $customReports = $this->getCustomReportsByName(); | |
353ffa53 TO |
102 | $cr = $this->getCustomReportsById(); |
103 | $id = $cr[$customReports[$info->key]]; | |
6a488035 TO |
104 | $optionValue = CRM_Core_BAO_OptionValue::del($id); |
105 | ||
106 | return $optionValue ? TRUE : FALSE; | |
107 | } | |
108 | ||
e0ef6999 EM |
109 | /** |
110 | * @param CRM_Extension_Info $info | |
111 | */ | |
6a488035 TO |
112 | public function onPreDisable(CRM_Extension_Info $info) { |
113 | $customReports = $this->getCustomReportsByName(); | |
353ffa53 TO |
114 | $cr = $this->getCustomReportsById(); |
115 | $id = $cr[$customReports[$info->key]]; | |
6a488035 TO |
116 | $optionValue = CRM_Core_BAO_OptionValue::setIsActive($id, 0); |
117 | } | |
118 | ||
e0ef6999 EM |
119 | /** |
120 | * @param CRM_Extension_Info $info | |
121 | */ | |
6a488035 TO |
122 | public function onPreEnable(CRM_Extension_Info $info) { |
123 | $customReports = $this->getCustomReportsByName(); | |
353ffa53 TO |
124 | $cr = $this->getCustomReportsById(); |
125 | $id = $cr[$customReports[$info->key]]; | |
6a488035 TO |
126 | $optionValue = CRM_Core_BAO_OptionValue::setIsActive($id, 1); |
127 | } | |
128 | ||
e0ef6999 EM |
129 | /** |
130 | * @return array | |
131 | */ | |
6a488035 TO |
132 | public function getCustomReportsByName() { |
133 | return CRM_Core_OptionGroup::values(self::REPORT_GROUP_NAME, TRUE, FALSE, FALSE, NULL, 'name', FALSE, TRUE); | |
134 | } | |
135 | ||
e0ef6999 EM |
136 | /** |
137 | * @return array | |
138 | */ | |
6a488035 TO |
139 | public function getCustomReportsById() { |
140 | return CRM_Core_OptionGroup::values(self::REPORT_GROUP_NAME, FALSE, FALSE, FALSE, NULL, 'id', FALSE, TRUE); | |
141 | } | |
96025800 | 142 | |
6a488035 | 143 | } |