3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
29 * This class stores logic for managing CiviCRM extensions.
32 * @copyright CiviCRM LLC (c) 2004-2016
34 class CRM_Extension_Manager_Search
extends CRM_Extension_Manager_Base
{
36 const CUSTOM_SEARCH_GROUP_NAME
= 'custom_search';
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'
46 * @param CRM_Extension_Info $info
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.');
57 $weight = CRM_Utils_Weight
::getDefaultWeight('CRM_Core_DAO_OptionValue',
58 array('option_group_id' => $this->groupId
)
62 'option_group_id' => $this->groupId
,
64 'description' => $info->label
. ' (' . $info->key
. ')',
66 'value' => max($customSearchesByName) +
1,
67 'label' => $info->key
,
72 $optionValue = CRM_Core_BAO_OptionValue
::add($params, $ids);
74 return $optionValue ?
TRUE : FALSE;
78 * @param CRM_Extension_Info $info
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.');
89 $cs = $this->getCustomSearchesById();
90 $id = $cs[$customSearchesByName[$info->key
]];
91 $optionValue = CRM_Core_BAO_OptionValue
::del($id);
97 * @param CRM_Extension_Info $info
99 public function onPreDisable(CRM_Extension_Info
$info) {
100 $customSearchesByName = $this->getCustomSearchesByName();
101 $cs = $this->getCustomSearchesById();
102 $id = $cs[$customSearchesByName[$info->key
]];
103 $optionValue = CRM_Core_BAO_OptionValue
::setIsActive($id, 0);
107 * @param CRM_Extension_Info $info
109 public function onPreEnable(CRM_Extension_Info
$info) {
110 $customSearchesByName = $this->getCustomSearchesByName();
111 $cs = $this->getCustomSearchesById();
112 $id = $cs[$customSearchesByName[$info->key
]];
113 $optionValue = CRM_Core_BAO_OptionValue
::setIsActive($id, 1);
119 protected function getCustomSearchesByName() {
120 return CRM_Core_OptionGroup
::values(self
::CUSTOM_SEARCH_GROUP_NAME
, TRUE, FALSE, FALSE, NULL, 'name', FALSE, TRUE);
126 protected function getCustomSearchesById() {
127 return CRM_Core_OptionGroup
::values(self
::CUSTOM_SEARCH_GROUP_NAME
, FALSE, FALSE, FALSE, NULL, 'id', FALSE, TRUE);