Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06b69b18 | 4 | | CiviCRM version 4.5 | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
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 | /** | |
39 | * | |
40 | */ | |
41 | CONST REPORT_GROUP_NAME = 'report_template'; | |
42 | ||
43 | public function __construct() { | |
44 | parent::__construct(TRUE); | |
45 | $this->groupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', | |
46 | self::REPORT_GROUP_NAME, 'id', 'name' | |
47 | ); | |
48 | } | |
49 | ||
50 | public function onPreInstall(CRM_Extension_Info $info) { | |
51 | $customReports = $this->getCustomReportsByName(); | |
52 | if (array_key_exists($info->key, $customReports)) { | |
53 | CRM_Core_Error::fatal('This report is already registered.'); | |
54 | } | |
55 | ||
56 | if ($info->typeInfo['component'] === 'Contact') { | |
57 | $compId = 'null'; | |
58 | } | |
59 | else { | |
60 | $comp = CRM_Core_Component::get($info->typeInfo['component']); | |
61 | $compId = $comp->componentID; | |
62 | } | |
63 | if (empty($compId)) { | |
64 | CRM_Core_Error::fatal("Component for which you're trying to install the extension (" . $info->typeInfo['component'] . ") is currently disabled."); | |
65 | } | |
66 | $weight = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', | |
67 | array('option_group_id' => $this->groupId) | |
68 | ); | |
69 | $ids = array(); | |
70 | $params = array( | |
71 | 'label' => $info->label . ' (' . $info->key . ')', | |
72 | 'value' => $info->typeInfo['reportUrl'], | |
73 | 'name' => $info->key, | |
74 | 'weight' => $weight, | |
75 | 'description' => $info->label . ' (' . $info->key . ')', | |
76 | 'component_id' => $compId, | |
77 | 'option_group_id' => $this->groupId, | |
78 | 'is_active' => 1, | |
79 | ); | |
80 | ||
81 | $optionValue = CRM_Core_BAO_OptionValue::add($params, $ids); | |
82 | } | |
83 | ||
84 | public function onPreUninstall(CRM_Extension_Info $info) { | |
85 | ||
86 | // if( !array_key_exists( $info->key, $this->customReports ) ) { | |
87 | // CRM_Core_Error::fatal( 'This report is not registered.' ); | |
88 | // } | |
89 | ||
90 | $customReports = $this->getCustomReportsByName(); | |
91 | $cr = $this->getCustomReportsById(); | |
92 | $id = $cr[$customReports[$info->key]]; | |
93 | $optionValue = CRM_Core_BAO_OptionValue::del($id); | |
94 | ||
95 | return $optionValue ? TRUE : FALSE; | |
96 | } | |
97 | ||
98 | public function onPreDisable(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, 0); | |
103 | } | |
104 | ||
105 | public function onPreEnable(CRM_Extension_Info $info) { | |
106 | $customReports = $this->getCustomReportsByName(); | |
107 | $cr = $this->getCustomReportsById(); | |
108 | $id = $cr[$customReports[$info->key]]; | |
109 | $optionValue = CRM_Core_BAO_OptionValue::setIsActive($id, 1); | |
110 | } | |
111 | ||
112 | public function getCustomReportsByName() { | |
113 | return CRM_Core_OptionGroup::values(self::REPORT_GROUP_NAME, TRUE, FALSE, FALSE, NULL, 'name', FALSE, TRUE); | |
114 | } | |
115 | ||
116 | public function getCustomReportsById() { | |
117 | return CRM_Core_OptionGroup::values(self::REPORT_GROUP_NAME, FALSE, FALSE, FALSE, NULL, 'id', FALSE, TRUE); | |
118 | } | |
119 | } |