/** * Implementation of hook_civicrm_postInstall * * Note: This hook only runs in CiviCRM 4.4+. */ function hrrecruitment_civicrm_postInstall() { $caseTypes = CRM_Case_PseudoConstant::caseType('name'); $value = array_search('Application', $caseTypes); //update url of Find Application CRM_Core_BAO_Navigation::processUpdate(array('name' => 'find_application'), array('url' => "civicrm/case/search?force=1&type={$value}&reset=1")); CRM_Core_BAO_Navigation::resetNavigation(); $value = CRM_Core_DAO::VALUE_SEPARATOR . $value . CRM_Core_DAO::VALUE_SEPARATOR; $sql = "UPDATE civicrm_custom_group SET extends_entity_column_value = '{$value}' WHERE extends_entity_column_value = 'Application'"; CRM_Core_DAO::executeQuery($sql); //change the profile Type of Application if ($ufID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', 'application_profile', 'id', 'name')) { $fieldsType = CRM_Core_BAO_UFGroup::calculateGroupType($ufID, TRUE); CRM_Core_BAO_UFGroup::updateGroupTypes($ufID, $fieldsType); } }
/** * Delete uf field. * * @param array $params * * @throws API_Exception * * @return array */ function civicrm_api3_uf_field_delete($params) { $fieldId = $params['id']; $ufGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFField', $fieldId, 'uf_group_id'); if (!$ufGroupId) { throw new API_Exception('Invalid value for field_id.'); } $result = CRM_Core_BAO_UFField::del($fieldId); $fieldsType = CRM_Core_BAO_UFGroup::calculateGroupType($ufGroupId, TRUE); CRM_Core_BAO_UFGroup::updateGroupTypes($ufGroupId, $fieldsType); return civicrm_api3_create_success($result, $params); }
/** * Process the form. * * @return void */ public function postProcess() { $ids = array('uf_group' => $this->_gid); if ($this->_action & CRM_Core_Action::DELETE) { $fieldValues = array('uf_group_id' => $this->_gid); CRM_Utils_Weight::delWeight('CRM_Core_DAO_UFField', $this->_id, $fieldValues); $deleted = CRM_Core_BAO_UFField::del($this->_id); //update group_type every time. CRM-3608 if ($this->_gid && $deleted) { //get the profile type. $fieldsType = CRM_Core_BAO_UFGroup::calculateGroupType($this->_gid, TRUE); CRM_Core_BAO_UFGroup::updateGroupTypes($this->_gid, $fieldsType); } CRM_Core_Session::setStatus(ts('Selected Profile Field has been deleted.'), ts('Profile Field Deleted'), 'success'); return; } // store the submitted values in an array $params = $this->controller->exportValues('Field'); if ($params['visibility'] == 'User and User Admin Only') { $params['is_searchable'] = $params['in_selector'] = 0; } if ($this->_action & CRM_Core_Action::UPDATE) { $ids['uf_field'] = $this->_id; } $name = NULL; if (isset($params['field_name'][1]) && isset($this->_selectFields[$params['field_name'][1]])) { // we dont get a name for a html formatting element $name = $this->_selectFields[$params['field_name'][1]]; } //Hack for Formatting Field Name if ($params['field_name'][0] == 'Formatting') { $params['field_name'][1] = 'formatting_' . rand(1000, 9999); } //check for duplicate fields if ($params["field_name"][0] != "Formatting" && CRM_Core_BAO_UFField::duplicateField($params, $ids)) { CRM_Core_Session::setStatus(ts('The selected field already exists in this profile.'), ts('Field Not Added'), 'error'); return; } else { $params['weight'] = CRM_Core_BAO_UFField::autoWeight($params); $ufField = CRM_Core_BAO_UFField::add($params, $ids); //reset other field is searchable and in selector settings, CRM-4363 if ($this->_hasSearchableORInSelector && in_array($ufField->field_type, array('Participant', 'Contribution', 'Membership', 'Activity', 'Case'))) { CRM_Core_BAO_UFField::resetInSelectorANDSearchable($this->_gid); } $config = CRM_Core_Config::singleton(); $showBestResult = FALSE; if (in_array($ufField->field_name, array('country', 'state_province')) && count($config->countryLimit) > 1) { // get state or country field weight if exists $field = 'state_province'; if ($ufField->field_name == 'state_province') { $field = 'country'; } $ufFieldDAO = new CRM_Core_DAO_UFField(); $ufFieldDAO->field_name = $field; $ufFieldDAO->location_type_id = $ufField->location_type_id; $ufFieldDAO->uf_group_id = $ufField->uf_group_id; if ($ufFieldDAO->find(TRUE)) { if ($field == 'country' && $ufFieldDAO->weight > $ufField->weight) { $showBestResult = TRUE; } elseif ($field == 'state_province' && $ufFieldDAO->weight < $ufField->weight) { $showBestResult = TRUE; } } } //update group_type every time. CRM-3608 if ($this->_gid && is_a($ufField, 'CRM_Core_DAO_UFField')) { // get the profile type. $fieldsType = CRM_Core_BAO_UFGroup::calculateGroupType($this->_gid, TRUE); CRM_Core_BAO_UFGroup::updateGroupTypes($this->_gid, $fieldsType); } CRM_Core_Session::setStatus(ts('Your CiviCRM Profile Field \'%1\' has been saved to \'%2\'.', array(1 => $name, 2 => $this->_title)), ts('Profile Field Saved'), 'success'); } $buttonName = $this->controller->getButtonName(); $session = CRM_Core_Session::singleton(); if ($buttonName == $this->getButtonName('next', 'new')) { $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/uf/group/field/add', "reset=1&action=add&gid={$this->_gid}&sbr={$showBestResult}")); } else { $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/uf/group/field', "reset=1&action=browse&gid={$this->_gid}")); $session->set('showBestResult', $showBestResult); } }
/** * @param $rev */ public function upgrade_3_4_3($rev) { // CRM-8147, update group_type for uf groups, check and add component field types $ufGroups = new CRM_Core_DAO_UFGroup(); $ufGroups->find(); $skipGroupTypes = array('Individual,Contact', 'Organization,Contact', 'Household,Contact', 'Contact', 'Individual', 'Organization', 'Household'); while ($ufGroups->fetch()) { if (!in_array($ufGroups->group_type, $skipGroupTypes)) { $groupTypes = CRM_Core_BAO_UFGroup::calculateGroupType($ufGroups->id, TRUE); CRM_Core_BAO_UFGroup::updateGroupTypes($ufGroups->id, $groupTypes); } } $ufGroups->free(); // CRM-8134 add phone_ext column if it wasn't already added for this site in 3.3.7 upgrade (3.3.7 was released after 3.4.0) $dao = new CRM_Contact_DAO_Contact(); $dbName = $dao->_database; $chkExtQuery = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = %1\n AND TABLE_NAME = 'civicrm_phone' AND COLUMN_NAME = 'phone_ext'"; $extensionExists = CRM_Core_DAO::singleValueQuery($chkExtQuery, array(1 => array($dbName, 'String')), TRUE, FALSE); if (!$extensionExists) { $colQuery = 'ALTER TABLE `civicrm_phone` ADD `phone_ext` VARCHAR( 16 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL AFTER `phone` '; CRM_Core_DAO::executeQuery($colQuery); } $sql = "SELECT id FROM civicrm_location_type WHERE name = 'Main'"; if (!CRM_Core_DAO::singleValueQuery($sql)) { $query = "\nINSERT INTO civicrm_location_type ( name, description, is_reserved, is_active )\n VALUES ( 'Main', 'Main office location', 0, 1 );"; CRM_Core_DAO::executeQuery($query); } $upgrade = new CRM_Upgrade_Form(); $upgrade->processSQL($rev); }