本文整理汇总了PHP中CRM_Core_BAO_OptionValue类的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_BAO_OptionValue类的具体用法?PHP CRM_Core_BAO_OptionValue怎么用?PHP CRM_Core_BAO_OptionValue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CRM_Core_BAO_OptionValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkOptionGroupValues
/**
* @return array
*/
public function checkOptionGroupValues()
{
$messages = array();
$problemValues = array();
$optionGroups = civicrm_api3('OptionGroup', 'get', array('sequential' => 1, 'data_type' => array('IS NOT NULL' => 1), 'options' => array('limit' => 0)));
if ($optionGroups['count'] > 0) {
foreach ($optionGroups['values'] as $optionGroup) {
$values = CRM_Core_BAO_OptionValue::getOptionValuesArray($optionGroup['id']);
if (count($values) > 0) {
foreach ($values as $value) {
$validate = CRM_Utils_Type::validate($value['value'], $optionGroup['data_type'], FALSE);
if (!$validate) {
$problemValues[] = array('group_name' => $optionGroup['title'], 'value_name' => $value['label']);
}
}
}
}
}
if (!empty($problemValues)) {
$strings = '';
foreach ($problemValues as $problemValue) {
$strings .= ts('<tr><td> "%1" </td><td> "%2" </td></tr>', array(1 => $problemValue['group_name'], 2 => $problemValue['value_name']));
}
$messages[] = new CRM_Utils_Check_Message(__FUNCTION__, ts('The Following Option Values contain value fields that do not match the Data Type of the Option Group</p>
<p><table><tbody><th>Option Group</th><th>Option Value</th></tbody><tbody>') . $strings . ts('</tbody></table></p>'), ts('Option Values with problematic Values'), \Psr\Log\LogLevel::NOTICE, 'fa-server');
}
return $messages;
}
示例2: getCustomOption
/**
* Returns all active options ordered by weight for a given field
*
* @param int $fieldId field whose options are needed
* @param boolean $inactiveNeeded do we need inactive options ?
*
* @return array $customOption all active options for fieldId
* @static
*/
static function getCustomOption($fieldID, $inactiveNeeded = FALSE)
{
$options = array();
if (!$fieldID) {
return $options;
}
$field = CRM_Core_BAO_CustomField::getFieldObject($fieldID);
// get the option group id
$optionGroupID = $field->option_group_id;
if (!$optionGroupID) {
return $options;
}
$optionValues = CRM_Core_BAO_OptionValue::getOptionValuesArray($optionGroupID);
foreach ($optionValues as $id => $value) {
if (!$inactiveNeeded && empty($value['is_active'])) {
continue;
}
$options[$id] = array();
$options[$id]['id'] = $id;
$options[$id]['label'] = $value['label'];
$options[$id]['value'] = $value['value'];
}
CRM_Utils_Hook::customFieldOptions($fieldID, $options, TRUE);
return $options;
}
示例3: onPreEnable
public function onPreEnable(CRM_Extension_Info $info)
{
$customSearchesByName = $this->getCustomSearchesByName();
$cs = $this->getCustomSearchesById();
$id = $cs[$customSearchesByName[$info->key]];
$optionValue = CRM_Core_BAO_OptionValue::setIsActive($id, 1);
}
示例4: createEntry
public function createEntry($id, $key)
{
$e = self::$_extensions;
$ids = array();
$groupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', self::OPTION_GROUP_NAME, 'id', 'name');
$params = array('option_group_id' => $groupId, 'weight' => CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', array('option_group_id' => $groupId)), 'label' => $e['per_id'][$id]['label'], 'name' => $e['per_id'][$id]['label'], 'value' => $key, 'grouping' => $e['per_id'][$id]['type'], 'is_active' => 1);
$optionValue = CRM_Core_BAO_OptionValue::add($params, $ids);
}
示例5: testEnsureOptionValueExistsDisabled
/**
* Ensure only one option value copes with disabled.
*
* (Our expectation is no change - ie. currently we are respecting 'someone's
* decision to disable it & leaving it in that state.
*/
public function testEnsureOptionValueExistsDisabled()
{
CRM_Core_BAO_OptionValue::ensureOptionValueExists(array('name' => 'Crashed', 'option_group_id' => 'contribution_status', 'is_active' => 0));
$value = $this->callAPISuccessGetSingle('OptionValue', array('name' => 'Crashed', 'option_group_id' => 'contribution_status'));
$this->assertEquals(0, $value['is_active']);
CRM_Core_BAO_OptionValue::ensureOptionValueExists(array('name' => 'Crashed', 'option_group_id' => 'contribution_status'));
$value = $this->callAPISuccessGetSingle('OptionValue', array('name' => 'Crashed', 'option_group_id' => 'contribution_status'));
$this->assertEquals(0, $value['is_active']);
}
示例6: civicrm_api3_option_value_delete
/**
* Deletes an existing OptionValue
*
* @param array $params
*
* {@example OptionValueDelete.php 0}
*
* @return array Api result
* {@getfields OptionValue_create}
* @access public
*/
function civicrm_api3_option_value_delete($params)
{
// we will get the option group id before deleting so we can flush pseudoconstants
$optionGroupID = civicrm_api('option_value', 'getvalue', array('version' => 3, 'id' => $params['id'], 'return' => 'option_group_id'));
if (CRM_Core_BAO_OptionValue::del((int) $params['id'])) {
civicrm_api('option_value', 'getfields', array('version' => 3, 'cache_clear' => 1, 'option_group_id' => $optionGroupID));
return civicrm_api3_create_success();
} else {
civicrm_api3_create_error('Could not delete OptionValue ' . $params['id']);
}
}
示例7: preProcess
/**
* Function to set variables up before form is built
*
* @return void
* @access public
*/
public function preProcess()
{
//get the activity values
$activityId = CRM_Utils_Request::retrieve('id', 'Positive', $this);
$context = CRM_Utils_Request::retrieve('context', 'String', $this);
$cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
//check for required permissions, CRM-6264
if ($activityId && !CRM_Activity_BAO_Activity::checkPermission($activityId, CRM_Core_Action::VIEW)) {
CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
}
$session = CRM_Core_Session::singleton();
if (!in_array($context, array('home', 'dashlet', 'dashletFullscreen'))) {
$url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$cid}&selectedChild=activity");
} else {
$url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1');
}
$session->pushUserContext($url);
$defaults = array();
$params = array('id' => $activityId);
CRM_Activity_BAO_Activity::retrieve($params, $defaults);
//set activity type name and description to template
list($activityTypeName, $activityTypeDescription) = CRM_Core_BAO_OptionValue::getActivityTypeDetails($defaults['activity_type_id']);
$this->assign('activityTypeName', $activityTypeName);
$this->assign('activityTypeDescription', $activityTypeDescription);
if (CRM_Utils_Array::value('mailingId', $defaults)) {
$this->_mailing_id = CRM_Utils_Array::value('source_record_id', $defaults);
$mailingReport = CRM_Mailing_BAO_Mailing::report($this->_mailing_id, TRUE);
CRM_Mailing_BAO_Mailing::getMailingContent($mailingReport, $this);
$this->assign('mailingReport', $mailingReport);
$full_open_report = CRM_Mailing_Event_BAO_Opened::getRows($this->_mailing_id, NULL, FALSE, NULL, NULL, NULL, $cid);
$this->assign('openreport', $full_open_report);
$click_thru_report = CRM_Mailing_Event_BAO_TrackableURLOpen::getRows($this->_mailing_id, NULL, FALSE, NULL, NULL, NULL, NULL, $cid);
$this->assign('clickreport', $click_thru_report);
}
foreach ($defaults as $key => $value) {
if (substr($key, -3) != '_id') {
$values[$key] = $value;
}
}
//get the campaign
if ($campaignId = CRM_Utils_Array::value('campaign_id', $defaults)) {
$campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId);
$values['campaign'] = $campaigns[$campaignId];
}
if ($engagementLevel = CRM_Utils_Array::value('engagement_level', $defaults)) {
$engagementLevels = CRM_Campaign_PseudoConstant::engagementLevel();
$values['engagement_level'] = CRM_Utils_Array::value($engagementLevel, $engagementLevels, $engagementLevel);
}
$values['attachment'] = CRM_Core_BAO_File::attachmentInfo('civicrm_activity', $activityId);
$this->assign('values', $values);
}
示例8: buildQuickForm
function buildQuickForm()
{
$this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
$optionGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'hrjc_hours_type', 'id', 'name');
$optionGroupIds = CRM_Core_BAO_OptionValue::getOptionValuesArray($optionGroupId);
foreach ($optionGroupIds as $key => $value) {
$this->_optionValue[$value['value']] = $value['label'];
$this->_id[$key] = $value['value'];
}
$this->assign('optionGroupIds', $optionGroupIds);
$this->addElement('select', 'hour_type_select', ts('Select Hour Type'), array('' => ts('- select -')) + $this->_optionValue);
$this->add('text', 'hour_value', ts('Value'));
$this->addFormRule(array('CRM_Hrjobcontract_Form_EditHourOption', 'formRule'), $this);
}
示例9: clickatell_civicrm_disable
/**
* Implementation of hook_civicrm_disable
*/
function clickatell_civicrm_disable()
{
$optionID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', 'clickatell', 'id', 'name');
if ($optionID) {
CRM_Core_BAO_OptionValue::setIsActive($optionID, FALSE);
}
$filter = array('name' => 'org.civicrm.sms.clickatell');
$Providers = CRM_SMS_BAO_Provider::getProviders(False, $filter, False);
if ($Providers) {
foreach ($Providers as $key => $value) {
CRM_SMS_BAO_Provider::setIsActive($value['id'], FALSE);
}
}
return _clickatell_civix_civicrm_disable();
}
示例10: preProcess
/**
* Function to set variables up before form is built
*
* @return void
* @access public
*/
public function preProcess()
{
//get the activity values
$activityId = CRM_Utils_Request::retrieve('id', 'Positive', $this);
$context = CRM_Utils_Request::retrieve('context', 'String', $this);
$cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
//check for required permissions, CRM-6264
if ($activityId && !CRM_Activity_BAO_Activity::checkPermission($activityId, CRM_Core_Action::VIEW)) {
CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
}
$session = CRM_Core_Session::singleton();
if ($context != 'home') {
$url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$cid}&selectedChild=activity");
} else {
$url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1');
}
$session->pushUserContext($url);
$params = array('id' => $activityId);
CRM_Activity_BAO_Activity::retrieve($params, $defaults);
//set activity type name and description to template
require_once 'CRM/Core/BAO/OptionValue.php';
list($activityTypeName, $activityTypeDescription) = CRM_Core_BAO_OptionValue::getActivityTypeDetails($defaults['activity_type_id']);
$this->assign('activityTypeName', $activityTypeName);
$this->assign('activityTypeDescription', $activityTypeDescription);
if (CRM_Utils_Array::value('mailingId', $defaults)) {
$this->_mailing_id = CRM_Utils_Array::value('source_record_id', $defaults);
require_once 'CRM/Mailing/BAO/Mailing.php';
$mailingReport =& CRM_Mailing_BAO_Mailing::report($this->_mailing_id, true);
CRM_Mailing_BAO_Mailing::getMailingContent($mailingReport, $this);
$this->assign('mailingReport', $mailingReport);
}
foreach ($defaults as $key => $value) {
if (substr($key, -3) != '_id') {
$values[$key] = $value;
}
}
require_once 'CRM/Core/BAO/File.php';
$values['attachment'] = CRM_Core_BAO_File::attachmentInfo('civicrm_activity', $activityId);
$this->assign('values', $values);
}
示例11: postProcess
/**
* Process the form submission.
*
* @param array $params
* @param string $type
* @param array $linkedEntities
*
* @throws \CiviCRM_API3_Exception
*/
public static function postProcess($params = array(), $type, $linkedEntities = array())
{
//Check entity_id not present in params take it from class variable
if (empty($params['entity_id'])) {
$params['entity_id'] = self::$_entityId;
}
//Process this function only when you get this variable
if ($params['allowRepeatConfigToSubmit'] == 1) {
if (!empty($params['entity_table']) && !empty($params['entity_id']) && $type) {
$params['used_for'] = $type;
if (empty($params['parent_entity_id'])) {
$params['parent_entity_id'] = self::$_parentEntityId;
}
if (!empty($params['schedule_reminder_id'])) {
$params['id'] = $params['schedule_reminder_id'];
} else {
$params['id'] = self::$_scheduleReminderID;
}
//Save post params to the schedule reminder table
$recurobj = new CRM_Core_BAO_RecurringEntity();
$dbParams = $recurobj->mapFormValuesToDB($params);
//Delete repeat configuration and rebuild
if (!empty($params['id'])) {
CRM_Core_BAO_ActionSchedule::del($params['id']);
unset($params['id']);
}
$actionScheduleObj = CRM_Core_BAO_ActionSchedule::add($dbParams);
//exclude dates
$excludeDateList = array();
if (CRM_Utils_Array::value('exclude_date_list', $params) && CRM_Utils_Array::value('parent_entity_id', $params) && $actionScheduleObj->entity_value) {
//Since we get comma separated values lets get them in array
$excludeDates = explode(",", $params['exclude_date_list']);
//Check if there exists any values for this option group
$optionGroupIdExists = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $type . '_repeat_exclude_dates_' . $params['parent_entity_id'], 'id', 'name');
if ($optionGroupIdExists) {
CRM_Core_BAO_OptionGroup::del($optionGroupIdExists);
}
$optionGroupParams = array('name' => $type . '_repeat_exclude_dates_' . $actionScheduleObj->entity_value, 'title' => $type . ' recursion', 'is_reserved' => 0, 'is_active' => 1);
$opGroup = CRM_Core_BAO_OptionGroup::add($optionGroupParams);
if ($opGroup->id) {
$oldWeight = 0;
$fieldValues = array('option_group_id' => $opGroup->id);
foreach ($excludeDates as $val) {
$optionGroupValue = array('option_group_id' => $opGroup->id, 'label' => CRM_Utils_Date::processDate($val), 'value' => CRM_Utils_Date::processDate($val), 'name' => $opGroup->name, 'description' => 'Used for recurring ' . $type, 'weight' => CRM_Utils_Weight::updateOtherWeights('CRM_Core_DAO_OptionValue', $oldWeight, CRM_Utils_Array::value('weight', $params), $fieldValues), 'is_active' => 1);
$excludeDateList[] = $optionGroupValue['value'];
CRM_Core_BAO_OptionValue::create($optionGroupValue);
}
}
}
//Set type for API
$apiEntityType = explode("_", $type);
if (!empty($apiEntityType[1])) {
$apiType = $apiEntityType[1];
}
//Delete relations if any from recurring entity tables before inserting new relations for this entity id
if ($params['entity_id']) {
//If entity has any pre delete function, consider that first
if (CRM_Utils_Array::value('pre_delete_func', CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]) && CRM_Utils_Array::value('helper_class', CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']])) {
$preDeleteResult = call_user_func_array(CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['pre_delete_func'], array($params['entity_id']));
if (!empty($preDeleteResult)) {
call_user_func(array(CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['helper_class'], $preDeleteResult));
}
}
//Ready to execute delete on entities if it has delete function set
if (CRM_Utils_Array::value('delete_func', CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]) && CRM_Utils_Array::value('helper_class', CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']])) {
//Check if pre delete function has some ids to be deleted
if (!empty(CRM_Core_BAO_RecurringEntity::$_entitiesToBeDeleted)) {
foreach (CRM_Core_BAO_RecurringEntity::$_entitiesToBeDeleted as $eid) {
$result = civicrm_api3(ucfirst(strtolower($apiType)), CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['delete_func'], array('sequential' => 1, 'id' => $eid));
if ($result['error']) {
CRM_Core_Error::statusBounce('Error creating recurring list');
}
}
} else {
$getRelatedEntities = CRM_Core_BAO_RecurringEntity::getEntitiesFor($params['entity_id'], $params['entity_table'], FALSE);
foreach ($getRelatedEntities as $key => $value) {
$result = civicrm_api3(ucfirst(strtolower($apiType)), CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['delete_func'], array('sequential' => 1, 'id' => $value['id']));
if ($result['error']) {
CRM_Core_Error::statusBounce('Error creating recurring list');
}
}
}
}
// find all entities from the recurring set. At this point we 'll get entities which were not deleted
// for e.g due to participants being present. We need to delete them from recurring tables anyway.
$pRepeatingEntities = CRM_Core_BAO_RecurringEntity::getEntitiesFor($params['entity_id'], $params['entity_table']);
foreach ($pRepeatingEntities as $val) {
CRM_Core_BAO_RecurringEntity::delEntity($val['id'], $val['table'], TRUE);
}
}
$recursion = new CRM_Core_BAO_RecurringEntity();
//.........这里部分代码省略.........
示例12: exportDAO
/**
* @param string $objectName
* Business-entity/xml-tag name.
* @param CRM_Core_DAO $object
* @param $mappedFields
*
* @return array
*/
public function exportDAO($objectName, $object, $mappedFields)
{
$dbFields =& $object->fields();
// Filter the list of keys and values so that we only export interesting stuff
$keyValues = array();
foreach ($dbFields as $name => $dontCare) {
// ignore all ids
if ($name == 'id' || substr($name, -3, 3) == '_id') {
continue;
}
if (isset($object->{$name}) && $object->{$name} !== NULL) {
// hack for extends_entity_column_value
if ($name == 'extends_entity_column_value') {
if (in_array($object->extends, array('Event', 'Activity', 'Relationship', 'Individual', 'Organization', 'Household', 'Case'))) {
if ($object->extends == 'Event') {
$key = 'event_type';
} elseif ($object->extends == 'Activity') {
$key = 'activity_type';
} elseif ($object->extends == 'Relationship') {
$key = 'relationship_type';
} elseif ($object->extends == 'Case') {
$key = 'case_type';
}
$types = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($object->{$name}, 1, -1));
$values = array();
if (in_array($object->extends, array('Individual', 'Organization', 'Household'))) {
$key = 'contact_type';
$values = $types;
} else {
foreach ($types as $type) {
if (in_array($key, array('activity_type', 'event_type', 'case_type'))) {
$ogID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $key, 'id', 'name');
$ovParams = array('option_group_id' => $ogID, 'value' => $type);
CRM_Core_BAO_OptionValue::retrieve($ovParams, $oValue);
$values[] = $oValue['name'];
} else {
$relTypeName = CRM_Core_DAO::getFieldValue('CRM_Contact_BAO_RelationshipType', $type, 'name_a_b', 'id');
$values[] = $relTypeName;
}
}
}
$keyValues['extends_entity_column_value_option_group'] = $key;
$value = implode(',', $values);
$object->extends_entity_column_value = $value;
} else {
echo "This extension: {$object->extends} is not yet handled";
exit;
}
}
$value = $object->{$name};
if ($name == 'field_name') {
// hack for profile field_name
if (substr($value, 0, 7) == 'custom_') {
$cfID = substr($value, 7);
list($tableName, $columnName, $groupID) = CRM_Core_BAO_CustomField::getTableColumnGroup($cfID);
$value = "custom.{$tableName}.{$columnName}";
}
}
$keyValues[$name] = $value;
}
}
$keyValues += $this->computeMappedFields($mappedFields, $object);
return $keyValues;
}
示例13: upgradeDomainFromEmail
/**
* This function preserve the civicrm_domain.email_name and civicrm_domain.email_address
* as a default option value into "from_email_address" option group
* and drop these columns from civicrm_domain table.
* @access public
*
* @return void
*/
function upgradeDomainFromEmail()
{
$query = "\nSELECT id\n FROM civicrm_option_group\n WHERE name = 'from_Email_address'";
$fmaGroup = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
$fmaGroupId = NULL;
if ($fmaGroup->fetch()) {
$fmaGroupId = $fmaGroup->id;
} else {
//insert 'from_mailing_address' option group.
$query = "\nINSERT INTO civicrm_option_group ( name, description, is_reserved, is_active )\nVALUES ('from_email_address', 'From Email Address', 0, 1)";
CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
//get the group id.
$query = "\nSELECT id\n FROM civicrm_option_group\n WHERE name = 'from_email_address'";
$dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
if ($dao->fetch()) {
$fmaGroupId = $dao->id;
}
}
if ($fmaGroupId) {
//get domain from email address and name as default value.
$domain = CRM_Core_BAO_Domain::getDomain();
$domain->selectAdd();
$domain->selectAdd('email_name', 'email_address');
$domain->find(TRUE);
$formEmailAddress = '"' . $domain->email_name . '"<' . $domain->email_address . '>';
//first check given domain email address exist in option
//value, if yes make it as domain email address by making
//it as default from email address..
//get the existing from email address.
$optionValues = array();
$grpParams['name'] = 'from_email_address';
CRM_Core_OptionValue::getValues($grpParams, $optionValues);
$maxVal = $maxWt = 1;
$insertEmailAddress = TRUE;
if (!empty($optionValues)) {
//make existing is_default = 0
$query = "\nUPDATE civicrm_option_value\n SET is_default = 0\n WHERE option_group_id = %1";
$params = array(1 => array($fmaGroupId, 'Integer'));
CRM_Core_DAO::executeQuery($query, $params);
//if domain from name and email exist as name or label in option value
//table need to preserve that name and label and take care that label
//and name both remain unique in db.
$labelValues = $nameValues = array();
foreach ($optionValues as $id => $value) {
if ($value['label'] == $formEmailAddress) {
$labelValues = $value;
} elseif ($value['name'] == $formEmailAddress) {
$nameValues = $value;
}
}
//as we consider label so label should preserve.
$updateValues = array();
if (!empty($labelValues)) {
$updateValues = $labelValues;
}
//if matching name found need to preserve it.
if (!empty($nameValues)) {
//copy domain from email address as label.
if (empty($updateValues)) {
$updateValues = $nameValues;
$updateValues['label'] = $formEmailAddress;
} else {
//since name is also imp so preserve it
//as name for domain email address record.
$updateValues['name'] = $nameValues['name'];
//name is unique so drop name value record.
//since we transfer this name to found label record.
CRM_Core_BAO_OptionValue::del($nameValues['id']);
}
}
if (!empty($updateValues)) {
$insertEmailAddress = FALSE;
//update label/name found record w/ manupulated values.
$updateValues['is_active'] = $updateValues['is_default'] = 1;
$optionValue = new CRM_Core_DAO_OptionValue();
$optionValue->copyValues($updateValues);
$optionValue->save();
}
//get the max value and wt.
if ($insertEmailAddress) {
$query = "\nSELECT max(ROUND(civicrm_option_value.value)) as maxVal,\n max(civicrm_option_value.weight) as maxWt\n FROM civicrm_option_value, civicrm_option_group\n WHERE civicrm_option_group.name = 'from_Email_address'\n AND civicrm_option_value.option_group_id = civicrm_option_group.id\nGROUP BY civicrm_option_group.id";
$dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
if ($dao->fetch()) {
$maxWt += $dao->maxWt;
$maxVal += $dao->maxVal;
}
}
}
if ($insertEmailAddress) {
//insert domain from email address and name.
$query = "\nINSERT INTO `civicrm_option_value`\n (`option_group_id`, `label`, `value`, `name` , `grouping`, `filter`, `is_default`,\n `weight`, `description`, `is_optgroup`, `is_reserved`, `is_active`, `component_id`)\n VALUES ( %1, %2, %3, %2, NULL, 0, 1, %4, 'Default domain email address and from name.', 0, 0, 1, NULL)";
$params = array(1 => array($fmaGroupId, 'Integer'), 2 => array($formEmailAddress, 'String'), 3 => array($maxVal, 'Integer'), 4 => array($maxWt, 'Integer'));
//.........这里部分代码省略.........
示例14: getDefaultValue
/**
* Get next available value.
* We will take the highest numeric value (or 0 if no numeric values exist)
* and add one. The calling function is responsible for any
* more complex decision making
* @param array $params
*/
public static function getDefaultValue($params)
{
$bao = new CRM_Core_BAO_OptionValue();
$bao->option_group_id = $params['option_group_id'];
if (isset($params['domain_id'])) {
$bao->domain_id = $params['domain_id'];
}
$bao->selectAdd();
$bao->whereAdd("value REGEXP '^[0-9]+\$'");
$bao->selectAdd('(ROUND(COALESCE(MAX(CONVERT(value, UNSIGNED)),0)) +1) as nextvalue');
$bao->find(TRUE);
return $bao->nextvalue;
}
示例15: testGetInstrumentFinancialAccount
/**
* check method getInstrumentFinancialAccount()
*/
function testGetInstrumentFinancialAccount()
{
$paymentInstrumentValue = 1;
$params = array('name' => 'Donations', 'is_deductible' => 0, 'is_active' => 1);
$ids = array();
$financialAccount = CRM_Financial_BAO_FinancialAccount::add($params, $ids);
$optionParams = array('name' => 'Credit Card', 'value' => $paymentInstrumentValue);
$optionValue = CRM_Core_BAO_OptionValue::retrieve($optionParams, $defaults);
$relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' "));
$financialParams = array('entity_table' => 'civicrm_option_value', 'entity_id' => $optionValue->id, 'account_relationship' => $relationTypeId, 'financial_account_id' => $financialAccount->id);
CRM_Financial_BAO_FinancialTypeAccount::add($financialParams, $ids);
$financialAccountId = CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount($paymentInstrumentValue);
$this->assertEquals($financialAccountId, $financialAccount->id, 'Verify Payment Instrument');
}