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);
27 $this->groupId
= CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_OptionGroup',
28 self
::REPORT_GROUP_NAME
, 'id', 'name'
33 * @param CRM_Extension_Info $info
35 * @throws CRM_Core_Exception
37 public function onPreInstall(CRM_Extension_Info
$info) {
38 $customReports = $this->getCustomReportsByName();
39 if (array_key_exists($info->key
, $customReports)) {
40 throw new CRM_Core_Exception(ts('This report is already registered.'));
43 if ($info->typeInfo
['component'] === 'Contact') {
47 $comp = CRM_Core_Component
::get($info->typeInfo
['component']);
48 $compId = $comp->componentID
;
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']]));
53 $weight = CRM_Utils_Weight
::getDefaultWeight('CRM_Core_DAO_OptionValue',
54 ['option_group_id' => $this->groupId
]
58 'label' => $info->label
. ' (' . $info->key
. ')',
59 'value' => $info->typeInfo
['reportUrl'],
62 'description' => $info->label
. ' (' . $info->key
. ')',
63 'component_id' => $compId,
64 'option_group_id' => $this->groupId
,
68 $optionValue = CRM_Core_BAO_OptionValue
::add($params, $ids);
72 * @param CRM_Extension_Info $info
76 public function onPreUninstall(CRM_Extension_Info
$info) {
77 $customReports = $this->getCustomReportsByName();
78 $cr = $this->getCustomReportsById();
79 $id = $cr[$customReports[$info->key
]];
80 $optionValue = CRM_Core_BAO_OptionValue
::del($id);
82 return $optionValue ?
TRUE : FALSE;
86 * @param CRM_Extension_Info $info
88 public function onPreDisable(CRM_Extension_Info
$info) {
89 $customReports = $this->getCustomReportsByName();
90 $cr = $this->getCustomReportsById();
91 $id = $cr[$customReports[$info->key
]];
92 $optionValue = CRM_Core_BAO_OptionValue
::setIsActive($id, 0);
96 * @param CRM_Extension_Info $info
98 public function onPreEnable(CRM_Extension_Info
$info) {
99 $customReports = $this->getCustomReportsByName();
100 $cr = $this->getCustomReportsById();
101 $id = $cr[$customReports[$info->key
]];
102 $optionValue = CRM_Core_BAO_OptionValue
::setIsActive($id, 1);
108 public function getCustomReportsByName() {
109 return CRM_Core_OptionGroup
::values(self
::REPORT_GROUP_NAME
, TRUE, FALSE, FALSE, NULL, 'name', FALSE, TRUE);
115 public function getCustomReportsById() {
116 return CRM_Core_OptionGroup
::values(self
::REPORT_GROUP_NAME
, FALSE, FALSE, FALSE, NULL, 'id', FALSE, TRUE);