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);
29 public function getGroupId() {
30 return CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_OptionGroup',
31 self
::CUSTOM_SEARCH_GROUP_NAME
, 'id', 'name'
36 * @param CRM_Extension_Info $info
39 * @throws CRM_Core_Exception
41 public function onPreInstall(CRM_Extension_Info
$info) {
42 $customSearchesByName = $this->getCustomSearchesByName();
43 if (array_key_exists($info->key
, $customSearchesByName)) {
44 throw new CRM_Core_Exception(ts('This custom search is already registered.'));
47 $weight = CRM_Utils_Weight
::getDefaultWeight('CRM_Core_DAO_OptionValue',
48 ['option_group_id' => $this->getGroupId()]
52 'option_group_id' => $this->getGroupId(),
54 'description' => $info->label
. ' (' . $info->key
. ')',
56 'value' => max($customSearchesByName) +
1,
57 'label' => $info->key
,
61 $optionValue = CRM_Core_BAO_OptionValue
::add($params);
63 return $optionValue ?
TRUE : FALSE;
67 * @param CRM_Extension_Info $info
72 public function onPreUninstall(CRM_Extension_Info
$info) {
73 $customSearchesByName = $this->getCustomSearchesByName();
74 if (!array_key_exists($info->key
, $customSearchesByName)) {
75 throw new CRM_Core_Exception('This custom search is not registered.');
78 $cs = $this->getCustomSearchesById();
79 $id = $cs[$customSearchesByName[$info->key
]];
80 CRM_Core_BAO_OptionValue
::del($id);
86 * @param CRM_Extension_Info $info
88 public function onPreDisable(CRM_Extension_Info
$info) {
89 $customSearchesByName = $this->getCustomSearchesByName();
90 $cs = $this->getCustomSearchesById();
91 $id = $cs[$customSearchesByName[$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 $customSearchesByName = $this->getCustomSearchesByName();
100 $cs = $this->getCustomSearchesById();
101 $id = $cs[$customSearchesByName[$info->key
]];
102 $optionValue = CRM_Core_BAO_OptionValue
::setIsActive($id, 1);
108 protected function getCustomSearchesByName() {
109 return CRM_Core_OptionGroup
::values(self
::CUSTOM_SEARCH_GROUP_NAME
, TRUE, FALSE, FALSE, NULL, 'name', FALSE, TRUE);
115 protected function getCustomSearchesById() {
116 return CRM_Core_OptionGroup
::values(self
::CUSTOM_SEARCH_GROUP_NAME
, FALSE, FALSE, FALSE, NULL, 'id', FALSE, TRUE);