groupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', self::CUSTOM_SEARCH_GROUP_NAME, 'id', 'name' ); } /** * @param CRM_Extension_Info $info * * @return bool * @throws Exception */ public function onPreInstall(CRM_Extension_Info $info) { $customSearchesByName = $this->getCustomSearchesByName(); if (array_key_exists($info->key, $customSearchesByName)) { CRM_Core_Error::fatal('This custom search is already registered.'); } $weight = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', array('option_group_id' => $this->groupId) ); $params = array( 'option_group_id' => $this->groupId, 'weight' => $weight, 'description' => $info->label . ' (' . $info->key . ')', 'name' => $info->key, 'value' => max($customSearchesByName) + 1, 'label' => $info->key, 'is_active' => 1, ); $ids = array(); $optionValue = CRM_Core_BAO_OptionValue::add($params, $ids); return $optionValue ? TRUE : FALSE; } /** * @param CRM_Extension_Info $info * * @return bool * @throws Exception */ public function onPreUninstall(CRM_Extension_Info $info) { $customSearchesByName = $this->getCustomSearchesByName(); if (!array_key_exists($info->key, $customSearchesByName)) { CRM_Core_Error::fatal('This custom search is not registered.'); } $cs = $this->getCustomSearchesById(); $id = $cs[$customSearchesByName[$info->key]]; $optionValue = CRM_Core_BAO_OptionValue::del($id); return TRUE; } /** * @param CRM_Extension_Info $info */ public function onPreDisable(CRM_Extension_Info $info) { $customSearchesByName = $this->getCustomSearchesByName(); $cs = $this->getCustomSearchesById(); $id = $cs[$customSearchesByName[$info->key]]; $optionValue = CRM_Core_BAO_OptionValue::setIsActive($id, 0); } /** * @param CRM_Extension_Info $info */ public function onPreEnable(CRM_Extension_Info $info) { $customSearchesByName = $this->getCustomSearchesByName(); $cs = $this->getCustomSearchesById(); $id = $cs[$customSearchesByName[$info->key]]; $optionValue = CRM_Core_BAO_OptionValue::setIsActive($id, 1); } /** * @return array */ protected function getCustomSearchesByName() { return CRM_Core_OptionGroup::values(self::CUSTOM_SEARCH_GROUP_NAME, TRUE, FALSE, FALSE, NULL, 'name', FALSE, TRUE); } /** * @return array */ protected function getCustomSearchesById() { return CRM_Core_OptionGroup::values(self::CUSTOM_SEARCH_GROUP_NAME, FALSE, FALSE, FALSE, NULL, 'id', FALSE, TRUE); } }