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_Search
extends CRM_Extension_Manager_Base
{
20 const CUSTOM_SEARCH_GROUP_NAME
= 'custom_search';
23 * CRM_Extension_Manager_Search constructor.
25 public function __construct() {
26 parent
::__construct(TRUE);
27 $this->groupId
= CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_OptionGroup',
28 self
::CUSTOM_SEARCH_GROUP_NAME
, 'id', 'name'
33 * @param CRM_Extension_Info $info
36 * @throws CRM_Core_Exception
38 public function onPreInstall(CRM_Extension_Info
$info) {
39 $customSearchesByName = $this->getCustomSearchesByName();
40 if (array_key_exists($info->key
, $customSearchesByName)) {
41 throw new CRM_Core_Exception(ts('This custom search is already registered.'));
44 $weight = CRM_Utils_Weight
::getDefaultWeight('CRM_Core_DAO_OptionValue',
45 ['option_group_id' => $this->groupId
]
49 'option_group_id' => $this->groupId
,
51 'description' => $info->label
. ' (' . $info->key
. ')',
53 'value' => max($customSearchesByName) +
1,
54 'label' => $info->key
,
59 $optionValue = CRM_Core_BAO_OptionValue
::add($params, $ids);
61 return $optionValue ?
TRUE : FALSE;
65 * @param CRM_Extension_Info $info
70 public function onPreUninstall(CRM_Extension_Info
$info) {
71 $customSearchesByName = $this->getCustomSearchesByName();
72 if (!array_key_exists($info->key
, $customSearchesByName)) {
73 CRM_Core_Error
::fatal('This custom search is not registered.');
76 $cs = $this->getCustomSearchesById();
77 $id = $cs[$customSearchesByName[$info->key
]];
78 $optionValue = CRM_Core_BAO_OptionValue
::del($id);
84 * @param CRM_Extension_Info $info
86 public function onPreDisable(CRM_Extension_Info
$info) {
87 $customSearchesByName = $this->getCustomSearchesByName();
88 $cs = $this->getCustomSearchesById();
89 $id = $cs[$customSearchesByName[$info->key
]];
90 $optionValue = CRM_Core_BAO_OptionValue
::setIsActive($id, 0);
94 * @param CRM_Extension_Info $info
96 public function onPreEnable(CRM_Extension_Info
$info) {
97 $customSearchesByName = $this->getCustomSearchesByName();
98 $cs = $this->getCustomSearchesById();
99 $id = $cs[$customSearchesByName[$info->key
]];
100 $optionValue = CRM_Core_BAO_OptionValue
::setIsActive($id, 1);
106 protected function getCustomSearchesByName() {
107 return CRM_Core_OptionGroup
::values(self
::CUSTOM_SEARCH_GROUP_NAME
, TRUE, FALSE, FALSE, NULL, 'name', FALSE, TRUE);
113 protected function getCustomSearchesById() {
114 return CRM_Core_OptionGroup
::values(self
::CUSTOM_SEARCH_GROUP_NAME
, FALSE, FALSE, FALSE, NULL, 'id', FALSE, TRUE);