本文整理汇总了PHP中CRM_Core_BAO_UFField::add方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_BAO_UFField::add方法的具体用法?PHP CRM_Core_BAO_UFField::add怎么用?PHP CRM_Core_BAO_UFField::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Core_BAO_UFField
的用法示例。
在下文中一共展示了CRM_Core_BAO_UFField::add方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: civicrm_api3_uf_field_create
/**
* Defines 'uf field' within a group.
*
* @param array $params
* Array per getfields metadata.
*
* @throws API_Exception
*
* @return array
* Newly created $ufFieldArray
*/
function civicrm_api3_uf_field_create($params)
{
civicrm_api3_verify_one_mandatory($params, NULL, array('field_name', 'uf_group_id'));
$groupId = CRM_Utils_Array::value('uf_group_id', $params);
if ((int) $groupId < 1) {
throw new API_Exception('Params must be a field_name-carrying array and a positive integer.');
}
$field_type = CRM_Utils_Array::value('field_type', $params);
$field_name = CRM_Utils_Array::value('field_name', $params);
$location_type_id = CRM_Utils_Array::value('location_type_id', $params, CRM_Utils_Array::value('website_type_id', $params));
$phone_type = CRM_Utils_Array::value('phone_type_id', $params, CRM_Utils_Array::value('phone_type', $params));
if (!CRM_Core_BAO_UFField::isValidFieldName($field_name)) {
throw new API_Exception('The field_name is not valid');
}
$params['field_name'] = array($field_type, $field_name, $location_type_id, $phone_type);
if (!CRM_Utils_Array::value('group_id', $params)) {
$params['group_id'] = $groupId;
}
$ids = $ufFieldArray = array();
$ids['uf_group'] = $groupId;
$fieldId = CRM_Utils_Array::value('id', $params);
if (!empty($fieldId)) {
$UFField = new CRM_Core_BAO_UFField();
$UFField->id = $fieldId;
if ($UFField->find(TRUE)) {
$ids['uf_group'] = $UFField->uf_group_id;
if (!CRM_Utils_Array::value('group_id', $params)) {
// this copied here from previous api function - not sure if required
$params['group_id'] = $UFField->uf_group_id;
}
} else {
throw new API_Exception("there is no field for this fieldId");
}
$ids['uf_field'] = $fieldId;
}
if (CRM_Core_BAO_UFField::duplicateField($params, $ids)) {
throw new API_Exception("The field was not added. It already exists in this profile.");
}
//@todo why is this even optional? Surely weight should just be 'managed' ??
if (CRM_Utils_Array::value('option.autoweight', $params, TRUE)) {
$params['weight'] = CRM_Core_BAO_UFField::autoWeight($params);
}
$ufField = CRM_Core_BAO_UFField::add($params, $ids);
$fieldsType = CRM_Core_BAO_UFGroup::calculateGroupType($groupId, TRUE);
CRM_Core_BAO_UFGroup::updateGroupTypes($groupId, $fieldsType);
_civicrm_api3_object_to_array($ufField, $ufFieldArray[$ufField->id]);
civicrm_api3('profile', 'getfields', array('cache_clear' => TRUE));
return civicrm_api3_create_success($ufFieldArray, $params);
}
示例2: crm_update_uf_field
/**
* Use this API to update uf field . See the CRM Data Model for uf_field property definitions
*
* @param $params array Associative array of property name/value pairs to update in field.
*
* @param $ufField Object A valid uf field object that to be updated.
*
* @return updated uf_field object
*
* @access public
*/
function crm_update_uf_field($params, $ufField)
{
_crm_initialize();
$fieldId = $ufField->id;
if (!isset($fieldId)) {
return _crm_error("parameter fieldId is not set");
}
if (!is_array($params)) {
return _crm_error("params is not an array ");
}
$field_type = $params['field_type'];
$field_name = $params['field_name'];
$location_type_id = $params['location_type_id'];
$phone_type = $params['phone_type'];
$params['field_name'] = array($field_type, $field_name, $location_type_id, $phone_type);
require_once 'CRM/Core/BAO/UFField.php';
$UFField =& new CRM_core_BAO_UFField();
$UFField->id = $fieldId;
$ids = array();
if ($UFField->find(true)) {
$ids['uf_group'] = $UFField->uf_group_id;
} else {
return _crm_error("there is no field for this fieldId");
}
$ids['uf_field'] = $fieldId;
if (CRM_Core_BAO_UFField::duplicateField($params, $ids)) {
return _crm_error("The field was not added. It already exists in this profile.");
}
return CRM_Core_BAO_UFField::add($params, $ids);
}
示例3: postProcess
/**
* Process the form
*
* @return void
* @access public
*/
public function postProcess()
{
$ids = array('uf_group' => $this->_gid);
if ($this->_action & CRM_Core_Action::DELETE) {
$fieldValues = array('uf_group_id' => $this->_gid);
$wt = CRM_Utils_Weight::delWeight('CRM_Core_DAO_UFField', $this->_id, $fieldValues);
$deleted = CRM_Core_BAO_UFField::del($this->_id);
//update group_type every time. CRM-3608
if ($this->_gid && $deleted) {
//get the profile type.
$groupType = 'null';
$fieldsType = CRM_Core_BAO_UFGroup::calculateGroupType($this->_gid);
if (!empty($fieldsType)) {
$groupType = implode(',', $fieldsType);
}
//set group type
CRM_Core_DAO::setFieldValue('CRM_Core_DAO_UFGroup', $this->_gid, 'group_type', $groupType);
}
CRM_Core_Session::setStatus(ts('Selected Profile Field has been deleted.'));
return;
}
// store the submitted values in an array
$params = $this->controller->exportValues('Field');
if ($params['visibility'] == 'User and User Admin Only') {
$params['is_searchable'] = 0;
$params['in_selector'] = 0;
}
if ($this->_action & CRM_Core_Action::UPDATE) {
$ids['uf_field'] = $this->_id;
}
//check for duplicate fields
if (CRM_Core_BAO_UFField::duplicateField($params, $ids)) {
CRM_Core_Session::setStatus(ts('The selected field was not added. It already exists in this profile.'));
return;
} else {
$ufField = CRM_Core_BAO_UFField::add($params, $ids);
$name = $this->_selectFields[$ufField->field_name];
//reset other field is searchable and in selector settings, CRM-4363
if ($this->_hasSearchableORInSelector && in_array($ufField->field_type, array('Participant', 'Contribution', 'Membership'))) {
CRM_Core_BAO_UFField::resetInSelectorANDSearchable($this->_gid);
}
$config =& CRM_Core_Config::singleton();
$showBestResult = false;
if (in_array($ufField->field_name, array('country', 'state_province')) && count($config->countryLimit) > 1) {
// get state or country field weight if exists
$field = 'state_province';
if ($ufField->field_name == 'state_province') {
$field = 'country';
}
$ufFieldDAO =& new CRM_Core_DAO_UFField();
$ufFieldDAO->field_name = $field;
$ufFieldDAO->location_type_id = $ufField->location_type_id;
$ufFieldDAO->uf_group_id = $ufField->uf_group_id;
if ($ufFieldDAO->find(true)) {
if ($field == 'country' && $ufFieldDAO->weight > $ufField->weight) {
$showBestResult = true;
} elseif ($field == 'state_province' && $ufFieldDAO->weight < $ufField->weight) {
$showBestResult = true;
}
}
}
//update group_type every time. CRM-3608
if ($this->_gid && is_a($ufField, 'CRM_Core_DAO_UFField')) {
//get the profile type.
$groupType = 'null';
$fieldsType = CRM_Core_BAO_UFGroup::calculateGroupType($this->_gid);
if (!empty($fieldsType)) {
$groupType = implode(',', $fieldsType);
}
//set group type
CRM_Core_DAO::setFieldValue('CRM_Core_DAO_UFGroup', $this->_gid, 'group_type', $groupType);
}
CRM_Core_Session::setStatus(ts('Your CiviCRM Profile Field \'%1\' has been saved.', array(1 => $name)));
}
$buttonName = $this->controller->getButtonName();
$session =& CRM_Core_Session::singleton();
if ($buttonName == $this->getButtonName('next', 'new')) {
CRM_Core_Session::setStatus(ts(' You can add another profile field.'));
$session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/uf/group/field', "reset=1&action=add&gid={$this->_gid}&sbr={$showBestResult}"));
} else {
$session->set('showBestResult', $showBestResult);
}
}
示例4: postProcess
/**
* Process the form
*
* @return void
* @access public
*/
function postProcess()
{
if ($this->_action & CRM_CORE_ACTION_DELETE) {
CRM_Core_BAO_UFField::del($this->_id);
CRM_Core_Session::setStatus(ts('Selected Profile Field has been deleted.'));
return;
}
// store the submitted values in an array
$params = $this->controller->exportValues('Field');
$ids = array();
if ($this->_action & CRM_CORE_ACTION_UPDATE) {
$ids['uf_field'] = $this->_id;
}
$ids['uf_group'] = $this->_gid;
//check for duplicate fields
if (CRM_Core_BAO_UFField::duplicateField($params, $ids)) {
CRM_Core_Session::setStatus(ts('The selected field was not added. It already exists in this profile.'));
return;
} else {
$ufField = CRM_Core_BAO_UFField::add($params, $ids);
$name = $this->_selectFields[$ufField->field_name];
CRM_Core_Session::setStatus(ts('Your civicrm profile field "%1" has been saved.', array(1 => $name)));
}
}
示例5: postProcess
/**
* Process the form.
*
* @return void
*/
public function postProcess()
{
$ids = array('uf_group' => $this->_gid);
if ($this->_action & CRM_Core_Action::DELETE) {
$fieldValues = array('uf_group_id' => $this->_gid);
CRM_Utils_Weight::delWeight('CRM_Core_DAO_UFField', $this->_id, $fieldValues);
$deleted = CRM_Core_BAO_UFField::del($this->_id);
//update group_type every time. CRM-3608
if ($this->_gid && $deleted) {
//get the profile type.
$fieldsType = CRM_Core_BAO_UFGroup::calculateGroupType($this->_gid, TRUE);
CRM_Core_BAO_UFGroup::updateGroupTypes($this->_gid, $fieldsType);
}
CRM_Core_Session::setStatus(ts('Selected Profile Field has been deleted.'), ts('Profile Field Deleted'), 'success');
return;
}
// store the submitted values in an array
$params = $this->controller->exportValues('Field');
if ($params['visibility'] == 'User and User Admin Only') {
$params['is_searchable'] = $params['in_selector'] = 0;
}
if ($this->_action & CRM_Core_Action::UPDATE) {
$ids['uf_field'] = $this->_id;
}
$name = NULL;
if (isset($params['field_name'][1]) && isset($this->_selectFields[$params['field_name'][1]])) {
// we dont get a name for a html formatting element
$name = $this->_selectFields[$params['field_name'][1]];
}
//Hack for Formatting Field Name
if ($params['field_name'][0] == 'Formatting') {
$params['field_name'][1] = 'formatting_' . rand(1000, 9999);
}
//check for duplicate fields
if ($params["field_name"][0] != "Formatting" && CRM_Core_BAO_UFField::duplicateField($params, $ids)) {
CRM_Core_Session::setStatus(ts('The selected field already exists in this profile.'), ts('Field Not Added'), 'error');
return;
} else {
$params['weight'] = CRM_Core_BAO_UFField::autoWeight($params);
$ufField = CRM_Core_BAO_UFField::add($params, $ids);
//reset other field is searchable and in selector settings, CRM-4363
if ($this->_hasSearchableORInSelector && in_array($ufField->field_type, array('Participant', 'Contribution', 'Membership', 'Activity', 'Case'))) {
CRM_Core_BAO_UFField::resetInSelectorANDSearchable($this->_gid);
}
$config = CRM_Core_Config::singleton();
$showBestResult = FALSE;
if (in_array($ufField->field_name, array('country', 'state_province')) && count($config->countryLimit) > 1) {
// get state or country field weight if exists
$field = 'state_province';
if ($ufField->field_name == 'state_province') {
$field = 'country';
}
$ufFieldDAO = new CRM_Core_DAO_UFField();
$ufFieldDAO->field_name = $field;
$ufFieldDAO->location_type_id = $ufField->location_type_id;
$ufFieldDAO->uf_group_id = $ufField->uf_group_id;
if ($ufFieldDAO->find(TRUE)) {
if ($field == 'country' && $ufFieldDAO->weight > $ufField->weight) {
$showBestResult = TRUE;
} elseif ($field == 'state_province' && $ufFieldDAO->weight < $ufField->weight) {
$showBestResult = TRUE;
}
}
}
//update group_type every time. CRM-3608
if ($this->_gid && is_a($ufField, 'CRM_Core_DAO_UFField')) {
// get the profile type.
$fieldsType = CRM_Core_BAO_UFGroup::calculateGroupType($this->_gid, TRUE);
CRM_Core_BAO_UFGroup::updateGroupTypes($this->_gid, $fieldsType);
}
CRM_Core_Session::setStatus(ts('Your CiviCRM Profile Field \'%1\' has been saved to \'%2\'.', array(1 => $name, 2 => $this->_title)), ts('Profile Field Saved'), 'success');
}
$buttonName = $this->controller->getButtonName();
$session = CRM_Core_Session::singleton();
if ($buttonName == $this->getButtonName('next', 'new')) {
$session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/uf/group/field/add', "reset=1&action=add&gid={$this->_gid}&sbr={$showBestResult}"));
} else {
$session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/uf/group/field', "reset=1&action=browse&gid={$this->_gid}"));
$session->set('showBestResult', $showBestResult);
}
}
示例6: civicrm_uf_field_update
/**
* Use this API to update uf field . See the CRM Data Model for uf_field property definitions
*
* @param $params array Associative array of property name/value pairs to update in field.
*
* @param $fieldId int A valid uf field id that to be updated.
*
* @return updated $ufFieldArray array
*
* @access public
*/
function civicrm_uf_field_update($params, $fieldId)
{
_civicrm_initialize();
if (!isset($fieldId)) {
return civicrm_create_error("parameter fieldId is not set");
}
if (!is_array($params)) {
return civicrm_create_error("params is not an array ");
}
$field_type = CRM_Utils_Array::value('field_type', $params);
$field_name = CRM_Utils_Array::value('field_name', $params);
$location_type_id = CRM_Utils_Array::value('location_type_id', $params);
$phone_type = CRM_Utils_Array::value('phone_type', $params);
$params['field_name'] = array($field_type, $field_name, $location_type_id, $phone_type);
require_once 'CRM/Core/BAO/UFField.php';
$UFField = new CRM_core_BAO_UFField();
$UFField->id = $fieldId;
if (!CRM_Utils_Array::value('group_id', $params) && $UFField->find(TRUE)) {
$params['group_id'] = $UFField->uf_group_id;
}
$ids = array();
if ($UFField->find(TRUE)) {
$ids['uf_group'] = $UFField->uf_group_id;
} else {
return civicrm_create_error("there is no field for this fieldId");
}
$ids['uf_field'] = $fieldId;
if (CRM_Core_BAO_UFField::duplicateField($params, $ids)) {
return civicrm_create_error("The field was not added. It already exists in this profile.");
}
$ufField = CRM_Core_BAO_UFField::add($params, $ids);
_civicrm_object_to_array($ufField, $ufFieldArray);
return $ufFieldArray;
}
示例7: civicrm_api3_uf_field_create
/**
* Defines 'uf field' within a group.
*
* @param array $params
* Array per getfields metadata.
*
* @throws API_Exception
*
* @return array
* Newly created $ufFieldArray
*/
function civicrm_api3_uf_field_create($params)
{
// CRM-14756: kind of a hack-ish fix. If the user gives the id, uf_group_id is retrieved and then set.
if (isset($params['id'])) {
$groupId = civicrm_api3('UFField', 'getvalue', array('return' => 'uf_group_id', 'id' => $params['id']));
} else {
$groupId = CRM_Utils_Array::value('uf_group_id', $params);
}
$field_type = CRM_Utils_Array::value('field_type', $params);
$field_name = CRM_Utils_Array::value('field_name', $params);
$location_type_id = CRM_Utils_Array::value('location_type_id', $params, CRM_Utils_Array::value('website_type_id', $params));
$phone_type = CRM_Utils_Array::value('phone_type_id', $params, CRM_Utils_Array::value('phone_type', $params));
if (strpos($field_name, 'formatting') !== 0 && !CRM_Core_BAO_UFField::isValidFieldName($field_name)) {
throw new API_Exception('The field_name is not valid');
}
$params['field_name'] = array($field_type, $field_name, $location_type_id, $phone_type);
if (!CRM_Utils_Array::value('group_id', $params)) {
$params['group_id'] = $groupId;
}
$ids = $ufFieldArray = array();
$ids['uf_group'] = $groupId;
$fieldId = CRM_Utils_Array::value('id', $params);
if (!empty($fieldId)) {
$UFField = new CRM_Core_BAO_UFField();
$UFField->id = $fieldId;
if ($UFField->find(TRUE)) {
$ids['uf_group'] = $UFField->uf_group_id;
if (!CRM_Utils_Array::value('group_id', $params)) {
// this copied here from previous api function - not sure if required
$params['group_id'] = $UFField->uf_group_id;
}
} else {
throw new API_Exception("there is no field for this fieldId");
}
$ids['uf_field'] = $fieldId;
}
if (CRM_Core_BAO_UFField::duplicateField($params, $ids)) {
throw new API_Exception("The field was not added. It already exists in this profile.");
}
//@todo why is this even optional? Surely weight should just be 'managed' ??
if (CRM_Utils_Array::value('option.autoweight', $params, TRUE)) {
$params['weight'] = CRM_Core_BAO_UFField::autoWeight($params);
}
$ufField = CRM_Core_BAO_UFField::add($params);
$fieldsType = CRM_Core_BAO_UFGroup::calculateGroupType($groupId, TRUE);
CRM_Core_BAO_UFGroup::updateGroupTypes($groupId, $fieldsType);
_civicrm_api3_object_to_array($ufField, $ufFieldArray[$ufField->id]);
civicrm_api3('profile', 'getfields', array('cache_clear' => TRUE));
return civicrm_api3_create_success($ufFieldArray, $params);
}
示例8: civicrm_api3_uf_field_create
/**
* Defines 'uf field' within a group.
*
* @param $groupId int Valid uf_group id
*
* @param $params array Associative array of property name/value pairs to create new uf field.
*
* @return Newly created $ufFieldArray array
*
* @access public
* {@getfields UFField_create}
* @example UFFieldCreate.php
*/
function civicrm_api3_uf_field_create($params)
{
civicrm_api3_verify_one_mandatory($params, NULL, array('field_name', 'uf_group_id'));
$groupId = CRM_Utils_Array::value('uf_group_id', $params);
if ((int) $groupId < 1) {
return civicrm_api3_create_error('Params must be a field_name-carrying array and a positive integer.');
}
$field_type = CRM_Utils_Array::value('field_type', $params);
$field_name = CRM_Utils_Array::value('field_name', $params);
$location_type_id = CRM_Utils_Array::value('location_type_id', $params);
$phone_type = CRM_Utils_Array::value('phone_type', $params);
$params['field_name'] = array($field_type, $field_name, $location_type_id, $phone_type);
if (!CRM_Utils_Array::value('group_id', $params)) {
$params['group_id'] = $groupId;
}
$ids = array();
$ids['uf_group'] = $groupId;
$fieldId = CRM_Utils_Array::value('id', $params);
if (!empty($fieldId)) {
$UFField = new CRM_core_BAO_UFField();
$UFField->id = $fieldId;
if ($UFField->find(TRUE)) {
$ids['uf_group'] = $UFField->uf_group_id;
if (!CRM_Utils_Array::value('group_id', $params)) {
// this copied here from previous api function - not sure if required
$params['group_id'] = $UFField->uf_group_id;
}
} else {
return civicrm_api3_create_error("there is no field for this fieldId");
}
$ids['uf_field'] = $fieldId;
}
if (CRM_Core_BAO_UFField::duplicateField($params, $ids)) {
return civicrm_api3_create_error("The field was not added. It already exists in this profile.");
}
$ufField = CRM_Core_BAO_UFField::add($params, $ids);
$fieldsType = CRM_Core_BAO_UFGroup::calculateGroupType($groupId, TRUE);
CRM_Core_BAO_UFGroup::updateGroupTypes($groupId, $fieldsType);
_civicrm_api3_object_to_array($ufField, $ufFieldArray[$ufField->id]);
return civicrm_api3_create_success($ufFieldArray, $params);
}