本文整理汇总了PHP中CRM_Core_BAO_CustomField::find方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_BAO_CustomField::find方法的具体用法?PHP CRM_Core_BAO_CustomField::find怎么用?PHP CRM_Core_BAO_CustomField::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Core_BAO_CustomField
的用法示例。
在下文中一共展示了CRM_Core_BAO_CustomField::find方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testDeleteCustomField
public function testDeleteCustomField()
{
$customGroup = $this->customGroupCreate(array('extends' => 'Individual'));
$fields = array('custom_group_id' => $customGroup['id'], 'label' => 'Throwaway Field', 'dataType' => 'Memo', 'htmlType' => 'TextArea');
$customField = $this->customFieldCreate($fields);
$fieldObject = new CRM_Core_BAO_CustomField();
$fieldObject->id = $customField['id'];
$fieldObject->find(TRUE);
CRM_Core_BAO_CustomField::deleteField($fieldObject);
$this->assertDBNull('CRM_Core_DAO_CustomField', $customGroup['id'], 'id', 'custom_group_id', 'Database check for deleted Custom Field.');
$this->customGroupDelete($customGroup['id']);
}
示例2: getOptionListSelector
/**
* wrapper for ajax option selector.
*
* @param array $params
* Associated array for params record id.
*
* @return array
* associated array of option list
* -rp = rowcount
* -page= offset
*/
public static function getOptionListSelector(&$params)
{
$options = array();
//get the default value from custom fields
$customFieldBAO = new CRM_Core_BAO_CustomField();
$customFieldBAO->id = $params['fid'];
if ($customFieldBAO->find(TRUE)) {
$defaultValue = $customFieldBAO->default_value;
$fieldHtmlType = $customFieldBAO->html_type;
} else {
CRM_Core_Error::fatal();
}
$defVal = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($defaultValue, 1, -1));
// format the params
$params['offset'] = ($params['page'] - 1) * $params['rp'];
$params['rowCount'] = $params['rp'];
$field = CRM_Core_BAO_CustomField::getFieldObject($params['fid']);
// get the option group id
$optionGroupID = $field->option_group_id;
if (!$optionGroupID) {
return $options;
}
$queryParams = array(1 => array($optionGroupID, 'Integer'));
$total = "SELECT COUNT(*) FROM civicrm_option_value WHERE option_group_id = %1";
$params['total'] = CRM_Core_DAO::singleValueQuery($total, $queryParams);
$limit = " LIMIT {$params['offset']}, {$params['rowCount']} ";
$orderBy = ' ORDER BY options.weight asc';
$query = "SELECT * FROM civicrm_option_value as options WHERE option_group_id = %1 {$orderBy} {$limit}";
$dao = CRM_Core_DAO::executeQuery($query, $queryParams);
$links = CRM_Custom_Page_Option::actionLinks();
$fields = array('id', 'label', 'value');
$config = CRM_Core_Config::singleton();
while ($dao->fetch()) {
$options[$dao->id] = array();
foreach ($fields as $k) {
$options[$dao->id][$k] = $dao->{$k};
}
$action = array_sum(array_keys($links));
$class = 'crm-entity';
// update enable/disable links depending on custom_field properties.
if ($dao->is_active) {
$action -= CRM_Core_Action::ENABLE;
} else {
$class .= ' disabled';
$action -= CRM_Core_Action::DISABLE;
}
if ($fieldHtmlType == 'CheckBox' || $fieldHtmlType == 'AdvMulti-Select' || $fieldHtmlType == 'Multi-Select') {
if (in_array($dao->value, $defVal)) {
$options[$dao->id]['is_default'] = '<img src="' . $config->resourceBase . 'i/check.gif" />';
} else {
$options[$dao->id]['is_default'] = '';
}
} else {
if ($defaultValue == $dao->value) {
$options[$dao->id]['is_default'] = '<img src="' . $config->resourceBase . 'i/check.gif" />';
} else {
$options[$dao->id]['is_default'] = '';
}
}
$options[$dao->id]['class'] = $dao->id . ',' . $class;
$options[$dao->id]['is_active'] = !empty($dao->is_active) ? 'Yes' : 'No';
$options[$dao->id]['links'] = CRM_Core_Action::formLink($links, $action, array('id' => $dao->id, 'fid' => $params['fid'], 'gid' => $params['gid']), ts('more'), FALSE, 'customOption.row.actions', 'customOption', $dao->id);
}
return $options;
}
示例3: civicrm_api3_custom_field_delete
/**
* Use this API to delete an existing custom group field.
*
* @param $params Array id of the field to be deleted
*
* @return array
* @example CustomFieldDelete.php
*
* {@example CustomFieldDelete.php 0}
* {@getfields CustomField_delete}
* @access public
**/
function civicrm_api3_custom_field_delete($params)
{
$field = new CRM_Core_BAO_CustomField();
$field->id = $params['id'];
$field->find(TRUE);
$customFieldDelete = CRM_Core_BAO_CustomField::deleteField($field);
civicrm_api('custom_field', 'getfields', array('version' => 3, 'cache_clear' => 1));
return $customFieldDelete ? civicrm_api3_create_error('Error while deleting custom field') : civicrm_api3_create_success();
}
示例4: browse
/**
* Browse all custom group fields.
*
* @param null
*
* @return void
* @access public
*/
function browse()
{
CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js');
//get the default value from custom fields
$customFieldBAO = new CRM_Core_BAO_CustomField();
$customFieldBAO->id = $this->_fid;
if ($customFieldBAO->find(TRUE)) {
$defaultValue = $customFieldBAO->default_value;
$fieldHtmlType = $customFieldBAO->html_type;
} else {
CRM_Core_Error::fatal();
}
$defVal = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($defaultValue, 1, -1));
// get the option group id
$optionGroupID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $this->_fid, 'option_group_id');
$query = "\nSELECT id, label\nFROM civicrm_custom_field\nWHERE option_group_id = %1";
$params = array(1 => array($optionGroupID, 'Integer'), 2 => array($this->_fid, 'Integer'));
$dao = CRM_Core_DAO::executeQuery($query, $params);
$reusedNames = array();
if ($dao->N > 1) {
while ($dao->fetch()) {
$reusedNames[] = $dao->label;
}
$reusedNames = implode(', ', $reusedNames);
$newTitle = ts('%1 - Multiple Choice Options', array(1 => $reusedNames));
CRM_Utils_System::setTitle($newTitle);
$this->assign('reusedNames', $reusedNames);
}
$query = "\nSELECT *\n FROM civicrm_option_value\n WHERE option_group_id = %1\nORDER BY weight, label\n";
$params = array(1 => array($optionGroupID, 'Integer'));
$dao = CRM_Core_DAO::executeQuery($query, $params);
$customOption = array();
$fields = array('label', 'value', 'is_active', 'weight');
$config = CRM_Core_Config::singleton();
while ($dao->fetch()) {
$customOption[$dao->id] = array();
foreach ($fields as $field) {
$customOption[$dao->id][$field] = $dao->{$field};
}
$action = array_sum(array_keys($this->actionLinks()));
// update enable/disable links depending on custom_field properties.
if ($dao->is_active) {
$action -= CRM_Core_Action::ENABLE;
} else {
$action -= CRM_Core_Action::DISABLE;
}
if ($fieldHtmlType == 'CheckBox' || $fieldHtmlType == 'AdvMulti-Select' || $fieldHtmlType == 'Multi-Select') {
if (in_array($dao->value, $defVal)) {
$customOption[$dao->id]['default_value'] = '<img src="' . $config->resourceBase . 'i/check.gif" />';
} else {
$customOption[$dao->id]['default_value'] = '';
}
} else {
if ($defaultValue == $dao->value) {
$customOption[$dao->id]['default_value'] = '<img src="' . $config->resourceBase . 'i/check.gif" />';
} else {
$customOption[$dao->id]['default_value'] = '';
}
}
$customOption[$dao->id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action, array('id' => $dao->id, 'fid' => $this->_fid, 'gid' => $this->_gid), ts('more'), FALSE, 'customOption.row.actions', 'customOption', $dao->id);
}
// Add order changing widget to selector
$returnURL = CRM_Utils_System::url('civicrm/admin/custom/group/field/option', "reset=1&action=browse&gid={$this->_gid}&fid={$this->_fid}");
$filter = "option_group_id = {$optionGroupID}";
CRM_Utils_Weight::addOrder($customOption, 'CRM_Core_DAO_OptionValue', 'id', $returnURL, $filter);
$this->assign('customOption', $customOption);
}
示例5: setProfileDefaults
/**
* Set default values for custom data used in profile.
*
* @param int $customFieldId
* Custom field id.
* @param string $elementName
* Custom field name.
* @param array $defaults
* Associated array of fields.
* @param int $contactId
* Contact id.
* @param int $mode
* Profile mode.
* @param mixed $value
* If passed - dont fetch value from db,.
* just format the given value
*
*/
public static function setProfileDefaults($customFieldId, $elementName, &$defaults, $contactId = NULL, $mode = NULL, $value = NULL)
{
//get the type of custom field
$customField = new CRM_Core_BAO_CustomField();
$customField->id = $customFieldId;
$customField->find(TRUE);
if (!$contactId) {
if ($mode == CRM_Profile_Form::MODE_CREATE) {
$value = $customField->default_value;
}
} else {
if (!isset($value)) {
$info = self::getTableColumnGroup($customFieldId);
$query = "SELECT {$info[0]}.{$info[1]} as value FROM {$info[0]} WHERE {$info[0]}.entity_id = {$contactId}";
$result = CRM_Core_DAO::executeQuery($query);
if ($result->fetch()) {
$value = $result->value;
}
}
if ($customField->data_type == 'Country') {
if (!$value) {
$config = CRM_Core_Config::singleton();
if ($config->defaultContactCountry) {
$value = $config->defaultContactCountry();
}
}
}
}
//set defaults if mode is registration
if (!trim($value) && $value !== 0 && !in_array($mode, array(CRM_Profile_Form::MODE_EDIT, CRM_Profile_Form::MODE_SEARCH))) {
$value = $customField->default_value;
}
if ($customField->data_type == 'Money' && isset($value)) {
$value = number_format($value, 2);
}
switch ($customField->html_type) {
case 'CheckBox':
case 'AdvMulti-Select':
case 'Multi-Select':
$customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldId, FALSE);
$defaults[$elementName] = array();
$checkedValue = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($value, 1, -1));
foreach ($customOption as $val) {
if (in_array($val['value'], $checkedValue)) {
if ($customField->html_type == 'CheckBox') {
$defaults[$elementName][$val['value']] = 1;
} elseif ($customField->html_type == 'Multi-Select' || $customField->html_type == 'AdvMulti-Select') {
$defaults[$elementName][$val['value']] = $val['value'];
}
}
}
break;
case 'Select Date':
if ($value) {
list($defaults[$elementName], $defaults[$elementName . '_time']) = CRM_Utils_Date::setDateDefaults($value, NULL, $customField->date_format, $customField->time_format);
}
break;
case 'Autocomplete-Select':
if ($customField->data_type == 'ContactReference') {
if (is_numeric($value)) {
$defaults[$elementName . '_id'] = $value;
$defaults[$elementName] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $value, 'sort_name');
}
} else {
$defaults[$elementName] = $value;
}
break;
default:
$defaults[$elementName] = $value;
}
}
示例6: browse
/**
* Browse all custom group fields.
*
* @return void
*/
public function browse()
{
$resourceManager = CRM_Core_Resources::singleton();
if (!empty($_GET['new']) && $resourceManager->ajaxPopupsEnabled) {
$resourceManager->addScriptFile('civicrm', 'js/crm.addNew.js', 999, 'html-header');
}
$customField = array();
$customFieldBAO = new CRM_Core_BAO_CustomField();
// fkey is gid
$customFieldBAO->custom_group_id = $this->_gid;
$customFieldBAO->orderBy('weight, label');
$customFieldBAO->find();
while ($customFieldBAO->fetch()) {
$customField[$customFieldBAO->id] = array();
CRM_Core_DAO::storeValues($customFieldBAO, $customField[$customFieldBAO->id]);
$action = array_sum(array_keys($this->actionLinks()));
if ($customFieldBAO->is_active) {
$action -= CRM_Core_Action::ENABLE;
} else {
$action -= CRM_Core_Action::DISABLE;
}
switch ($customFieldBAO->data_type) {
case "String":
case "Int":
case "Float":
case "Money":
// if Multi Select field is selected in custom field
if ($customFieldBAO->html_type == 'Text') {
$action -= CRM_Core_Action::BROWSE;
}
break;
case "ContactReference":
case "Memo":
case "Date":
case "Boolean":
case "StateProvince":
case "Country":
case "File":
case "Link":
$action -= CRM_Core_Action::BROWSE;
break;
}
$customFieldDataType = CRM_Core_BAO_CustomField::dataType();
$customField[$customFieldBAO->id]['data_type'] = $customFieldDataType[$customField[$customFieldBAO->id]['data_type']];
$customField[$customFieldBAO->id]['order'] = $customField[$customFieldBAO->id]['weight'];
$customField[$customFieldBAO->id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action, array('id' => $customFieldBAO->id, 'gid' => $this->_gid), ts('more'), FALSE, 'customField.row.actions', 'CustomField', $customFieldBAO->id);
}
$returnURL = CRM_Utils_System::url('civicrm/admin/custom/group/field', "reset=1&action=browse&gid={$this->_gid}");
$filter = "custom_group_id = {$this->_gid}";
CRM_Utils_Weight::addOrder($customField, 'CRM_Core_DAO_CustomField', 'id', $returnURL, $filter);
$this->assign('customField', $customField);
}
示例7: browse
/**
* Browse all custom group fields.
*
* @param null
*
* @return void
* @access public
*/
function browse()
{
require_once 'CRM/Core/BAO/CustomField.php';
$customField = array();
$customFieldBAO = new CRM_Core_BAO_CustomField();
// fkey is gid
$customFieldBAO->custom_group_id = $this->_gid;
$customFieldBAO->orderBy('weight, label');
$customFieldBAO->find();
while ($customFieldBAO->fetch()) {
$customField[$customFieldBAO->id] = array();
CRM_Core_DAO::storeValues($customFieldBAO, $customField[$customFieldBAO->id]);
$action = array_sum(array_keys($this->actionLinks()));
if ($customFieldBAO->is_active) {
$action -= CRM_Core_Action::ENABLE;
} else {
$action -= CRM_Core_Action::DISABLE;
}
switch ($customFieldBAO->data_type) {
case "String":
case "Int":
case "Float":
case "Money":
// if Multi Select field is selected in custom field
if ($customFieldBAO->html_type == 'Text') {
$action -= CRM_Core_Action::BROWSE;
}
break;
case "ContactReference":
case "Memo":
case "Date":
case "Boolean":
case "StateProvince":
case "Country":
case "File":
case "Link":
$action -= CRM_Core_Action::BROWSE;
break;
}
$customFieldDataType = CRM_Core_BAO_CustomField::dataType();
$customField[$customFieldBAO->id]['data_type'] = $customFieldDataType[$customField[$customFieldBAO->id]['data_type']];
$customField[$customFieldBAO->id]['order'] = $customField[$customFieldBAO->id]['weight'];
$customField[$customFieldBAO->id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action, array('id' => $customFieldBAO->id, 'gid' => $this->_gid));
}
$returnURL = CRM_Utils_System::url('civicrm/admin/custom/group/field', "reset=1&action=browse&gid={$this->_gid}");
$filter = "custom_group_id = {$this->_gid}";
require_once 'CRM/Utils/Weight.php';
CRM_Utils_Weight::addOrder($customField, 'CRM_Core_DAO_CustomField', 'id', $returnURL, $filter);
$this->assign('customField', $customField);
}