/** * Implementation of hook_civicrm_uninstall * * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_uninstall */ function hrjobcontract_civicrm_uninstall() { $subTypeInfo = CRM_Contact_BAO_ContactType::subTypeInfo('Organization'); $sub_type_name = array('Health Insurance Provider', 'Life Insurance Provider'); foreach ($sub_type_name as $sub_type_name) { $subTypeName = ucfirst(CRM_Utils_String::munge($sub_type_name)); $orid = array_key_exists($subTypeName, $subTypeInfo); if ($orid) { $id = $subTypeInfo[$subTypeName]['id']; CRM_Contact_BAO_ContactType::del($id); } } $jobContractMenu = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Navigation', 'job_contracts', 'id', 'name'); if (!empty($jobContractMenu)) { CRM_Core_BAO_Navigation::processDelete($jobContractMenu); } CRM_Core_DAO::executeQuery("DELETE FROM civicrm_navigation WHERE name IN ('job_contracts', 'import_export_job_contracts', 'jobImport', 'hoursType', 'pay_scale','hours_location', 'hrjc_contact_type', 'hrjc_location', 'hrjc_pay_cycle', 'hrjc_benefit_name', 'hrjc_benefit_type', 'hrjc_deduction_name', 'hrjc_deduction_type', 'hrjc_health_provider', 'hrjc_life_provider', 'hrjc_pension_type', 'hrjc_revision_change_reason')"); CRM_Core_BAO_Navigation::resetNavigation(); //delete custom groups and field $customGroup = civicrm_api3('CustomGroup', 'get', array('name' => "HRJobContract_Summary")); $customGroupData = CRM_Utils_Array::first($customGroup['values']); if (!empty($customGroupData['id'])) { civicrm_api3('CustomGroup', 'delete', array('id' => $customGroupData['id'])); } $customGroup = civicrm_api3('CustomGroup', 'get', array('name' => "HRJobContract_Summary")); $customGroupData = CRM_Utils_Array::first($customGroup['values']); if (!empty($customGroupData['id'])) { civicrm_api3('CustomGroup', 'delete', array('id' => $customGroupData['id'])); } //delete all option group and values CRM_Core_DAO::executeQuery("DELETE FROM civicrm_option_group WHERE name IN ('job_contracts', 'hoursType', 'pay_scale','hours_location', 'hrjc_contact_type', 'hrjc_location', 'hrjc_pay_cycle', 'hrjc_benefit_name', 'hrjc_benefit_type', 'hrjc_deduction_name', 'hrjc_deduction_type', 'hrjc_health_provider', 'hrjc_life_provider', 'hrjc_pension_type', 'hrjc_revision_change_reason', 'hrjc_contract_type', 'hrjc_level_type', 'hrjc_department', 'hrjc_hours_type', 'hrjc_pay_grade', 'hrjc_health_provider', 'hrjc_life_provider', 'hrjc_location', 'hrjc_pension_type', 'hrjc_region', 'hrjc_pay_scale')"); //delete job contract files to entities relations CRM_Core_DAO::executeQuery("DELETE FROM civicrm_entity_file WHERE entity_table LIKE 'civicrm_hrjobcontract_%'"); return _hrjobcontract_civix_civicrm_uninstall(); }
function browse() { $basicType = CRM_Contact_BAO_ContactType::contactTypeInfo(true); $subType = CRM_Contact_BAO_ContactType::subTypeInfo(null, true); $rows = array_merge($basicType, $subType); foreach ($rows as $key => $value) { $mask = null; if (CRM_Utils_Array::value('is_reserved', $value)) { $mask -= CRM_Core_Action::DELETE + 1; } $rows[$key]['action'] = CRM_Core_Action::formLink(self::links(), $mask, array('id' => $value['id'])); } $this->assign('rows', $rows); }
/** * Retrieve the first non-generic contact type * * @param int $id id of uf_group * * @return string contact type */ static function getContactType($id) { $validTypes = array_filter(array_keys(CRM_Core_SelectValues::contactType())); $validSubTypes = CRM_Contact_BAO_ContactType::subTypeInfo(); $typesParts = explode(CRM_Core_DAO::VALUE_SEPARATOR, CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $id, 'group_type')); $types = explode(',', $typesParts[0]); $cType = NULL; foreach ($types as $type) { if (in_array($type, $validTypes)) { $cType = $type; } elseif (array_key_exists($type, $validSubTypes)) { $cType = CRM_Utils_Array::value('parent', $validSubTypes[$type]); } if ($cType) { break; } } return $cType; }
/** * Retrieve the first non-generic contact type * * @param int $id id of uf_group * @return string contact type */ static function getContactType($id) { require_once 'CRM/Contact/BAO/ContactType.php'; $validTypes = array_filter(array_keys(CRM_Core_SelectValues::contactType())); $validSubTypes = CRM_Contact_BAO_ContactType::subTypeInfo(); $types = explode(',', CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $id, 'group_type')); $cType = null; foreach ($types as $type) { if (in_array($type, $validTypes)) { $cType = $type; } else { if (array_key_exists($type, $validSubTypes)) { $cType = CRM_Utils_Array::value('parent', $validSubTypes[$type]); } } if ($cType) { break; } } return $cType; }
/** * Browse all custom data groups. * * @param string $action the action to be invoked * * @return void * @access public */ function browse($action = NULL) { // get all custom groups sorted by weight $customGroup = array(); $dao = new CRM_Core_DAO_CustomGroup(); $dao->orderBy('weight, title'); $dao->find(); while ($dao->fetch()) { $customGroup[$dao->id] = array(); CRM_Core_DAO::storeValues($dao, $customGroup[$dao->id]); // form all action links $action = array_sum(array_keys($this->actionLinks())); // update enable/disable links depending on custom_group properties. if ($dao->is_active) { $action -= CRM_Core_Action::ENABLE; } else { $action -= CRM_Core_Action::DISABLE; } $customGroup[$dao->id]['order'] = $customGroup[$dao->id]['weight']; $customGroup[$dao->id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action, array('id' => $dao->id)); } $customGroupExtends = CRM_Core_SelectValues::customGroupExtends(); foreach ($customGroup as $key => $array) { CRM_Core_DAO_CustomGroup::addDisplayEnums($customGroup[$key]); $customGroup[$key]['extends_display'] = $customGroupExtends[$customGroup[$key]['extends']]; } //fix for Displaying subTypes $subTypes = array(); $subTypes['Activity'] = CRM_Core_PseudoConstant::activityType(FALSE, TRUE, FALSE, 'label', TRUE); $subTypes['Contribution'] = CRM_Contribute_PseudoConstant::contributionType(); $subTypes['Membership'] = CRM_Member_BAO_MembershipType::getMembershipTypes(FALSE); $subTypes['Event'] = CRM_Core_OptionGroup::values('event_type'); $subTypes['Grant'] = CRM_Core_OptionGroup::values('grant_type'); $subTypes['Campaign'] = CRM_Campaign_PseudoConstant::campaignType(); $subTypes['Participant'] = array(); $subTypes['ParticipantRole'] = CRM_Core_OptionGroup::values('participant_role'); $subTypes['ParticipantEventName'] = CRM_Event_PseudoConstant::event(); $subTypes['ParticipantEventType'] = CRM_Core_OptionGroup::values('event_type'); $subTypes['Individual'] = CRM_Contact_BAO_ContactType::subTypePairs('Individual', FALSE, NULL); $subTypes['Household'] = CRM_Contact_BAO_ContactType::subTypePairs('Household', FALSE, NULL); $subTypes['Organization'] = CRM_Contact_BAO_ContactType::subTypePairs('Organization', FALSE, NULL); $relTypeInd = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, 'Individual'); $relTypeOrg = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, 'Organization'); $relTypeHou = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, 'Household'); $allRelationshipType = array(); $allRelationshipType = array_merge($relTypeInd, $relTypeOrg); $allRelationshipType = array_merge($allRelationshipType, $relTypeHou); //adding subtype specific relationships CRM-5256 $relSubType = CRM_Contact_BAO_ContactType::subTypeInfo(); foreach ($relSubType as $subType => $val) { $subTypeRelationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, $val['parent'], FALSE, 'label', TRUE, $subType); $allRelationshipType = array_merge($allRelationshipType, $subTypeRelationshipTypes); } $subTypes['Relationship'] = $allRelationshipType; $cSubTypes = CRM_Core_Component::contactSubTypes(); $contactSubTypes = array(); foreach ($cSubTypes as $key => $value) { $contactSubTypes[$key] = $key; } $subTypes['Contact'] = $contactSubTypes; CRM_Core_BAO_CustomGroup::getExtendedObjectTypes($subTypes); foreach ($customGroup as $key => $values) { $subValue = CRM_Utils_Array::value('extends_entity_column_value', $customGroup[$key]); $subName = CRM_Utils_Array::value('extends_entity_column_id', $customGroup[$key]); $type = CRM_Utils_Array::value('extends', $customGroup[$key]); if ($subValue) { $subValue = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($subValue, 1, -1)); $colValue = NULL; foreach ($subValue as $sub) { if ($sub) { if ($type == 'Participant') { if ($subName == 1) { $colValue = $colValue ? $colValue . ', ' . $subTypes['ParticipantRole'][$sub] : $subTypes['ParticipantRole'][$sub]; } elseif ($subName == 2) { $colValue = $colValue ? $colValue . ', ' . $subTypes['ParticipantEventName'][$sub] : $subTypes['ParticipantEventName'][$sub]; } elseif ($subName == 3) { $colValue = $colValue ? $colValue . ', ' . $subTypes['ParticipantEventType'][$sub] : $subTypes['ParticipantEventType'][$sub]; } } elseif ($type == 'Relationship') { $colValue = $colValue ? $colValue . ', ' . $subTypes[$type][$sub . '_a_b'] : $subTypes[$type][$sub . '_a_b']; if (isset($subTypes[$type][$sub . '_b_a'])) { $colValue = $colValue ? $colValue . ', ' . $subTypes[$type][$sub . '_b_a'] : $subTypes[$type][$sub . '_b_a']; } } else { $colValue = $colValue ? $colValue . (isset($subTypes[$type][$sub]) ? ', ' . $subTypes[$type][$sub] : '') : (isset($subTypes[$type][$sub]) ? $subTypes[$type][$sub] : ''); } } } $customGroup[$key]["extends_entity_column_value"] = $colValue; } else { if (is_array(CRM_Utils_Array::value($type, $subTypes))) { $customGroup[$key]["extends_entity_column_value"] = ts("Any"); } } } $returnURL = CRM_Utils_System::url('civicrm/admin/custom/group', "reset=1&action=browse"); CRM_Utils_Weight::addOrder($customGroup, 'CRM_Core_DAO_CustomGroup', 'id', $returnURL); $this->assign('rows', $customGroup); }
/** * Get a list of fields which can be added to profiles. * * @param int $gid : UF group ID * @param array $defaults : Form defaults * @return array, multidimensional; e.g. $result['FieldGroup']['field_name']['label'] */ public static function getAvailableFields($gid = NULL, $defaults = array()) { $fields = array('Contact' => array(), 'Individual' => CRM_Contact_BAO_Contact::importableFields('Individual', FALSE, FALSE, TRUE, TRUE, TRUE), 'Household' => CRM_Contact_BAO_Contact::importableFields('Household', FALSE, FALSE, TRUE, TRUE, TRUE), 'Organization' => CRM_Contact_BAO_Contact::importableFields('Organization', FALSE, FALSE, TRUE, TRUE, TRUE)); // include hook injected fields $fields['Contact'] = array_merge($fields['Contact'], CRM_Contact_BAO_Query_Hook::singleton()->getFields()); // add current employer for individuals $fields['Individual']['current_employer'] = array('name' => 'organization_name', 'title' => ts('Current Employer')); $addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options', TRUE, NULL, TRUE); if (!$addressOptions['county']) { unset($fields['Individual']['county'], $fields['Household']['county'], $fields['Organization']['county']); } // break out common contact fields array CRM-3037. // from a UI perspective this makes very little sense foreach ($fields['Individual'] as $key => $value) { if (!empty($fields['Household'][$key]) && !empty($fields['Organization'][$key])) { $fields['Contact'][$key] = $value; unset($fields['Individual'][$key], $fields['Household'][$key], $fields['Organization'][$key]); } } // Internal field not exposed to forms unset($fields['Contact']['contact_type']); unset($fields['Contact']['master_id']); // convert phone extension in to psedo-field phone + phone extension //unset extension unset($fields['Contact']['phone_ext']); //add psedo field $fields['Contact']['phone_and_ext'] = array('name' => 'phone_and_ext', 'title' => ts('Phone and Extension'), 'hasLocationType' => 1); // include Subtypes For Profile $subTypes = CRM_Contact_BAO_ContactType::subTypeInfo(); foreach ($subTypes as $name => $val) { //custom fields for sub type $subTypeFields = CRM_Core_BAO_CustomField::getFieldsForImport($name, FALSE, FALSE, FALSE, TRUE, TRUE); if (array_key_exists($val['parent'], $fields)) { $fields[$name] = $fields[$val['parent']] + $subTypeFields; } else { $fields[$name] = $subTypeFields; } } if (CRM_Core_Permission::access('CiviContribute')) { $contribFields = CRM_Contribute_BAO_Contribution::getContributionFields(FALSE); if (!empty($contribFields)) { unset($contribFields['is_test']); unset($contribFields['is_pay_later']); unset($contribFields['contribution_id']); $contribFields['contribution_note'] = array('name' => 'contribution_note', 'title' => ts('Contribution Note')); $fields['Contribution'] = array_merge($contribFields, self::getContribBatchEntryFields()); } } if (CRM_Core_Permission::access('CiviEvent')) { $participantFields = CRM_Event_BAO_Query::getParticipantFields(); if ($participantFields) { // Remove fields not supported by profiles CRM_Utils_Array::remove($participantFields, 'external_identifier', 'event_id', 'participant_contact_id', 'participant_role_id', 'participant_status_id', 'participant_is_test', 'participant_fee_level', 'participant_id', 'participant_is_pay_later', 'participant_campaign'); if (isset($participantFields['participant_campaign_id'])) { $participantFields['participant_campaign_id']['title'] = ts('Campaign'); } $fields['Participant'] = $participantFields; } } if (CRM_Core_Permission::access('CiviMember')) { $membershipFields = CRM_Member_BAO_Membership::getMembershipFields(); // Remove fields not supported by profiles CRM_Utils_Array::remove($membershipFields, 'membership_id', 'membership_type_id', 'member_is_test', 'is_override', 'status_id', 'member_is_pay_later'); if ($gid && CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $gid, 'name') == 'membership_batch_entry') { $fields['Membership'] = array_merge($membershipFields, self::getMemberBatchEntryFields()); } else { $fields['Membership'] = $membershipFields; } } if (CRM_Core_Permission::access('CiviCase')) { $caseFields = CRM_Case_BAO_Query::getFields(TRUE); $caseFields = array_merge($caseFields, CRM_Core_BAO_CustomField::getFieldsForImport('Case')); if ($caseFields) { // Remove fields not supported by profiles CRM_Utils_Array::remove($caseFields, 'case_id', 'case_type', 'case_start_date', 'case_end_date', 'case_role', 'case_status', 'case_deleted'); } $fields['Case'] = $caseFields; } $activityFields = CRM_Activity_BAO_Activity::getProfileFields(); if ($activityFields) { // campaign related fields. if (isset($activityFields['activity_campaign_id'])) { $activityFields['activity_campaign_id']['title'] = ts('Campaign'); } $fields['Activity'] = $activityFields; } $fields['Formatting']['format_free_html_' . rand(1000, 9999)] = array('name' => 'free_html', 'import' => FALSE, 'export' => FALSE, 'title' => 'Free HTML'); // Sort by title foreach ($fields as &$values) { $values = CRM_Utils_Array::crmArraySortByField($values, 'title'); } //group selected and unwanted fields list $ufFields = $gid ? CRM_Core_BAO_UFGroup::getFields($gid, FALSE, NULL, NULL, NULL, TRUE, NULL, TRUE) : array(); $groupFieldList = array_merge($ufFields, array('note', 'email_greeting_custom', 'postal_greeting_custom', 'addressee_custom', 'id')); //unset selected fields foreach ($groupFieldList as $key => $value) { if (is_int($key)) { unset($fields['Individual'][$value], $fields['Household'][$value], $fields['Organization'][$value]); continue; } if (!empty($defaults['field_name']) && $defaults['field_name']['0'] == $value['field_type'] && $defaults['field_name']['1'] == $key) { continue; } unset($fields[$value['field_type']][$key]); } return $fields; }
/** * Given a contact id and a field set, return the values from the db * for this contact * * @param int $cid * @param array $fields * The profile fields of interest. * @param array $values * The values for the above fields. * @param bool $searchable * Searchable or not. * @param array $componentWhere * Component condition. * @param bool $absolute * Return urls in absolute form (useful when sending an email). * @param null $additionalWhereClause */ public static function getValues($cid, &$fields, &$values, $searchable = TRUE, $componentWhere = NULL, $absolute = FALSE, $additionalWhereClause = NULL) { if (empty($cid) && empty($componentWhere)) { return NULL; } // get the contact details (hier) $returnProperties = CRM_Contact_BAO_Contact::makeHierReturnProperties($fields); $params = $cid ? array(array('contact_id', '=', $cid, 0, 0)) : array(); // add conditions specified by components. eg partcipant_id etc if (!empty($componentWhere)) { $params = array_merge($params, $componentWhere); } $query = new CRM_Contact_BAO_Query($params, $returnProperties, $fields); $options =& $query->_options; $details = $query->searchQuery(0, 0, NULL, FALSE, FALSE, FALSE, FALSE, FALSE, $additionalWhereClause); if (!$details->fetch()) { return; } $query->convertToPseudoNames($details); $config = CRM_Core_Config::singleton(); $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'); $imProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'); $websiteTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Website', 'website_type_id'); $multipleFields = array('url'); //start of code to set the default values foreach ($fields as $name => $field) { // fix for CRM-3962 if ($name == 'id') { $name = 'contact_id'; } // skip fields that should not be displayed separately if (!empty($field['skipDisplay'])) { continue; } // Create a unique, non-empty index for each field. $index = $field['title']; if ($index === '') { $index = ' '; } while (array_key_exists($index, $values)) { $index .= ' '; } $params[$index] = $values[$index] = ''; $customFieldName = NULL; // hack for CRM-665 if (isset($details->{$name}) || $name == 'group' || $name == 'tag') { // to handle gender / suffix / prefix if (in_array(substr($name, 0, -3), array('gender', 'prefix', 'suffix'))) { $params[$index] = $details->{$name}; $values[$index] = $details->{$name}; } elseif (in_array($name, CRM_Contact_BAO_Contact::$_greetingTypes)) { $dname = $name . '_display'; $values[$index] = $details->{$dname}; $name = $name . '_id'; $params[$index] = $details->{$name}; } elseif (in_array($name, array('state_province', 'country', 'county'))) { $values[$index] = $details->{$name}; $idx = $name . '_id'; $params[$index] = $details->{$idx}; } elseif ($name === 'preferred_communication_method') { $communicationFields = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method'); $compref = array(); $pref = explode(CRM_Core_DAO::VALUE_SEPARATOR, $details->{$name}); foreach ($pref as $k) { if ($k) { $compref[] = $communicationFields[$k]; } } $params[$index] = $details->{$name}; $values[$index] = implode(',', $compref); } elseif ($name === 'preferred_language') { $params[$index] = $details->{$name}; $values[$index] = CRM_Core_PseudoConstant::getLabel('CRM_Contact_DAO_Contact', 'preferred_language', $details->{$name}); } elseif ($name == 'group') { $groups = CRM_Contact_BAO_GroupContact::getContactGroup($cid, 'Added', NULL, FALSE, TRUE); $title = $ids = array(); foreach ($groups as $g) { // CRM-8362: User and User Admin visibility groups should be included in display if user has // VIEW permission on that group $groupPerm = CRM_Contact_BAO_Group::checkPermission($g['group_id'], $g['title']); if ($g['visibility'] != 'User and User Admin Only' || CRM_Utils_Array::key(CRM_Core_Permission::VIEW, $groupPerm)) { $title[] = $g['title']; if ($g['visibility'] == 'Public Pages') { $ids[] = $g['group_id']; } } } $values[$index] = implode(', ', $title); $params[$index] = implode(',', $ids); } elseif ($name == 'tag') { $entityTags = CRM_Core_BAO_EntityTag::getTag($cid); $allTags = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE)); $title = array(); foreach ($entityTags as $tagId) { $title[] = $allTags[$tagId]; } $values[$index] = implode(', ', $title); $params[$index] = implode(',', $entityTags); } elseif ($name == 'activity_status_id') { $activityStatus = CRM_Core_PseudoConstant::activityStatus(); $values[$index] = $activityStatus[$details->{$name}]; $params[$index] = $details->{$name}; } elseif ($name == 'activity_date_time') { $values[$index] = CRM_Utils_Date::customFormat($details->{$name}); $params[$index] = $details->{$name}; } elseif ($name == 'contact_sub_type') { $contactSubTypeNames = explode(CRM_Core_DAO::VALUE_SEPARATOR, $details->{$name}); if (!empty($contactSubTypeNames)) { $contactSubTypeLabels = array(); // get all contact subtypes $allContactSubTypes = CRM_Contact_BAO_ContactType::subTypeInfo(); // build contact subtype labels array foreach ($contactSubTypeNames as $cstName) { if ($cstName) { $contactSubTypeLabels[] = $allContactSubTypes[$cstName]['label']; } } $values[$index] = implode(',', $contactSubTypeLabels); } $params[$index] = $details->{$name}; } else { if (substr($name, 0, 7) === 'do_not_' || substr($name, 0, 3) === 'is_') { if ($details->{$name}) { $values[$index] = '[ x ]'; } } else { if ($cfID = CRM_Core_BAO_CustomField::getKeyID($name)) { $htmlType = $field['html_type']; // field_type is only set when we are retrieving profile values // when sending email, we call the same function to get custom field // values etc, i.e. emulating a profile $fieldType = CRM_Utils_Array::value('field_type', $field); if ($htmlType == 'File') { $entityId = $cid; if (!$cid && $fieldType == 'Activity' && !empty($componentWhere[0][2])) { $entityId = $componentWhere[0][2]; } $fileURL = CRM_Core_BAO_CustomField::getFileURL($entityId, $cfID, NULL, $absolute, $additionalWhereClause); $params[$index] = $values[$index] = $fileURL['file_url']; } else { $customVal = NULL; if (isset($dao) && property_exists($dao, 'data_type') && ($dao->data_type == 'Int' || $dao->data_type == 'Boolean')) { $customVal = (int) $details->{$name}; } elseif (isset($dao) && property_exists($dao, 'data_type') && $dao->data_type == 'Float') { $customVal = (double) $details->{$name}; } elseif (!CRM_Utils_System::isNull(explode(CRM_Core_DAO::VALUE_SEPARATOR, $details->{$name}))) { $customVal = $details->{$name}; } //CRM-4582 if (CRM_Utils_System::isNull($customVal)) { continue; } $params[$index] = $customVal; $values[$index] = CRM_Core_BAO_CustomField::getDisplayValue($customVal, $cfID, $options); if ($field['data_type'] == 'ContactReference') { $params[$index] = $values[$index]; } if (CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $cfID, 'is_search_range')) { $customFieldName = "{$name}_from"; } } } elseif ($name == 'image_URL') { list($width, $height) = getimagesize(CRM_Utils_String::unstupifyUrl($details->{$name})); list($thumbWidth, $thumbHeight) = CRM_Contact_BAO_Contact::getThumbSize($width, $height); $image_URL = '<img src="' . $details->{$name} . '" height= ' . $thumbHeight . ' width= ' . $thumbWidth . ' />'; $values[$index] = "<a href='#' onclick='contactImagePopUp(\"{$details->{$name}}\", {$width}, {$height});'>{$image_URL}</a>"; } elseif (in_array($name, array('birth_date', 'deceased_date', 'membership_start_date', 'membership_end_date', 'join_date'))) { $values[$index] = CRM_Utils_Date::customFormat($details->{$name}); $params[$index] = CRM_Utils_Date::isoToMysql($details->{$name}); } else { $dao = ''; if ($index == 'Campaign') { $dao = 'CRM_Campaign_DAO_Campaign'; } elseif ($index == 'Contribution Page') { $dao = 'CRM_Contribute_DAO_ContributionPage'; } if ($dao) { $value = CRM_Core_DAO::getFieldValue($dao, $details->{$name}, 'title'); } else { $value = $details->{$name}; } $values[$index] = $value; } } } } elseif (strpos($name, '-') !== FALSE) { list($fieldName, $id, $type) = CRM_Utils_System::explode('-', $name, 3); if (!in_array($fieldName, $multipleFields)) { if ($id == 'Primary') { // fix for CRM-1543 // not sure why we'd every use Primary location type id // we need to fix the source if we are using it // $locationTypeName = CRM_Contact_BAO_Contact::getPrimaryLocationType( $cid ); $locationTypeName = 1; } else { $locationTypeName = CRM_Utils_Array::value($id, $locationTypes); } if (!$locationTypeName) { continue; } $detailName = "{$locationTypeName}-{$fieldName}"; $detailName = str_replace(' ', '_', $detailName); if (in_array($fieldName, array('phone', 'im', 'email', 'openid'))) { if ($type) { $detailName .= "-{$type}"; } } if (in_array($fieldName, array('state_province', 'country', 'county'))) { $values[$index] = $details->{$detailName}; $idx = $detailName . '_id'; $params[$index] = $details->{$idx}; } elseif ($fieldName == 'im') { $providerId = $detailName . '-provider_id'; if (isset($imProviders[$details->{$providerId}])) { $values[$index] = $details->{$detailName} . " (" . $imProviders[$details->{$providerId}] . ")"; } else { $values[$index] = $details->{$detailName}; } $params[$index] = $details->{$detailName}; } elseif ($fieldName == 'phone') { $phoneExtField = str_replace('phone', 'phone_ext', $detailName); if (isset($details->{$phoneExtField})) { $values[$index] = $details->{$detailName} . " (" . $details->{$phoneExtField} . ")"; } else { $values[$index] = $details->{$detailName}; } $params[$index] = $details->{$detailName}; } else { $values[$index] = $params[$index] = $details->{$detailName}; } } else { $detailName = "website-{$id}-{$fieldName}"; $url = CRM_Utils_System::fixURL($details->{$detailName}); if ($details->{$detailName}) { $websiteTypeId = "website-{$id}-website_type_id"; $websiteType = $websiteTypes[$details->{$websiteTypeId}]; $values[$index] = "<a href=\"{$url}\">{$details->{$detailName}} ( {$websiteType} )</a>"; } else { $values[$index] = ''; } } } if (CRM_Utils_Array::value('visibility', $field) == 'Public Pages and Listings' && CRM_Core_Permission::check('profile listings and forms')) { if (CRM_Utils_System::isNull($params[$index])) { $params[$index] = $values[$index]; } if (!isset($params[$index])) { continue; } if (!$customFieldName) { $fieldName = $field['name']; } else { $fieldName = $customFieldName; } $url = NULL; if (CRM_Core_BAO_CustomField::getKeyID($field['name'])) { $htmlType = $field['html_type']; if ($htmlType == 'Link') { $url = $params[$index]; } elseif (in_array($htmlType, array('CheckBox', 'Multi-Select', 'AdvMulti-Select', 'Multi-Select State/Province', 'Multi-Select Country'))) { $valSeperator = CRM_Core_DAO::VALUE_SEPARATOR; $selectedOptions = explode($valSeperator, $params[$index]); foreach ($selectedOptions as $key => $multiOption) { if ($multiOption) { $url[] = CRM_Utils_System::url('civicrm/profile', 'reset=1&force=1&gid=' . $field['group_id'] . '&' . urlencode($fieldName) . '=' . urlencode($multiOption)); } } } else { $url = CRM_Utils_System::url('civicrm/profile', 'reset=1&force=1&gid=' . $field['group_id'] . '&' . urlencode($fieldName) . '=' . urlencode($params[$index])); } } else { $url = CRM_Utils_System::url('civicrm/profile', 'reset=1&force=1&gid=' . $field['group_id'] . '&' . urlencode($fieldName) . '=' . urlencode($params[$index])); } if ($url && !empty($values[$index]) && $searchable) { if (is_array($url) && !empty($url)) { $links = array(); $eachMultiValue = explode(', ', $values[$index]); foreach ($eachMultiValue as $key => $valueLabel) { $links[] = '<a href="' . $url[$key] . '">' . $valueLabel . '</a>'; } $values[$index] = implode(', ', $links); } else { $values[$index] = '<a href="' . $url . '">' . $values[$index] . '</a>'; } } } } }
/** * Function to actually build the form * * @return void * @access public */ public function buildQuickForm() { if ($this->_action & CRM_Core_Action::DELETE) { $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete Profile Field'), 'spacing' => ' ', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel')))); return; } if (isset($this->_id)) { $params = array('id' => $this->_id); CRM_Core_BAO_UFField::retrieve($params, $defaults); // set it to null if so (avoids crappy E_NOTICE errors below $defaults['location_type_id'] = CRM_Utils_Array::value('location_type_id', $defaults); $specialFields = array('street_address', 'supplemental_address_1', 'supplemental_address_2', 'city', 'postal_code', 'postal_code_suffix', 'geo_code_1', 'geo_code_2', 'state_province', 'country', 'county', 'phone', 'email', 'im', 'address_name'); if (!$defaults['location_type_id'] && in_array($defaults['field_name'], $specialFields)) { $defaults['location_type_id'] = 0; } $defaults['field_name'] = array($defaults['field_type'], $defaults['field_name'], $defaults['location_type_id'], CRM_Utils_Array::value('phone_type_id', $defaults)); $this->_gid = $defaults['uf_group_id']; } else { $defaults['is_active'] = 1; } if ($this->_action & CRM_Core_Action::ADD) { $fieldValues = array('uf_group_id' => $this->_gid); $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_UFField', $fieldValues); } // lets trim all the whitespace $this->applyFilter('__ALL__', 'trim'); //hidden field to catch the group id in profile $this->add('hidden', 'group_id', $this->_gid); //hidden field to catch the field id in profile $this->add('hidden', 'field_id', $this->_id); $fields = array(); $fields['Individual'] =& CRM_Contact_BAO_Contact::importableFields('Individual', false, false, true); $fields['Household'] =& CRM_Contact_BAO_Contact::importableFields('Household', false, false, true); $fields['Organization'] =& CRM_Contact_BAO_Contact::importableFields('Organization', false, false, true); // add current employer for individuals $fields['Individual']['current_employer'] = array('name' => 'organization_name', 'title' => ts('Current Employer')); // unset unwanted fields $unsetFieldArray = array('note', 'email_greeting_custom', 'postal_greeting_custom', 'addressee_custom', 'id'); foreach ($unsetFieldArray as $value) { unset($fields['Individual'][$value]); unset($fields['Household'][$value]); unset($fields['Organization'][$value]); } require_once 'CRM/Core/BAO/Preferences.php'; $addressOptions = CRM_Core_BAO_Preferences::valueOptions('address_options', true, null, true); if (!$addressOptions['county']) { unset($fields['Individual']['county']); unset($fields['Household']['county']); unset($fields['Organization']['county']); } //build the common contact fields array CRM-3037. foreach ($fields['Individual'] as $key => $value) { if (CRM_Utils_Array::value($key, $fields['Household']) && CRM_Utils_Array::value($key, $fields['Organization'])) { $fields['Contact'][$key] = $value; //as we move common fields to contacts. There fore these fields //are unset from resoective array's. unset($fields['Individual'][$key]); unset($fields['Household'][$key]); unset($fields['Organization'][$key]); } } // add current employer for individuals $fields['Contact']['id'] = array('name' => 'id', 'title' => ts('Internal Contact ID')); unset($fields['Contact']['contact_type']); // since we need a hierarchical list to display contact types & subtypes, // this is what we going to display in first selector $contactTypes = CRM_Contact_BAO_ContactType::getSelectElements(false, false); unset($contactTypes['']); // include Subtypes For Profile $subTypes = CRM_Contact_BAO_ContactType::subTypeInfo(); foreach ($subTypes as $name => $val) { //custom fields for sub type $subTypeFields = CRM_Core_BAO_CustomField::getFieldsForImport($name); if (array_key_exists($val['parent'], $fields)) { $fields[$name] = $fields[$val['parent']] + $subTypeFields; } else { $fields[$name] = $subTypeFields; } } unset($subTypes); if (CRM_Core_Permission::access('Quest')) { require_once 'CRM/Quest/BAO/Student.php'; $fields['Student'] =& CRM_Quest_BAO_Student::exportableFields(); } if (CRM_Core_Permission::access('CiviContribute')) { $contribFields =& CRM_Contribute_BAO_Contribution::getContributionFields(); if (!empty($contribFields)) { unset($contribFields['is_test']); unset($contribFields['is_pay_later']); unset($contribFields['contribution_id']); $fields['Contribution'] =& $contribFields; } } if (CRM_Core_Permission::access('CiviEvent')) { require_once 'CRM/Event/BAO/Query.php'; $participantFields =& CRM_Event_BAO_Query::getParticipantFields(true); if (!empty($participantFields)) { unset($participantFields['external_identifier']); unset($participantFields['event_id']); unset($participantFields['participant_contact_id']); unset($participantFields['participant_is_test']); unset($participantFields['participant_fee_level']); unset($participantFields['participant_id']); unset($participantFields['participant_is_pay_later']); $fields['Participant'] =& $participantFields; } } if (CRM_Core_Permission::access('CiviMember')) { require_once 'CRM/Member/BAO/Membership.php'; $membershipFields =& CRM_Member_BAO_Membership::getMembershipFields(); unset($membershipFields['membership_id']); unset($membershipFields['join_date']); unset($membershipFields['membership_start_date']); unset($membershipFields['membership_type_id']); unset($membershipFields['membership_end_date']); unset($membershipFields['member_is_test']); unset($membershipFields['is_override']); unset($membershipFields['status_id']); unset($membershipFields['member_is_pay_later']); $fields['Membership'] =& $membershipFields; } $noSearchable = array(); foreach ($fields as $key => $value) { foreach ($value as $key1 => $value1) { //CRM-2676, replacing the conflict for same custom field name from different custom group. require_once 'CRM/Core/BAO/CustomField.php'; if ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($key1)) { $customGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $customFieldId, 'custom_group_id'); $customGroupName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $customGroupId, 'title'); $this->_mapperFields[$key][$key1] = $value1['title'] . ' :: ' . $customGroupName; } else { $this->_mapperFields[$key][$key1] = $value1['title']; } $hasLocationTypes[$key][$key1] = CRM_Utils_Array::value('hasLocationType', $value1); // hide the 'is searchable' field for 'File' custom data if (isset($value1['data_type']) && isset($value1['html_type']) && ($value1['data_type'] == 'File' && $value1['html_type'] == 'File' || $value1['data_type'] == 'Link' && $value1['html_type'] == 'Link')) { if (!in_array($value1['title'], $noSearchable)) { $noSearchable[] = $value1['title']; } } } } $this->assign('noSearchable', $noSearchable); require_once 'CRM/Core/BAO/LocationType.php'; $this->_location_types =& CRM_Core_PseudoConstant::locationType(); $defaultLocationType =& CRM_Core_BAO_LocationType::getDefault(); /* FIXME: dirty hack to make the default option show up first. This * avoids a mozilla browser bug with defaults on dynamically constructed * selector widgets. */ if ($defaultLocationType) { $defaultLocation = $this->_location_types[$defaultLocationType->id]; unset($this->_location_types[$defaultLocationType->id]); $this->_location_types = array($defaultLocationType->id => $defaultLocation) + $this->_location_types; } $this->_location_types = array('Primary') + $this->_location_types; $contactTypes = !empty($contactTypes) ? array('Contact' => 'Contacts') + $contactTypes : array(); $sel1 = array('' => '- select -') + $contactTypes; if (CRM_Core_Permission::access('Quest')) { $sel1['Student'] = 'Students'; } if (CRM_Core_Permission::access('CiviEvent')) { $sel1['Participant'] = 'Participants'; } if (!empty($contribFields)) { $sel1['Contribution'] = 'Contributions'; } if (!empty($membershipFields)) { $sel1['Membership'] = 'Membership'; } foreach ($sel1 as $key => $sel) { if ($key) { $sel2[$key] = $this->_mapperFields[$key]; } } $sel3[''] = null; $phoneTypes = CRM_Core_PseudoConstant::phoneType(); ksort($phoneTypes); foreach ($sel1 as $k => $sel) { if ($k) { foreach ($this->_location_types as $key => $value) { $sel4[$k]['phone'][$key] =& $phoneTypes; } } } foreach ($sel1 as $k => $sel) { if ($k) { if (is_array($this->_mapperFields[$k])) { foreach ($this->_mapperFields[$k] as $key => $value) { if ($hasLocationTypes[$k][$key]) { $sel3[$k][$key] = $this->_location_types; } else { $sel3[$key] = null; } } } } } $this->_defaults = array(); $js = "<script type='text/javascript'>\n"; $formName = "document.{$this->_name}"; $alreadyMixProfile = false; if (CRM_Core_BAO_UFField::checkProfileType($this->_gid)) { $alreadyMixProfile = true; } $this->assign('alreadyMixProfile', $alreadyMixProfile); $attributes = array('onclick' => "showLabel();mixProfile();", 'onblur' => 'showLabel();mixProfile();'); $sel =& $this->addElement('hierselect', "field_name", ts('Field Name'), $attributes); $formValues = array(); $formValues = $this->exportValues(); if (empty($formValues)) { for ($k = 1; $k < 4; $k++) { if (!$defaults['field_name'][$k]) { $js .= "{$formName}['field_name[{$k}]'].style.display = 'none';\n"; } } } else { if (!empty($formValues['field_name'])) { foreach ($formValues['field_name'] as $value) { for ($k = 1; $k < 4; $k++) { if (!isset($formValues['field_name'][$k]) || !$formValues['field_name'][$k]) { $js .= "{$formName}['field_name[{$k}]'].style.display = 'none';\n"; } else { $js .= "{$formName}['field_name[{$k}]'].style.display = '';\n"; } } } } else { for ($k = 1; $k < 4; $k++) { if (!isset($defaults['field_name'][$k])) { $js .= "{$formName}['field_name[{$k}]'].style.display = 'none';\n"; } } } } foreach ($sel2 as $k => $v) { if (is_array($sel2[$k])) { asort($sel2[$k]); } } $sel->setOptions(array($sel1, $sel2, $sel3, $sel4)); $js .= "</script>\n"; $this->assign('initHideBoxes', $js); $this->add('select', 'visibility', ts('Visibility'), CRM_Core_SelectValues::ufVisibility(), true, array("onChange" => "showHideSeletorSearch(this.value);")); //CRM-4363 $js = array('onclick' => "mixProfile();"); // should the field appear in selectors (as a column)? $this->add('checkbox', 'in_selector', ts('Results Column?'), null, null, $js); $this->add('checkbox', 'is_searchable', ts('Searchable?'), null, null, $js); // weight $this->add('text', 'weight', ts('Order'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField', 'weight'), true); $this->addRule('weight', ts('is a numeric field'), 'numeric'); $this->add('textarea', 'help_post', ts('Field Help'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField', 'help_post')); // listings title $this->add('text', 'listings_title', ts('Listings Title'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField', 'listings_title')); $this->addRule('listings_title', ts('Please enter a valid title for this field when displayed in user listings.'), 'title'); $this->add('checkbox', 'is_required', ts('Required?')); $this->add('checkbox', 'is_active', ts('Active?')); $this->add('checkbox', 'is_view', ts('View Only?')); // $this->add( 'checkbox', 'is_registration', ts( 'Display in Registration Form?' ) ); //$this->add( 'checkbox', 'is_match' , ts( 'Key to Match Contacts?' ) ); $this->add('text', 'label', ts('Field Label'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField', 'label')); $js = null; if ($this->_hasSearchableORInSelector) { $js = array('onclick' => "return verify( );"); } // add buttons $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'isDefault' => true, 'js' => $js), array('type' => 'next', 'name' => ts('Save and New'), 'subName' => 'new', 'js' => $js), array('type' => 'cancel', 'name' => ts('Cancel')))); $this->addFormRule(array('CRM_UF_Form_Field', 'formRule'), $this); // if view mode pls freeze it with the done button. if ($this->_action & CRM_Core_Action::VIEW) { $this->freeze(); $this->addElement('button', 'done', ts('Done'), array('onclick' => "location.href='civicrm/admin/uf/group/field?reset=1&action=browse&gid=" . $this->_gid . "'")); } $this->setDefaults($defaults); }
/** * Build the form object. * * * @return void */ public function buildQuickForm() { $this->applyFilter('__ALL__', 'trim'); $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_CustomGroup'); //title $this->add('text', 'title', ts('Set Name'), $attributes['title'], TRUE); //Fix for code alignment, CRM-3058 $contactTypes = array('Contact', 'Individual', 'Household', 'Organization'); $this->assign('contactTypes', json_encode($contactTypes)); $sel1 = array("" => ts("- select -")) + CRM_Core_SelectValues::customGroupExtends(); $sel2 = array(); $activityType = CRM_Core_PseudoConstant::activityType(FALSE, TRUE, FALSE, 'label', TRUE); $eventType = CRM_Core_OptionGroup::values('event_type'); $grantType = CRM_Core_OptionGroup::values('grant_type'); $campaignTypes = CRM_Campaign_PseudoConstant::campaignType(); $membershipType = CRM_Member_BAO_MembershipType::getMembershipTypes(FALSE); $participantRole = CRM_Core_OptionGroup::values('participant_role'); $relTypeInd = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, 'Individual'); $relTypeOrg = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, 'Organization'); $relTypeHou = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, 'Household'); ksort($sel1); asort($activityType); asort($eventType); asort($grantType); asort($membershipType); asort($participantRole); $allRelationshipType = array(); $allRelationshipType = array_merge($relTypeInd, $relTypeOrg); $allRelationshipType = array_merge($allRelationshipType, $relTypeHou); //adding subtype specific relationships CRM-5256 $subTypes = CRM_Contact_BAO_ContactType::subTypeInfo(); foreach ($subTypes as $subType => $val) { $subTypeRelationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, $val['parent'], FALSE, 'label', TRUE, $subType); $allRelationshipType = array_merge($allRelationshipType, $subTypeRelationshipTypes); } $sel2['Event'] = $eventType; $sel2['Grant'] = $grantType; $sel2['Activity'] = $activityType; $sel2['Campaign'] = $campaignTypes; $sel2['Membership'] = $membershipType; $sel2['ParticipantRole'] = $participantRole; $sel2['ParticipantEventName'] = CRM_Event_PseudoConstant::event(NULL, FALSE, "( is_template IS NULL OR is_template != 1 )"); $sel2['ParticipantEventType'] = $eventType; $sel2['Contribution'] = CRM_Contribute_PseudoConstant::financialType(); $sel2['Relationship'] = $allRelationshipType; $sel2['Individual'] = CRM_Contact_BAO_ContactType::subTypePairs('Individual', FALSE, NULL); $sel2['Household'] = CRM_Contact_BAO_ContactType::subTypePairs('Household', FALSE, NULL); $sel2['Organization'] = CRM_Contact_BAO_ContactType::subTypePairs('Organization', FALSE, NULL); CRM_Core_BAO_CustomGroup::getExtendedObjectTypes($sel2); foreach ($sel2 as $main => $sub) { if (!empty($sel2[$main])) { if ($main == 'Relationship') { $relName = self::getFormattedList($sel2[$main]); $sel2[$main] = array('' => ts("- Any -")) + $relName; } else { $sel2[$main] = array('' => ts("- Any -")) + $sel2[$main]; } } } $cSubTypes = CRM_Core_Component::contactSubTypes(); if (!empty($cSubTypes)) { $contactSubTypes = array(); foreach ($cSubTypes as $key => $value) { $contactSubTypes[$key] = $key; } $sel2['Contact'] = array("" => "- Any -") + $contactSubTypes; } else { if (!isset($this->_id)) { $formName = 'document.forms.' . $this->_name; $js = "<script type='text/javascript'>\n"; $js .= "{$formName}['extends_1'].style.display = 'none';\n"; $js .= "</script>"; $this->assign('initHideBlocks', $js); } } $sel =& $this->add('hierselect', 'extends', ts('Used For'), array('name' => 'extends[0]', 'style' => 'vertical-align: top;'), TRUE); $sel->setOptions(array($sel1, $sel2)); if (is_a($sel->_elements[1], 'HTML_QuickForm_select')) { // make second selector a multi-select - $sel->_elements[1]->setMultiple(TRUE); $sel->_elements[1]->setSize(5); } if ($this->_action == CRM_Core_Action::UPDATE) { $subName = CRM_Utils_Array::value('extends_entity_column_id', $this->_defaults); if ($this->_defaults['extends'] == 'Participant') { if ($subName == 1) { $this->_defaults['extends'] = 'ParticipantRole'; } elseif ($subName == 2) { $this->_defaults['extends'] = 'ParticipantEventName'; } elseif ($subName == 3) { $this->_defaults['extends'] = 'ParticipantEventType'; } } //allow to edit settings if custom set is empty CRM-5258 $this->_isGroupEmpty = CRM_Core_BAO_CustomGroup::isGroupEmpty($this->_id); if (!$this->_isGroupEmpty) { if (!empty($this->_subtypes)) { // we want to allow adding / updating subtypes for this case, // and therefore freeze the first selector only. $sel->_elements[0]->freeze(); } else { // freeze both the selectors $sel->freeze(); } } $this->assign('isCustomGroupEmpty', $this->_isGroupEmpty); $this->assign('gid', $this->_id); } $this->assign('defaultSubtypes', json_encode($this->_subtypes)); // help text $this->add('wysiwyg', 'help_pre', ts('Pre-form Help'), $attributes['help_pre']); $this->add('wysiwyg', 'help_post', ts('Post-form Help'), $attributes['help_post']); // weight $this->add('text', 'weight', ts('Order'), $attributes['weight'], TRUE); $this->addRule('weight', ts('is a numeric field'), 'numeric'); // display style $this->add('select', 'style', ts('Display Style'), CRM_Core_SelectValues::customGroupStyle()); // is this set collapsed or expanded ? $this->addElement('checkbox', 'collapse_display', ts('Collapse this set on initial display')); // is this set collapsed or expanded ? in advanced search $this->addElement('checkbox', 'collapse_adv_display', ts('Collapse this set in Advanced Search')); // is this set active ? $this->addElement('checkbox', 'is_active', ts('Is this Custom Data Set active?')); // does this set have multiple record? $multiple = $this->addElement('checkbox', 'is_multiple', ts('Does this Custom Field Set allow multiple records?'), NULL); // $min_multiple = $this->add('text', 'min_multiple', ts('Minimum number of multiple records'), $attributes['min_multiple'] ); // $this->addRule('min_multiple', ts('is a numeric field') , 'numeric'); $max_multiple = $this->add('text', 'max_multiple', ts('Maximum number of multiple records'), $attributes['max_multiple']); $this->addRule('max_multiple', ts('is a numeric field'), 'numeric'); //allow to edit settings if custom set is empty CRM-5258 $this->assign('isGroupEmpty', $this->_isGroupEmpty); if (!$this->_isGroupEmpty) { $multiple->freeze(); //$min_multiple->freeze(); $max_multiple->freeze(); } $this->assign('showStyle', FALSE); $this->assign('showMultiple', FALSE); $buttons = array(array('type' => 'next', 'name' => ts('Save'), 'spacing' => ' ', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))); if (!$this->_isGroupEmpty && !empty($this->_subtypes)) { $buttons[0]['class'] = 'crm-warnDataLoss'; } $this->addButtons($buttons); // TODO: Is this condition ever true? Can this code be removed? if ($this->_action & CRM_Core_Action::VIEW) { $this->freeze(); $this->addElement('button', 'done', ts('Done'), array('onclick' => "location.href='civicrm/admin/custom/group?reset=1&action=browse'")); } }
/** * Build the mapping form. * * @param CRM_Core_Form $form * @param string $mappingType * (Export/Import/Search Builder). * @param int $mappingId * @param int $columnNo * @param int $blockCount * (no of blocks shown). * @param NULL $exportMode * * @return void */ public static function buildMappingForm(&$form, $mappingType = 'Export', $mappingId = NULL, $columnNo, $blockCount = 3, $exportMode = NULL) { if ($mappingType == 'Export') { $name = "Map"; $columnCount = array('1' => $columnNo); } elseif ($mappingType == 'Search Builder') { $name = "Builder"; $columnCount = $columnNo; } //get the saved mapping details if ($mappingType == 'Export') { $form->applyFilter('saveMappingName', 'trim'); //to save the current mappings if (!isset($mappingId)) { $saveDetailsName = ts('Save this field mapping'); $form->add('text', 'saveMappingName', ts('Name')); $form->add('text', 'saveMappingDesc', ts('Description')); } else { $form->assign('loadedMapping', $mappingId); $params = array('id' => $mappingId); $temp = array(); $mappingDetails = CRM_Core_BAO_Mapping::retrieve($params, $temp); $form->assign('savedName', $mappingDetails->name); $form->add('hidden', 'mappingId', $mappingId); $form->addElement('checkbox', 'updateMapping', ts('Update this field mapping'), NULL); $saveDetailsName = ts('Save as a new field mapping'); $form->add('text', 'saveMappingName', ts('Name')); $form->add('text', 'saveMappingDesc', ts('Description')); } $form->addElement('checkbox', 'saveMapping', $saveDetailsName, NULL, array('onclick' => "showSaveDetails(this)")); $form->addFormRule(array('CRM_Export_Form_Map', 'formRule'), $form->get('mappingTypeId')); } elseif ($mappingType == 'Search Builder') { $form->addElement('submit', 'addBlock', ts('Also include contacts where'), array('class' => 'submit-link')); } $defaults = array(); $hasLocationTypes = array(); $hasRelationTypes = array(); $fields = array(); if ($mappingType == 'Export') { $required = TRUE; } elseif ($mappingType == 'Search Builder') { $required = FALSE; } $contactType = array('Individual', 'Household', 'Organization'); foreach ($contactType as $value) { $contactFields = CRM_Contact_BAO_Contact::exportableFields($value, FALSE, $required); $contactFields = array_merge($contactFields, CRM_Contact_BAO_Query_Hook::singleton()->getFields()); // exclude the address options disabled in the Address Settings $fields[$value] = CRM_Core_BAO_Address::validateAddressOptions($contactFields); ksort($fields[$value]); if ($mappingType == 'Export') { $relationships = array(); $relationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, $value); asort($relationshipTypes); foreach ($relationshipTypes as $key => $var) { list($type) = explode('_', $key); $relationships[$key]['title'] = $var; $relationships[$key]['headerPattern'] = '/' . preg_quote($var, '/') . '/'; $relationships[$key]['export'] = TRUE; $relationships[$key]['relationship_type_id'] = $type; $relationships[$key]['related'] = TRUE; $relationships[$key]['hasRelationType'] = 1; } if (!empty($relationships)) { $fields[$value] = array_merge($fields[$value], array('related' => array('title' => ts('- related contact info -'))), $relationships); } } } //get the current employer for mapping. if ($required) { $fields['Individual']['current_employer']['title'] = ts('Current Employer'); } // add component fields $compArray = array(); //we need to unset groups, tags, notes for component export if ($exportMode != CRM_Export_Form_Select::CONTACT_EXPORT) { foreach (array('groups', 'tags', 'notes') as $value) { unset($fields['Individual'][$value]); unset($fields['Household'][$value]); unset($fields['Organization'][$value]); } } if ($mappingType == 'Search Builder') { //build the common contact fields array. $fields['Contact'] = array(); foreach ($fields['Individual'] as $key => $value) { if (!empty($fields['Household'][$key]) && !empty($fields['Organization'][$key])) { $fields['Contact'][$key] = $value; unset($fields['Organization'][$key], $fields['Household'][$key], $fields['Individual'][$key]); } } if (array_key_exists('note', $fields['Contact'])) { $noteTitle = $fields['Contact']['note']['title']; $fields['Contact']['note']['title'] = $noteTitle . ': ' . ts('Body and Subject'); $fields['Contact']['note_body'] = array('title' => $noteTitle . ': ' . ts('Body Only'), 'name' => 'note_body'); $fields['Contact']['note_subject'] = array('title' => $noteTitle . ': ' . ts('Subject Only'), 'name' => 'note_subject'); } } if ($mappingType == 'Search Builder' || $exportMode == CRM_Export_Form_Select::CONTRIBUTE_EXPORT) { if (CRM_Core_Permission::access('CiviContribute')) { $fields['Contribution'] = CRM_Contribute_BAO_Contribution::exportableFields(); foreach (array('contribution_contact_id', 'contribution_soft_credit_name', 'contribution_soft_credit_amount', 'contribution_soft_credit_type', 'contribution_soft_credit_contribution_id') as $element) { unset($fields['Contribution'][$element]); } $compArray['Contribution'] = ts('Contribution'); } } if ($mappingType == 'Search Builder' || $exportMode == CRM_Export_Form_Select::EVENT_EXPORT) { if (CRM_Core_Permission::access('CiviEvent')) { $fields['Participant'] = CRM_Event_BAO_Participant::exportableFields(); //get the component payment fields if ($exportMode == CRM_Export_Form_Select::EVENT_EXPORT) { $componentPaymentFields = array(); foreach (CRM_Export_BAO_Export::componentPaymentFields() as $payField => $payTitle) { $componentPaymentFields[$payField] = array('title' => $payTitle); } $fields['Participant'] = array_merge($fields['Participant'], $componentPaymentFields); } $compArray['Participant'] = ts('Participant'); } } if ($mappingType == 'Search Builder' || $exportMode == CRM_Export_Form_Select::MEMBER_EXPORT) { if (CRM_Core_Permission::access('CiviMember')) { $fields['Membership'] = CRM_Member_BAO_Membership::getMembershipFields($exportMode); unset($fields['Membership']['membership_contact_id']); $compArray['Membership'] = ts('Membership'); } } if ($mappingType == 'Search Builder' || $exportMode == CRM_Export_Form_Select::PLEDGE_EXPORT) { if (CRM_Core_Permission::access('CiviPledge')) { $fields['Pledge'] = CRM_Pledge_BAO_Pledge::exportableFields(); unset($fields['Pledge']['pledge_contact_id']); $compArray['Pledge'] = ts('Pledge'); } } if ($mappingType == 'Search Builder' || $exportMode == CRM_Export_Form_Select::CASE_EXPORT) { if (CRM_Core_Permission::access('CiviCase')) { $fields['Case'] = CRM_Case_BAO_Case::exportableFields(); $compArray['Case'] = ts('Case'); $fields['Activity'] = CRM_Activity_BAO_Activity::exportableFields('Case'); $compArray['Activity'] = ts('Case Activity'); unset($fields['Case']['case_contact_id']); } } if ($mappingType == 'Search Builder' || $exportMode == CRM_Export_Form_Select::GRANT_EXPORT) { if (CRM_Core_Permission::access('CiviGrant')) { $fields['Grant'] = CRM_Grant_BAO_Grant::exportableFields(); unset($fields['Grant']['grant_contact_id']); if ($mappingType == 'Search Builder') { unset($fields['Grant']['grant_type_id']); } $compArray['Grant'] = ts('Grant'); } } if ($mappingType == 'Search Builder' || $exportMode == CRM_Export_Form_Select::ACTIVITY_EXPORT) { $fields['Activity'] = CRM_Activity_BAO_Activity::exportableFields('Activity'); $compArray['Activity'] = ts('Activity'); } //Contact Sub Type For export $contactSubTypes = array(); $subTypes = CRM_Contact_BAO_ContactType::subTypeInfo(); foreach ($subTypes as $subType => $val) { //adding subtype specific relationships CRM-5256 $csRelationships = array(); if ($mappingType == 'Export') { $subTypeRelationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, $val['parent'], FALSE, 'label', TRUE, $subType); foreach ($subTypeRelationshipTypes as $key => $var) { if (!array_key_exists($key, $fields[$val['parent']])) { list($type) = explode('_', $key); $csRelationships[$key]['title'] = $var; $csRelationships[$key]['headerPattern'] = '/' . preg_quote($var, '/') . '/'; $csRelationships[$key]['export'] = TRUE; $csRelationships[$key]['relationship_type_id'] = $type; $csRelationships[$key]['related'] = TRUE; $csRelationships[$key]['hasRelationType'] = 1; } } } $fields[$subType] = $fields[$val['parent']] + $csRelationships; //custom fields for sub type $subTypeFields = CRM_Core_BAO_CustomField::getFieldsForImport($subType); $fields[$subType] += $subTypeFields; if (!empty($subTypeFields) || !empty($csRelationships)) { $contactSubTypes[$subType] = $val['label']; } } unset($subTypes); foreach ($fields as $key => $value) { foreach ($value as $key1 => $value1) { //CRM-2676, replacing the conflict for same custom field name from different custom group. $customGroupName = self::getCustomGroupName($key1); if ($customGroupName) { $relatedMapperFields[$key][$key1] = $mapperFields[$key][$key1] = $customGroupName . ': ' . $value1['title']; } else { $relatedMapperFields[$key][$key1] = $mapperFields[$key][$key1] = $value1['title']; } if (isset($value1['hasLocationType'])) { $hasLocationTypes[$key][$key1] = $value1['hasLocationType']; } if (isset($value1['hasRelationType'])) { $hasRelationTypes[$key][$key1] = $value1['hasRelationType']; unset($relatedMapperFields[$key][$key1]); } } if (array_key_exists('related', $relatedMapperFields[$key])) { unset($relatedMapperFields[$key]['related']); } } $mapperKeys = array_keys($mapperFields); $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'); $defaultLocationType = CRM_Core_BAO_LocationType::getDefault(); // FIXME: dirty hack to make the default option show up first. This // avoids a mozilla browser bug with defaults on dynamically constructed // selector widgets. if ($defaultLocationType) { $defaultLocation = $locationTypes[$defaultLocationType->id]; unset($locationTypes[$defaultLocationType->id]); $locationTypes = array($defaultLocationType->id => $defaultLocation) + $locationTypes; } $locationTypes = array(' ' => ts('Primary')) + $locationTypes; // since we need a hierarchical list to display contact types & subtypes, // this is what we going to display in first selector $contactTypes = CRM_Contact_BAO_ContactType::getSelectElements(FALSE, FALSE); if ($mappingType == 'Search Builder') { $contactTypes = array('Contact' => ts('Contacts')) + $contactTypes; } $sel1 = array('' => ts('- select record type -')) + $contactTypes + $compArray; foreach ($sel1 as $key => $sel) { if ($key) { // sort everything BUT the contactType which is sorted seperately by // an initial commit of CRM-13278 (check ksort above) if (!in_array($key, $contactType)) { asort($mapperFields[$key]); } $sel2[$key] = array('' => ts('- select field -')) + $mapperFields[$key]; } } $sel3[''] = NULL; $sel5[''] = NULL; $phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id'); $imProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'); asort($phoneTypes); foreach ($sel1 as $k => $sel) { if ($k) { foreach ($locationTypes as $key => $value) { if (trim($key) != '') { $sel4[$k]['phone'][$key] =& $phoneTypes; $sel4[$k]['im'][$key] =& $imProviders; } } } } foreach ($sel1 as $k => $sel) { if ($k) { foreach ($mapperFields[$k] as $key => $value) { if (isset($hasLocationTypes[$k][$key])) { $sel3[$k][$key] = $locationTypes; } else { $sel3[$key] = NULL; } } } } // Array for core fields and relationship custom data $relationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, NULL, TRUE); if ($mappingType == 'Export') { foreach ($sel1 as $k => $sel) { if ($k) { foreach ($mapperFields[$k] as $field => $dontCare) { if (isset($hasRelationTypes[$k][$field])) { list($id, $first, $second) = explode('_', $field); // FIX ME: For now let's not expose custom data related to relationship $relationshipCustomFields = array(); //$relationshipCustomFields = self::getRelationTypeCustomGroupData( $id ); //asort($relationshipCustomFields); $relationshipType = new CRM_Contact_BAO_RelationshipType(); $relationshipType->id = $id; if ($relationshipType->find(TRUE)) { $direction = "contact_sub_type_{$second}"; if (isset($relationshipType->{$direction})) { $relatedFields = array_merge((array) $relatedMapperFields[$relationshipType->{$direction}], (array) $relationshipCustomFields); } else { $target_type = 'contact_type_' . $second; $relatedFields = array_merge((array) $relatedMapperFields[$relationshipType->{$target_type}], (array) $relationshipCustomFields); } } $relationshipType->free(); asort($relatedFields); $sel5[$k][$field] = $relatedFields; } } } } //Location Type for relationship fields foreach ($sel5 as $k => $v) { if ($v) { foreach ($v as $rel => $fields) { foreach ($fields as $field => $fieldLabel) { if (isset($hasLocationTypes[$k][$field])) { $sel6[$k][$rel][$field] = $locationTypes; } } } } } //PhoneTypes for relationship fields $sel7[''] = NULL; foreach ($sel6 as $k => $rel) { if ($k) { foreach ($rel as $phonekey => $phonevalue) { foreach ($locationTypes as $locType => $loc) { if (trim($locType) != '') { $sel7[$k][$phonekey]['phone'][$locType] =& $phoneTypes; $sel7[$k][$phonekey]['im'][$locType] =& $imProviders; } } } } } } //special fields that have location, hack for primary location $specialFields = array('street_address', 'supplemental_address_1', 'supplemental_address_2', 'city', 'postal_code', 'postal_code_suffix', 'geo_code_1', 'geo_code_2', 'state_province', 'country', 'phone', 'email', 'im'); if (isset($mappingId)) { $colCnt = 0; list($mappingName, $mappingContactType, $mappingLocation, $mappingPhoneType, $mappingImProvider, $mappingRelation, $mappingOperator, $mappingValue) = CRM_Core_BAO_Mapping::getMappingFields($mappingId); $blkCnt = count($mappingName); if ($blkCnt >= $blockCount) { $blockCount = $blkCnt + 1; } for ($x = 1; $x < $blockCount; $x++) { if (isset($mappingName[$x])) { $colCnt = count($mappingName[$x]); if ($colCnt >= $columnCount[$x]) { $columnCount[$x] = $colCnt; } } } } $form->_blockCount = $blockCount; $form->_columnCount = $columnCount; $form->set('blockCount', $form->_blockCount); $form->set('columnCount', $form->_columnCount); $defaults = $noneArray = $nullArray = array(); //used to warn for mismatch column count or mismatch mapping $warning = 0; for ($x = 1; $x < $blockCount; $x++) { for ($i = 0; $i < $columnCount[$x]; $i++) { $sel =& $form->addElement('hierselect', "mapper[{$x}][{$i}]", ts('Mapper for Field %1', array(1 => $i)), NULL); $jsSet = FALSE; if (isset($mappingId)) { $locationId = isset($mappingLocation[$x][$i]) ? $mappingLocation[$x][$i] : 0; if (isset($mappingName[$x][$i])) { if (is_array($mapperFields[$mappingContactType[$x][$i]])) { if (isset($mappingRelation[$x][$i])) { $contactDetails = strtolower(str_replace(" ", "_", $mappingName[$x][$i])); $relLocationId = isset($mappingLocation[$x][$i]) ? $mappingLocation[$x][$i] : 0; if (!$relLocationId && in_array($mappingName[$x][$i], $specialFields)) { $relLocationId = " "; } $relPhoneType = isset($mappingPhoneType[$x][$i]) ? $mappingPhoneType[$x][$i] : NULL; $defaults["mapper[{$x}][{$i}]"] = array($mappingContactType[$x][$i], $mappingRelation[$x][$i], $locationId, $phoneType, $mappingName[$x][$i], $relLocationId, $relPhoneType); if (!$locationId) { $noneArray[] = array($x, $i, 2); } if (!$phoneType && !$imProvider) { $noneArray[] = array($x, $i, 3); } if (!$mappingName[$x][$i]) { $noneArray[] = array($x, $i, 4); } if (!$relLocationId) { $noneArray[] = array($x, $i, 5); } if (!$relPhoneType) { $noneArray[] = array($x, $i, 6); } $noneArray[] = array($x, $i, 2); } else { $phoneType = isset($mappingPhoneType[$x][$i]) ? $mappingPhoneType[$x][$i] : NULL; $imProvider = isset($mappingImProvider[$x][$i]) ? $mappingImProvider[$x][$i] : NULL; if (!$locationId && in_array($mappingName[$x][$i], $specialFields)) { $locationId = " "; } $defaults["mapper[{$x}][{$i}]"] = array($mappingContactType[$x][$i], $mappingName[$x][$i], $locationId, $phoneType); if (!$mappingName[$x][$i]) { $noneArray[] = array($x, $i, 1); } if (!$locationId) { $noneArray[] = array($x, $i, 2); } if (!$phoneType && !$imProvider) { $noneArray[] = array($x, $i, 3); } $noneArray[] = array($x, $i, 4); $noneArray[] = array($x, $i, 5); $noneArray[] = array($x, $i, 6); } $jsSet = TRUE; if (CRM_Utils_Array::value($i, CRM_Utils_Array::value($x, $mappingOperator))) { $defaults["operator[{$x}][{$i}]"] = CRM_Utils_Array::value($i, $mappingOperator[$x]); } if (CRM_Utils_Array::value($i, CRM_Utils_Array::value($x, $mappingValue))) { $defaults["value[{$x}][{$i}]"] = CRM_Utils_Array::value($i, $mappingValue[$x]); } } } } //Fix for Search Builder if ($mappingType == 'Export') { $j = 7; } else { $j = 4; } $formValues = $form->exportValues(); if (!$jsSet) { if (empty($formValues)) { // Incremented length for third select box(relationship type) for ($k = 1; $k < $j; $k++) { $noneArray[] = array($x, $i, $k); } } else { if (!empty($formValues['mapper'][$x])) { foreach ($formValues['mapper'][$x] as $value) { for ($k = 1; $k < $j; $k++) { if (!isset($formValues['mapper'][$x][$i][$k]) || !$formValues['mapper'][$x][$i][$k]) { $noneArray[] = array($x, $i, $k); } else { $nullArray[] = array($x, $i, $k); } } } } else { for ($k = 1; $k < $j; $k++) { $noneArray[] = array($x, $i, $k); } } } } //Fix for Search Builder if ($mappingType == 'Export') { if (!isset($mappingId) || $i >= count(reset($mappingName))) { if (isset($formValues['mapper']) && isset($formValues['mapper'][$x][$i][1]) && array_key_exists($formValues['mapper'][$x][$i][1], $relationshipTypes)) { $sel->setOptions(array($sel1, $sel2, $sel5, $sel6, $sel7, $sel3, $sel4)); } else { $sel->setOptions(array($sel1, $sel2, $sel3, $sel4, $sel5, $sel6, $sel7)); } } else { $sel->setOptions(array($sel1, $sel2, $sel3, $sel4, $sel5, $sel6, $sel7)); } } else { $sel->setOptions(array($sel1, $sel2, $sel3, $sel4)); } if ($mappingType == 'Search Builder') { //CRM -2292, restricted array set $operatorArray = array('' => ts('-operator-')) + CRM_Core_SelectValues::getSearchBuilderOperators(); $form->add('select', "operator[{$x}][{$i}]", '', $operatorArray); $form->add('text', "value[{$x}][{$i}]", ''); } } //end of columnCnt for if ($mappingType == 'Search Builder') { $title = ts('Another search field'); } else { $title = ts('Select more fields'); } $form->addElement('submit', "addMore[{$x}]", $title, array('class' => 'submit-link')); } //end of block for $js = "<script type='text/javascript'>\n"; $formName = "document.{$name}"; if (!empty($nullArray)) { $js .= "var nullArray = ["; $elements = array(); $seen = array(); foreach ($nullArray as $element) { $key = "{$element[0]}, {$element[1]}, {$element[2]}"; if (!isset($seen[$key])) { $elements[] = "[{$key}]"; $seen[$key] = 1; } } $js .= implode(', ', $elements); $js .= "]"; $js .= "\n for (var i=0;i<nullArray.length;i++) {\n if ( {$formName}['mapper['+nullArray[i][0]+']['+nullArray[i][1]+']['+nullArray[i][2]+']'] ) {\n {$formName}['mapper['+nullArray[i][0]+']['+nullArray[i][1]+']['+nullArray[i][2]+']'].style.display = '';\n }\n }\n"; } if (!empty($noneArray)) { $js .= "var noneArray = ["; $elements = array(); $seen = array(); foreach ($noneArray as $element) { $key = "{$element[0]}, {$element[1]}, {$element[2]}"; if (!isset($seen[$key])) { $elements[] = "[{$key}]"; $seen[$key] = 1; } } $js .= implode(', ', $elements); $js .= "]"; $js .= "\n for (var i=0;i<noneArray.length;i++) {\n if ( {$formName}['mapper['+noneArray[i][0]+']['+noneArray[i][1]+']['+noneArray[i][2]+']'] ) {\n {$formName}['mapper['+noneArray[i][0]+']['+noneArray[i][1]+']['+noneArray[i][2]+']'].style.display = 'none';\n }\n }\n"; } $js .= "</script>\n"; $form->assign('initHideBoxes', $js); $form->assign('columnCount', $columnCount); $form->assign('blockCount', $blockCount); $form->setDefaults($defaults); $form->setDefaultAction('refresh'); }
/** * Implementation of hook_civicrm_uninstall */ function hrjob_civicrm_uninstall() { $subTypeInfo = CRM_Contact_BAO_ContactType::subTypeInfo('Organization'); $sub_type_name = array('Health Insurance Provider', 'Life Insurance Provider'); foreach ($sub_type_name as $sub_type_name) { $subTypeName = ucfirst(CRM_Utils_String::munge($sub_type_name)); $orid = array_key_exists($subTypeName, $subTypeInfo); if ($orid) { $id = $subTypeInfo[$subTypeName]['id']; CRM_Contact_BAO_ContactType::del($id); } } //delete job import navigation menu CRM_Core_DAO::executeQuery("DELETE FROM civicrm_navigation WHERE name IN ('jobImport','hoursType')"); CRM_Core_BAO_Navigation::resetNavigation(); //delete custom groups and field $customGroup = civicrm_api3('CustomGroup', 'getsingle', array('return' => "id", 'name' => "HRJob_Summary")); civicrm_api3('CustomGroup', 'delete', array('id' => $customGroup['id'])); //delete all option group and values CRM_Core_DAO::executeQuery("DELETE FROM civicrm_option_group WHERE name IN ('hrjob_contract_type', 'hrjob_level_type', 'hrjob_department', 'hrjob_hours_type', 'hrjob_pay_grade', 'hrjob_health_provider', 'hrjob_life_provider', 'hrjob_location', 'hrjob_pension_type', 'hrjob_region', 'hrjob_pay_scale')"); return _hrjob_civix_civicrm_uninstall(); }
/** * get subtypes given the contact type * * @param string $contactType * @return array $subTypes */ public static function getSubtypes($contactType) { $subTypes = array(); $types = CRM_Contact_BAO_ContactType::subTypeInfo($contactType); if (count($types) > 0) { foreach ($types as $type) { $subTypes[] = $type['name']; } } return $subTypes; }
/** * Function to actually build the form * * @param null * * @return void * @access public */ public function buildQuickForm() { $this->applyFilter('__ALL__', 'trim'); $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_CustomGroup'); //title $this->add('text', 'title', ts('Group Name'), $attributes['title'], true); $this->addRule('title', ts('Name already exists in Database.'), 'objectExists', array('CRM_Core_DAO_CustomGroup', $this->_id, 'title')); //Fix for code alignment, CRM-3058 require_once "CRM/Contribute/PseudoConstant.php"; require_once "CRM/Member/BAO/MembershipType.php"; require_once 'CRM/Event/PseudoConstant.php'; require_once "CRM/Contact/BAO/Relationship.php"; require_once 'CRM/Core/OptionGroup.php'; require_once 'CRM/Contact/BAO/ContactType.php'; $contactTypes = array('Contact', 'Individual', 'Household', 'Organization'); $this->assign('contactTypes', json_encode($contactTypes)); $sel1 = array("" => "- select -") + CRM_Core_SelectValues::customGroupExtends(); $sel2 = array(); $activityType = CRM_Core_PseudoConstant::activityType(false, true); $eventType = CRM_Core_OptionGroup::values('event_type'); $membershipType = CRM_Member_BAO_MembershipType::getMembershipTypes(false); $participantRole = CRM_Core_OptionGroup::values('participant_role'); $relTypeInd = CRM_Contact_BAO_Relationship::getContactRelationshipType(null, 'null', null, 'Individual'); $relTypeOrg = CRM_Contact_BAO_Relationship::getContactRelationshipType(null, 'null', null, 'Organization'); $relTypeHou = CRM_Contact_BAO_Relationship::getContactRelationshipType(null, 'null', null, 'Household'); ksort($sel1); asort($activityType); asort($eventType); asort($membershipType); asort($participantRole); $allRelationshipType = array(); $allRelationshipType = array_merge($relTypeInd, $relTypeOrg); $allRelationshipType = array_merge($allRelationshipType, $relTypeHou); //adding subtype specific relationships CRM-5256 $subTypes = CRM_Contact_BAO_ContactType::subTypeInfo(); foreach ($subTypes as $subType => $val) { $subTypeRelationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(null, null, null, $val['parent'], false, 'label', true, $subType); $allRelationshipType = array_merge($allRelationshipType, $subTypeRelationshipTypes); } $sel2['Event'] = $eventType; $sel2['Activity'] = $activityType; $sel2['Membership'] = $membershipType; $sel2['ParticipantRole'] = $participantRole; $sel2['ParticipantEventName'] = CRM_Event_PseudoConstant::event(null, false, "( is_template IS NULL OR is_template != 1 )"); $sel2['ParticipantEventType'] = $eventType; $sel2['Contribution'] = CRM_Contribute_PseudoConstant::contributionType(); $sel2['Relationship'] = $allRelationshipType; $sel2['Individual'] = CRM_Contact_BAO_ContactType::subTypePairs('Individual', false, null); $sel2['Household'] = CRM_Contact_BAO_ContactType::subTypePairs('Household', false, null); $sel2['Organization'] = CRM_Contact_BAO_ContactType::subTypePairs('Organization', false, null); foreach ($sel2 as $main => $sub) { if (!empty($sel2[$main])) { $sel2[$main] = array('' => ts("- Any -")) + $sel2[$main]; } } require_once "CRM/Core/Component.php"; $cSubTypes = CRM_Core_Component::contactSubTypes(); if (!empty($cSubTypes)) { $contactSubTypes = array(); foreach ($cSubTypes as $key => $value) { $contactSubTypes[$key] = $key; } $sel2['Contact'] = array("" => "-- Any --") + $contactSubTypes; } else { if (!isset($this->_id)) { $formName = 'document.forms.' . $this->_name; $js = "<script type='text/javascript'>\n"; $js .= "{$formName}['extends[1]'].style.display = 'none';\n"; $js .= "</script>"; $this->assign('initHideBlocks', $js); } } $sel =& $this->add('hierselect', 'extends', ts('Used For'), array('onClick' => 'showHideStyle();', 'name' => 'extends[0]', 'style' => 'vertical-align: top;'), true); $sel->setOptions(array($sel1, $sel2)); if (is_a($sel->_elements[1], 'HTML_QuickForm_select')) { // make second selector a multi-select - $sel->_elements[1]->setMultiple(true); $sel->_elements[1]->setSize(5); } if ($this->_action == CRM_Core_Action::UPDATE) { //allow to edit settings if custom group is empty CRM-5258 $this->_isGroupEmpty = CRM_Core_BAO_CustomGroup::isGroupEmpty($this->_id); if (!$this->_isGroupEmpty) { if (!empty($this->_subtypes) && count(array_intersect($this->_subtypes, $sel2[$this->_defaults['extends']])) < count($sel2[$this->_defaults['extends']])) { // we want to allow adding subtypes for this case, // and therefore freeze the first selector only. $sel->_elements[0]->freeze(); } else { // freeze both the selectors $sel->freeze(); } } $this->assign('gid', $this->_id); } // help text $this->addWysiwyg('help_pre', ts('Pre-form Help'), $attributes['help_pre']); $this->addWysiwyg('help_post', ts('Post-form Help'), $attributes['help_post']); // weight $this->add('text', 'weight', ts('Order'), $attributes['weight'], true); $this->addRule('weight', ts('is a numeric field'), 'numeric'); // display style $this->add('select', 'style', ts('Display Style'), CRM_Core_SelectValues::customGroupStyle()); // is this group collapsed or expanded ? $this->addElement('checkbox', 'collapse_display', ts('Collapse this group on initial display')); // is this group collapsed or expanded ? in advanced search $this->addElement('checkbox', 'collapse_adv_display', ts('Collapse this group in Advanced Search')); // is this group active ? $this->addElement('checkbox', 'is_active', ts('Is this Custom Data Group active?')); // does this group have multiple record? $multiple = $this->addElement('checkbox', 'is_multiple', ts('Does this Custom Data Group allow multiple records?'), null, array('onclick' => "showRange();")); // $min_multiple = $this->add('text', 'min_multiple', ts('Minimum number of multiple records'), $attributes['min_multiple'] ); // $this->addRule('min_multiple', ts('is a numeric field') , 'numeric'); $max_multiple = $this->add('text', 'max_multiple', ts('Maximum number of multiple records'), $attributes['max_multiple']); $this->addRule('max_multiple', ts('is a numeric field'), 'numeric'); //allow to edit settings if custom group is empty CRM-5258 $this->assign('isGroupEmpty', $this->_isGroupEmpty); if (!$this->_isGroupEmpty) { $multiple->freeze(); //$min_multiple->freeze(); $max_multiple->freeze(); } $this->assign('showStyle', false); $this->assign('showMultiple', false); $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'spacing' => ' ', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel')))); // views are implemented as frozen form if ($this->_action & CRM_Core_Action::VIEW) { $this->freeze(); $this->addElement('button', 'done', ts('Done'), array('onclick' => "location.href='civicrm/admin/custom/group?reset=1&action=browse'")); } }
public function upgrade_1108() { $this->ctx->log->info('Applying update 1108'); if (CRM_Core_DAO::checkFieldExists('civicrm_hrjob_health', 'provider') && CRM_Core_DAO::checkFieldExists('civicrm_hrjob_health', 'provider_life_insurance')) { $opt_grp_name = array('hrjob_health_provider' => array('name' => 'Health_Insurance_Provider', 'label' => ts('Health Insurance Provider'), 'column' => 'provider'), 'hrjob_life_provider' => array('name' => 'Life_Insurance_Provider', 'label' => ts('Life Insurance Provider'), 'column' => 'provider_life_insurance')); $org_id = array_search('Organization', CRM_Contact_BAO_ContactType::basicTypePairs(FALSE, 'id')); $orgSubType = CRM_Contact_BAO_ContactType::subTypeInfo('Organization'); foreach ($opt_grp_name as $oKey => $oValue) { $subID = array_key_exists($oValue['name'], $orgSubType); if (!$subID) { CRM_Contact_BAO_ContactType::add(array('parent_id' => $org_id, 'is_active' => 1, 'name' => $oValue['name'], 'label' => $oValue['label'])); } $options = CRM_Core_OptionGroup::values($oKey, TRUE, FALSE); foreach ($options as $orgKey => $orgValue) { $params = array('organization_name' => $orgValue, 'sort_name' => $orgValue, 'display_name' => $orgValue, 'legal_name' => $orgValue, 'contact_type' => 'Organization', 'contact_sub_type' => $oValue['name']); $result = civicrm_api3('contact', 'create', $params); if ($result['id']) { CRM_Core_DAO::executeQuery("UPDATE civicrm_hrjob_health SET {$oValue['column']} = {$result['id']} WHERE {$oValue['column']} LIKE '{$orgValue}'"); CRM_Core_DAO::executeQuery("UPDATE civicrm_hrjob_health SET {$oValue['column']} = NULL WHERE {$oValue['column']} = ''"); } } CRM_Core_OptionGroup::deleteAssoc($oKey); } CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_hrjob_health`\n MODIFY COLUMN `provider` int(10) unsigned DEFAULT NULL,\n MODIFY COLUMN `provider_life_insurance` int(10) unsigned DEFAULT NULL,\n ADD CONSTRAINT `FK_civicrm_hrjob_health_provider` FOREIGN KEY (`provider`) REFERENCES `civicrm_contact`(`id`) ON DELETE SET NULL,\n ADD CONSTRAINT `FK_civicrm_hrjob_health_provider_life_insurance` FOREIGN KEY (`provider_life_insurance`) REFERENCES `civicrm_contact`(`id`) ON DELETE SET NULL"); } return TRUE; }
/** * Clean and validate the filter before it is used in a db query. * * @param string $entityType * @param string $subType * * @return string * @throws \CRM_Core_Exception * @throws \CiviCRM_API3_Exception */ protected static function validateSubTypeByEntity($entityType, $subType) { $subType = trim($subType, CRM_Core_DAO::VALUE_SEPARATOR); if (is_numeric($subType)) { return $subType; } $contactTypes = CRM_Contact_BAO_ContactType::basicTypeInfo(TRUE); if ($entityType != 'Contact' && !array_key_exists($entityType, $contactTypes)) { throw new CRM_Core_Exception('Invalid Entity Filter'); } $subTypes = CRM_Contact_BAO_ContactType::subTypeInfo($entityType, TRUE); if (!array_key_exists($subType, $subTypes)) { throw new CRM_Core_Exception('Invalid Filter'); } return $subType; }