Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
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_Search extends CRM_Extension_Manager_Base { | |
37 | ||
38 | /** | |
6a488035 | 39 | */ |
7da04cde | 40 | const CUSTOM_SEARCH_GROUP_NAME = 'custom_search'; |
6a488035 | 41 | |
e0ef6999 | 42 | /** |
e0ef6999 | 43 | */ |
6a488035 TO |
44 | public function __construct() { |
45 | parent::__construct(TRUE); | |
46 | $this->groupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', | |
47 | self::CUSTOM_SEARCH_GROUP_NAME, 'id', 'name' | |
48 | ); | |
49 | } | |
50 | ||
e0ef6999 EM |
51 | /** |
52 | * @param CRM_Extension_Info $info | |
53 | * | |
54 | * @return bool | |
55 | * @throws Exception | |
56 | */ | |
6a488035 TO |
57 | public function onPreInstall(CRM_Extension_Info $info) { |
58 | $customSearchesByName = $this->getCustomSearchesByName(); | |
59 | if (array_key_exists($info->key, $customSearchesByName)) { | |
60 | CRM_Core_Error::fatal('This custom search is already registered.'); | |
61 | } | |
62 | ||
63 | $weight = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', | |
64 | array('option_group_id' => $this->groupId) | |
65 | ); | |
66 | ||
67 | $params = array( | |
68 | 'option_group_id' => $this->groupId, | |
69 | 'weight' => $weight, | |
70 | 'description' => $info->label . ' (' . $info->key . ')', | |
71 | 'name' => $info->key, | |
72 | 'value' => max($customSearchesByName) + 1, | |
73 | 'label' => $info->key, | |
74 | 'is_active' => 1, | |
75 | ); | |
76 | ||
77 | $ids = array(); | |
78 | $optionValue = CRM_Core_BAO_OptionValue::add($params, $ids); | |
79 | ||
80 | return $optionValue ? TRUE : FALSE; | |
81 | } | |
82 | ||
e0ef6999 EM |
83 | /** |
84 | * @param CRM_Extension_Info $info | |
85 | * | |
86 | * @return bool | |
87 | * @throws Exception | |
88 | */ | |
6a488035 TO |
89 | public function onPreUninstall(CRM_Extension_Info $info) { |
90 | $customSearchesByName = $this->getCustomSearchesByName(); | |
91 | if (!array_key_exists($info->key, $customSearchesByName)) { | |
92 | CRM_Core_Error::fatal('This custom search is not registered.'); | |
93 | } | |
94 | ||
353ffa53 TO |
95 | $cs = $this->getCustomSearchesById(); |
96 | $id = $cs[$customSearchesByName[$info->key]]; | |
6a488035 TO |
97 | $optionValue = CRM_Core_BAO_OptionValue::del($id); |
98 | ||
99 | return TRUE; | |
100 | } | |
101 | ||
e0ef6999 EM |
102 | /** |
103 | * @param CRM_Extension_Info $info | |
104 | */ | |
6a488035 TO |
105 | public function onPreDisable(CRM_Extension_Info $info) { |
106 | $customSearchesByName = $this->getCustomSearchesByName(); | |
353ffa53 TO |
107 | $cs = $this->getCustomSearchesById(); |
108 | $id = $cs[$customSearchesByName[$info->key]]; | |
6a488035 TO |
109 | $optionValue = CRM_Core_BAO_OptionValue::setIsActive($id, 0); |
110 | } | |
111 | ||
e0ef6999 EM |
112 | /** |
113 | * @param CRM_Extension_Info $info | |
114 | */ | |
6a488035 TO |
115 | public function onPreEnable(CRM_Extension_Info $info) { |
116 | $customSearchesByName = $this->getCustomSearchesByName(); | |
353ffa53 TO |
117 | $cs = $this->getCustomSearchesById(); |
118 | $id = $cs[$customSearchesByName[$info->key]]; | |
6a488035 TO |
119 | $optionValue = CRM_Core_BAO_OptionValue::setIsActive($id, 1); |
120 | } | |
121 | ||
e0ef6999 EM |
122 | /** |
123 | * @return array | |
124 | */ | |
6a488035 TO |
125 | protected function getCustomSearchesByName() { |
126 | return CRM_Core_OptionGroup::values(self::CUSTOM_SEARCH_GROUP_NAME, TRUE, FALSE, FALSE, NULL, 'name', FALSE, TRUE); | |
127 | } | |
128 | ||
e0ef6999 EM |
129 | /** |
130 | * @return array | |
131 | */ | |
6a488035 TO |
132 | protected function getCustomSearchesById() { |
133 | return CRM_Core_OptionGroup::values(self::CUSTOM_SEARCH_GROUP_NAME, FALSE, FALSE, FALSE, NULL, 'id', FALSE, TRUE); | |
134 | } | |
135 | } |