本文整理汇总了PHP中CRM_Contact_BAO_ContactType::getBasicType方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Contact_BAO_ContactType::getBasicType方法的具体用法?PHP CRM_Contact_BAO_ContactType::getBasicType怎么用?PHP CRM_Contact_BAO_ContactType::getBasicType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Contact_BAO_ContactType
的用法示例。
在下文中一共展示了CRM_Contact_BAO_ContactType::getBasicType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getImage
/**
* given a contact type, get the contact image
*
* @param string $contact_type
*
* @return string
* @access public
* @static
*/
static function getImage($contactType, $urlOnly = false, $contactId = null)
{
static $imageInfo = array();
if (!array_key_exists($contactType, $imageInfo)) {
$imageInfo[$contactType] = array();
$typeInfo = array();
$params = array('name' => $contactType);
require_once 'CRM/Contact/BAO/ContactType.php';
CRM_Contact_BAO_ContactType::retrieve($params, $typeInfo);
if (CRM_Utils_Array::value('image_URL', $typeInfo)) {
$imageUrl = $typeInfo['image_URL'];
$config = CRM_Core_Config::singleton();
if (!preg_match("/^(\\/|(http(s)?:)).+\$/i", $imageUrl)) {
$imageUrl = $config->resourceBase . $imageUrl;
}
$imageInfo[$contactType]['image'] = "<div class=\"icon crm-icon {$typeInfo['name']}-icon\" style=\"background: url('{$imageUrl}')\" title=\"{$contactType}\"></div>";
$imageInfo[$contactType]['url'] = $imageUrl;
} else {
$isSubtype = array_key_exists('parent_id', $typeInfo) && $typeInfo['parent_id'] ? true : false;
if ($isSubtype) {
$type = CRM_Contact_BAO_ContactType::getBasicType($typeInfo['name']) . "-subtype";
} else {
$type = $typeInfo['name'];
}
$imageInfo[$contactType]['image'] = "<div class=\"icon crm-icon {$type}-icon\" title=\"{$contactType}\"></div>";
$imageInfo[$contactType]['url'] = null;
}
}
$summaryOvelayProfileId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', 'summary_overlay', 'id', 'name');
$profileURL = CRM_Utils_System::url('civicrm/profile/view', "reset=1&gid={$summaryOvelayProfileId}&id={$contactId}&snippet=4");
$imageInfo[$contactType]['summary-link'] = '<a href="' . $profileURL . '" class="crm-summary-link">' . $imageInfo[$contactType]["image"] . '</a>';
return $urlOnly ? $imageInfo[$contactType]['url'] : $imageInfo[$contactType]['summary-link'];
}
示例2: getImage
/**
* given a contact type, get the contact image
*
* @param string $contact_type
*
* @return string
* @access public
* @static
*/
static function getImage($contactType, $urlOnly = false)
{
static $imageInfo = array();
if (!array_key_exists($contactType, $imageInfo)) {
$imageInfo[$contactType] = array();
$params = array('name' => $contactType);
CRM_Contact_BAO_ContactType::retrieve($params, $typeInfo);
if ($typeInfo['image_URL']) {
$imageUrl = $typeInfo['image_URL'];
$config =& CRM_Core_Config::singleton();
if (!preg_match("/^(\\/|(http(s)?:)).+\$/i", $imageUrl)) {
$imageUrl = $config->resourceBase . $imageUrl;
}
$imageInfo[$contactType]['image'] = "<div class=\"icon crm-icon {$typeInfo['name']}-icon\" style=\"background: url('{$imageUrl}')\"></div>";
$imageInfo[$contactType]['url'] = $imageUrl;
} else {
$isSubtype = array_key_exists('parent_id', $typeInfo) && $typeInfo['parent_id'] ? true : false;
if ($isSubtype) {
$type = CRM_Contact_BAO_ContactType::getBasicType($typeInfo['name']) . "-subtype";
} else {
$type = $typeInfo['name'];
}
$imageInfo[$contactType]['image'] = "<div class=\"icon crm-icon {$type}-icon\"></div>";
$imageInfo[$contactType]['url'] = null;
}
}
return $urlOnly ? $imageInfo[$contactType]['url'] : $imageInfo[$contactType]['image'];
}
示例3: getImage
/**
* Given a contact type, get the contact image.
*
* @param string $contactType
* Contact type.
* @param bool $urlOnly
* If we need to return only image url.
* @param int $contactId
* Contact id.
* @param bool $addProfileOverlay
* If profile overlay class should be added.
*
* @return string
*/
public static function getImage($contactType, $urlOnly = FALSE, $contactId = NULL, $addProfileOverlay = TRUE)
{
static $imageInfo = array();
$contactType = explode(CRM_Core_DAO::VALUE_SEPARATOR, trim($contactType, CRM_Core_DAO::VALUE_SEPARATOR));
$contactType = $contactType[0];
if (!array_key_exists($contactType, $imageInfo)) {
$imageInfo[$contactType] = array();
$typeInfo = array();
$params = array('name' => $contactType);
CRM_Contact_BAO_ContactType::retrieve($params, $typeInfo);
if (!empty($typeInfo['image_URL'])) {
$imageUrl = $typeInfo['image_URL'];
$config = CRM_Core_Config::singleton();
if (!preg_match("/^(\\/|(http(s)?:)).+\$/i", $imageUrl)) {
$imageUrl = $config->resourceBase . $imageUrl;
}
$imageInfo[$contactType]['image'] = "<div class=\"icon crm-icon {$typeInfo['name']}-icon\" style=\"background: url('{$imageUrl}')\" title=\"{$contactType}\"></div>";
$imageInfo[$contactType]['url'] = $imageUrl;
} else {
$isSubtype = array_key_exists('parent_id', $typeInfo) && $typeInfo['parent_id'] ? TRUE : FALSE;
if ($isSubtype) {
$type = CRM_Contact_BAO_ContactType::getBasicType($typeInfo['name']) . '-subtype';
} else {
$type = CRM_Utils_Array::value('name', $typeInfo);
}
// do not add title since it hides contact name
if ($addProfileOverlay) {
$imageInfo[$contactType]['image'] = "<div class=\"icon crm-icon {$type}-icon\"></div>";
} else {
$imageInfo[$contactType]['image'] = "<div class=\"icon crm-icon {$type}-icon\" title=\"{$contactType}\"></div>";
}
$imageInfo[$contactType]['url'] = NULL;
}
}
if ($addProfileOverlay) {
static $summaryOverlayProfileId = NULL;
if (!$summaryOverlayProfileId) {
$summaryOverlayProfileId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', 'summary_overlay', 'id', 'name');
}
$profileURL = CRM_Utils_System::url('civicrm/profile/view', "reset=1&gid={$summaryOverlayProfileId}&id={$contactId}&snippet=4");
$imageInfo[$contactType]['summary-link'] = '<a href="' . $profileURL . '" class="crm-summary-link">' . $imageInfo[$contactType]['image'] . '</a>';
} else {
$imageInfo[$contactType]['summary-link'] = $imageInfo[$contactType]['image'];
}
return $urlOnly ? $imageInfo[$contactType]['url'] : $imageInfo[$contactType]['summary-link'];
}
示例4: formatCustomField
/**
* Format custom fields before inserting
*
* @param int $customFieldId custom field id
* @param array $customFormatted formatted array
* @param mix $value value of custom field
* @param string $customFieldExtend custom field extends
* @param int $customValueId custom option value id
* @param int $entityId entity id (contribution, membership...)
*
* @return array $customFormatted formatted custom field array
* @static
*/
static function formatCustomField($customFieldId, &$customFormatted, $value, $customFieldExtend, $customValueId = null, $entityId = null, $inline = false)
{
//get the custom fields for the entity
//subtype and basic type
$customDataSubType = null;
if (in_array($customFieldExtend, CRM_Contact_BAO_ContactType::subTypes())) {
// This is the case when getFieldsForImport() requires fields
// of subtype and its parent.CRM-5143
$customDataSubType = $customFieldExtend;
$customFieldExtend = CRM_Contact_BAO_ContactType::getBasicType($customDataSubType);
}
$customFields = CRM_Core_BAO_CustomField::getFields($customFieldExtend, false, $inline, $customDataSubType);
if (!array_key_exists($customFieldId, $customFields)) {
return;
}
// return if field is a 'code' field
if (CRM_Utils_Array::value('is_view', $customFields[$customFieldId])) {
return;
}
list($tableName, $columnName, $groupID) = self::getTableColumnGroup($customFieldId);
if (is_array($customFieldExtend)) {
$customFieldExtend = $customFieldExtend[0];
}
if (!$customValueId && !$customFields[$customFieldId]['is_multiple'] && $entityId) {
//get the entity table for the custom field
require_once "CRM/Core/BAO/CustomQuery.php";
$entityTable = CRM_Core_BAO_CustomQuery::$extendsMap[$customFieldExtend];
$query = "\nSELECT id \n FROM {$tableName}\n WHERE entity_id={$entityId}";
$customValueId = CRM_Core_DAO::singleValueQuery($query);
}
//fix checkbox, now check box always submits values
if ($customFields[$customFieldId]['html_type'] == 'CheckBox') {
if ($value) {
// Note that only during merge this is not an array, and you can directly use value
if (is_array($value)) {
$selectedValues = null;
foreach ($value as $selId => $val) {
if ($val) {
$selectedValues .= $selId . CRM_Core_BAO_CustomOption::VALUE_SEPERATOR;
}
}
if ($selectedValues) {
$value = CRM_Core_BAO_CustomOption::VALUE_SEPERATOR . $selectedValues;
} else {
$value = '';
}
}
}
}
if ($customFields[$customFieldId]['html_type'] == 'Multi-Select' || $customFields[$customFieldId]['html_type'] == 'AdvMulti-Select') {
if ($value) {
// Note that only during merge this is not an array,
// and you can directly use value, CRM-4385
if (is_array($value)) {
$value = CRM_Core_BAO_CustomOption::VALUE_SEPERATOR . implode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, array_values($value)) . CRM_Core_BAO_CustomOption::VALUE_SEPERATOR;
}
} else {
$value = '';
}
}
$date = null;
if ($customFields[$customFieldId]['data_type'] == 'Date') {
if (!CRM_Utils_System::isNull($value)) {
$format = $customFields[$customFieldId]['date_format'];
if (in_array($format, array('dd-mm', 'mm/dd'))) {
$dateTimeArray = explode(' ', $value);
$separator = '/';
if ($format == 'dd-mm') {
$separator = '-';
}
$value = $dateTimeArray[0] . $separator . '1902';
if (array_key_exists(1, $dateTimeArray)) {
$value .= ' ' . $dateTimeArray[1];
}
}
$date = CRM_Utils_Date::processDate($value);
}
$value = $date;
}
if ($customFields[$customFieldId]['data_type'] == 'Float' || $customFields[$customFieldId]['data_type'] == 'Money') {
if (!$value) {
$value = 0;
}
if ($customFields[$customFieldId]['data_type'] == 'Money') {
require_once 'CRM/Utils/Rule.php';
$value = CRM_Utils_Rule::cleanMoney($value);
}
//.........这里部分代码省略.........
示例5: formatProfileContactParams
/**
* Format profile contact parameters.
*
* @param array $params
* @param $fields
* @param int $contactID
* @param int $ufGroupId
* @param null $ctype
* @param bool $skipCustom
*
* @return array
*/
public static function formatProfileContactParams(&$params, &$fields, $contactID = NULL, $ufGroupId = NULL, $ctype = NULL, $skipCustom = FALSE)
{
$data = $contactDetails = array();
// get the contact details (hier)
if ($contactID) {
list($details, $options) = self::getHierContactDetails($contactID, $fields);
$contactDetails = $details[$contactID];
$data['contact_type'] = CRM_Utils_Array::value('contact_type', $contactDetails);
$data['contact_sub_type'] = CRM_Utils_Array::value('contact_sub_type', $contactDetails);
} else {
//we should get contact type only if contact
if ($ufGroupId) {
$data['contact_type'] = CRM_Core_BAO_UFField::getProfileType($ufGroupId);
//special case to handle profile with only contact fields
if ($data['contact_type'] == 'Contact') {
$data['contact_type'] = 'Individual';
} elseif (CRM_Contact_BAO_ContactType::isaSubType($data['contact_type'])) {
$data['contact_type'] = CRM_Contact_BAO_ContactType::getBasicType($data['contact_type']);
}
} elseif ($ctype) {
$data['contact_type'] = $ctype;
} else {
$data['contact_type'] = 'Individual';
}
}
//fix contact sub type CRM-5125
if (array_key_exists('contact_sub_type', $params) && !empty($params['contact_sub_type'])) {
$data['contact_sub_type'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, (array) $params['contact_sub_type']) . CRM_Core_DAO::VALUE_SEPARATOR;
} elseif (array_key_exists('contact_sub_type_hidden', $params) && !empty($params['contact_sub_type_hidden'])) {
// if profile was used, and had any subtype, we obtain it from there
$data['contact_sub_type'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, (array) $params['contact_sub_type_hidden']) . CRM_Core_DAO::VALUE_SEPARATOR;
}
if ($ctype == 'Organization') {
$data['organization_name'] = CRM_Utils_Array::value('organization_name', $contactDetails);
} elseif ($ctype == 'Household') {
$data['household_name'] = CRM_Utils_Array::value('household_name', $contactDetails);
}
$locationType = array();
$count = 1;
if ($contactID) {
//add contact id
$data['contact_id'] = $contactID;
$primaryLocationType = self::getPrimaryLocationType($contactID);
} else {
$defaultLocation = CRM_Core_BAO_LocationType::getDefault();
$defaultLocationId = $defaultLocation->id;
}
// get the billing location type
$locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
$billingLocationTypeId = array_search('Billing', $locationTypes);
$blocks = array('email', 'phone', 'im', 'openid');
$multiplFields = array('url');
// prevent overwritten of formatted array, reset all block from
// params if it is not in valid format (since import pass valid format)
foreach ($blocks as $blk) {
if (array_key_exists($blk, $params) && !is_array($params[$blk])) {
unset($params[$blk]);
}
}
$primaryPhoneLoc = NULL;
$session = CRM_Core_Session::singleton();
foreach ($params as $key => $value) {
$fieldName = $locTypeId = $typeId = NULL;
list($fieldName, $locTypeId, $typeId) = CRM_Utils_System::explode('-', $key, 3);
//store original location type id
$actualLocTypeId = $locTypeId;
if ($locTypeId == 'Primary') {
if ($contactID) {
if (in_array($fieldName, $blocks)) {
$locTypeId = self::getPrimaryLocationType($contactID, FALSE, $fieldName);
} else {
$locTypeId = self::getPrimaryLocationType($contactID, FALSE, 'address');
}
$primaryLocationType = $locTypeId;
} else {
$locTypeId = $defaultLocationId;
}
}
if (is_numeric($locTypeId) && !in_array($fieldName, $multiplFields) && substr($fieldName, 0, 7) != 'custom_') {
$index = $locTypeId;
if (is_numeric($typeId)) {
$index .= '-' . $typeId;
}
if (!in_array($index, $locationType)) {
$locationType[$count] = $index;
$count++;
}
$loc = CRM_Utils_Array::key($index, $locationType);
//.........这里部分代码省略.........
示例6: postProcess
/**
* Process the user submitted custom data values.
*
*
* @return void
*/
public function postProcess()
{
$params = $this->controller->exportValues($this->_name);
//if the delete record button is clicked
if ($this->_deleteButtonName) {
if (!empty($_POST[$this->_deleteButtonName]) && $this->_recordId) {
$filterParams['id'] = $this->_customGroupId;
$returnProperties = array('is_multiple', 'table_name');
CRM_Core_DAO::commonRetrieve("CRM_Core_DAO_CustomGroup", $filterParams, $returnValues, $returnProperties);
if (!empty($returnValues['is_multiple'])) {
if ($tableName = CRM_Utils_Array::value('table_name', $returnValues)) {
$sql = "DELETE FROM {$tableName} WHERE id = %1 AND entity_id = %2";
$sqlParams = array(1 => array($this->_recordId, 'Integer'), 2 => array($this->_id, 'Integer'));
CRM_Core_DAO::executeQuery($sql, $sqlParams);
CRM_Core_Session::setStatus(ts('Your record has been deleted.'), ts('Deleted'), 'success');
}
}
return;
}
}
CRM_Utils_Hook::processProfile($this->_ufGroup['name']);
if (!empty($params['image_URL'])) {
CRM_Contact_BAO_Contact::processImageParams($params);
}
$greetingTypes = array('addressee' => 'addressee_id', 'email_greeting' => 'email_greeting_id', 'postal_greeting' => 'postal_greeting_id');
$details = array();
if ($this->_id) {
$contactDetails = CRM_Contact_BAO_Contact::getHierContactDetails($this->_id, $greetingTypes);
$details = $contactDetails[0][$this->_id];
}
if (!(!empty($details['addressee_id']) || !empty($details['email_greeting_id']) || CRM_Utils_Array::value('postal_greeting_id', $details))) {
$profileType = CRM_Core_BAO_UFField::getProfileType($this->_gid);
//Though Profile type is contact we need
//Individual/Household/Organization for setting Greetings.
if ($profileType == 'Contact') {
$profileType = 'Individual';
//if we editing Household/Organization.
if ($this->_id) {
$profileType = CRM_Contact_BAO_Contact::getContactType($this->_id);
}
}
if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
$profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType);
}
foreach ($greetingTypes as $key => $value) {
if (!array_key_exists($key, $params)) {
$params[$key] = CRM_Contact_BAO_Contact_Utils::defaultGreeting($profileType, $key);
}
}
}
$transaction = new CRM_Core_Transaction();
//used to send subscribe mail to the group which user want.
//if the profile double option in is enabled
$mailingType = array();
$result = NULL;
foreach ($params as $name => $values) {
if (substr($name, 0, 6) == 'email-') {
$result['email'] = $values;
}
}
//array of group id, subscribed by contact
$contactGroup = array();
if (!empty($params['group']) && CRM_Core_BAO_UFGroup::isProfileDoubleOptin()) {
$groupSubscribed = array();
if (!empty($result['email'])) {
if ($this->_id) {
$contactGroups = new CRM_Contact_DAO_GroupContact();
$contactGroups->contact_id = $this->_id;
$contactGroups->status = 'Added';
$contactGroups->find();
$contactGroup = array();
while ($contactGroups->fetch()) {
$contactGroup[] = $contactGroups->group_id;
$groupSubscribed[$contactGroups->group_id] = 1;
}
}
foreach ($params['group'] as $key => $val) {
if (!$val) {
unset($params['group'][$key]);
continue;
}
$groupTypes = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $key, 'group_type', 'id');
$groupType = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($groupTypes, 1, -1));
//filter group of mailing type and unset it from params
if (in_array(2, $groupType)) {
//if group is already subscribed , ignore it
$groupExist = CRM_Utils_Array::key($key, $contactGroup);
if (!isset($groupExist)) {
$mailingType[] = $key;
unset($params['group'][$key]);
}
}
}
}
//.........这里部分代码省略.........
示例7: buildProfile
//.........这里部分代码省略.........
}
$sel->setOptions(array($orgInfo, $types));
} 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/>');
示例8: buildProfile
//.........这里部分代码省略.........
$form->addDate($name, $title, $required, array('formatType' => 'custom'));
} else {
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 {
示例9: formatCustomField
/**
* Format custom fields before inserting.
*
* @param int $customFieldId
* Custom field id.
* @param array $customFormatted
* Formatted array.
* @param mix $value
* Value of custom field.
* @param string $customFieldExtend
* Custom field extends.
* @param int $customValueId
* Custom option value id.
* @param int $entityId
* Entity id (contribution, membership...).
* @param bool $inline
* Consider inline custom groups only.
* @param bool $checkPermission
* If false, do not include permissioning clause.
* @param bool $includeViewOnly
* If true, fields marked 'View Only' are included. Required for APIv3.
*
* @return array|NULL
* formatted custom field array
*/
public static function formatCustomField($customFieldId, &$customFormatted, $value, $customFieldExtend, $customValueId = NULL, $entityId = NULL, $inline = FALSE, $checkPermission = TRUE, $includeViewOnly = FALSE)
{
//get the custom fields for the entity
//subtype and basic type
$customDataSubType = NULL;
if ($customFieldExtend) {
// This is the case when getFieldsForImport() requires fields
// of subtype and its parent.CRM-5143
// CRM-16065 - Custom field set data not being saved if contact has more than one contact sub type
$customDataSubType = array_intersect(CRM_Contact_BAO_ContactType::subTypes(), (array) $customFieldExtend);
if (!empty($customDataSubType) && is_array($customDataSubType)) {
$customFieldExtend = CRM_Contact_BAO_ContactType::getBasicType($customDataSubType);
if (is_array($customFieldExtend)) {
$customFieldExtend = array_unique(array_values($customFieldExtend));
}
}
}
$customFields = CRM_Core_BAO_CustomField::getFields($customFieldExtend, FALSE, $inline, $customDataSubType, NULL, FALSE, FALSE, $checkPermission);
if (!array_key_exists($customFieldId, $customFields)) {
return NULL;
}
// return if field is a 'code' field
if (!$includeViewOnly && !empty($customFields[$customFieldId]['is_view'])) {
return NULL;
}
list($tableName, $columnName, $groupID) = self::getTableColumnGroup($customFieldId);
if (!$customValueId && !$customFields[$customFieldId]['is_multiple'] && $entityId) {
$query = "\nSELECT id\n FROM {$tableName}\n WHERE entity_id={$entityId}";
$customValueId = CRM_Core_DAO::singleValueQuery($query);
}
//fix checkbox, now check box always submits values
if ($customFields[$customFieldId]['html_type'] == 'CheckBox') {
if ($value) {
// Note that only during merge this is not an array, and you can directly use value
if (is_array($value)) {
$selectedValues = array();
foreach ($value as $selId => $val) {
if ($val) {
$selectedValues[] = $selId;
}
}
if (!empty($selectedValues)) {
$value = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, $selectedValues) . CRM_Core_DAO::VALUE_SEPARATOR;
} else {
$value = '';
}
}
}
}
if ($customFields[$customFieldId]['html_type'] == 'Multi-Select' || $customFields[$customFieldId]['html_type'] == 'AdvMulti-Select') {
if ($value) {
// Note that only during merge this is not an array,
// and you can directly use value, CRM-4385
if (is_array($value)) {
$value = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, array_values($value)) . CRM_Core_DAO::VALUE_SEPARATOR;
}
} else {
$value = '';
}
}
if (($customFields[$customFieldId]['html_type'] == 'Multi-Select' || $customFields[$customFieldId]['html_type'] == 'AdvMulti-Select' || $customFields[$customFieldId]['html_type'] == 'CheckBox') && $customFields[$customFieldId]['data_type'] == 'String' && !empty($customFields[$customFieldId]['text_length']) && !empty($value)) {
// lets make sure that value is less than the length, else we'll
// be losing some data, CRM-7481
if (strlen($value) >= $customFields[$customFieldId]['text_length']) {
// need to do a few things here
// 1. lets find a new length
$newLength = $customFields[$customFieldId]['text_length'];
$minLength = strlen($value);
while ($newLength < $minLength) {
$newLength = $newLength * 2;
}
// set the custom field meta data to have a length larger than value
// alter the custom value table column to match this length
CRM_Core_BAO_SchemaHandler::alterFieldLength($customFieldId, $tableName, $columnName, $newLength);
}
//.........这里部分代码省略.........
示例10: formRule
//.........这里部分代码省略.........
if ($customFieldId[0] == 'custom') {
$customField =& new CRM_Core_DAO_CustomField();
$customField->id = $customFieldId[1];
$customField->find(true);
if (!$customField->is_active && $is_active) {
$errors['field_name'] = ts('Cannot set this field "Active" since the selected custom field is disabled.');
}
}
}
//check profile is configured for double option process
//adding group field, email field should be present in the group
//fixed for issue CRM-2861 & CRM-4153
$config =& CRM_Core_Config::singleton();
if ($config->profileDoubleOptIn) {
if ($fields['field_name'][1] == 'group') {
require_once 'CRM/Core/BAO/UFField.php';
$dao =& new CRM_Core_BAO_UFField();
$dao->uf_group_id = $fields['group_id'];
$dao->find();
$emailField = false;
while ($dao->fetch()) {
//check email field is present in the group
if ($dao->field_name == 'email') {
$emailField = true;
}
}
if (!$emailField) {
$disableSetting = "define( 'CIVICRM_PROFILE_DOUBLE_OPTIN' , 0 );";
$errors['field_name'] = ts('Your site is currently configured to require double-opt in when users join (subscribe) to Group(s) via a Profile form. In this mode, you need to include an Email field in a Profile BEFORE you can add the Group(s) field. This ensures that an opt-in confirmation email can be sent. Your site administrator can disable double opt-in by adding this line to the CiviCRM settings file: <em>%1</em>', array(1 => $disableSetting));
}
}
}
//fix for CRM-3037
$fieldType = $fields['field_name'][0];
//get the group type.
$groupType = CRM_Core_BAO_UFGroup::calculateGroupType($self->_gid, CRM_Utils_Array::value('field_id', $fields));
switch ($fieldType) {
case 'Individual':
if (in_array('Household', $groupType) || in_array('Organization', $groupType)) {
$errors['field_name'] = ts('Cannot add or update profile field type Individual with combination of Household or Organization');
} else {
self::formRuleSubType($fieldType, $groupType, $errors);
}
break;
case 'Household':
if (in_array('Individual', $groupType) || in_array('Organization', $groupType)) {
$errors['field_name'] = ts('Cannot add or update profile field type Household with combination of Individual or Organization');
} else {
self::formRuleSubType($fieldType, $groupType, $errors);
}
break;
case 'Organization':
if (in_array('Household', $groupType) || in_array('Individual', $groupType)) {
$errors['field_name'] = ts('Cannot add or update profile field type Organization with combination of Household or Individual');
} else {
self::formRuleSubType($fieldType, $groupType, $errors);
}
break;
case 'Participant':
if (in_array('Membership', $groupType) || in_array('Contribution', $groupType) || in_array('Organization', $groupType) || in_array('Household', $groupType)) {
$errors['field_name'] = ts('Cannot add or update profile field type Participant with combination of Membership or Contribution or Household or Organization');
} else {
self::formRuleSubType($fieldType, $groupType, $errors);
}
break;
case 'Contribution':
if (in_array('Participant', $groupType) || in_array('Membership', $groupType) || in_array('Organization', $groupType) || in_array('Household', $groupType)) {
$errors['field_name'] = ts('Cannot add or update profile field type Contribution with combination of Membership or Participant or Household or Organization');
} else {
self::formRuleSubType($fieldType, $groupType, $errors);
}
break;
case 'Membership':
if (in_array('Participant', $groupType) || in_array('Contribution', $groupType) || in_array('Organization', $groupType) || in_array('Household', $groupType)) {
$errors['field_name'] = ts('Cannot add or update profile field type Membership with combination of Participant or Contribution or Household or Organization');
} else {
self::formRuleSubType($fieldType, $groupType, $errors);
}
break;
default:
$profileType = CRM_Core_BAO_UFField::getProfileType($fields['group_id'], true, false, true);
if (CRM_Contact_BAO_ContactType::isaSubType($fieldType)) {
if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
if ($fieldType != $profileType) {
$errors['field_name'] = ts('Cannot add or update profile field type "%1" with combination
of "%2".', array(1 => $fieldType, 2 => $profileType));
}
} else {
$basicType = CRM_Contact_BAO_ContactType::getBasicType($fieldType);
if ($profileType && $profileType != $basicType && $profileType != 'Contact') {
$errors['field_name'] = ts('Cannot add or update profile field type "%1" with combination
of "%2".', array(1 => $fieldType, 2 => $profileType));
}
}
} elseif ($fields['field_name'][1] == 'contact_sub_type' && !in_array($profileType, array('Individual', 'Household', 'Organization')) && !in_array($profileType, CRM_Contact_BAO_ContactType::subTypes())) {
$errors['field_name'] = ts('Cannot add or update profile field Contact Subtype as profile type is not one of Individual, Household or Organization.');
}
}
return empty($errors) ? true : $errors;
}
示例11: formRule
//.........这里部分代码省略.........
}
if (!$emailField) {
$disableSettingURL = CRM_Utils_System::url('civicrm/admin/setting/preferences/mailing', 'reset=1');
$errors['field_name'] = ts('Your site is currently configured to require double-opt in when users join (subscribe) to Group(s) via a Profile form. In this mode, you need to include an Email field in a Profile BEFORE you can add the Group(s) field. This ensures that an opt-in confirmation email can be sent. Your site administrator can disable double opt-in on the civimail admin settings: <em>%1</em>', array(1 => $disableSettingURL));
}
}
}
//fix for CRM-3037
$fieldType = $fields['field_name'][0];
//get the group type.
$groupType = CRM_Core_BAO_UFGroup::calculateGroupType($self->_gid, FALSE, CRM_Utils_Array::value('field_id', $fields));
switch ($fieldType) {
case 'Contact':
self::formRuleSubType($fieldType, $groupType, $errors);
break;
case 'Individual':
if (in_array('Activity', $groupType) || in_array('Household', $groupType) || in_array('Organization', $groupType)) {
//CRM-7603 - need to support activity + individual.
//$errors['field_name'] =
//ts( 'Cannot add or update profile field type Individual with combination of Household or Organization or Activity' );
if (in_array('Household', $groupType) || in_array('Organization', $groupType)) {
$errors['field_name'] = ts('Cannot add or update profile field type Individual with combination of Household or Organization');
}
} else {
self::formRuleSubType($fieldType, $groupType, $errors);
}
break;
case 'Household':
if (in_array('Activity', $groupType) || in_array('Individual', $groupType) || in_array('Organization', $groupType)) {
$errors['field_name'] = ts('Cannot add or update profile field type Household with combination of Individual or Organization or Activity');
} else {
self::formRuleSubType($fieldType, $groupType, $errors);
}
break;
case 'Organization':
if (in_array('Activity', $groupType) || in_array('Household', $groupType) || in_array('Individual', $groupType)) {
$errors['field_name'] = ts('Cannot add or update profile field type Organization with combination of Household or Individual or Activity');
} else {
self::formRuleSubType($fieldType, $groupType, $errors);
}
break;
case 'Activity':
if (in_array('Individual', $groupType) || in_array('Membership', $groupType) || in_array('Contribution', $groupType) || in_array('Organization', $groupType) || in_array('Household', $groupType) || in_array('Participant', $groupType)) {
//CRM-7603 - need to support activity + contact type.
//$errors['field_name'] =
//ts( 'Cannot add or update profile field type Activity with combination Participant or Membership or Contribution or Household or Organization or Individual' );
if (in_array('Membership', $groupType) || in_array('Contribution', $groupType) || in_array('Participant', $groupType)) {
$errors['field_name'] = ts('Cannot add or update profile field type Activity with combination Participant or Membership or Contribution');
}
} else {
self::formRuleSubType($fieldType, $groupType, $errors);
}
if ($isCustomField && !isset($errors['field_name'])) {
self::formRuleCustomDataExtentColumnValue($customField, $self->_gid, $fieldType, $errors);
}
break;
case 'Participant':
if (in_array('Membership', $groupType) || in_array('Contribution', $groupType) || in_array('Organization', $groupType) || in_array('Household', $groupType) || in_array('Activity', $groupType)) {
$errors['field_name'] = ts('Cannot add or update profile field type Participant with combination of Activity or Membership or Contribution or Household or Organization.');
} else {
self::formRuleSubType($fieldType, $groupType, $errors);
}
break;
case 'Contribution':
//special case where in we allow contribution + oganization fields, for on behalf feature
$profileId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', 'on_behalf_organization', 'id', 'name');
if (in_array('Participant', $groupType) || in_array('Membership', $groupType) || $profileId != $self->_gid && in_array('Organization', $groupType) || in_array('Household', $groupType) || in_array('Activity', $groupType)) {
$errors['field_name'] = ts('Cannot add or update profile field type Contribution with combination of Activity or Membership or Participant or Household or Organization');
} else {
self::formRuleSubType($fieldType, $groupType, $errors);
}
break;
case 'Membership':
//special case where in we allow contribution + oganization fields, for on behalf feature
$profileId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', 'on_behalf_organization', 'id', 'name');
if (in_array('Participant', $groupType) || in_array('Contribution', $groupType) || $profileId != $self->_gid && in_array('Organization', $groupType) || in_array('Household', $groupType) || in_array('Activity', $groupType)) {
$errors['field_name'] = ts('Cannot add or update profile field type Membership with combination of Activity or Participant or Contribution or Household or Organization');
} else {
self::formRuleSubType($fieldType, $groupType, $errors);
}
break;
default:
$profileType = CRM_Core_BAO_UFField::getProfileType($fields['group_id'], TRUE, FALSE, TRUE);
if (CRM_Contact_BAO_ContactType::isaSubType($fieldType)) {
if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
if ($fieldType != $profileType) {
$errors['field_name'] = ts('Cannot add or update profile field type "%1" with combination of "%2".', array(1 => $fieldType, 2 => $profileType));
}
} else {
$basicType = CRM_Contact_BAO_ContactType::getBasicType($fieldType);
if ($profileType && $profileType != $basicType && $profileType != 'Contact') {
$errors['field_name'] = ts('Cannot add or update profile field type "%1" with combination of "%2".', array(1 => $fieldType, 2 => $profileType));
}
}
} elseif (CRM_Utils_Array::value(1, $fields['field_name']) == 'contact_sub_type' && !in_array($profileType, array('Individual', 'Household', 'Organization')) && !in_array($profileType, CRM_Contact_BAO_ContactType::subTypes())) {
$errors['field_name'] = ts('Cannot add or update profile field Contact Subtype as profile type is not one of Individual, Household or Organization.');
}
}
return empty($errors) ? TRUE : $errors;
}
示例12: buildProfile
//.........这里部分代码省略.........
} elseif (in_array($fieldName, array('membership_start_date', 'membership_end_date', 'join_date'))) {
$form->addDate($name, $title, $required, array('formatType' => 'custom'));
} 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);
}
示例13: allowEditSubtype
/**
* Function to check whether allow to edit any contact's subtype
* on the basis of custom data and relationship of specific subtype
*
* @param int $contactId contact id.
* @param string $subType subtype.
*
* @return boolean true/false.
* @static
*/
static function allowEditSubtype($contactId, $subType, $groupTree = null)
{
if (!$contactId || empty($subType)) {
return true;
}
require_once 'CRM/Contact/BAO/ContactType.php';
$contactType = CRM_Contact_BAO_ContactType::getBasicType($subType);
$subTypeGroupTree = array();
if (!array_key_exists($contactType . '_' . $subType, $subTypeGroupTree) && empty($groupTree)) {
$form = null;
require_once 'CRM/Core/BAO/CustomGroup.php';
$subTypeGroupTree[$contactType . '_' . $subType] = CRM_Core_BAO_CustomGroup::getTree($contactType, $form, $contactId, null, $subType, null);
} else {
$subTypeGroupTree[$contactType . '_' . $subType] = $groupTree;
}
if (!empty($subTypeGroupTree[$contactType . '_' . $subType])) {
foreach ($subTypeGroupTree[$contactType . '_' . $subType] as $groupId => $groupDetails) {
if (CRM_Utils_Array::value('extends_entity_column_value', $groupDetails)) {
$customValue = CRM_Utils_Array::retrieveValueRecursive($groupDetails['fields'], 'element_value');
if (!empty($customValue)) {
return false;
} else {
continue;
}
}
}
}
if (!array_key_exists('rel_' . $contactType . '_' . $subType, $subTypeGroupTree)) {
require_once 'CRM/Contact/BAO/Relationship.php';
$relationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(null, null, null, $contactType, false, 'label', true, $subType, true);
$subTypeGroupTree['rel_' . $contactType . '_' . $subType] = $relationshipTypes;
}
$relationships = CRM_Contact_BAO_Relationship::getRelationship($contactId);
if (!empty($relationships)) {
foreach ($relationships as $relId => $details) {
if (in_array($details['relation'], $subTypeGroupTree['rel_' . $contactType . '_' . $subType])) {
return false;
} else {
continue;
}
}
}
return true;
}
示例14: createProfileContact
/**
* function to add/edit/register contacts through profile.
*
* @params array $params Array of profile fields to be edited/added.
* @params int $contactID contact_id of the contact to be edited/added.
* @params array $fields array of fields from UFGroup
* @params int $addToGroupID specifies the default group to which contact is added.
* @params int $ufGroupId uf group id (profile id)
* @param string $ctype contact type
*
* @return int contact id created/edited
* @static
* @access public
*/
static function createProfileContact(&$params, &$fields, $contactID = null, $addToGroupID = null, $ufGroupId = null, $ctype = null, $visibility = false)
{
// add ufGroupID to params array ( CRM-2012 )
if ($ufGroupId) {
$params['uf_group_id'] = $ufGroupId;
}
require_once 'CRM/Utils/Hook.php';
if ($contactID) {
$editHook = true;
CRM_Utils_Hook::pre('edit', 'Profile', $contactID, $params);
} else {
$editHook = false;
CRM_Utils_Hook::pre('create', 'Profile', null, $params);
}
$data = $contactDetails = array();
// get the contact details (hier)
if ($contactID) {
list($details, $options) = self::getHierContactDetails($contactID, $fields);
$contactDetails = $details[$contactID];
$data['contact_type'] = CRM_Utils_Array::value('contact_type', $contactDetails);
} else {
//we should get contact type only if contact
if ($ufGroupId) {
require_once "CRM/Core/BAO/UFField.php";
$data['contact_type'] = CRM_Core_BAO_UFField::getProfileType($ufGroupId);
//special case to handle profile with only contact fields
if ($data['contact_type'] == 'Contact') {
$data['contact_type'] = 'Individual';
} else {
if (CRM_Contact_BAO_ContactType::isaSubType($data['contact_type'])) {
$data['contact_type'] = CRM_Contact_BAO_ContactType::getBasicType($data['contact_type']);
}
}
} else {
if ($ctype) {
$data['contact_type'] = $ctype;
} else {
$data['contact_type'] = 'Individual';
}
}
}
//fix contact sub type CRM-5125
if ($subType = CRM_Utils_Array::value('contact_sub_type', $params)) {
$data['contact_sub_type'] = $subType;
} else {
if ($subType = CRM_Utils_Array::value('contact_sub_type_hidden', $params)) {
// if profile was used, and had any subtype, we obtain it from there
$data['contact_sub_type'] = $subType;
}
}
if ($ctype == "Organization") {
$data["organization_name"] = $contactDetails["organization_name"];
} else {
if ($ctype == "Household") {
$data["household_name"] = $contactDetails["household_name"];
}
}
$locationType = array();
$count = 1;
if ($contactID) {
//add contact id
$data['contact_id'] = $contactID;
$primaryLocationType = self::getPrimaryLocationType($contactID);
} else {
require_once "CRM/Core/BAO/LocationType.php";
$defaultLocation =& CRM_Core_BAO_LocationType::getDefault();
$defaultLocationId = $defaultLocation->id;
}
// get the billing location type
$locationTypes =& CRM_Core_PseudoConstant::locationType();
$billingLocationTypeId = array_search('Billing', $locationTypes);
$blocks = array('email', 'phone', 'im', 'openid');
// prevent overwritten of formatted array, reset all block from
// params if it is not in valid format (since import pass valid format)
foreach ($blocks as $blk) {
if (array_key_exists($blk, $params) && !is_array($params[$blk])) {
unset($params[$blk]);
}
}
$primaryPhoneLoc = null;
foreach ($params as $key => $value) {
$fieldName = $locTypeId = $typeId = null;
list($fieldName, $locTypeId, $typeId) = CRM_Utils_System::explode('-', $key, 3);
//store original location type id
$actualLocTypeId = $locTypeId;
if ($locTypeId == 'Primary') {
//.........这里部分代码省略.........
示例15: buildQuickForm
/**
* Function to actually build the form
*
* @return void
* @access public
*/
public function buildQuickForm()
{
//lets have single status message, CRM-4363
$return = false;
$statusMessage = null;
//we should not allow component and mix profiles in search mode
if ($this->_mode != self::MODE_REGISTER) {
//check for mix profile fields (eg: individual + other contact type)
if (CRM_Core_BAO_UFField::checkProfileType($this->_gid)) {
$statusMessage = ts('Profile search, view and edit are not supported for Profiles which include fields for more than one record type.');
}
$profileType = CRM_Core_BAO_UFField::getProfileType($this->_gid);
if ($this->_id) {
list($contactType, $contactSubType) = CRM_Contact_BAO_Contact::getContactTypes($this->_id);
$profileSubType = false;
if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
$profileSubType = $profileType;
$profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType);
}
if ($profileType != 'Contact' && ($profileSubType && $contactSubType && $profileSubType != $contactSubType || $profileType != $contactType)) {
$return = true;
if (!$statusMessage) {
$statusMessage = ts("This profile is configured for contact type '%1'. It cannot be used to edit contacts of other types.", array(1 => $profileSubType ? $profileSubType : $profileType));
}
}
}
if (in_array($profileType, array("Membership", "Participant", "Contribution"))) {
$return = true;
if (!$statusMessage) {
$statusMessage = ts('Profile is not configured for the selected action.');
}
}
}
//lets have sigle status message,
$this->assign('statusMessage', $statusMessage);
if ($return) {
return false;
}
$sBlocks = array();
$hBlocks = array();
$config =& CRM_Core_Config::singleton();
$this->assign('id', $this->_id);
$this->assign('mode', $this->_mode);
$this->assign('action', $this->_action);
$this->assign_by_ref('fields', $this->_fields);
$this->assign('fieldset', isset($this->_fieldset) ? $this->_fieldset : "");
// do we need inactive options ?
if ($this->_action & CRM_Core_Action::VIEW) {
$inactiveNeeded = true;
} else {
$inactiveNeeded = false;
}
$session =& CRM_Core_Session::singleton();
// should we restrict what we display
$admin = true;
if ($this->_mode == self::MODE_EDIT) {
$admin = false;
// show all fields that are visibile:
// if we are a admin OR the same user OR acl-user with access to the profile
require_once 'CRM/ACL/API.php';
if (CRM_Core_Permission::check('administer users') || $this->_id == $session->get('userID') || in_array($this->_gid, CRM_ACL_API::group(CRM_Core_Permission::EDIT, null, 'civicrm_uf_group', CRM_Core_PseudoConstant::ufGroup()))) {
$admin = true;
}
}
$userID = $session->get('userID');
$anonUser = false;
// if false, user is not logged-in.
if (!$userID) {
require_once 'CRM/Core/BAO/LocationType.php';
$defaultLocationType =& CRM_Core_BAO_LocationType::getDefault();
$primaryLocationType = $defaultLocationType->id;
$anonUser = true;
$this->assign('anonUser', true);
}
$addCaptcha = array();
$emailPresent = false;
// cache the state country fields. based on the results, we could use our javascript solution
// in create or register mode
$stateCountryMap = array();
// add the form elements
foreach ($this->_fields as $name => $field) {
// make sure that there is enough permission to expose this field
if (!$admin && $field['visibility'] == 'User and User Admin Only' || CRM_Utils_Array::value('is_view', $field)) {
unset($this->_fields[$name]);
continue;
}
// since the CMS manages the email field, suppress the email display if in
// register mode which occur within the CMS form
if ($this->_mode == self::MODE_REGISTER && substr($name, 0, 5) == 'email') {
unset($this->_fields[$name]);
continue;
}
list($prefixName, $index) = CRM_Utils_System::explode('-', $name, 2);
if ($prefixName == 'state_province' || $prefixName == 'country') {
//.........这里部分代码省略.........