本文整理汇总了PHP中CRM_Core_BAO_CustomField类的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_BAO_CustomField类的具体用法?PHP CRM_Core_BAO_CustomField怎么用?PHP CRM_Core_BAO_CustomField使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CRM_Core_BAO_CustomField类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setDefaultValues
/**
* Set the default form values
*
* @access protected
*
* @return array the default array reference
*/
function setDefaultValues()
{
$defaults = array();
$stateCountryMap = array();
foreach ($this->_fields as $name => $field) {
if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($field['name'])) {
CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $defaults, NULL, CRM_Profile_Form::MODE_REGISTER);
}
//CRM-5403
if (substr($name, 0, 14) === 'state_province' || substr($name, 0, 7) === 'country' || substr($name, 0, 6) === 'county') {
list($fieldName, $index) = CRM_Utils_System::explode('-', $name, 2);
if (!array_key_exists($index, $stateCountryMap)) {
$stateCountryMap[$index] = array();
}
$stateCountryMap[$index][$fieldName] = $name;
}
}
// also take care of state country widget
if (!empty($stateCountryMap)) {
CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap, $defaults);
}
//set default for country.
CRM_Core_BAO_UFGroup::setRegisterDefaults($this->_fields, $defaults);
// now fix all state country selectors
CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults);
return $defaults;
}
示例2: buildWhereClause
/**
* @inheritDoc
*/
protected function buildWhereClause()
{
foreach ($this->where as $key => $value) {
$table_name = NULL;
$column_name = NULL;
$field = $this->getField($key);
if (in_array($key, $this->entityFieldNames)) {
$table_name = self::MAIN_TABLE_ALIAS;
$column_name = $key;
} elseif (($cf_id = \CRM_Core_BAO_CustomField::getKeyID($key)) != FALSE) {
//list($table_name, $column_name) = $this->addCustomField($this->apiFieldSpec['custom_' . $cf_id], 'INNER');
} elseif (strpos($key, '.')) {
$fkInfo = $this->addFkField($key, 'INNER');
if ($fkInfo) {
list($table_name, $column_name) = $fkInfo;
$this->validateNestedInput($key, $value);
}
}
if (!$table_name || !$column_name || is_null($value)) {
throw new \API_Exception("Invalid field '{$key}' in where clause.");
}
if (!is_array($value)) {
$this->query->where(array("`{$table_name}`.`{$column_name}` = @value"), array("@value" => $value));
} elseif (count($value) !== 1) {
throw new \API_Exception("Invalid value in where clause for field '{$key}'");
} else {
$clause = \CRM_Core_DAO::createSQLFilter("`{$table_name}`.`{$column_name}`", $value);
if ($clause === NULL) {
throw new \API_Exception("Invalid value in where clause for field '{$key}'");
}
$this->query->where($clause);
}
}
}
示例3: checkIsMultiRecord
/**
* Function the check whether the field belongs.
* to multi-record custom set
*/
public function checkIsMultiRecord()
{
$customId = $_GET['customId'];
$isMultiple = CRM_Core_BAO_CustomField::isMultiRecordField($customId);
$isMultiple = array('is_multi' => $isMultiple);
CRM_Utils_JSON::output($isMultiple);
}
示例4: setUp
function setUp()
{
parent::setUp();
// Create Group For Individual Contact Type
$groupIndividual = array('title' => 'TestGroup For Indivi' . substr(sha1(rand()), 0, 5), 'extends' => array('Individual'), 'style' => 'Inline', 'is_active' => 1);
$this->CustomGroupIndividual = $this->customGroupCreate($groupIndividual);
$this->IndividualField = $this->customFieldCreate(array('custom_group_id' => $this->CustomGroupIndividual['id']));
// Create Group For Individual-Student Contact Sub Type
$groupIndiStudent = array('title' => 'Student Test' . substr(sha1(rand()), 0, 5), 'extends' => array('Individual', array('Student')), 'style' => 'Inline', 'is_active' => 1);
$this->CustomGroupIndiStudent = $this->customGroupCreate($groupIndiStudent);
$this->IndiStudentField = $this->customFieldCreate(array('custom_group_id' => $this->CustomGroupIndiStudent['id']));
$params = array('first_name' => 'Mathev', 'last_name' => 'Adison', 'contact_type' => 'Individual');
$this->individual = $this->individualCreate($params);
$params = array('first_name' => 'Steve', 'last_name' => 'Tosun', 'contact_type' => 'Individual', 'contact_sub_type' => 'Student');
$this->individualStudent = $this->individualCreate($params);
$params = array('first_name' => 'Mark', 'last_name' => 'Dawson', 'contact_type' => 'Individual', 'contact_sub_type' => 'Parent');
$this->individualParent = $this->individualCreate($params);
$params = array('organization_name' => 'Wellspring', 'contact_type' => 'Organization');
$this->organization = $this->organizationCreate($params);
$params = array('organization_name' => 'SubUrban', 'contact_type' => 'Organization', 'contact_sub_type' => 'Sponsor');
$this->organizationSponsor = $this->organizationCreate($params);
//refresh php cached variables
CRM_Core_PseudoConstant::flush();
CRM_Core_BAO_CustomField::getTableColumnGroup($this->IndividualField['id'], True);
CRM_Core_BAO_CustomField::getTableColumnGroup($this->IndiStudentField['id'], True);
}
示例5: setDefaultValues
function setDefaultValues()
{
// check if the user is registered and we have a contact ID
$session =& CRM_Core_Session::singleton();
$contactID = $session->get('userID');
if ($contactID) {
$options = array();
$fields = array();
foreach ($this->_fields as $name => $dontCare) {
$fields[$name] = 1;
}
$fields['state_province'] = $fields['country'] = $fields['email'] = 1;
$contact =& CRM_Contact_BAO_Contact::contactDetails($contactID, $options, $fields);
foreach ($fields as $name => $dontCare) {
if ($contact->{$name}) {
if (substr($name, 0, 7) == 'custom_') {
$id = substr($name, 7);
$this->_defaults[$name] = CRM_Core_BAO_CustomField::getDefaultValue($contact->{$name}, $id, $options);
} else {
$this->_defaults[$name] = $contact->{$name};
}
}
}
}
// hack to simplify credit card entry for testing
/**
$this->_defaults['credit_card_type'] = 'Visa';
$this->_defaults['credit_card_number'] = '4807731747657838';
$this->_defaults['cvv2'] = '000';
$this->_defaults['credit_card_exp_date'] = array( 'Y' => '2008', 'M' => '01' );
**/
return $this->_defaults;
}
示例6: checkIsMultiRecord
/**
* Function the check whether the field belongs
* to multi-record custom set
*/
function checkIsMultiRecord()
{
$customId = $_GET['customId'];
$isMultiple = CRM_Core_BAO_CustomField::isMultiRecordField($customId);
$isMultiple = array('is_multi' => $isMultiple);
echo json_encode($isMultiple);
CRM_Utils_System::civiExit();
}
示例7: postProcess
/**
* Process the form when submitted.
*
* @return void
*/
public function postProcess()
{
$field = new CRM_Core_DAO_CustomField();
$field->id = $this->_id;
$field->find(TRUE);
CRM_Core_BAO_CustomField::deleteField($field);
// also delete any profiles associted with this custom field
CRM_Core_Session::setStatus(ts('The custom field \'%1\' has been deleted.', array(1 => $field->label)), '', 'success');
}
示例8: testDeleteCustomfield
function testDeleteCustomfield()
{
$customGroup = Custom::createGroup(array(), 'Individual');
$fields = array('groupId' => $customGroup->id, 'dataType' => 'Memo', 'htmlType' => 'TextArea');
$customField = Custom::createField(array(), $fields);
CRM_Core_BAO_CustomField::deleteField($customField);
$this->assertDBNull('CRM_Core_DAO_CustomField', $customGroup->id, 'id', 'custom_group_id', 'Database check for deleted Custom Field.');
Custom::deleteGroup($customGroup);
}
示例9: setDefaultValues
/**
* Set the default form values.
*
*
* @return array
* the default array reference
*/
public function setDefaultValues()
{
$defaults = array();
foreach ($this->_fields as $name => $field) {
if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($field['name'])) {
CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $defaults, NULL, CRM_Profile_Form::MODE_REGISTER);
}
}
//set default for country.
CRM_Core_BAO_UFGroup::setRegisterDefaults($this->_fields, $defaults);
return $defaults;
}
示例10: testSetGetValuesYesNoRadio
/**
* Test setValues() and getValues() methods with custom field YesNo(Boolean) Radio
*/
public function testSetGetValuesYesNoRadio()
{
$params = array();
$contactID = Contact::createIndividual();
//create Custom Group
$customGroup = Custom::createGroup($params, 'Individual', TRUE);
//create Custom Field of type YesNo(Boolean) Radio
$fields = array('groupId' => $customGroup->id, 'dataType' => 'Boolean', 'htmlType' => 'Radio');
$customField = Custom::createField($params, $fields);
// Retrieve the field ID for sample custom field 'test_Boolean'
$params = array('label' => 'test_Boolean');
$field = array();
//get field Id
CRM_Core_BAO_CustomField::retrieve($params, $field);
$fieldID = $field['id'];
// valid boolean value '1' for Boolean Radio
$yesNo = '1';
$params = array('entityID' => $contactID, 'custom_' . $fieldID => $yesNo);
$result = CRM_Core_BAO_CustomValueTable::setValues($params);
$this->assertEquals($result['is_error'], 0, 'Verify that is_error = 0 (success).');
// Check that the YesNo radio value is stored
$values = array();
$params = array('entityID' => $contactID, 'custom_' . $fieldID => 1);
$values = CRM_Core_BAO_CustomValueTable::getValues($params);
$this->assertEquals($values['is_error'], 0, 'Verify that is_error = 0 (success).');
$this->assertEquals($values["custom_{$fieldID}_1"], $yesNo, 'Verify that the boolean value is stored for contact ' . $contactID);
// Now set YesNo radio to an invalid boolean value and try to reset
$badYesNo = '20';
$params = array('entityID' => $contactID, 'custom_' . $fieldID => $badYesNo);
$errorScope = CRM_Core_TemporaryErrorScope::useException();
$message = NULL;
try {
$result = CRM_Core_BAO_CustomValueTable::setValues($params);
} catch (Exception $e) {
$message = $e->getMessage();
}
$errorScope = NULL;
// Check that an exception has been thrown
$this->assertNotNull($message, 'Verify than an exception is thrown when bad boolean is passed');
$params = array('entityID' => $contactID, 'custom_' . $fieldID => 1);
$values = CRM_Core_BAO_CustomValueTable::getValues($params);
$this->assertEquals($values["custom_{$fieldID}_1"], $yesNo, 'Verify that the date value has NOT been updated for contact ' . $contactID);
// Cleanup
Custom::deleteField($customField);
Custom::deleteGroup($customGroup);
Contact::delete($contactID);
}
示例11: buildQuickForm
/**
* Build the form object.
*/
public function buildQuickForm()
{
$ufGroupId = $this->get('ufGroupId');
if (!$ufGroupId) {
CRM_Core_Error::fatal('ufGroupId is missing');
}
$this->_title = ts('Update multiple contacts') . ' - ' . CRM_Core_BAO_UFGroup::getTitle($ufGroupId);
CRM_Utils_System::setTitle($this->_title);
$this->addDefaultButtons(ts('Save'));
$this->_fields = CRM_Core_BAO_UFGroup::getFields($ufGroupId, FALSE, CRM_Core_Action::VIEW);
// remove file type field and then limit fields
$suppressFields = FALSE;
$removehtmlTypes = array('File', 'Autocomplete-Select');
foreach ($this->_fields as $name => $field) {
if ($cfID = CRM_Core_BAO_CustomField::getKeyID($name) && in_array($this->_fields[$name]['html_type'], $removehtmlTypes)) {
$suppressFields = TRUE;
unset($this->_fields[$name]);
}
}
//FIX ME: phone ext field is added at the end and it gets removed because of below code
//$this->_fields = array_slice($this->_fields, 0, $this->_maxFields);
$this->addButtons(array(array('type' => 'submit', 'name' => ts('Update Contact(s)'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
$this->assign('profileTitle', $this->_title);
$this->assign('componentIds', $this->_contactIds);
// if below fields are missing we should not reset sort name / display name
// CRM-6794
$preserveDefaultsArray = array('first_name', 'last_name', 'middle_name', 'organization_name', 'prefix_id', 'suffix_id', 'household_name');
foreach ($this->_contactIds as $contactId) {
$profileFields = $this->_fields;
CRM_Core_BAO_Address::checkContactSharedAddressFields($profileFields, $contactId);
foreach ($profileFields as $name => $field) {
CRM_Core_BAO_UFGroup::buildProfile($this, $field, NULL, $contactId);
if (in_array($field['name'], $preserveDefaultsArray)) {
$this->_preserveDefault = FALSE;
}
}
}
$this->assign('fields', $this->_fields);
// don't set the status message when form is submitted.
$buttonName = $this->controller->getButtonName('submit');
if ($suppressFields && $buttonName != '_qf_BatchUpdateProfile_next') {
CRM_Core_Session::setStatus(ts("File or Autocomplete-Select type field(s) in the selected profile are not supported for Update multiple contacts."), ts('Some Fields Excluded'), 'info');
}
$this->addDefaultButtons(ts('Update Contacts'));
$this->addFormRule(array('CRM_Contact_Form_Task_Batch', 'formRule'));
}
示例12: civicrm_api3_pcpteams_create
/**
* File for the CiviCRM APIv3 group functions
*
* @package CiviCRM_APIv3
* @subpackage API_pcpteams
* @copyright CiviCRM LLC (c) 2004-2014
*/
function civicrm_api3_pcpteams_create($params)
{
// since we are allowing html input from the user
// we also need to purify it, so lets clean it up
// $params['pcp_title'] = $pcp['title'];
// $params['pcp_contact_id'] = $pcp['contact_id'];
$htmlFields = array('intro_text', 'page_text', 'title');
foreach ($htmlFields as $field) {
if (!empty($params[$field])) {
$params[$field] = CRM_Utils_String::purifyHTML($params[$field]);
}
}
$entity_table = CRM_PCP_BAO_PCP::getPcpEntityTable($params['page_type']);
$pcpBlock = new CRM_PCP_DAO_PCPBlock();
$pcpBlock->entity_table = $entity_table;
$pcpBlock->entity_id = $params['page_id'];
$pcpBlock->find(TRUE);
$params['pcp_block_id'] = $pcpBlock->id;
$params['goal_amount'] = CRM_Utils_Rule::cleanMoney($params['goal_amount']);
// 1 -> waiting review
// 2 -> active / approved (default for now)
$params['status_id'] = CRM_Utils_Array::value('status_id', $params, 2);
// active by default for now
$params['is_active'] = CRM_Utils_Array::value('is_active', $params, 1);
$pcp = CRM_Pcpteams_BAO_PCP::create($params, FALSE);
//Custom Set
$customFields = CRM_Core_BAO_CustomField::getFields('PCP', FALSE, FALSE, NULL, NULL, TRUE);
$isCustomValueSet = FALSE;
foreach ($customFields as $fieldID => $fieldValue) {
list($tableName, $columnName, $cgId) = CRM_Core_BAO_CustomField::getTableColumnGroup($fieldID);
if (!empty($params[$columnName]) || !empty($params["custom_{$fieldID}"])) {
$isCustomValueSet = TRUE;
//FIXME: to find out the custom value exists, set -1 as default now
$params["custom_{$fieldID}_-1"] = !empty($params[$columnName]) ? $params[$columnName] : $params["custom_{$fieldID}"];
}
}
if ($isCustomValueSet) {
$params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $pcp->id, 'PCP');
CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_pcp', $pcp->id);
}
//end custom set
$values = array();
@_civicrm_api3_object_to_array_unique_fields($pcp, $values[$pcp->id]);
return civicrm_api3_create_success($values, $params, 'Pcpteams', 'create');
}
示例13: registerInterview
static function registerInterview()
{
$fields = array('result', 'voter_id', 'survey_id', 'activity_id', 'surveyTitle', 'interviewer_id', 'activity_type_id');
$params = array();
foreach ($fields as $fld) {
$params[$fld] = CRM_Utils_Array::value($fld, $_POST);
}
$params['details'] = CRM_Utils_Array::value('note', $_POST);
$voterId = $params['voter_id'];
$activityId = $params['activity_id'];
$customKey = "field_{$voterId}_custom";
foreach ($_POST as $key => $value) {
if (strpos($key, $customKey) !== FALSE) {
$customFieldKey = str_replace(str_replace(substr($customKey, -6), '', $customKey), '', $key);
$params[$customFieldKey] = $value;
}
}
if (isset($_POST['field']) && !empty($_POST['field'][$voterId]) && is_array($_POST['field'][$voterId])) {
foreach ($_POST['field'][$voterId] as $fieldKey => $value) {
$params[$fieldKey] = $value;
}
}
//lets pickup contat related fields.
foreach ($_POST as $key => $value) {
if (strpos($key, "field_{$voterId}_") !== FALSE && strpos($key, "field_{$voterId}_custom") === FALSE) {
$key = substr($key, strlen("field_{$voterId}_"));
$params[$key] = $value;
}
}
$result = array('status' => 'fail', 'voter_id' => $voterId, 'activity_id' => $params['interviewer_id']);
//time to validate custom data.
$errors = CRM_Core_BAO_CustomField::validateCustomData($params);
if (is_array($errors) && !empty($errors)) {
$result['errors'] = $errors;
echo json_encode($result);
CRM_Utils_System::civiExit();
}
//process the response/interview data.
$activityId = CRM_Campaign_Form_Task_Interview::registerInterview($params);
if ($activityId) {
$result['status'] = 'success';
}
echo json_encode($result);
CRM_Utils_System::civiExit();
}
示例14: testCreateWithCustomData
/**
* Create() method with custom data.
*/
public function testCreateWithCustomData()
{
$contactId = $this->individualCreate();
//create custom data
$customGroup = $this->customGroupCreate(array('extends' => 'Contribution'));
$customGroupID = $customGroup['id'];
$customGroup = $customGroup['values'][$customGroupID];
$fields = array('label' => 'testFld', 'data_type' => 'String', 'html_type' => 'Text', 'is_active' => 1, 'custom_group_id' => $customGroupID);
$customField = CRM_Core_BAO_CustomField::create($fields);
$params = array('contact_id' => $contactId, 'currency' => 'USD', 'financial_type_id' => 1, 'contribution_status_id' => 1, 'payment_instrument_id' => 1, 'source' => 'STUDENT', 'receive_date' => '20080522000000', 'receipt_date' => '20080522000000', 'id' => NULL, 'non_deductible_amount' => 0.0, 'total_amount' => 200.0, 'fee_amount' => 5, 'net_amount' => 195, 'trxn_id' => '22ereerwww322323', 'invoice_id' => '22ed39c9e9ee6ef6031621ce0eafe6da70', 'thankyou_date' => '20080522');
$params['custom'] = array($customField->id => array(-1 => array('value' => 'Test custom value', 'type' => 'String', 'custom_field_id' => $customField->id, 'custom_group_id' => $customGroupID, 'table_name' => $customGroup['table_name'], 'column_name' => $customField->column_name, 'file_id' => NULL)));
$contribution = CRM_Contribute_BAO_Contribution::create($params);
// Check that the custom field value is saved
$customValueParams = array('entityID' => $contribution->id, 'custom_' . $customField->id => 1);
$values = CRM_Core_BAO_CustomValueTable::getValues($customValueParams);
$this->assertEquals('Test custom value', $values['custom_' . $customField->id], 'Check the custom field value');
$this->assertEquals($params['trxn_id'], $contribution->trxn_id, 'Check for transcation id creation.');
$this->assertEquals($contactId, $contribution->contact_id, 'Check for contact id for Conribution.');
}
示例15: registerInterview
static function registerInterview()
{
$fields = array('result', 'voter_id', 'ufGroupId', 'activity_id', 'surveyTitle', 'interviewer_id', 'activity_type_id');
$params = array();
foreach ($fields as $fld) {
$params[$fld] = CRM_Utils_Array::value($fld, $_POST);
}
$params['details'] = CRM_Utils_Array::value('note', $_POST);
$voterId = $params['voter_id'];
$activityId = $params['activity_id'];
$customKey = "field_{$voterId}_custom";
foreach ($_POST as $key => $value) {
if (strpos($key, $customKey) !== false) {
$customFieldKey = str_replace(str_replace(substr($customKey, -6), '', $customKey), '', $key);
$params[$customFieldKey] = $value;
}
}
if (isset($_POST['field']) && CRM_Utils_Array::value($voterId, $_POST['field']) && is_array($_POST['field'][$voterId])) {
foreach ($_POST['field'][$voterId] as $fieldKey => $value) {
$params[$fieldKey] = $value;
}
}
require_once "CRM/Utils/JSON.php";
$result = array('status' => 'fail', 'voter_id' => $voterId, 'activity_id' => $params['interviewer_id']);
//time to validate custom data.
require_once 'CRM/Core/BAO/CustomField.php';
$errors = CRM_Core_BAO_CustomField::validateCustomData($params);
if (is_array($errors) && !empty($errors)) {
$result['errors'] = $errors;
echo json_encode($result);
CRM_Utils_System::civiExit();
}
//process the response/interview data.
require_once 'CRM/Campaign/Form/Task/Interview.php';
$activityId = CRM_Campaign_Form_Task_Interview::registerInterview($params);
if ($activityId) {
$result['status'] = 'success';
}
require_once "CRM/Utils/JSON.php";
echo json_encode($result);
CRM_Utils_System::civiExit();
}