本文整理汇总了PHP中CRM_Core_BAO_UFGroup::setComponentDefaults方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_BAO_UFGroup::setComponentDefaults方法的具体用法?PHP CRM_Core_BAO_UFGroup::setComponentDefaults怎么用?PHP CRM_Core_BAO_UFGroup::setComponentDefaults使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Core_BAO_UFGroup
的用法示例。
在下文中一共展示了CRM_Core_BAO_UFGroup::setComponentDefaults方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: civicrm_api3_profile_get
/**
* Retrieve Profile field values.
*
* @param array $params Associative array of property name/value
* pairs to get profile field values
*
* @return Profile field values|CRM_Error
*
* @todo add example
* @todo add test cases
*
*/
function civicrm_api3_profile_get($params)
{
civicrm_api3_verify_mandatory($params, NULL, array('profile_id', 'contact_id'));
if (!CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $params['profile_id'], 'is_active')) {
return civicrm_api3_create_error('Invalid value for profile_id');
}
$isContactActivityProfile = CRM_Core_BAO_UFField::checkContactActivityProfileType($params['profile_id']);
if (CRM_Core_BAO_UFField::checkProfileType($params['profile_id']) && !$isContactActivityProfile) {
return civicrm_api3_create_error('Can not retrieve values for profiles include fields for more than one record type.');
}
$profileFields = CRM_Core_BAO_UFGroup::getFields($params['profile_id'], FALSE, NULL, NULL, NULL, FALSE, NULL, TRUE, NULL, CRM_Core_Permission::EDIT);
$values = array();
if ($isContactActivityProfile) {
civicrm_api3_verify_mandatory($params, NULL, array('activity_id'));
require_once 'CRM/Profile/Form.php';
$errors = CRM_Profile_Form::validateContactActivityProfile($params['activity_id'], $params['contact_id'], $params['profile_id']);
if (!empty($errors)) {
return civicrm_api3_create_error(array_pop($errors));
}
$contactFields = $activityFields = array();
foreach ($profileFields as $fieldName => $field) {
if (CRM_Utils_Array::value('field_type', $field) == 'Activity') {
$activityFields[$fieldName] = $field;
} else {
$contactFields[$fieldName] = $field;
}
}
CRM_Core_BAO_UFGroup::setProfileDefaults($params['contact_id'], $contactFields, $values, TRUE);
if ($params['activity_id']) {
CRM_Core_BAO_UFGroup::setComponentDefaults($activityFields, $params['activity_id'], 'Activity', $values, TRUE);
}
} else {
CRM_Core_BAO_UFGroup::setProfileDefaults($params['contact_id'], $profileFields, $values, TRUE);
}
$result = civicrm_api3_create_success();
$result['values'] = $values;
return $result;
}
示例2: setDefaultsValues
/**
* Set default values for the form. Note that in edit/view mode
* the default values are retrieved from the database
*
*
* @return void
*/
public function setDefaultsValues()
{
$this->_defaults = array();
if ($this->_multiRecordProfile && $this->_multiRecord == CRM_Core_Action::DELETE) {
return;
}
if ($this->_mode != self::MODE_SEARCH) {
// set default values for country / state to start with
CRM_Core_BAO_UFGroup::setRegisterDefaults($this->_fields, $this->_defaults);
}
if ($this->_id && !$this->_multiRecordProfile) {
if ($this->_isContactActivityProfile) {
$contactFields = $activityFields = array();
foreach ($this->_fields as $fieldName => $field) {
if (CRM_Utils_Array::value('field_type', $field) == 'Activity') {
$activityFields[$fieldName] = $field;
} else {
$contactFields[$fieldName] = $field;
}
}
CRM_Core_BAO_UFGroup::setProfileDefaults($this->_id, $contactFields, $this->_defaults, TRUE);
if ($this->_activityId) {
CRM_Core_BAO_UFGroup::setComponentDefaults($activityFields, $this->_activityId, 'Activity', $this->_defaults, TRUE);
}
} else {
CRM_Core_BAO_UFGroup::setProfileDefaults($this->_id, $this->_fields, $this->_defaults, TRUE);
}
}
//set custom field defaults
if ($this->_multiRecordProfile) {
foreach ($this->_multiRecordFields as $key => $field) {
$fieldIds[] = CRM_Core_BAO_CustomField::getKeyID($key);
}
$defaultValues = array();
if ($this->_multiRecord && $this->_multiRecord == CRM_Core_Action::UPDATE) {
$defaultValues = CRM_Core_BAO_CustomValueTable::getEntityValues($this->_id, NULL, $fieldIds, TRUE);
if ($this->_recordExists == TRUE) {
$defaultValues = $defaultValues[$this->_recordId];
} else {
$defaultValues = NULL;
}
}
if (!empty($defaultValues)) {
foreach ($defaultValues as $key => $value) {
$name = "custom_{$key}";
$htmlType = $this->_multiRecordFields[$name]['html_type'];
if ($htmlType != 'File') {
if (isset($value)) {
CRM_Core_BAO_CustomField::setProfileDefaults($key, $name, $this->_defaults, $this->_id, $this->_mode, $value);
} else {
$this->_defaults[$name] = "";
}
}
if ($htmlType == 'File') {
$entityId = $this->_id;
if (CRM_Utils_Array::value('field_type', $field) == 'Activity' && $this->_activityId) {
$entityId = $this->_activityId;
}
$url = CRM_Core_BAO_CustomField::getFileURL($entityId, $key);
if ($url) {
$customFiles[$name]['displayURL'] = ts("Attached File") . ": {$url['file_url']}";
$deleteExtra = ts("Are you sure you want to delete attached file?");
$fileId = $url['file_id'];
$deleteURL = CRM_Utils_System::url('civicrm/file', "reset=1&id={$fileId}&eid={$entityId}&fid={$key}&action=delete");
$text = ts("Delete Attached File");
$customFiles[$field['name']]['deleteURL'] = "<a href=\"{$deleteURL}\" onclick = \"if (confirm( ' {$deleteExtra} ' )) this.href+='&confirmed=1'; else return false;\">{$text}</a>";
// also delete the required rule that we've set on the form element
$this->removeFileRequiredRules($name);
}
}
}
}
} else {
foreach ($this->_fields as $name => $field) {
if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
$htmlType = $field['html_type'];
if ((!isset($this->_defaults[$name]) || $htmlType == 'File') && CRM_Utils_Array::value('field_type', $field) != 'Activity') {
CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults, $this->_id, $this->_mode);
}
if ($htmlType == 'File') {
$entityId = $this->_id;
if (CRM_Utils_Array::value('field_type', $field) == 'Activity' && $this->_activityId) {
$entityId = $this->_activityId;
}
$url = CRM_Core_BAO_CustomField::getFileURL($entityId, $customFieldID);
if ($url) {
$customFiles[$field['name']]['displayURL'] = ts("Attached File") . ": {$url['file_url']}";
$deleteExtra = ts("Are you sure you want to delete attached file?");
$fileId = $url['file_id'];
$deleteURL = CRM_Utils_System::url('civicrm/file', "reset=1&id={$fileId}&eid={$entityId}&fid={$customFieldID}&action=delete");
$text = ts("Delete Attached File");
$customFiles[$field['name']]['deleteURL'] = "<a href=\"{$deleteURL}\" onclick = \"if (confirm( ' {$deleteExtra} ' )) this.href+='&confirmed=1'; else return false;\">{$text}</a>";
// also delete the required rule that we've set on the form element
//.........这里部分代码省略.........
示例3: civicrm_api3_profile_get
/**
* Retrieve Profile field values.
*
* NOTE this api is not standard & since it is tested we need to honour that
* but the correct behaviour is for it to return an id indexed array as this supports
* multiple instances - if a single profile is passed in we will not return a normal api result array
* in order to avoid breaking code. (This could still be confusing :-( but we have to keep the tested behaviour working
*
* Note that if contact_id is empty an array of defaults is returned
*
* @param array $params
* Associative array of property name/value.
* pairs to get profile field values
*
* @throws API_Exception
* @return array
*/
function civicrm_api3_profile_get($params)
{
$nonStandardLegacyBehaviour = is_numeric($params['profile_id']) ? TRUE : FALSE;
if (!empty($params['check_permissions']) && !empty($params['contact_id']) && !1 === civicrm_api3('contact', 'getcount', array('contact_id' => $params['contact_id'], 'check_permissions' => 1))) {
throw new API_Exception('permission denied');
}
$profiles = (array) $params['profile_id'];
$values = array();
$ufGroupBAO = new CRM_Core_BAO_UFGroup();
foreach ($profiles as $profileID) {
$profileID = _civicrm_api3_profile_getProfileID($profileID);
$values[$profileID] = array();
if (strtolower($profileID) == 'billing') {
$values[$profileID] = _civicrm_api3_profile_getbillingpseudoprofile($params);
continue;
}
if (!CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $profileID, 'is_active')) {
throw new API_Exception('Invalid value for profile_id : ' . $profileID);
}
$isContactActivityProfile = CRM_Core_BAO_UFField::checkContactActivityProfileType($profileID);
$profileFields = CRM_Core_BAO_UFGroup::getFields($profileID, FALSE, NULL, NULL, NULL, FALSE, NULL, empty($params['check_permissions']) ? FALSE : TRUE, NULL, CRM_Core_Permission::EDIT);
if ($isContactActivityProfile) {
civicrm_api3_verify_mandatory($params, NULL, array('activity_id'));
$errors = CRM_Profile_Form::validateContactActivityProfile($params['activity_id'], $params['contact_id'], $params['profile_id']);
if (!empty($errors)) {
throw new API_Exception(array_pop($errors));
}
$contactFields = $activityFields = array();
foreach ($profileFields as $fieldName => $field) {
if (CRM_Utils_Array::value('field_type', $field) == 'Activity') {
$activityFields[$fieldName] = $field;
} else {
$contactFields[$fieldName] = $field;
// we should return 'Primary' with & without capitalisation. it is more consistent with api to not
// capitalise, but for form support we need it for now. Hopefully we can move away from it
$contactFields[strtolower($fieldName)] = $field;
}
}
$ufGroupBAO->setProfileDefaults($params['contact_id'], $contactFields, $values[$profileID], TRUE);
if ($params['activity_id']) {
$ufGroupBAO->setComponentDefaults($activityFields, $params['activity_id'], 'Activity', $values[$profileID], TRUE);
}
} elseif (!empty($params['contact_id'])) {
$ufGroupBAO->setProfileDefaults($params['contact_id'], $profileFields, $values[$profileID], TRUE);
foreach ($values[$profileID] as $fieldName => $field) {
// we should return 'Primary' with & without capitalisation. it is more consistent with api to not
// capitalise, but for form support we need it for now. Hopefully we can move away from it
$values[$profileID][strtolower($fieldName)] = $field;
}
} else {
$values[$profileID] = array_fill_keys(array_keys($profileFields), '');
}
}
if ($nonStandardLegacyBehaviour) {
$result = civicrm_api3_create_success();
$result['values'] = $values[$profileID];
return $result;
} else {
return civicrm_api3_create_success($values, $params, 'Profile', 'Get');
}
}
示例4: setDefaultsValues
/**
* This function sets the default values for the form. Note that in edit/view mode
* the default values are retrieved from the database
*
* @access public
*
* @return void
*/
function setDefaultsValues()
{
$this->_defaults = array();
if ($this->_id) {
if ($this->_isContactActivityProfile) {
$contactFields = $activityFields = array();
foreach ($this->_fields as $fieldName => $field) {
if (CRM_Utils_Array::value('field_type', $field) == 'Activity') {
$activityFields[$fieldName] = $field;
} else {
$contactFields[$fieldName] = $field;
}
}
CRM_Core_BAO_UFGroup::setProfileDefaults($this->_id, $contactFields, $this->_defaults, TRUE);
if ($this->_activityId) {
CRM_Core_BAO_UFGroup::setComponentDefaults($activityFields, $this->_activityId, 'Activity', $this->_defaults, TRUE);
}
} else {
CRM_Core_BAO_UFGroup::setProfileDefaults($this->_id, $this->_fields, $this->_defaults, TRUE);
}
}
//set custom field defaults
foreach ($this->_fields as $name => $field) {
if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
$htmlType = $field['html_type'];
if ((!isset($this->_defaults[$name]) || $htmlType == 'File') && CRM_Utils_Array::value('field_type', $field) != 'Activity') {
CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults, $this->_id, $this->_mode);
}
if ($htmlType == 'File') {
$entityId = $this->_id;
if (CRM_Utils_Array::value('field_type', $field) == 'Activity' && $this->_activityId) {
$entityId = $this->_activityId;
}
$url = CRM_Core_BAO_CustomField::getFileURL($entityId, $customFieldID);
if ($url) {
$customFiles[$field['name']]['displayURL'] = ts("Attached File") . ": {$url['file_url']}";
$deleteExtra = ts("Are you sure you want to delete attached file?");
$fileId = $url['file_id'];
$deleteURL = CRM_Utils_System::url('civicrm/file', "reset=1&id={$fileId}&eid={$entityId}&fid={$customFieldID}&action=delete");
$text = ts("Delete Attached File");
$customFiles[$field['name']]['deleteURL'] = "<a href=\"{$deleteURL}\" onclick = \"if (confirm( ' {$deleteExtra} ' )) this.href+='&confirmed=1'; else return false;\">{$text}</a>";
// also delete the required rule that we've set on the form element
$this->removeFileRequiredRules($field['name']);
}
}
}
}
if (isset($customFiles)) {
$this->assign('customFiles', $customFiles);
}
if (CRM_Utils_Array::value('image_URL', $this->_defaults)) {
list($imageWidth, $imageHeight) = getimagesize($this->_defaults['image_URL']);
list($imageThumbWidth, $imageThumbHeight) = CRM_Contact_BAO_Contact::getThumbSize($imageWidth, $imageHeight);
$this->assign("imageWidth", $imageWidth);
$this->assign("imageHeight", $imageHeight);
$this->assign("imageThumbWidth", $imageThumbWidth);
$this->assign("imageThumbHeight", $imageThumbHeight);
$this->assign("imageURL", $this->_defaults['image_URL']);
}
if (array_key_exists('contact_sub_type', $this->_defaults) && !empty($this->_defaults['contact_sub_type'])) {
$this->_defaults['contact_sub_type'] = explode(CRM_Core_DAO::VALUE_SEPARATOR, trim($this->_defaults['contact_sub_type'], CRM_Core_DAO::VALUE_SEPARATOR));
}
$this->setDefaults($this->_defaults);
}