/** * 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); }
/** * global validation rules for the form * * @param array $fields posted values of the form * * @return array list of errors to be posted back to the form * @static * @access public */ static function formRule(&$fields, &$files, $self) { $is_required = CRM_Utils_Array::value('is_required', $fields, false); $is_registration = CRM_Utils_Array::value('is_registration', $fields, false); $is_view = CRM_Utils_Array::value('is_view', $fields, false); $in_selector = CRM_Utils_Array::value('in_selector', $fields, false); $is_searchable = CRM_Utils_Array::value('is_searchable', $fields, false); $visibility = CRM_Utils_Array::value('visibility', $fields, false); $is_active = CRM_Utils_Array::value('is_active', $fields, false); $errors = array(); if ($is_view && $is_registration) { $errors['is_registration'] = ts('View Only cannot be selected if this field is to be included on the registration form'); } if ($is_view && $is_required) { $errors['is_view'] = ts('A View Only field cannot be required'); } $fieldName = $fields['field_name'][0]; if (!$fieldName) { $errors['field_name'] = ts('Please select a field name'); } if ($in_selector && in_array($fieldName, array('Contribution', 'Participant', 'Membership'))) { $errors['in_selector'] = ts("'In Selector' cannot be checked for %1 fields.", array(1 => $fieldName)); } if (!empty($fields['field_id'])) { //get custom field id $customFieldId = explode('_', $fieldName); if ($customFieldId[0] == 'custom') { $customField =& new CRM_Core_DAO_CustomField(); $customField->id = $customFieldId[1]; $customField->find(true); if (!$customField->is_active && $is_active) { $errors['field_name'] = ts('Cannot set this field "Active" since the selected custom field is disabled.'); } } } //check profile is configured for double option process //adding group field, email field should be present in the group //fixed for issue CRM-2861 & CRM-4153 $config =& CRM_Core_Config::singleton(); if ($config->profileDoubleOptIn) { if ($fields['field_name'][1] == 'group') { require_once 'CRM/Core/BAO/UFField.php'; $dao =& new CRM_Core_BAO_UFField(); $dao->uf_group_id = $fields['group_id']; $dao->find(); $emailField = false; while ($dao->fetch()) { //check email field is present in the group if ($dao->field_name == 'email') { $emailField = true; } } if (!$emailField) { $disableSetting = "define( 'CIVICRM_PROFILE_DOUBLE_OPTIN' , 0 );"; $errors['field_name'] = ts('Your site is currently configured to require double-opt in when users join (subscribe) to Group(s) via a Profile form. In this mode, you need to include an Email field in a Profile BEFORE you can add the Group(s) field. This ensures that an opt-in confirmation email can be sent. Your site administrator can disable double opt-in by adding this line to the CiviCRM settings file: <em>%1</em>', array(1 => $disableSetting)); } } } //fix for CRM-3037 $fieldType = $fields['field_name'][0]; //get the group type. $groupType = CRM_Core_BAO_UFGroup::calculateGroupType($self->_gid, CRM_Utils_Array::value('field_id', $fields)); switch ($fieldType) { case 'Individual': if (in_array('Household', $groupType) || in_array('Organization', $groupType)) { $errors['field_name'] = ts('Cannot add or update profile field type Individual with combination of Household or Organization'); } else { self::formRuleSubType($fieldType, $groupType, $errors); } break; case 'Household': if (in_array('Individual', $groupType) || in_array('Organization', $groupType)) { $errors['field_name'] = ts('Cannot add or update profile field type Household with combination of Individual or Organization'); } else { self::formRuleSubType($fieldType, $groupType, $errors); } break; case 'Organization': if (in_array('Household', $groupType) || in_array('Individual', $groupType)) { $errors['field_name'] = ts('Cannot add or update profile field type Organization with combination of Household or Individual'); } else { self::formRuleSubType($fieldType, $groupType, $errors); } break; case 'Participant': if (in_array('Membership', $groupType) || in_array('Contribution', $groupType) || in_array('Organization', $groupType) || in_array('Household', $groupType)) { $errors['field_name'] = ts('Cannot add or update profile field type Participant with combination of Membership or Contribution or Household or Organization'); } else { self::formRuleSubType($fieldType, $groupType, $errors); } break; case 'Contribution': if (in_array('Participant', $groupType) || in_array('Membership', $groupType) || in_array('Organization', $groupType) || in_array('Household', $groupType)) { $errors['field_name'] = ts('Cannot add or update profile field type Contribution with combination of Membership or Participant or Household or Organization'); } else { self::formRuleSubType($fieldType, $groupType, $errors); } break; case 'Membership': if (in_array('Participant', $groupType) || in_array('Contribution', $groupType) || in_array('Organization', $groupType) || in_array('Household', $groupType)) { $errors['field_name'] = ts('Cannot add or update profile field type Membership with combination of Participant or Contribution or Household or Organization'); } else { self::formRuleSubType($fieldType, $groupType, $errors); } break; default: $profileType = CRM_Core_BAO_UFField::getProfileType($fields['group_id'], true, false, true); if (CRM_Contact_BAO_ContactType::isaSubType($fieldType)) { if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) { if ($fieldType != $profileType) { $errors['field_name'] = ts('Cannot add or update profile field type "%1" with combination of "%2".', array(1 => $fieldType, 2 => $profileType)); } } else { $basicType = CRM_Contact_BAO_ContactType::getBasicType($fieldType); if ($profileType && $profileType != $basicType && $profileType != 'Contact') { $errors['field_name'] = ts('Cannot add or update profile field type "%1" with combination of "%2".', array(1 => $fieldType, 2 => $profileType)); } } } elseif ($fields['field_name'][1] == 'contact_sub_type' && !in_array($profileType, array('Individual', 'Household', 'Organization')) && !in_array($profileType, CRM_Contact_BAO_ContactType::subTypes())) { $errors['field_name'] = ts('Cannot add or update profile field Contact Subtype as profile type is not one of Individual, Household or Organization.'); } } return empty($errors) ? true : $errors; }
/** * Global validation rules for the form. * * @param array $fields * Posted values of the form. * * @param $files * @param $self * * @return array * list of errors to be posted back to the form */ public static function formRule($fields, $files, $self) { $is_required = CRM_Utils_Array::value('is_required', $fields, FALSE); $is_registration = CRM_Utils_Array::value('is_registration', $fields, FALSE); $is_view = CRM_Utils_Array::value('is_view', $fields, FALSE); $in_selector = CRM_Utils_Array::value('in_selector', $fields, FALSE); $is_active = CRM_Utils_Array::value('is_active', $fields, FALSE); $errors = array(); if ($is_view && $is_registration) { $errors['is_registration'] = ts('View Only cannot be selected if this field is to be included on the registration form'); } if ($is_view && $is_required) { $errors['is_view'] = ts('A View Only field cannot be required'); } $entityName = $fields['field_name'][0]; if (!$entityName) { $errors['field_name'] = ts('Please select a field name'); } if ($in_selector && in_array($entityName, array('Contribution', 'Participant', 'Membership', 'Activity'))) { $errors['in_selector'] = ts("'In Selector' cannot be checked for %1 fields.", array(1 => $entityName)); } $isCustomField = FALSE; $profileFieldName = CRM_Utils_Array::value(1, $fields['field_name']); if ($profileFieldName) { //get custom field id $customFieldId = explode('_', $profileFieldName); if ($customFieldId[0] == 'custom') { $customField = new CRM_Core_DAO_CustomField(); $customField->id = $customFieldId[1]; $customField->find(TRUE); $isCustomField = TRUE; if (!empty($fields['field_id']) && !$customField->is_active && $is_active) { $errors['field_name'] = ts('Cannot set this field "Active" since the selected custom field is disabled.'); } //check if profile already has a different multi-record custom set field configured $customGroupId = CRM_Core_BAO_CustomField::isMultiRecordField($profileFieldName); if ($customGroupId) { if ($profileMultiRecordCustomGid = CRM_Core_BAO_UFField::checkMultiRecordFieldExists($self->_gid)) { if ($customGroupId != $profileMultiRecordCustomGid) { $errors['field_name'] = ts("You cannot configure multi-record custom fields belonging to different custom sets in one profile"); } } } } } // Get list of fields already in the group $groupFields = CRM_Core_BAO_UFGroup::getFields($fields['group_id'], FALSE, NULL, NULL, NULL, TRUE, NULL, TRUE); // Check if we already added a primary field of the same communication type self::formRulePrimaryCheck($fields, $profileFieldName, $groupFields, $errors); //check profile is configured for double option process //adding group field, email field should be present in the group //fixed for issue CRM-2861 & CRM-4153 if (CRM_Core_BAO_UFGroup::isProfileDoubleOptin()) { if (CRM_Utils_Array::value(1, $fields['field_name']) == 'group') { $dao = new CRM_Core_BAO_UFField(); $dao->uf_group_id = $fields['group_id']; $dao->find(); $emailField = FALSE; while ($dao->fetch()) { //check email field is present in the group if ($dao->field_name == 'email') { $emailField = TRUE; break; } } if (!$emailField) { $disableSettingURL = CRM_Utils_System::url('civicrm/admin/setting/preferences/mailing', 'reset=1'); $errors['field_name'] = ts('Your site is currently configured to require double-opt in when users join (subscribe) to Group(s) via a Profile form. In this mode, you need to include an Email field in a Profile BEFORE you can add the Group(s) field. This ensures that an opt-in confirmation email can be sent. Your site administrator can disable double opt-in on the civimail admin settings: <em>%1</em>', array(1 => $disableSettingURL)); } } } //fix for CRM-3037 $fieldType = $fields['field_name'][0]; //get the group type. $groupType = CRM_Core_BAO_UFGroup::calculateGroupType($self->_gid, FALSE, CRM_Utils_Array::value('field_id', $fields)); switch ($fieldType) { case 'Contact': self::formRuleSubType($fieldType, $groupType, $errors); break; case 'Individual': if (in_array('Activity', $groupType) || in_array('Household', $groupType) || in_array('Organization', $groupType)) { //CRM-7603 - need to support activity + individual. //$errors['field_name'] = //ts( 'Cannot add or update profile field type Individual with combination of Household or Organization or Activity' ); if (in_array('Household', $groupType) || in_array('Organization', $groupType)) { $errors['field_name'] = ts('Cannot add or update profile field type Individual with combination of Household or Organization'); } } else { self::formRuleSubType($fieldType, $groupType, $errors); } break; case 'Household': if (in_array('Activity', $groupType) || in_array('Individual', $groupType) || in_array('Organization', $groupType)) { $errors['field_name'] = ts('Cannot add or update profile field type Household with combination of Individual or Organization or Activity'); } else { self::formRuleSubType($fieldType, $groupType, $errors); } break; case 'Organization': if (in_array('Activity', $groupType) || in_array('Household', $groupType) || in_array('Individual', $groupType)) { $errors['field_name'] = ts('Cannot add or update profile field type Organization with combination of Household or Individual or Activity'); } else { self::formRuleSubType($fieldType, $groupType, $errors); } break; case 'Activity': if (in_array('Individual', $groupType) || in_array('Membership', $groupType) || in_array('Contribution', $groupType) || in_array('Organization', $groupType) || in_array('Household', $groupType) || in_array('Participant', $groupType)) { //CRM-7603 - need to support activity + contact type. //$errors['field_name'] = //ts( 'Cannot add or update profile field type Activity with combination Participant or Membership or Contribution or Household or Organization or Individual' ); if (in_array('Membership', $groupType) || in_array('Contribution', $groupType) || in_array('Participant', $groupType)) { $errors['field_name'] = ts('Cannot add or update profile field type Activity with combination Participant or Membership or Contribution'); } } else { self::formRuleSubType($fieldType, $groupType, $errors); } if ($isCustomField && !isset($errors['field_name'])) { self::formRuleCustomDataExtentColumnValue($customField, $self->_gid, $fieldType, $errors); } break; case 'Participant': if (in_array('Membership', $groupType) || in_array('Contribution', $groupType) || in_array('Organization', $groupType) || in_array('Household', $groupType) || in_array('Activity', $groupType)) { $errors['field_name'] = ts('Cannot add or update profile field type Participant with combination of Activity or Membership or Contribution or Household or Organization.'); } else { self::formRuleSubType($fieldType, $groupType, $errors); } break; case 'Contribution': //special case where in we allow contribution + oganization fields, for on behalf feature $profileId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', 'on_behalf_organization', 'id', 'name'); if (in_array('Participant', $groupType) || in_array('Membership', $groupType) || $profileId != $self->_gid && in_array('Organization', $groupType) || in_array('Household', $groupType) || in_array('Activity', $groupType)) { $errors['field_name'] = ts('Cannot add or update profile field type Contribution with combination of Activity or Membership or Participant or Household or Organization'); } else { self::formRuleSubType($fieldType, $groupType, $errors); } break; case 'Membership': //special case where in we allow contribution + oganization fields, for on behalf feature $profileId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', 'on_behalf_organization', 'id', 'name'); if (in_array('Participant', $groupType) || in_array('Contribution', $groupType) || $profileId != $self->_gid && in_array('Organization', $groupType) || in_array('Household', $groupType) || in_array('Activity', $groupType)) { $errors['field_name'] = ts('Cannot add or update profile field type Membership with combination of Activity or Participant or Contribution or Household or Organization'); } else { self::formRuleSubType($fieldType, $groupType, $errors); } break; default: $profileType = CRM_Core_BAO_UFField::getProfileType($fields['group_id'], TRUE, FALSE, TRUE); if (CRM_Contact_BAO_ContactType::isaSubType($fieldType)) { if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) { if ($fieldType != $profileType) { $errors['field_name'] = ts('Cannot add or update profile field type "%1" with combination of "%2".', array(1 => $fieldType, 2 => $profileType)); } } else { $basicType = CRM_Contact_BAO_ContactType::getBasicType($fieldType); if ($profileType && $profileType != $basicType && $profileType != 'Contact') { $errors['field_name'] = ts('Cannot add or update profile field type "%1" with combination of "%2".', array(1 => $fieldType, 2 => $profileType)); } } } elseif (CRM_Utils_Array::value(1, $fields['field_name']) == 'contact_sub_type' && !in_array($profileType, array('Individual', 'Household', 'Organization')) && !in_array($profileType, CRM_Contact_BAO_ContactType::subTypes())) { $errors['field_name'] = ts('Cannot add or update profile field Contact Subtype as profile type is not one of Individual, Household or Organization.'); } } return empty($errors) ? TRUE : $errors; }
/** * @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); }