本文整理汇总了PHP中CRM_Contact_BAO_ContactType::subTypePairs方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Contact_BAO_ContactType::subTypePairs方法的具体用法?PHP CRM_Contact_BAO_ContactType::subTypePairs怎么用?PHP CRM_Contact_BAO_ContactType::subTypePairs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Contact_BAO_ContactType
的用法示例。
在下文中一共展示了CRM_Contact_BAO_ContactType::subTypePairs方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: import
/**
* handle the values in import mode
*
* @param int $onDuplicate the code for what action to take on duplicates
* @param array $values the array of values belonging to this line
*
* @return boolean the result of this processing
* @access public
*/
function import($onDuplicate, &$values, $doGeocodeAddress = false)
{
$config =& CRM_Core_Config::singleton();
$this->_unparsedStreetAddressContacts = array();
if (!$doGeocodeAddress) {
// CRM-5854, reset the geocode method to null to prevent geocoding
$config->geocodeMethod = null;
}
// first make sure this is a valid line
//$this->_updateWithId = false;
$response = $this->summary($values);
$statusFieldName = $this->_statusFieldName;
if ($response != CRM_Import_Parser::VALID) {
$importRecordParams = array($statusFieldName => 'INVALID', "{$statusFieldName}Msg" => "Invalid (Error Code: {$response})");
$this->updateImportRecord($values[count($values) - 1], $importRecordParams);
return $response;
}
$params =& $this->getActiveFieldParams();
$formatted = array('contact_type' => $this->_contactType);
static $contactFields = null;
if ($contactFields == null) {
require_once "CRM/Contact/DAO/Contact.php";
$contactFields =& CRM_Contact_DAO_Contact::import();
}
//check if external identifier exists in database
if (CRM_Utils_Array::value('external_identifier', $params) && (CRM_Utils_Array::value('id', $params) || in_array($onDuplicate, array(CRM_Import_Parser::DUPLICATE_SKIP, CRM_Import_Parser::DUPLICATE_NOCHECK)))) {
require_once "CRM/Contact/BAO/Contact.php";
if ($internalCid = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $params['external_identifier'], 'id', 'external_identifier')) {
if ($internalCid != CRM_Utils_Array::value('id', $params)) {
$errorMessage = ts('External Identifier already exists in database.');
array_unshift($values, $errorMessage);
$importRecordParams = array($statusFieldName => 'ERROR', "{$statusFieldName}Msg" => $errorMessage);
$this->updateImportRecord($values[count($values) - 1], $importRecordParams);
return CRM_Import_Parser::ERROR;
}
}
}
if (!empty($this->_contactSubType)) {
$params['contact_sub_type'] = $this->_contactSubType;
}
if ($subType = CRM_Utils_Array::value('contact_sub_type', $params)) {
if (CRM_Contact_BAO_ContactType::isExtendsContactType($subType, $this->_contactType, false, 'label')) {
$subTypes = CRM_Contact_BAO_ContactType::subTypePairs($this->_contactType, false, null);
$params['contact_sub_type'] = array_search($subType, $subTypes);
} elseif (!CRM_Contact_BAO_ContactType::isExtendsContactType($subType, $this->_contactType)) {
$message = "Mismatched or Invalid Contact SubType.";
array_unshift($values, $message);
return CRM_Import_Parser::NO_MATCH;
}
}
//get contact id to format common data in update/fill mode,
//if external identifier is present, CRM-4423
if ($this->_updateWithId && !CRM_Utils_Array::value('id', $params) && CRM_Utils_Array::value('external_identifier', $params)) {
if ($cid = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $params['external_identifier'], 'id', 'external_identifier')) {
$formatted['id'] = $cid;
}
}
//format common data, CRM-4062
$this->formatCommonData($params, $formatted, $contactFields);
$relationship = false;
$createNewContact = true;
// Support Match and Update Via Contact ID
if ($this->_updateWithId) {
$createNewContact = false;
if (!CRM_Utils_Array::value('id', $params) && CRM_Utils_Array::value('external_identifier', $params)) {
if ($cid) {
$params['id'] = $cid;
} else {
//update contact if dedupe found contact id, CRM-4148
$dedupeParams = $formatted;
//special case to check dedupe if external id present.
//if we send external id dedupe will stop.
unset($dedupeParams['external_identifier']);
$checkDedupe = _civicrm_duplicate_formatted_contact($dedupeParams);
if (civicrm_duplicate($checkDedupe)) {
$matchingContactIds = explode(',', $checkDedupe['error_message']['params'][0]);
if (count($matchingContactIds) == 1) {
$params['id'] = array_pop($matchingContactIds);
} else {
$message = "More than one matching contact found for given criteria.";
array_unshift($values, $message);
$this->_retCode = CRM_Import_Parser::NO_MATCH;
}
} else {
$createNewContact = true;
}
}
}
$error = _civicrm_duplicate_formatted_contact($formatted);
if (civicrm_duplicate($error)) {
$matchedIDs = explode(',', $error['error_message']['params'][0]);
//.........这里部分代码省略.........
示例2: preProcess
//.........这里部分代码省略.........
$mainUser = user_load($mainUfId);
} elseif ($config->userFramework == 'Joomla') {
$mainUser = JFactory::getUser($mainUfId);
}
$this->assign('mainUfId', $mainUfId);
$this->assign('mainUfName', $mainUser ? $mainUser->name : NULL);
}
$flipUrl = CRM_Utils_System::url('civicrm/contact/merge', "reset=1&action=update&cid={$oid}&oid={$cid}&rgid={$rgid}&gid={$gid}");
if (!$flip) {
$flipUrl .= '&flip=1';
}
$this->assign('flip', $flipUrl);
$this->prev = $this->next = NULL;
foreach (array('prev', 'next') as $position) {
if (!empty($pos[$position])) {
if ($pos[$position]['id1'] && $pos[$position]['id2']) {
$urlParam = "reset=1&cid={$pos[$position]['id1']}&oid={$pos[$position]['id2']}&mergeId={$pos[$position]['mergeId']}&action=update";
if ($rgid) {
$urlParam .= "&rgid={$rgid}";
}
if ($gid) {
$urlParam .= "&gid={$gid}";
}
$this->{$position} = CRM_Utils_System::url('civicrm/contact/merge', $urlParam);
$this->assign($position, $this->{$position});
}
}
}
// get user info of other contact.
$otherUfId = CRM_Core_BAO_UFMatch::getUFId($oid);
$otherUser = NULL;
if ($otherUfId) {
// d6 compatible
if ($config->userSystem->is_drupal == '1') {
$otherUser = user_load($otherUfId);
} elseif ($config->userFramework == 'Joomla') {
$otherUser = JFactory::getUser($otherUfId);
}
$this->assign('otherUfId', $otherUfId);
$this->assign('otherUfName', $otherUser ? $otherUser->name : NULL);
}
$cmsUser = $mainUfId && $otherUfId ? TRUE : FALSE;
$this->assign('user', $cmsUser);
$session = CRM_Core_Session::singleton();
// context fixed.
if ($rgid) {
$urlParam = "reset=1&action=browse&rgid={$rgid}";
if ($gid) {
$urlParam .= "&gid={$gid}";
}
$session->pushUserContext(CRM_Utils_System::url('civicrm/contact/dedupefind', $urlParam));
}
// ensure that oid is not the current user, if so refuse to do the merge
if ($session->get('userID') == $oid) {
$display_name = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $oid, 'display_name');
$message = ts('The contact record which is linked to the currently logged in user account - \'%1\' - cannot be deleted.', array(1 => $display_name));
CRM_Core_Error::statusBounce($message);
}
$rowsElementsAndInfo = CRM_Dedupe_Merger::getRowsElementsAndInfo($cid, $oid);
$main =& $rowsElementsAndInfo['main_details'];
$other =& $rowsElementsAndInfo['other_details'];
if ($main['contact_id'] != $cid) {
CRM_Core_Error::fatal(ts('The main contact record does not exist'));
}
if ($other['contact_id'] != $oid) {
CRM_Core_Error::fatal(ts('The other contact record does not exist'));
}
$subtypes = CRM_Contact_BAO_ContactType::subTypePairs(NULL, TRUE, '');
$this->assign('contact_type', $main['contact_type']);
if (!empty($main['contact_sub_type'])) {
$this->assign('main_contact_subtype', CRM_Utils_Array::value('contact_sub_type', $subtypes[$main['contact_sub_type'][0]]));
}
if (!empty($other['contact_sub_type'])) {
$this->assign('other_contact_subtype', CRM_Utils_Array::value('contact_sub_type', $subtypes[$other['contact_sub_type'][0]]));
}
$this->assign('main_name', $main['display_name']);
$this->assign('other_name', $other['display_name']);
$this->assign('main_cid', $main['contact_id']);
$this->assign('other_cid', $other['contact_id']);
$this->assign('rgid', $rgid);
$this->_cid = $cid;
$this->_oid = $oid;
$this->_rgid = $rgid;
$this->_contactType = $main['contact_type'];
$this->addElement('checkbox', 'toggleSelect', NULL, NULL, array('onclick' => "return toggleCheckboxVals('move_',this);"));
$this->assign('mainLocBlock', json_encode($rowsElementsAndInfo['main_loc_block']));
$this->assign('rows', $rowsElementsAndInfo['rows']);
$this->_locBlockIds = array('main' => $rowsElementsAndInfo['main_details']['loc_block_ids'], 'other' => $rowsElementsAndInfo['other_details']['loc_block_ids']);
// add elements
foreach ($rowsElementsAndInfo['elements'] as $element) {
$this->addElement($element[0], $element[1], array_key_exists('2', $element) ? $element[2] : NULL, array_key_exists('3', $element) ? $element[3] : NULL, array_key_exists('4', $element) ? $element[4] : NULL, array_key_exists('5', $element) ? $element[5] : NULL);
}
// add related table elements
foreach ($rowsElementsAndInfo['rel_table_elements'] as $relTableElement) {
$element = $this->addElement($relTableElement[0], $relTableElement[1]);
$element->setChecked(TRUE);
}
$this->assign('rel_tables', $rowsElementsAndInfo['rel_tables']);
$this->assign('userContextURL', $session->readUserContext());
}
示例3: browse
/**
* 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");
//.........这里部分代码省略.........
示例4: buildQuickForm
/**
* Function to actually build the form
*
* @return None
* @access public
*/
public function buildQuickForm()
{
//load form for child blocks
if ($this->_addBlockName) {
return eval('CRM_Contact_Form_Edit_' . $this->_addBlockName . '::buildQuickForm( $this );');
}
if ($this->_action == CRM_Core_Action::UPDATE) {
$deleteExtra = ts('Are you sure you want to delete contact image.');
$deleteURL = array(CRM_Core_Action::DELETE => array('name' => ts('Delete Contact Image'), 'url' => 'civicrm/contact/image', 'qs' => 'reset=1&cid=%%id%%&action=delete', 'extra' => 'onclick = "if (confirm( \'' . $deleteExtra . '\' ) ) this.href+=\'&confirmed=1\'; else return false;"'));
$deleteURL = CRM_Core_Action::formLink($deleteURL, CRM_Core_Action::DELETE, array('id' => $this->_contactId));
$this->assign('deleteURL', $deleteURL);
}
//build contact type specific fields
eval('CRM_Contact_Form_Edit_' . $this->_contactType . '::buildQuickForm( $this, $this->_action );');
// build Custom data if Custom data present in edit option
$buildCustomData = NULL;
if (array_key_exists('CustomData', $this->_editOptions)) {
$buildCustomData = "removeDefaultCustomFields( ), highlightTabs( );";
}
// subtype is a common field. lets keep it here
$subtypes = CRM_Contact_BAO_ContactType::subTypePairs($this->_contactType);
if (!empty($subtypes)) {
$sel = $this->add('select', 'contact_sub_type', ts('Contact Type'), $subtypes, FALSE, array('id' => 'contact_sub_type', 'multiple' => 'multiple', 'title' => ts('- subtype -'), 'onchange' => $buildCustomData));
}
// build edit blocks ( custom data, demographics, communication preference, notes, tags and groups )
foreach ($this->_editOptions as $name => $label) {
if ($name == 'Address') {
$this->_blocks['Address'] = $this->_editOptions['Address'];
continue;
}
eval('CRM_Contact_Form_Edit_' . $name . '::buildQuickForm( $this );');
}
// build location blocks.
CRM_Contact_Form_Location::buildQuickForm($this);
// add attachment
$this->addElement('file', 'image_URL', ts('Browse/Upload Image'), 'size=30 maxlength=60');
$this->addUploadElement('image_URL');
// add the dedupe button
$this->addElement('submit', $this->_dedupeButtonName, ts('Check for Matching Contact(s)'));
$this->addElement('submit', $this->_duplicateButtonName, ts('Save Matching Contact'));
$this->addElement('submit', $this->getButtonName('next', 'sharedHouseholdDuplicate'), ts('Save With Duplicate Household'));
$buttons = array(array('type' => 'upload', 'name' => ts('Save'), 'subName' => 'view', 'isDefault' => TRUE), array('type' => 'upload', 'name' => ts('Save and New'), 'spacing' => ' ', 'subName' => 'new'), array('type' => 'cancel', 'name' => ts('Cancel')));
if (CRM_Utils_Array::value('contact_sub_type', $this->_values)) {
$this->_oldSubtypes = explode(CRM_Core_DAO::VALUE_SEPARATOR, trim($this->_values['contact_sub_type'], CRM_Core_DAO::VALUE_SEPARATOR));
if (!empty($this->_oldSubtypes)) {
$buttons[0]['js'] = array('onclick' => "return warnSubtypeDataLoss()");
}
}
$this->assign('oldSubtypes', json_encode($this->_oldSubtypes));
$this->addButtons($buttons);
}
示例5: buildProfile
//.........这里部分代码省略.........
} elseif (CRM_Utils_Array::value('name', $field) == 'membership_status') {
$form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'label'), $required);
} elseif (in_array($fieldName, array('gender_id', 'communication_style_id'))) {
$options = array();
$pseudoValues = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', $fieldName);
foreach ($pseudoValues as $key => $var) {
$options[$key] = $form->createElement('radio', NULL, ts($title), $var, $key);
}
$group = $form->addGroup($options, $name, $title);
if ($required) {
$form->addRule($name, ts('%1 is a required field.', array(1 => $title)), 'required');
} else {
$group->setAttribute('allowClear', TRUE);
}
} elseif ($fieldName === 'prefix_id' || $fieldName === 'suffix_id') {
$form->addSelect($name, array('label' => $title, 'entity' => 'contact', 'field' => $fieldName, 'class' => 'six', 'placeholder' => ''), $required);
} elseif ($fieldName === 'contact_sub_type') {
$gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $field);
if ($usedFor == 'onbehalf') {
$profileType = 'Organization';
} elseif ($usedFor == 'honor') {
$profileType = CRM_Core_BAO_UFField::getProfileType($form->_params['honoree_profile_id']);
} else {
$profileType = $gId ? CRM_Core_BAO_UFField::getProfileType($gId) : NULL;
if ($profileType == 'Contact') {
$profileType = 'Individual';
}
}
$setSubtype = FALSE;
if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
$setSubtype = $profileType;
$profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType);
}
$subtypes = $profileType ? CRM_Contact_BAO_ContactType::subTypePairs($profileType) : array();
if ($setSubtype) {
$subtypeList = array();
$subtypeList[$setSubtype] = $subtypes[$setSubtype];
} else {
$subtypeList = $subtypes;
}
$form->add('select', $name, $title, $subtypeList, $required, array('class' => 'crm-select2', 'multiple' => TRUE));
} elseif (in_array($fieldName, CRM_Contact_BAO_Contact::$_greetingTypes)) {
//add email greeting, postal greeting, addressee, CRM-4575
$gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $field);
$profileType = CRM_Core_BAO_UFField::getProfileType($gId, TRUE, FALSE, TRUE);
if (empty($profileType) || in_array($profileType, array('Contact', 'Contribution', 'Participant', 'Membership'))) {
$profileType = 'Individual';
}
if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
$profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType);
}
$greeting = array('contact_type' => $profileType, 'greeting_type' => $fieldName);
$form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::greeting($greeting), $required);
// add custom greeting element
$form->add('text', $fieldName . '_custom', ts('Custom %1', array(1 => ucwords(str_replace('_', ' ', $fieldName)))), NULL, FALSE);
} elseif ($fieldName === 'preferred_communication_method') {
$communicationFields = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method');
foreach ($communicationFields as $key => $var) {
if ($key == '') {
continue;
}
$communicationOptions[] = $form->createElement('checkbox', $key, NULL, $var);
}
$form->addGroup($communicationOptions, $name, $title, '<br/>');
} elseif ($fieldName === 'preferred_mail_format') {
$form->add('select', $name, $title, CRM_Core_SelectValues::pmf());
示例6: buildQuickForm
/**
* 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();
}
}
//.........这里部分代码省略.........
示例7: buildProfile
//.........这里部分代码省略.........
if ($field['name'] == 'membership_type_id') {
require_once 'CRM/Member/PseudoConstant.php';
$form->add('select', 'membership_type_id', $title, array('' => ts('- select -')) + CRM_Member_PseudoConstant::membershipType(), $required);
} else {
if ($field['name'] == 'status_id') {
require_once 'CRM/Member/PseudoConstant.php';
$form->add('select', 'status_id', $title, array('' => ts('- select -')) + CRM_Member_PseudoConstant::membershipStatus(), $required);
} else {
if ($fieldName === 'gender') {
$genderOptions = array();
$gender = CRM_Core_PseudoConstant::gender();
foreach ($gender as $key => $var) {
$genderOptions[$key] = HTML_QuickForm::createElement('radio', null, ts('Gender'), $var, $key);
}
$form->addGroup($genderOptions, $name, $title);
if ($required) {
$form->addRule($name, ts('%1 is a required field.', array(1 => $title)), 'required');
}
} else {
if ($fieldName === 'individual_prefix') {
$form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualPrefix(), $required);
} else {
if ($fieldName === 'individual_suffix') {
$form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualSuffix(), $required);
} else {
if ($fieldName === 'contact_sub_type') {
$gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $form->_fields[$fieldName]);
$profileType = $gId ? CRM_Core_BAO_UFField::getProfileType($gId) : null;
$setSubtype = false;
if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
$setSubtype = $profileType;
$profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType);
}
$subtypes = $profileType ? CRM_Contact_BAO_ContactType::subTypePairs($profileType) : array();
if ($setSubtype) {
$subtypeList = array();
$subtypeList[$setSubtype] = $subtypes[$setSubtype];
} else {
$subtypeList = array('' => ts('- select -')) + $subtypes;
}
$form->add('select', $name, $title, $subtypeList, $required);
} else {
if (in_array($fieldName, array('email_greeting', 'postal_greeting', 'addressee'))) {
//add email greeting, postal greeting, addressee, CRM-4575
$gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $field);
$profileType = CRM_Core_BAO_UFField::getProfileType($gId, true, false, true);
if (empty($profileType) || in_array($profileType, array('Contact', 'Contribution', 'Participant', 'Membership'))) {
$profileType = 'Individual';
}
if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
$profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType);
}
if ($fieldName == 'email_greeting') {
$emailGreeting = array('contact_type' => $profileType, 'greeting_type' => 'email_greeting');
$form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::greeting($emailGreeting), $required);
// adding custom email greeting element alongwith email greeting
$form->add('text', 'email_greeting_custom', ts('Custom Email Greeting'), null, false);
} else {
if ($fieldName === 'postal_greeting') {
$postalGreeting = array('contact_type' => $profileType, 'greeting_type' => 'postal_greeting');
$form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::greeting($postalGreeting), $required);
// adding custom postal greeting element alongwith postal greeting
$form->add('text', 'postal_greeting_custom', ts('Custom Postal Greeting'), null, false);
} else {
if ($fieldName === 'addressee') {
$addressee = array('contact_type' => $profileType, 'greeting_type' => 'addressee');
示例8: import
/**
* Handle the values in import mode.
*
* @param int $onDuplicate
* The code for what action to take on duplicates.
* @param array $values
* The array of values belonging to this line.
*
* @param bool $doGeocodeAddress
*
* @return bool
* the result of this processing
*/
public function import($onDuplicate, &$values, $doGeocodeAddress = FALSE)
{
$config = CRM_Core_Config::singleton();
$this->_unparsedStreetAddressContacts = array();
if (!$doGeocodeAddress) {
// CRM-5854, reset the geocode method to null to prevent geocoding
$config->geocodeMethod = NULL;
}
// first make sure this is a valid line
//$this->_updateWithId = false;
$response = $this->summary($values);
$statusFieldName = $this->_statusFieldName;
if ($response != CRM_Import_Parser::VALID) {
$importRecordParams = array($statusFieldName => 'INVALID', "{$statusFieldName}Msg" => "Invalid (Error Code: {$response})");
$this->updateImportRecord($values[count($values) - 1], $importRecordParams);
return $response;
}
$params =& $this->getActiveFieldParams();
$formatted = array('contact_type' => $this->_contactType);
static $contactFields = NULL;
if ($contactFields == NULL) {
$contactFields = CRM_Contact_DAO_Contact::import();
}
//check if external identifier exists in database
if (!empty($params['external_identifier']) && (!empty($params['id']) || in_array($onDuplicate, array(CRM_Import_Parser::DUPLICATE_SKIP, CRM_Import_Parser::DUPLICATE_NOCHECK)))) {
if ($internalCid = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $params['external_identifier'], 'id', 'external_identifier')) {
if ($internalCid != CRM_Utils_Array::value('id', $params)) {
$errorMessage = ts('External ID already exists in Database.');
array_unshift($values, $errorMessage);
$importRecordParams = array($statusFieldName => 'ERROR', "{$statusFieldName}Msg" => $errorMessage);
$this->updateImportRecord($values[count($values) - 1], $importRecordParams);
return CRM_Import_Parser::DUPLICATE;
}
}
}
if (!empty($this->_contactSubType)) {
$params['contact_sub_type'] = $this->_contactSubType;
}
if ($subType = CRM_Utils_Array::value('contact_sub_type', $params)) {
if (CRM_Contact_BAO_ContactType::isExtendsContactType($subType, $this->_contactType, FALSE, 'label')) {
$subTypes = CRM_Contact_BAO_ContactType::subTypePairs($this->_contactType, FALSE, NULL);
$params['contact_sub_type'] = array_search($subType, $subTypes);
} elseif (!CRM_Contact_BAO_ContactType::isExtendsContactType($subType, $this->_contactType)) {
$message = "Mismatched or Invalid Contact Subtype.";
array_unshift($values, $message);
return CRM_Import_Parser::NO_MATCH;
}
}
// Get contact id to format common data in update/fill mode,
// prioritising a dedupe rule check over an external_identifier check, but falling back on ext id.
if ($this->_updateWithId && empty($params['id'])) {
$possibleMatches = $this->getPossibleContactMatches($params);
foreach ($possibleMatches as $possibleID) {
$params['id'] = $formatted['id'] = $possibleID;
}
}
//format common data, CRM-4062
$this->formatCommonData($params, $formatted, $contactFields);
$relationship = FALSE;
$createNewContact = TRUE;
// Support Match and Update Via Contact ID
if ($this->_updateWithId && isset($params['id'])) {
$createNewContact = FALSE;
// @todo - it feels like all the rows from here to the end of the IF
// could be removed in favour of a simple check for whether the contact_type & id match
// the call to the deprecated function seems to add no value other that to do an additional
// check for the contact_id & type.
$error = _civicrm_api3_deprecated_duplicate_formatted_contact($formatted);
if (CRM_Core_Error::isAPIError($error, CRM_Core_ERROR::DUPLICATE_CONTACT)) {
$matchedIDs = explode(',', $error['error_message']['params'][0]);
if (count($matchedIDs) >= 1) {
$updateflag = TRUE;
foreach ($matchedIDs as $contactId) {
if ($params['id'] == $contactId) {
$contactType = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $params['id'], 'contact_type');
if ($formatted['contact_type'] == $contactType) {
//validation of subtype for update mode
//CRM-5125
$contactSubType = NULL;
if (!empty($params['contact_sub_type'])) {
$contactSubType = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $params['id'], 'contact_sub_type');
}
if (!empty($contactSubType) && (!CRM_Contact_BAO_ContactType::isAllowEdit($params['id'], $contactSubType) && $contactSubType != CRM_Utils_Array::value('contact_sub_type', $formatted))) {
$message = "Mismatched contact SubTypes :";
array_unshift($values, $message);
$updateflag = FALSE;
$this->_retCode = CRM_Import_Parser::NO_MATCH;
//.........这里部分代码省略.........
示例9: buildQuickForm
/**
* 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
//.........这里部分代码省略.........
示例10: preProcess
function preProcess()
{
require_once 'api/v2/Contact.php';
require_once 'CRM/Core/BAO/CustomGroup.php';
require_once 'CRM/Core/OptionGroup.php';
require_once 'CRM/Core/OptionValue.php';
if (!CRM_Core_Permission::check('merge duplicate contacts')) {
CRM_Core_Error::fatal(ts('You do not have access to this page'));
}
$cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this, true);
$oid = CRM_Utils_Request::retrieve('oid', 'Positive', $this, true);
$rgid = CRM_Utils_Request::retrieve('rgid', 'Positive', $this, false);
$gid = CRM_Utils_Request::retrieve('gid', 'Positive', $this, false);
self::validateContacts($cid, $oid);
// Block access if user does not have EDIT permissions for both contacts.
require_once 'CRM/Contact/BAO/Contact/Permission.php';
if (!(CRM_Contact_BAO_Contact_Permission::allow($cid, CRM_Core_Permission::EDIT) && CRM_Contact_BAO_Contact_Permission::allow($oid, CRM_Core_Permission::EDIT))) {
CRM_Utils_System::permissionDenied();
}
// get user info of main contact.
$config = CRM_Core_Config::singleton();
require_once 'CRM/Core/Permission.php';
$viewUser = CRM_Core_Permission::check('access user profiles');
$mainUfId = CRM_Core_BAO_UFMatch::getUFId($cid);
if ($mainUfId) {
if ($config->userFramework == 'Drupal') {
$mainUser = user_load($mainUfId);
} else {
if ($config->userFramework == 'Joomla') {
$mainUser = JFactory::getUser($mainUfId);
}
}
}
$this->assign('mainUfId', $mainUfId);
$this->assign('mainUfName', $mainUser->name);
// get user info of other contact.
$otherUfId = CRM_Core_BAO_UFMatch::getUFId($oid);
if ($otherUfId) {
if ($config->userFramework == 'Drupal') {
$otherUser = user_load($otherUfId);
} else {
if ($config->userFramework == 'Joomla') {
$otherUser = JFactory::getUser($otherUfId);
}
}
}
$this->assign('otherUfId', $otherUfId);
$this->assign('otherUfName', $otherUser->name);
$cmsUser = $mainUfId && $otherUfId ? true : false;
$this->assign('user', $cmsUser);
$session = CRM_Core_Session::singleton();
// context fixed.
if ($rgid) {
$urlParam = "reset=1&action=browse&rgid={$rgid}";
if ($gid) {
$urlParam .= "&gid={$gid}";
}
$session->pushUserContext(CRM_Utils_system::url('civicrm/contact/dedupefind', $urlParam));
}
// ensure that oid is not the current user, if so refuse to do the merge
if ($session->get('userID') == $oid) {
$display_name = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $oid, 'display_name');
$message = ts('The contact record which is linked to the currently logged in user account - \'%1\' - cannot be deleted.', array(1 => $display_name));
CRM_Core_Error::statusBounce($message);
}
$diffs = CRM_Dedupe_Merger::findDifferences($cid, $oid);
$mainParams = array('contact_id' => $cid, 'return.display_name' => 1, 'return.contact_sub_type' => 1);
$otherParams = array('contact_id' => $oid, 'return.display_name' => 1, 'return.contact_sub_type' => 1);
// API 2 has to have the requested fields spelt-out for it
foreach (CRM_Dedupe_Merger::$validFields as $field) {
$mainParams["return.{$field}"] = $otherParams["return.{$field}"] = 1;
}
$main =& civicrm_contact_get($mainParams);
//CRM-4524
$main = reset($main);
if ($main['contact_id'] != $cid) {
CRM_Core_Error::fatal(ts('The main contact record does not exist'));
}
$other =& civicrm_contact_get($otherParams);
//CRM-4524
$other = reset($other);
if ($other['contact_id'] != $oid) {
CRM_Core_Error::fatal(ts('The other contact record does not exist'));
}
require_once 'CRM/Contact/BAO/ContactType.php';
$subtypes = CRM_Contact_BAO_ContactType::subTypePairs(null, true, '');
$this->assign('contact_type', $main['contact_type']);
$this->assign('main_contact_subtype', $subtypes[$main['contact_sub_type']]);
$this->assign('other_contact_subtype', $subtypes[$other['contact_sub_type']]);
$this->assign('main_name', $main['display_name']);
$this->assign('other_name', $other['display_name']);
$this->assign('main_cid', $main['contact_id']);
$this->assign('other_cid', $other['contact_id']);
$this->_cid = $cid;
$this->_oid = $oid;
$this->_rgid = $rgid;
$this->_contactType = $main['contact_type'];
$this->addElement('checkbox', 'toggleSelect', null, null, array('onclick' => "return toggleCheckboxVals('move_',this);"));
require_once "CRM/Contact/DAO/Contact.php";
$fields =& CRM_Contact_DAO_Contact::fields();
//.........这里部分代码省略.........
示例11: buildSubTypes
static function buildSubTypes()
{
$parent = CRM_Utils_Array::value('parentId', $_POST);
switch ($parent) {
case 1:
$contactType = 'Individual';
break;
case 2:
$contactType = 'Household';
break;
case 4:
$contactType = 'Organization';
break;
}
require_once 'CRM/Contact/BAO/ContactType.php';
$subTypes = CRM_Contact_BAO_ContactType::subTypePairs($contactType, false, null);
asort($subTypes);
echo json_encode($subTypes);
exit;
}
示例12: buildProfile
//.........这里部分代码省略.........
} elseif ($field['name'] == 'membership_type') {
list($orgInfo, $types) = CRM_Member_BAO_MembershipType::getMembershipTypeInfo();
$sel =& $form->addElement('hierselect', $name, $title);
$select = array('' => ts('- select -'));
$sel->setOptions(array($select + $orgInfo, $types));
} elseif ($field['name'] == 'membership_status') {
$form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'label'), $required);
} elseif ($fieldName === 'gender') {
$genderOptions = array();
$gender = CRM_Core_PseudoConstant::gender();
foreach ($gender as $key => $var) {
$genderOptions[$key] = $form->createElement('radio', NULL, ts('Gender'), $var, $key);
}
$form->addGroup($genderOptions, $name, $title);
if ($required) {
$form->addRule($name, ts('%1 is a required field.', array(1 => $title)), 'required');
}
} elseif ($fieldName === 'individual_prefix') {
$form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualPrefix(), $required);
} elseif ($fieldName === 'individual_suffix') {
$form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualSuffix(), $required);
} elseif ($fieldName === 'contact_sub_type') {
$gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $form->_fields[$fieldName]);
if ($onBehalf) {
$profileType = 'Organization';
} else {
$profileType = $gId ? CRM_Core_BAO_UFField::getProfileType($gId) : NULL;
}
$setSubtype = FALSE;
if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
$setSubtype = $profileType;
$profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType);
}
$subtypes = $profileType ? CRM_Contact_BAO_ContactType::subTypePairs($profileType) : array();
if ($setSubtype) {
$subtypeList = array();
$subtypeList[$setSubtype] = $subtypes[$setSubtype];
} else {
$subtypeList = $subtypes;
}
$sel = $form->add('select', $name, $title, $subtypeList, $required);
$sel->setMultiple(TRUE);
} elseif (in_array($fieldName, CRM_Contact_BAO_Contact::$_greetingTypes)) {
//add email greeting, postal greeting, addressee, CRM-4575
$gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $field);
$profileType = CRM_Core_BAO_UFField::getProfileType($gId, TRUE, FALSE, TRUE);
if (empty($profileType) || in_array($profileType, array('Contact', 'Contribution', 'Participant', 'Membership'))) {
$profileType = 'Individual';
}
if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
$profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType);
}
$greeting = array('contact_type' => $profileType, 'greeting_type' => $fieldName);
$form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::greeting($greeting), $required);
// add custom greeting element
$form->add('text', $fieldName . '_custom', ts('Custom %1', array(1 => ucwords(str_replace('_', ' ', $fieldName)))), NULL, FALSE);
} elseif ($fieldName === 'preferred_communication_method') {
$communicationFields = CRM_Core_PseudoConstant::pcm();
foreach ($communicationFields as $key => $var) {
if ($key == '') {
continue;
}
$communicationOptions[] = $form->createElement('checkbox', $key, NULL, $var);
}
$form->addGroup($communicationOptions, $name, $title, '<br/>');
} elseif ($fieldName === 'preferred_mail_format') {
示例13: getRowsElementsAndInfo
/**
* A function to build an array of information required by merge function and the merge UI.
*
* @param int $mainId main contact with whom merge has to happen
* @param int $otherId duplicate contact which would be deleted after merge operation
*
* @return array|bool|int
* @static
* @access public
*/
static function getRowsElementsAndInfo($mainId, $otherId)
{
$qfZeroBug = 'e8cddb72-a257-11dc-b9cc-0016d3330ee9';
// Fetch contacts
foreach (array('main' => $mainId, 'other' => $otherId) as $moniker => $cid) {
$params = array('contact_id' => $cid, 'version' => 3, 'return' => array_merge(array('display_name'), self::getContactFields()));
$result = civicrm_api('contact', 'get', $params);
if (empty($result['values'][$cid]['contact_type'])) {
return FALSE;
}
${$moniker} = $result['values'][$cid];
}
static $fields = array();
if (empty($fields)) {
$fields = CRM_Contact_DAO_Contact::fields();
CRM_Core_DAO::freeResult();
}
// get all contact subtypes
$contactSubTypes = CRM_Contact_BAO_ContactType::subTypePairs(NULL, TRUE, '');
// FIXME: there must be a better way
foreach (array('main', 'other') as $moniker) {
$contact =& ${$moniker};
$preferred_communication_method = CRM_Utils_array::value('preferred_communication_method', $contact);
$value = empty($preferred_communication_method) ? array() : $preferred_communication_method;
$specialValues[$moniker] = array('preferred_communication_method' => $value, 'contact_sub_type' => $value, 'communication_style_id' => $value);
if (!empty($contact['preferred_communication_method'])) {
// api 3 returns pref_comm_method as an array, which breaks the lookup; so we reconstruct
$prefCommList = is_array($specialValues[$moniker]['preferred_communication_method']) ? implode(CRM_Core_DAO::VALUE_SEPARATOR, $specialValues[$moniker]['preferred_communication_method']) : $specialValues[$moniker]['preferred_communication_method'];
$specialValues[$moniker]['preferred_communication_method'] = CRM_Core_DAO::VALUE_SEPARATOR . $prefCommList . CRM_Core_DAO::VALUE_SEPARATOR;
}
$names = array('preferred_communication_method' => array('newName' => 'preferred_communication_method_display', 'groupName' => 'preferred_communication_method'));
CRM_Core_OptionGroup::lookupValues($specialValues[$moniker], $names);
if (!empty($contact['contact_sub_type'])) {
$specialValues[$moniker]['contact_sub_type'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $contact['contact_sub_type']);
// fix contact sub type label for contact with sub type
$subtypes = array();
foreach ($contact['contact_sub_type'] as $key => $value) {
$subtypes[] = CRM_Utils_Array::retrieveValueRecursive($contactSubTypes, $value);
}
$contact['contact_sub_type_display'] = $specialValues[$moniker]['contact_sub_type_display'] = implode(', ', $subtypes);
}
if (!empty($contact['communication_style'])) {
$specialValues[$moniker]['communication_style_id_display'] = $contact['communication_style'];
}
}
static $optionValueFields = array();
if (empty($optionValueFields)) {
$optionValueFields = CRM_Core_OptionValue::getFields();
}
foreach ($optionValueFields as $field => $params) {
$fields[$field]['title'] = $params['title'];
}
$diffs = self::findDifferences($main, $other);
$rows = $elements = $relTableElements = $migrationInfo = array();
foreach ($diffs['contact'] as $field) {
foreach (array('main', 'other') as $moniker) {
$contact =& ${$moniker};
$value = CRM_Utils_Array::value($field, $contact);
if (isset($specialValues[$moniker][$field]) && is_string($specialValues[$moniker][$field])) {
$value = CRM_Core_DAO::VALUE_SEPARATOR . trim($specialValues[$moniker][$field], CRM_Core_DAO::VALUE_SEPARATOR) . CRM_Core_DAO::VALUE_SEPARATOR;
}
$label = isset($specialValues[$moniker]["{$field}_display"]) ? $specialValues[$moniker]["{$field}_display"] : $value;
if (!empty($fields[$field]['type']) && $fields[$field]['type'] == CRM_Utils_Type::T_DATE) {
if ($value) {
$value = str_replace('-', '', $value);
$label = CRM_Utils_Date::customFormat($label);
} else {
$value = "null";
}
} elseif (!empty($fields[$field]['type']) && $fields[$field]['type'] == CRM_Utils_Type::T_BOOLEAN) {
if ($label === '0') {
$label = ts('[ ]');
}
if ($label === '1') {
$label = ts('[x]');
}
} elseif ($field == 'individual_prefix' || $field == 'prefix_id') {
$label = CRM_Utils_Array::value('individual_prefix', $contact);
$value = CRM_Utils_Array::value('prefix_id', $contact);
$field = 'prefix_id';
} elseif ($field == 'individual_suffix' || $field == 'suffix_id') {
$label = CRM_Utils_Array::value('individual_suffix', $contact);
$value = CRM_Utils_Array::value('suffix_id', $contact);
$field = 'suffix_id';
}
$rows["move_{$field}"][$moniker] = $label;
if ($moniker == 'other') {
//CRM-14334
if ($value === NULL || $value == '') {
$value = 'null';
//.........这里部分代码省略.........
示例14: buildSubTypes
static function buildSubTypes()
{
$parent = CRM_Utils_Array::value('parentId', $_REQUEST);
switch ($parent) {
case 1:
$contactType = 'Individual';
break;
case 2:
$contactType = 'Household';
break;
case 4:
$contactType = 'Organization';
break;
}
$subTypes = CRM_Contact_BAO_ContactType::subTypePairs($contactType, FALSE, NULL);
asort($subTypes);
CRM_Utils_JSON::output($subTypes);
}
示例15: buildSubTypes
public static function buildSubTypes()
{
$parent = CRM_Utils_Request::retrieve('parentId', 'Positive', CRM_Core_DAO::$_nullObject);
switch ($parent) {
case 1:
$contactType = 'Individual';
break;
case 2:
$contactType = 'Household';
break;
case 4:
$contactType = 'Organization';
break;
}
$subTypes = CRM_Contact_BAO_ContactType::subTypePairs($contactType, FALSE, NULL);
asort($subTypes);
CRM_Utils_JSON::output($subTypes);
}