本文整理汇总了PHP中CRM_Core_PseudoConstant::flush方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_PseudoConstant::flush方法的具体用法?PHP CRM_Core_PseudoConstant::flush怎么用?PHP CRM_Core_PseudoConstant::flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Core_PseudoConstant
的用法示例。
在下文中一共展示了CRM_Core_PseudoConstant::flush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
示例2: testCaseType
public function testCaseType()
{
CRM_Core_PseudoConstant::flush();
$caseTypes = CRM_Case_PseudoConstant::caseType();
$expectedTypes = array(1 => 'Housing Support', 2 => 'Adult Day Care Referral');
$this->assertEquals($expectedTypes, $caseTypes);
}
示例3: setUp
public function setUp()
{
$this->_entity = 'Address';
parent::setUp();
$this->_contactID = $this->organizationCreate();
$this->_locationType = $this->locationTypeCreate();
CRM_Core_PseudoConstant::flush();
$this->_params = array('contact_id' => $this->_contactID, 'location_type_id' => $this->_locationType->id, 'street_name' => 'Ambachtstraat', 'street_number' => '23', 'street_address' => 'Ambachtstraat 23', 'postal_code' => '6971 BN', 'country_id' => '1152', 'city' => 'Brummen', 'is_primary' => 1);
}
示例4: setUp
public function setUp()
{
$this->_apiversion = 3;
parent::setUp();
$this->useTransaction();
$this->_contactID = $this->organizationCreate();
$loc = $this->locationTypeCreate();
$this->_locationType = $loc->id;
CRM_Core_PseudoConstant::flush();
$this->_params = array('contact_id' => $this->_contactID, 'location_type_id' => $this->_locationType, 'phone' => '(123) 456-7890', 'is_primary' => 1, 'phone_type_id' => 1);
}
示例5: setUp
public function setUp()
{
$this->_apiversion = 3;
parent::setUp();
$this->useTransaction(TRUE);
$this->_contactID = $this->organizationCreate();
$activity = $this->activityCreate();
$this->_activityID = $activity['id'];
CRM_Core_PseudoConstant::flush();
$this->_params = array('contact_id' => $this->_contactID, 'activity_id' => $this->_activityID, 'record_type_id' => 2);
}
示例6: setUp
function setUp()
{
$this->_apiversion = 3;
parent::setUp();
$this->_contactID = $this->organizationCreate();
$activity = $this->activityCreate();
$this->_activityID = $activity['id'];
CRM_Core_PseudoConstant::flush();
$this->quickCleanup(array('civicrm_activity_contact'));
$this->_params = array('contact_id' => $this->_contactID, 'activity_id' => $this->_activityID, 'record_type_id' => 2);
}
示例7: testLocationTypeGet
/**
* Test civicrm_address_getoptions( 'location_type_id' )
*/
public function testLocationTypeGet()
{
// needed to get rid of cached values from previous tests
CRM_Core_PseudoConstant::flush();
$params = array('field' => 'location_type_id');
$result = $this->callAPIAndDocument('address', 'getoptions', $params, __FUNCTION__, __FILE__);
$this->assertTrue($result['count'] > 3, "In line " . __LINE__);
$this->assertContains('Home', $result['values'], "In line " . __LINE__);
$this->assertContains('Work', $result['values'], "In line " . __LINE__);
$this->assertContains('Main', $result['values'], "In line " . __LINE__);
$this->assertContains('Billing', $result['values'], "In line " . __LINE__);
}
示例8: civicrm_location_add
/**
* Create an additional location for an existing contact
*
* @param array $params input properties
*
* @return array the created location's params
*
* @access public
*/
function civicrm_location_add(&$params)
{
_civicrm_initialize();
$error = _civicrm_location_check_params($params);
if (civicrm_error($error)) {
return $error;
}
$locationTypeId = CRM_Utils_Array::value('location_type_id', $params);
if (!$locationTypeId && '3.0' != CRM_Utils_Array::value('version', $params)) {
require_once 'CRM/Core/DAO/LocationType.php';
$locationTypeDAO = new CRM_Core_DAO_LocationType();
$locationTypeDAO->name = $params['location_type'];
$locationTypeDAO->find(true);
$locationTypeId = $locationTypeDAO->id;
CRM_Core_PseudoConstant::flush('locationType');
if (!isset($locationTypeId)) {
return civicrm_create_error(ts('$location_type is not valid one'));
}
}
$location =& _civicrm_location_add($params, $locationTypeId);
return $location;
}
示例9: del
/**
* Delete Option Value.
*
* @param int $optionValueId
*
* @return bool
*
*/
public static function del($optionValueId)
{
$optionValue = new CRM_Core_DAO_OptionValue();
$optionValue->id = $optionValueId;
if (self::updateRecords($optionValueId, CRM_Core_Action::DELETE)) {
CRM_Core_PseudoConstant::flush();
return $optionValue->delete();
}
return FALSE;
}
示例10: civicrm_api3_generic_getfields
/**
* Get information about fields for a given api request.
*
* Getfields information is used for documentation, validation, default setting
* We first query the scheme using the $dao->fields function & then augment
* that information by calling the _spec functions that apply to the relevant function
* Note that we use 'unique' field names as described in the xml/schema files
* for get requests & just field name for create. This is because some get functions
* access multiple objects e.g. contact api accesses is_deleted from the activity
* table & from the contact table
*
* @param array $apiRequest
* Api request as an array. Keys are.
* - entity: string
* - action: string
* - version: string
* - function: callback (mixed)
* - params: array, varies
*
* @param bool $unique
* Determines whether to key by unique field names (only affects get-type) actions
*
* @return array
* API success object
*/
function civicrm_api3_generic_getfields($apiRequest, $unique = TRUE)
{
static $results = array();
if (CRM_Utils_Array::value('cache_clear', $apiRequest['params'])) {
$results = array();
// we will also clear pseudoconstants here - should potentially be moved to relevant BAO classes
CRM_Core_PseudoConstant::flush();
if (!empty($apiRequest['params']['fieldname'])) {
CRM_Utils_PseudoConstant::flushConstant($apiRequest['params']['fieldname']);
}
if (!empty($apiRequest['params']['option_group_id'])) {
$optionGroupName = civicrm_api('option_group', 'getvalue', array('version' => 3, 'id' => $apiRequest['params']['option_group_id'], 'return' => 'name'));
if (is_string($optionGroupName)) {
CRM_Utils_PseudoConstant::flushConstant(_civicrm_api_get_camel_name($optionGroupName));
}
}
}
$entity = $apiRequest['entity'];
$lowercase_entity = _civicrm_api_get_entity_name_from_camel($entity);
$subentity = CRM_Utils_Array::value('contact_type', $apiRequest['params']);
$action = CRM_Utils_Array::value('action', $apiRequest['params']);
$sequential = empty($apiRequest['params']['sequential']) ? 0 : 1;
$apiRequest['params']['options'] = CRM_Utils_Array::value('options', $apiRequest['params'], array());
$optionsToResolve = (array) CRM_Utils_Array::value('get_options', $apiRequest['params']['options'], array());
if (!$action || $action == 'getvalue' || $action == 'getcount') {
$action = 'get';
}
// If no options, return results from cache
if (!$apiRequest['params']['options'] && isset($results[$entity . $subentity]) && isset($action, $results[$entity . $subentity]) && isset($action, $results[$entity . $subentity][$sequential])) {
return $results[$entity . $subentity][$action][$sequential];
}
// defaults based on data model and API policy
switch ($action) {
case 'getfields':
$values = _civicrm_api_get_fields($entity, FALSE, $apiRequest['params']);
return civicrm_api3_create_success($values, $apiRequest['params'], $entity, 'getfields');
case 'create':
case 'update':
case 'replace':
$unique = FALSE;
case 'get':
case 'getsingle':
case 'getcount':
case 'getstat':
$metadata = _civicrm_api_get_fields($apiRequest['entity'], $unique, $apiRequest['params']);
if (empty($metadata['id'])) {
// if id is not set we will set it eg. 'id' from 'case_id', case_id will be an alias
if (!empty($metadata[strtolower($apiRequest['entity']) . '_id'])) {
$metadata['id'] = $metadata[$lowercase_entity . '_id'];
unset($metadata[$lowercase_entity . '_id']);
$metadata['id']['api.aliases'] = array($lowercase_entity . '_id');
}
} else {
// really the preference would be to set the unique name in the xml
// question is which is a less risky fix this close to a release - setting in xml for the known failure
// (note) or setting for all api where fields is returning 'id' & we want to accept 'note_id' @ the api layer
// nb we don't officially accept note_id anyway - rationale here is more about centralising a now-tested
// inconsistency
$metadata['id']['api.aliases'] = array($lowercase_entity . '_id');
}
break;
case 'delete':
$metadata = array('id' => array('title' => $entity . ' ID', 'api.required' => 1, 'api.aliases' => array($lowercase_entity . '_id'), 'type' => CRM_Utils_Type::T_INT));
break;
// Note: adding setvalue case here instead of in a generic spec function because
// some APIs override the generic setvalue fn which causes the generic spec to be overlooked.
// Note: adding setvalue case here instead of in a generic spec function because
// some APIs override the generic setvalue fn which causes the generic spec to be overlooked.
case 'setvalue':
$metadata = array('field' => array('title' => 'Field name', 'api.required' => 1, 'type' => CRM_Utils_Type::T_STRING), 'id' => array('title' => $entity . ' ID', 'api.required' => 1, 'type' => CRM_Utils_Type::T_INT), 'value' => array('title' => 'Value', 'description' => "Field value to set", 'api.required' => 1));
if (array_intersect(array('all', 'field'), $optionsToResolve)) {
$options = civicrm_api3_generic_getfields(array('entity' => $entity, array('params' => array('action' => 'create'))));
$metadata['field']['options'] = CRM_Utils_Array::collect('title', $options['values']);
}
break;
//.........这里部分代码省略.........
示例11: testHookFieldOptions
/**
* Ensure hook_civicrm_fieldOptions is working
*/
public function testHookFieldOptions()
{
CRM_Core_PseudoConstant::flush();
// Test replacing all options with a hook
$this->targetField = 'case_type_id';
$this->replaceOptions = array('foo' => 'Foo', 'bar' => 'Bar');
$result = $this->callAPISuccess('case', 'getoptions', array('field' => 'case_type_id'));
$this->assertEquals($result['values'], $this->replaceOptions);
// TargetField doesn't match - should get unmodified option list
$originalGender = CRM_Contact_BAO_Contact::buildOptions('gender_id');
$this->assertNotEquals($originalGender, $this->replaceOptions);
// This time we should get foo bar appended to the list
$this->targetField = 'gender_id';
$this->appendOptions = array('foo' => 'Foo', 'bar' => 'Bar');
$this->replaceOptions = NULL;
CRM_Core_PseudoConstant::flush();
$result = CRM_Contact_BAO_Contact::buildOptions('gender_id');
$this->assertEquals($result, $originalGender + $this->appendOptions);
}
示例12: flushAll
/**
* Flush all caches related to pseudo-constants.
*
* This may be inefficient and should generally be avoided.
*/
public static function flushAll()
{
foreach (self::findConstants() as $constant) {
self::flushConstant($constant);
}
CRM_Core_PseudoConstant::flush();
}
示例13: tearDown
public function tearDown()
{
$this->quickCleanup(array('civicrm_contribution', 'civicrm_contribution_soft', 'civicrm_event', 'civicrm_contribution_page', 'civicrm_participant', 'civicrm_participant_payment', 'civicrm_line_item', 'civicrm_financial_trxn', 'civicrm_financial_item', 'civicrm_entity_financial_trxn', 'civicrm_contact', 'civicrm_membership', 'civicrm_membership_payment', 'civicrm_payment_processor'));
CRM_Core_PseudoConstant::flush('taxRates');
}
示例14: entityCustomGroupWithSingleFieldCreate
/**
* Create a custom group with a single text custom field. See
* participant:testCreateWithCustom for how to use this
*
* @param string $function
* __FUNCTION__.
* @param string $filename
* $file __FILE__.
*
* @return array
* ids of created objects
*/
public function entityCustomGroupWithSingleFieldCreate($function, $filename)
{
$params = array('title' => $function);
$entity = substr(basename($filename), 0, strlen(basename($filename)) - 8);
$params['extends'] = $entity ? $entity : 'Contact';
$customGroup = $this->CustomGroupCreate($params);
$customField = $this->customFieldCreate(array('custom_group_id' => $customGroup['id'], 'label' => $function));
CRM_Core_PseudoConstant::flush();
return array('custom_group_id' => $customGroup['id'], 'custom_field_id' => $customField['id']);
}
示例15: civicrm_api3_generic_getfields
/**
* Get information about fields for a given api request. Getfields information
* is used for documentation, validation, default setting
* We first query the scheme using the $dao->fields function & then augment
* that information by calling the _spec functions that apply to the relevant function
* Note that we use 'unique' field names as described in the xml/schema files
* for get requests & just field name for create. This is because some get functions
* access multiple objects e.g. contact api accesses is_deleted from the activity
* table & from the contact table
*
* @param array $apiRequest api request as an array. Keys are
* - entity: string
* - action: string
* - version: string
* - function: callback (mixed)
* - params: array, varies
* @return array API success object
*/
function civicrm_api3_generic_getfields($apiRequest)
{
static $results = array();
if (CRM_Utils_Array::value('cache_clear', $apiRequest['params'])) {
$results = array();
// we will also clear pseudoconstants here - should potentially be moved to relevant BAO classes
CRM_Core_PseudoConstant::flush();
if (!empty($apiRequest['params']['fieldname'])) {
CRM_Utils_PseudoConstant::flushConstant($apiRequest['params']['fieldname']);
}
if (!empty($apiRequest['params']['option_group_id'])) {
$optionGroupName = civicrm_api('option_group', 'getvalue', array('version' => 3, 'id' => $apiRequest['params']['option_group_id'], 'return' => 'name'));
if (is_string($optionGroupName)) {
CRM_Utils_PseudoConstant::flushConstant(_civicrm_api_get_camel_name($optionGroupName));
}
}
}
$entity = _civicrm_api_get_camel_name($apiRequest['entity']);
$lcase_entity = _civicrm_api_get_entity_name_from_camel($entity);
$subentity = CRM_Utils_Array::value('contact_type', $apiRequest['params']);
$action = strtolower(CRM_Utils_Array::value('action', $apiRequest['params']));
$sequential = empty($apiRequest['params']) ? 0 : 1;
$apiOptions = CRM_Utils_Array::value('options', $apiRequest['params'], array());
if ($action == 'getvalue' || $action == 'getvalue' || $action == 'getcount') {
$action = 'get';
}
if (empty($action)) {
$action = 'get';
}
// determines whether to use unique field names - seem comment block above
$unique = TRUE;
if (empty($apiOptions) && isset($results[$entity . $subentity]) && isset($action, $results[$entity . $subentity]) && isset($action, $results[$entity . $subentity][$sequential])) {
return $results[$entity . $subentity][$action][$sequential];
}
// defaults based on data model and API policy
switch ($action) {
case 'getfields':
$values = _civicrm_api_get_fields($entity, false, $apiRequest['params']);
return civicrm_api3_create_success($values, $apiRequest['params'], $entity, 'getfields');
case 'create':
case 'update':
case 'replace':
$unique = FALSE;
case 'get':
$metadata = _civicrm_api_get_fields($apiRequest['entity'], $unique, $apiRequest['params']);
if (empty($metadata['id'])) {
// if id is not set we will set it eg. 'id' from 'case_id', case_id will be an alias
if (!empty($metadata[strtolower($apiRequest['entity']) . '_id'])) {
$metadata['id'] = $metadata[$lcase_entity . '_id'];
unset($metadata[$lcase_entity . '_id']);
$metadata['id']['api.aliases'] = array($lcase_entity . '_id');
}
} else {
// really the preference would be to set the unique name in the xml
// question is which is a less risky fix this close to a release - setting in xml for the known failure
// (note) or setting for all api where fields is returning 'id' & we want to accept 'note_id' @ the api layer
// nb we don't officially accept note_id anyway - rationale here is more about centralising a now-tested
// inconsistency
$metadata['id']['api.aliases'] = array($lcase_entity . '_id');
}
break;
case 'delete':
$metadata = array('id' => array('title' => 'Unique Identifier', 'api.required' => 1, 'api.aliases' => array($lcase_entity . '_id'), 'type' => CRM_Utils_Type::T_INT));
break;
case 'getoptions':
$metadata = array('field' => array('title' => 'Field to retrieve options for', 'api.required' => 1), 'context' => array('title' => 'Context string'));
break;
default:
// oddballs are on their own
$metadata = array();
}
// find any supplemental information
$hypApiRequest = array('entity' => $apiRequest['entity'], 'action' => $action, 'version' => $apiRequest['version']);
$hypApiRequest += _civicrm_api_resolve($hypApiRequest);
$helper = '_' . $hypApiRequest['function'] . '_spec';
if (function_exists($helper)) {
// alter
$helper($metadata, $apiRequest);
}
$fieldsToResolve = (array) CRM_Utils_Array::value('get_options', $apiOptions, array());
foreach ($metadata as $fieldname => $fieldSpec) {
_civicrm_api3_generic_get_metadata_options($metadata, $apiRequest['entity'], $fieldname, $fieldSpec, $fieldsToResolve);
//.........这里部分代码省略.........