3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 |
9 +--------------------------------------------------------------------+
13 * This class stores logic for managing CiviCRM extensions.
16 * @copyright CiviCRM LLC https://civicrm.org/licensing
18 class CRM_Extension_Manager_Report
extends CRM_Extension_Manager_Base
{
20 const REPORT_GROUP_NAME
= 'report_template';
23 * CRM_Extension_Manager_Report constructor.
25 public function __construct() {
26 parent
::__construct(TRUE);
29 public function getGroupId() {
30 return CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_OptionGroup',
31 self
::REPORT_GROUP_NAME
, 'id', 'name'
36 * @param CRM_Extension_Info $info
38 * @throws CRM_Core_Exception
40 public function onPreInstall(CRM_Extension_Info
$info) {
41 $customReports = $this->getCustomReportsByName();
42 if (array_key_exists($info->key
, $customReports)) {
43 throw new CRM_Core_Exception(ts('This report is already registered.'));
46 if ($info->typeInfo
['component'] === 'Contact') {
50 $comp = CRM_Core_Component
::get($info->typeInfo
['component']);
51 $compId = $comp->componentID
;
54 throw new CRM_Core_Exception(ts('Component for which you are trying to install the extension (%1) is currently disabled.', [1 => $info->typeInfo
['component']]));
56 $weight = CRM_Utils_Weight
::getDefaultWeight('CRM_Core_DAO_OptionValue',
57 ['option_group_id' => $this->getGroupId()]
60 'label' => $info->label
. ' (' . $info->key
. ')',
61 'value' => $info->typeInfo
['reportUrl'],
64 'description' => $info->label
. ' (' . $info->key
. ')',
65 'component_id' => $compId,
66 'option_group_id' => $this->getGroupId(),
70 $optionValue = CRM_Core_BAO_OptionValue
::add($params);
74 * @param CRM_Extension_Info $info
78 public function onPreUninstall(CRM_Extension_Info
$info) {
79 $customReports = $this->getCustomReportsByName();
80 $cr = $this->getCustomReportsById();
81 $id = $cr[$customReports[$info->key
]];
82 $optionValue = CRM_Core_BAO_OptionValue
::del($id);
84 return $optionValue ?
TRUE : FALSE;
88 * @param CRM_Extension_Info $info
90 public function onPreDisable(CRM_Extension_Info
$info) {
91 $customReports = $this->getCustomReportsByName();
92 $cr = $this->getCustomReportsById();
93 $id = $cr[$customReports[$info->key
]];
94 $optionValue = CRM_Core_BAO_OptionValue
::setIsActive($id, 0);
98 * @param CRM_Extension_Info $info
100 public function onPreEnable(CRM_Extension_Info
$info) {
101 $customReports = $this->getCustomReportsByName();
102 $cr = $this->getCustomReportsById();
103 $id = $cr[$customReports[$info->key
]];
104 $optionValue = CRM_Core_BAO_OptionValue
::setIsActive($id, 1);
110 public function getCustomReportsByName() {
111 return CRM_Core_OptionGroup
::values(self
::REPORT_GROUP_NAME
, TRUE, FALSE, FALSE, NULL, 'name', FALSE, TRUE);
117 public function getCustomReportsById() {
118 return CRM_Core_OptionGroup
::values(self
::REPORT_GROUP_NAME
, FALSE, FALSE, FALSE, NULL, 'id', FALSE, TRUE);