Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * This class stores logic for managing CiviCRM extensions. | |
14 | * | |
15 | * @package CRM | |
ca5cec67 | 16 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
17 | */ |
18 | class CRM_Extension_Manager_Report extends CRM_Extension_Manager_Base { | |
19 | ||
7da04cde | 20 | const REPORT_GROUP_NAME = 'report_template'; |
6a488035 | 21 | |
8246bca4 | 22 | /** |
23 | * CRM_Extension_Manager_Report constructor. | |
24 | */ | |
6a488035 TO |
25 | public function __construct() { |
26 | parent::__construct(TRUE); | |
27 | $this->groupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', | |
28 | self::REPORT_GROUP_NAME, 'id', 'name' | |
29 | ); | |
30 | } | |
31 | ||
e0ef6999 EM |
32 | /** |
33 | * @param CRM_Extension_Info $info | |
34 | * | |
df9f2d1a | 35 | * @throws CRM_Core_Exception |
e0ef6999 | 36 | */ |
6a488035 TO |
37 | public function onPreInstall(CRM_Extension_Info $info) { |
38 | $customReports = $this->getCustomReportsByName(); | |
39 | if (array_key_exists($info->key, $customReports)) { | |
df9f2d1a | 40 | throw new CRM_Core_Exception(ts('This report is already registered.')); |
6a488035 TO |
41 | } |
42 | ||
43 | if ($info->typeInfo['component'] === 'Contact') { | |
44 | $compId = 'null'; | |
45 | } | |
46 | else { | |
47 | $comp = CRM_Core_Component::get($info->typeInfo['component']); | |
48 | $compId = $comp->componentID; | |
49 | } | |
50 | if (empty($compId)) { | |
df9f2d1a | 51 | throw new CRM_Core_Exception(ts('Component for which you are trying to install the extension (%1) is currently disabled.', [1 => $info->typeInfo['component']])); |
6a488035 TO |
52 | } |
53 | $weight = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', | |
be2fb01f | 54 | ['option_group_id' => $this->groupId] |
6a488035 | 55 | ); |
be2fb01f CW |
56 | $ids = []; |
57 | $params = [ | |
6a488035 TO |
58 | 'label' => $info->label . ' (' . $info->key . ')', |
59 | 'value' => $info->typeInfo['reportUrl'], | |
60 | 'name' => $info->key, | |
61 | 'weight' => $weight, | |
62 | 'description' => $info->label . ' (' . $info->key . ')', | |
63 | 'component_id' => $compId, | |
64 | 'option_group_id' => $this->groupId, | |
65 | 'is_active' => 1, | |
be2fb01f | 66 | ]; |
6a488035 TO |
67 | |
68 | $optionValue = CRM_Core_BAO_OptionValue::add($params, $ids); | |
69 | } | |
70 | ||
e0ef6999 EM |
71 | /** |
72 | * @param CRM_Extension_Info $info | |
73 | * | |
74 | * @return bool | |
75 | */ | |
6a488035 | 76 | public function onPreUninstall(CRM_Extension_Info $info) { |
6a488035 | 77 | $customReports = $this->getCustomReportsByName(); |
353ffa53 TO |
78 | $cr = $this->getCustomReportsById(); |
79 | $id = $cr[$customReports[$info->key]]; | |
6a488035 TO |
80 | $optionValue = CRM_Core_BAO_OptionValue::del($id); |
81 | ||
82 | return $optionValue ? TRUE : FALSE; | |
83 | } | |
84 | ||
e0ef6999 EM |
85 | /** |
86 | * @param CRM_Extension_Info $info | |
87 | */ | |
6a488035 TO |
88 | public function onPreDisable(CRM_Extension_Info $info) { |
89 | $customReports = $this->getCustomReportsByName(); | |
353ffa53 TO |
90 | $cr = $this->getCustomReportsById(); |
91 | $id = $cr[$customReports[$info->key]]; | |
6a488035 TO |
92 | $optionValue = CRM_Core_BAO_OptionValue::setIsActive($id, 0); |
93 | } | |
94 | ||
e0ef6999 EM |
95 | /** |
96 | * @param CRM_Extension_Info $info | |
97 | */ | |
6a488035 TO |
98 | public function onPreEnable(CRM_Extension_Info $info) { |
99 | $customReports = $this->getCustomReportsByName(); | |
353ffa53 TO |
100 | $cr = $this->getCustomReportsById(); |
101 | $id = $cr[$customReports[$info->key]]; | |
6a488035 TO |
102 | $optionValue = CRM_Core_BAO_OptionValue::setIsActive($id, 1); |
103 | } | |
104 | ||
e0ef6999 EM |
105 | /** |
106 | * @return array | |
107 | */ | |
6a488035 TO |
108 | public function getCustomReportsByName() { |
109 | return CRM_Core_OptionGroup::values(self::REPORT_GROUP_NAME, TRUE, FALSE, FALSE, NULL, 'name', FALSE, TRUE); | |
110 | } | |
111 | ||
e0ef6999 EM |
112 | /** |
113 | * @return array | |
114 | */ | |
6a488035 TO |
115 | public function getCustomReportsById() { |
116 | return CRM_Core_OptionGroup::values(self::REPORT_GROUP_NAME, FALSE, FALSE, FALSE, NULL, 'id', FALSE, TRUE); | |
117 | } | |
96025800 | 118 | |
6a488035 | 119 | } |