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