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