本文整理汇总了PHP中CRM_Contact_BAO_GroupContactCache类的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Contact_BAO_GroupContactCache类的具体用法?PHP CRM_Contact_BAO_GroupContactCache怎么用?PHP CRM_Contact_BAO_GroupContactCache使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CRM_Contact_BAO_GroupContactCache类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: browse
/**
* called when action is browse.
*
*/
public function browse()
{
$in = CRM_Contact_BAO_GroupContact::getContactGroup($this->_contactId, 'Added');
// keep track of all 'added' contact groups so we can remove them from the smart group
// section
$staticGroups = array();
if (!empty($in)) {
foreach ($in as $group) {
$staticGroups[$group['group_id']] = 1;
}
}
$allGroup = CRM_Contact_BAO_GroupContactCache::contactGroup($this->_contactId);
$this->assign('groupSmart', NULL);
$this->assign('groupParent', NULL);
if (!empty($allGroup)) {
$smart = $parent = array();
foreach ($allGroup['group'] as $group) {
// delete all smart groups which are also in static groups
if (isset($staticGroups[$group['id']])) {
continue;
}
if (empty($group['children'])) {
$smart[] = $group;
} else {
$parent[] = $group;
}
}
if (!empty($smart)) {
$this->assign_by_ref('groupSmart', $smart);
}
if (!empty($parent)) {
$this->assign_by_ref('groupParent', $parent);
}
}
}
示例2: where
function where()
{
$petition_id = intval($this->_params['petition_id_value']);
$group_id = NULL;
if (array_key_exists('group_id_value', $this->_params)) {
$group_id = intval($this->_params['group_id_value']);
}
$petition_activity_type_id = intval(CRM_Core_OptionGroup::getValue('activity_type', 'Petition', 'name'));
$activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
$source_activity_record_type_id = intval(CRM_Utils_Array::key('Activity Source', $activityContacts));
$this->_where = "WHERE ";
$signed = '';
$group = '';
// Include people who have signed the petition OR people who are in the passed in group
// First the signers.
$signed = "{$this->_aliases['civicrm_contact']}.id IN (SELECT contact_id\n FROM civicrm_activity_contact ac JOIN civicrm_activity a ON\n ac.activity_id = a.id WHERE ac.record_type_id = {$source_activity_record_type_id}\n AND source_record_id = {$petition_id} AND a.activity_type_id = {$petition_activity_type_id})";
// Now the people in the specified group
if ($group_id) {
// Check if we are a smart group or regular group
$results = civicrm_api3('Group', 'getsingle', array('id' => $group_id));
if (!empty($results['id'])) {
$group = "{$this->_aliases['civicrm_contact']}.id IN (SELECT contact_id FROM ";
if (!empty($results['saved_search_id'])) {
// Populate the cache
CRM_Contact_BAO_GroupContactCache::check($group_id);
$group .= "civicrm_group_contact_cache cc WHERE cc.group_id = {$group_id})";
} else {
$group .= "civicrm_group_contact gc WHERE gc.group_id = {$group_id}\n AND gc.status = 'Added')";
}
}
}
if (!empty($group)) {
$this->_where .= " ({$signed}) OR ({$group}) ";
} else {
$this->_where .= "{$signed}";
}
}
示例3: key
/**
* Takes an associative array and creates a participant object.
*
* the function extract all the params it needs to initialize the create a
* participant object. the params array could contain additional unused name/value
* pairs
*
* @param array $params
* (reference ) an assoc array of name/value pairs.
*
* @return CRM_Event_BAO_Participant
*/
public static function &add(&$params)
{
if (!empty($params['id'])) {
CRM_Utils_Hook::pre('edit', 'Participant', $params['id'], $params);
} else {
CRM_Utils_Hook::pre('create', 'Participant', NULL, $params);
}
// converting dates to mysql format
if (!empty($params['register_date'])) {
$params['register_date'] = CRM_Utils_Date::isoToMysql($params['register_date']);
}
if (!empty($params['participant_fee_amount'])) {
$params['participant_fee_amount'] = CRM_Utils_Rule::cleanMoney($params['participant_fee_amount']);
}
if (!empty($params['fee_amount'])) {
$params['fee_amount'] = CRM_Utils_Rule::cleanMoney($params['fee_amount']);
}
// ensure that role ids are encoded as a string
if (isset($params['role_id']) && is_array($params['role_id'])) {
if (in_array(key($params['role_id']), CRM_Core_DAO::acceptedSQLOperators(), TRUE)) {
$op = key($params['role_id']);
$params['role_id'] = $params['role_id'][$op];
} else {
$params['role_id'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $params['role_id']);
}
}
$participantBAO = new CRM_Event_BAO_Participant();
if (!empty($params['id'])) {
$participantBAO->id = CRM_Utils_Array::value('id', $params);
$participantBAO->find(TRUE);
$participantBAO->register_date = CRM_Utils_Date::isoToMysql($participantBAO->register_date);
}
$participantBAO->copyValues($params);
//CRM-6910
//1. If currency present, it should be valid one.
//2. We should have currency when amount is not null.
$currency = $participantBAO->fee_currency;
if ($currency || !CRM_Utils_System::isNull($participantBAO->fee_amount)) {
if (!CRM_Utils_Rule::currencyCode($currency)) {
$config = CRM_Core_Config::singleton();
$currency = $config->defaultCurrency;
}
}
$participantBAO->fee_currency = $currency;
$participantBAO->save();
$session = CRM_Core_Session::singleton();
CRM_Contact_BAO_GroupContactCache::opportunisticCacheFlush();
if (!empty($params['id'])) {
CRM_Utils_Hook::post('edit', 'Participant', $participantBAO->id, $participantBAO);
} else {
CRM_Utils_Hook::post('create', 'Participant', $participantBAO->id, $participantBAO);
}
return $participantBAO;
}
示例4: deleteCustomValue
/**
* Delete custom value.
*/
public static function deleteCustomValue()
{
CRM_Utils_System::setHttpHeader('Content-Type', 'text/plain');
$customValueID = CRM_Utils_Type::escape($_REQUEST['valueID'], 'Positive');
$customGroupID = CRM_Utils_Type::escape($_REQUEST['groupID'], 'Positive');
$contactId = CRM_Utils_Request::retrieve('contactId', 'Positive', CRM_Core_DAO::$_nullObject);
CRM_Core_BAO_CustomValue::deleteCustomValue($customValueID, $customGroupID);
if ($contactId) {
echo CRM_Contact_BAO_Contact::getCountComponent('custom_' . $customGroupID, $contactId);
}
CRM_Contact_BAO_GroupContactCache::opportunisticCacheFlush();
CRM_Utils_System::civiExit();
}
示例5: removeContactsFromGroup
/**
* Given an array of contact ids, remove all the contacts from the group
*
* @param array $contactIds
* (reference ) the array of contact ids to be removed.
* @param int $groupId
* The id of the group.
*
* @param string $method
* @param string $status
* @param NULL $tracking
*
* @return array
* (total, removed, notRemoved) count of contacts removed to group
*/
public static function removeContactsFromGroup(&$contactIds, $groupId, $method = 'Admin', $status = 'Removed', $tracking = NULL)
{
if (!is_array($contactIds)) {
return array(0, 0, 0);
}
if ($status == 'Removed' || $status == 'Deleted') {
$op = 'delete';
} else {
$op = 'edit';
}
CRM_Utils_Hook::pre($op, 'GroupContact', $groupId, $contactIds);
$date = date('YmdHis');
$numContactsRemoved = 0;
$numContactsNotRemoved = 0;
$group = new CRM_Contact_DAO_Group();
$group->id = $groupId;
$group->find(TRUE);
foreach ($contactIds as $contactId) {
if ($status == 'Deleted') {
$query = "DELETE FROM civicrm_group_contact WHERE contact_id={$contactId} AND group_id={$groupId}";
$dao = CRM_Core_DAO::executeQuery($query);
$historyParams = array('group_id' => $groupId, 'contact_id' => $contactId, 'status' => $status, 'method' => $method, 'date' => $date, 'tracking' => $tracking);
CRM_Contact_BAO_SubscriptionHistory::create($historyParams);
} else {
$groupContact = new CRM_Contact_DAO_GroupContact();
$groupContact->group_id = $groupId;
$groupContact->contact_id = $contactId;
// check if the selected contact id already a member, or if this is
// an opt-out of a smart group.
// if not a member remove to groupContact else keep the count of contacts that are not removed
if ($groupContact->find(TRUE) || $group->saved_search_id) {
// remove the contact from the group
$numContactsRemoved++;
} else {
$numContactsNotRemoved++;
}
//now we grant the negative membership to contact if not member. CRM-3711
$historyParams = array('group_id' => $groupId, 'contact_id' => $contactId, 'status' => $status, 'method' => $method, 'date' => $date, 'tracking' => $tracking);
CRM_Contact_BAO_SubscriptionHistory::create($historyParams);
$groupContact->status = $status;
$groupContact->save();
}
}
// also reset the acl cache
$config = CRM_Core_Config::singleton();
if (!$config->doNotResetCache) {
CRM_ACL_BAO_Cache::resetCache();
}
// reset the group contact cache for all group(s)
// if this group is being used as a smart group
CRM_Contact_BAO_GroupContactCache::remove();
CRM_Utils_Hook::post($op, 'GroupContact', $groupId, $contactIds);
return array(count($contactIds), $numContactsRemoved, $numContactsNotRemoved);
}
示例6: addGroupContactCache
function addGroupContactCache($groups, $tableAlias = NULL, $joinTable = "contact_a")
{
$config = CRM_Core_Config::singleton();
// find all the groups that are part of a saved search
$groupIDs = implode(',', $groups);
if (empty($groupIDs)) {
return NULL;
}
$sql = "\nSELECT id, cache_date, saved_search_id, children\nFROM civicrm_group\nWHERE id IN ( {$groupIDs} )\n AND ( saved_search_id != 0\n OR saved_search_id IS NOT NULL\n OR children IS NOT NULL )\n";
$group = CRM_Core_DAO::executeQuery($sql);
$ssWhere = array();
while ($group->fetch()) {
if ($tableAlias == NULL) {
$alias = "`civicrm_group_contact_cache_{$group->id}`";
} else {
$alias = $tableAlias;
}
$this->_useDistinct = TRUE;
if (!$this->_smartGroupCache || $group->cache_date == NULL) {
CRM_Contact_BAO_GroupContactCache::load($group);
}
$this->_tables[$alias] = $this->_whereTables[$alias] = " LEFT JOIN civicrm_group_contact_cache {$alias} ON {$joinTable}.id = {$alias}.contact_id ";
$ssWhere[] = "{$alias}.group_id = {$group->id}";
}
if (!empty($ssWhere)) {
return implode(' OR ', $ssWhere);
}
return NULL;
}
示例7: whereClause
public static function whereClause($type, &$tables, &$whereTables, $contactID = NULL)
{
$acls = CRM_ACL_BAO_Cache::build($contactID);
//CRM_Core_Error::debug( "a: $contactID", $acls );
$whereClause = NULL;
$clauses = array();
if (!empty($acls)) {
$aclKeys = array_keys($acls);
$aclKeys = implode(',', $aclKeys);
$query = "\nSELECT a.operation, a.object_id\n FROM civicrm_acl_cache c, civicrm_acl a\n WHERE c.acl_id = a.id\n AND a.is_active = 1\n AND a.object_table = 'civicrm_saved_search'\n AND a.id IN ( {$aclKeys} )\nORDER BY a.object_id\n";
$dao = CRM_Core_DAO::executeQuery($query);
// do an or of all the where clauses u see
$ids = array();
while ($dao->fetch()) {
// make sure operation matches the type TODO
if (self::matchType($type, $dao->operation)) {
if (!$dao->object_id) {
$ids = array();
$whereClause = ' ( 1 ) ';
break;
}
$ids[] = $dao->object_id;
}
}
if (!empty($ids)) {
$ids = implode(',', $ids);
$query = "\nSELECT g.*\n FROM civicrm_group g\n WHERE g.id IN ( {$ids} )\n AND g.is_active = 1\n";
$dao = CRM_Core_DAO::executeQuery($query);
$staticGroupIDs = array();
$cachedGroupIDs = array();
while ($dao->fetch()) {
// currently operation is restrcited to VIEW/EDIT
if ($dao->where_clause) {
if ($dao->select_tables) {
$tmpTables = array();
foreach (unserialize($dao->select_tables) as $tmpName => $tmpInfo) {
if ($tmpName == '`civicrm_group_contact-' . $dao->id . '`') {
$tmpName = '`civicrm_group_contact-ACL`';
$tmpInfo = str_replace('civicrm_group_contact-' . $dao->id, 'civicrm_group_contact-ACL', $tmpInfo);
} elseif ($tmpName == '`civicrm_group_contact_cache_' . $dao->id . '`') {
$tmpName = '`civicrm_group_contact_cache-ACL`';
$tmpInfo = str_replace('civicrm_group_contact_cache_' . $dao->id, 'civicrm_group_contact_cache-ACL', $tmpInfo);
}
$tmpTables[$tmpName] = $tmpInfo;
}
$tables = array_merge($tables, $tmpTables);
}
if ($dao->where_tables) {
$tmpTables = array();
foreach (unserialize($dao->where_tables) as $tmpName => $tmpInfo) {
if ($tmpName == '`civicrm_group_contact-' . $dao->id . '`') {
$tmpName = '`civicrm_group_contact-ACL`';
$tmpInfo = str_replace('civicrm_group_contact-' . $dao->id, 'civicrm_group_contact-ACL', $tmpInfo);
$staticGroupIDs[] = $dao->id;
} elseif ($tmpName == '`civicrm_group_contact_cache_' . $dao->id . '`') {
$tmpName = '`civicrm_group_contact_cache-ACL`';
$tmpInfo = str_replace('civicrm_group_contact_cache_' . $dao->id, 'civicrm_group_contact_cache-ACL', $tmpInfo);
$cachedGroupIDs[] = $dao->id;
}
$tmpTables[$tmpName] = $tmpInfo;
}
$whereTables = array_merge($whereTables, $tmpTables);
}
}
if (($dao->saved_search_id || $dao->children || $dao->parents) && $dao->cache_date == NULL) {
CRM_Contact_BAO_GroupContactCache::load($dao);
}
}
if ($staticGroupIDs) {
$clauses[] = '( `civicrm_group_contact-ACL`.group_id IN (' . join(', ', $staticGroupIDs) . ') AND `civicrm_group_contact-ACL`.status IN ("Added") )';
}
if ($cachedGroupIDs) {
$clauses[] = '`civicrm_group_contact_cache-ACL`.group_id IN (' . join(', ', $cachedGroupIDs) . ')';
}
}
}
if (!empty($clauses)) {
$whereClause = ' ( ' . implode(' OR ', $clauses) . ' ) ';
}
// call the hook to get additional whereClauses
CRM_Utils_Hook::aclWhereClause($type, $tables, $whereTables, $contactID, $whereClause);
if (empty($whereClause)) {
$whereClause = ' ( 0 ) ';
}
return $whereClause;
}
示例8: removeContactsFromGroup
/**
* Given an array of contact ids, remove all the contacts from the group
*
* @param array $contactIds (reference ) the array of contact ids to be removed
* @param int $groupId the id of the group
*
* @return array (total, removed, notRemoved) count of contacts removed to group
* @access public
* @static
*/
static function removeContactsFromGroup(&$contactIds, $groupId, $method = 'Admin', $status = 'Removed', $tracking = null)
{
if (!is_array($contactIds)) {
return array(0, 0, 0);
}
require_once 'CRM/Utils/Hook.php';
if ($status == 'Removed') {
$op = 'delete';
} else {
$op = 'edit';
}
CRM_Utils_Hook::pre($op, 'GroupContact', $groupId, $contactIds);
$date = date('YmdHis');
$numContactsRemoved = 0;
$numContactsNotRemoved = 0;
require_once "CRM/Contact/DAO/Group.php";
$group =& new CRM_Contact_DAO_Group();
$group->id = $groupId;
$group->find(true);
foreach ($contactIds as $contactId) {
$groupContact =& new CRM_Contact_DAO_GroupContact();
$groupContact->group_id = $groupId;
$groupContact->contact_id = $contactId;
// check if the selected contact id already a member, or if this is
// an opt-out of a smart group.
// if not a member remove to groupContact else keep the count of contacts that are not removed
if ($groupContact->find(true) || $group->saved_search_id) {
// remove the contact from the group
$numContactsRemoved++;
} else {
$numContactsNotRemoved++;
}
//now we grant the negative membership to contact if not member. CRM-3711
$historyParams = array('group_id' => $groupId, 'contact_id' => $contactId, 'status' => $status, 'method' => $method, 'date' => $date, 'tracking' => $tracking);
CRM_Contact_BAO_SubscriptionHistory::create($historyParams);
$groupContact->status = $status;
$groupContact->save();
}
// also reset the acl cache
require_once 'CRM/ACL/BAO/Cache.php';
CRM_ACL_BAO_Cache::resetCache();
// reset the group contact cache for all group(s)
// if this group is being used as a smart group
require_once 'CRM/Contact/BAO/GroupContactCache.php';
CRM_Contact_BAO_GroupContactCache::remove();
CRM_Utils_Hook::post($op, 'GroupContact', $groupId, $contactIds);
return array(count($contactIds), $numContactsRemoved, $numContactsNotRemoved);
}
示例9: implode
/**
* Create a new group.
*
* @param array $params
*
* @return CRM_Contact_BAO_Group|NULL
* The new group BAO (if created)
*/
public static function &create(&$params)
{
if (!empty($params['id'])) {
CRM_Utils_Hook::pre('edit', 'Group', $params['id'], $params);
} else {
CRM_Utils_Hook::pre('create', 'Group', NULL, $params);
}
// form the name only if missing: CRM-627
$nameParam = CRM_Utils_Array::value('name', $params, NULL);
if (!$nameParam && empty($params['id'])) {
$params['name'] = CRM_Utils_String::titleToVar($params['title']);
}
// convert params if array type
if (isset($params['group_type'])) {
if (is_array($params['group_type'])) {
$params['group_type'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($params['group_type'])) . CRM_Core_DAO::VALUE_SEPARATOR;
}
} else {
$params['group_type'] = '';
}
$session = CRM_Core_Session::singleton();
$cid = $session->get('userID');
// this action is add
if ($cid && empty($params['id'])) {
$params['created_id'] = $cid;
}
// this action is update
if ($cid && !empty($params['id'])) {
$params['modified_id'] = $cid;
}
$group = new CRM_Contact_BAO_Group();
$group->copyValues($params);
//@todo very hacky fix for the fact this function wants to receive 'parents' as an array further down but
// needs it as a separated string for the DB. Preferred approaches are having the copyParams or save fn
// use metadata to translate the array to the appropriate DB type or altering the param in the api layer,
// or at least altering the param in same section as 'group_type' rather than repeating here. However, further down
// we need the $params one to be in it's original form & we are not sure what test coverage we have on that
if (isset($group->parents) && is_array($group->parents)) {
$group->parents = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($group->parents)) . CRM_Core_DAO::VALUE_SEPARATOR;
}
if (empty($params['id']) && !$nameParam) {
$group->name .= "_tmp";
}
$group->save();
if (!$group->id) {
return NULL;
}
if (empty($params['id']) && !$nameParam) {
$group->name = substr($group->name, 0, -4) . "_{$group->id}";
}
$group->buildClause();
$group->save();
// add custom field values
if (!empty($params['custom'])) {
CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_group', $group->id);
}
// make the group, child of domain/site group by default.
$domainGroupID = CRM_Core_BAO_Domain::getGroupId();
if (CRM_Utils_Array::value('no_parent', $params) !== 1) {
if (empty($params['parents']) && $domainGroupID != $group->id && CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MULTISITE_PREFERENCES_NAME, 'is_enabled') && !CRM_Contact_BAO_GroupNesting::hasParentGroups($group->id)) {
// if no parent present and the group doesn't already have any parents,
// make sure site group goes as parent
$params['parents'] = array($domainGroupID => 1);
} elseif (array_key_exists('parents', $params) && !is_array($params['parents'])) {
$params['parents'] = array($params['parents'] => 1);
}
if (!empty($params['parents'])) {
foreach ($params['parents'] as $parentId => $dnc) {
if ($parentId && !CRM_Contact_BAO_GroupNesting::isParentChild($parentId, $group->id)) {
CRM_Contact_BAO_GroupNesting::add($parentId, $group->id);
}
}
}
// clear any descendant groups cache if exists
$finalGroups = CRM_Core_BAO_Cache::deleteGroup('descendant groups for an org');
// this is always required, since we don't know when a
// parent group is removed
CRM_Contact_BAO_GroupNestingCache::update();
// update group contact cache for all parent groups
$parentIds = CRM_Contact_BAO_GroupNesting::getParentGroupIds($group->id);
foreach ($parentIds as $parentId) {
CRM_Contact_BAO_GroupContactCache::add($parentId);
}
}
if (!empty($params['organization_id'])) {
$groupOrg = array();
$groupOrg = $params;
$groupOrg['group_id'] = $group->id;
CRM_Contact_BAO_GroupOrganization::add($groupOrg);
}
CRM_Contact_BAO_GroupContactCache::add($group->id);
if (!empty($params['id'])) {
//.........这里部分代码省略.........
示例10: testRemoveFromParentSmartGroup
/**
* Allow removing contact from a parent group even if contact is in
* a child group. (CRM-8858)
*/
function testRemoveFromParentSmartGroup()
{
// Create smart group $parent
$params = array('name' => 'Deceased Contacts', 'title' => 'Deceased Contacts', 'is_active' => 1, 'formValues' => array('is_deceased' => 1));
$parent = CRM_Contact_BAO_Group::createSmartGroup($params);
$this->registerTestObjects(array($parent));
// Create group $child in $parent
$params = array('name' => 'Child Group', 'title' => 'Child Group', 'is_active' => 1, 'parents' => array($parent->id => 1));
$child = CRM_Contact_BAO_Group::create($params);
$this->registerTestObjects(array($child));
// Create $c1, $c2, $c3
$deceased = $this->createTestObject('CRM_Contact_DAO_Contact', array('is_deceased' => 1), 3);
// Add $c1, $c2, $c3 to $child
foreach ($deceased as $contact) {
$result = $this->callAPISuccess('group_contact', 'create', array('contact_id' => $contact->id, 'group_id' => $child->id));
}
// GroupContactCache::load()
CRM_Contact_BAO_GroupContactCache::load($parent, TRUE);
$this->assertCacheMatches(array($deceased[0]->id, $deceased[1]->id, $deceased[2]->id), $parent->id);
// Remove $c1 from $parent
$result = civicrm_api('group_contact', 'create', array('contact_id' => $deceased[0]->id, 'group_id' => $parent->id, 'status' => 'Removed', 'version' => '3'));
$this->assertAPISuccess($result);
// Assert $c1 not in $parent
CRM_Contact_BAO_GroupContactCache::load($parent, TRUE);
$this->assertCacheMatches(array($deceased[1]->id, $deceased[2]->id), $parent->id);
// Assert $c1 still in $child
$this->assertDBQuery(1, 'select count(*) from civicrm_group_contact where group_id=%1 and contact_id=%2 and status=%3', array(1 => array($child->id, 'Integer'), 2 => array($deceased[0]->id, 'Integer'), 3 => array('Added', 'String')));
}
示例11: setupSmartGroup
/**
* Set up a smart group testing scenario.
*
* @return array
*/
protected function setupSmartGroup()
{
$params = array('name' => 'Deceased Contacts', 'title' => 'Deceased Contacts', 'is_active' => 1, 'formValues' => array('is_deceased' => 1));
$group = CRM_Contact_BAO_Group::createSmartGroup($params);
$this->registerTestObjects(array($group));
// Create contacts $y1, $y2, $y3 which do match $g; create $n1, $n2, $n3 which do not match $g
$living = $this->createTestObject('CRM_Contact_DAO_Contact', array('is_deceased' => 0), 3);
$deceased = $this->createTestObject('CRM_Contact_DAO_Contact', array('is_deceased' => 1), 3);
$this->assertEquals(3, count($deceased));
$this->assertEquals(3, count($living));
// Assert: $g cache has exactly $y1, $y2, $y3
CRM_Contact_BAO_GroupContactCache::load($group, TRUE);
$group->find(TRUE);
$this->assertCacheMatches(array($deceased[0]->id, $deceased[1]->id, $deceased[2]->id), $group->id);
// Reload the group so we have the cache_date & refresh_date.
return array($group, $living, $deceased);
}
示例12: postProcess
/**
* Process the user submitted custom data values.
*/
public function postProcess()
{
// Get the form values and groupTree
//CRM-18183
$params = $this->controller->exportValues($this->_name);
CRM_Core_BAO_CustomValueTable::postProcess($params, 'civicrm_contact', $this->_tableID, $this->_entityType);
$table = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_groupID, 'table_name');
$cgcount = CRM_Core_BAO_CustomGroup::customGroupDataExistsForEntity($this->_tableID, $table, TRUE);
$cgcount += 1;
$buttonName = $this->controller->getButtonName();
if ($buttonName == $this->getButtonName('upload', 'new')) {
CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url('civicrm/contact/view/cd/edit', "reset=1&type={$this->_contactType}&groupID={$this->_groupID}&entityID={$this->_tableID}&cgcount={$cgcount}&multiRecordDisplay=single&mode=add"));
}
// Add entry in the log table
CRM_Core_BAO_Log::register($this->_tableID, 'civicrm_contact', $this->_tableID);
if (CRM_Core_Resources::isAjaxMode()) {
$this->ajaxResponse += CRM_Contact_Form_Inline::renderFooter($this->_tableID);
}
// reset the group contact cache for this group
CRM_Contact_BAO_GroupContactCache::remove();
}
示例13: whereGroupClause
/**
* Build where clause for groups.
*
* This has been overridden in order to:
* 1) only build the group clause when filtering
* 2) render the id field as id rather than contact_id in
* order to allow us to join on hte created temp table as if it
* were the contact table.
*
* Further refactoring could break down the parent function so it can be selectively
* leveraged.
*
* @param string $field
* @param mixed $value
* @param string $op
*
* @return string
*/
public function whereGroupClause($field, $value, $op)
{
if ($op == 'notin') {
// We do not have an optimisation for this scenario at this stage. Use
// parent.
return parent::whereGroupClause($field, $value, $op);
}
if (empty($this->groupTempTable)) {
$group = new CRM_Contact_DAO_Group();
$group->is_active = 1;
$group->find();
$smartGroups = array();
while ($group->fetch()) {
if (in_array($group->id, $this->_params['gid_value']) && $group->saved_search_id) {
$smartGroups[] = $group->id;
}
}
CRM_Contact_BAO_GroupContactCache::check($smartGroups);
$smartGroupQuery = '';
if (!empty($smartGroups)) {
$smartGroups = implode(',', $smartGroups);
$smartGroupQuery = " UNION DISTINCT\n SELECT DISTINCT smartgroup_contact.contact_id as id\n FROM civicrm_group_contact_cache smartgroup_contact\n WHERE smartgroup_contact.group_id IN ({$smartGroups}) ";
}
$sqlOp = $this->getSQLOperator($op);
if (!is_array($value)) {
$value = array($value);
}
$clause = "{$field['dbAlias']} IN (" . implode(', ', $value) . ")";
$query = "SELECT DISTINCT {$this->_aliases['civicrm_group']}.contact_id as id\n FROM civicrm_group_contact {$this->_aliases['civicrm_group']}\n WHERE {$clause} AND {$this->_aliases['civicrm_group']}.status = 'Added'\n {$smartGroupQuery} ";
$this->buildGroupTempTable($query);
}
return "1";
}
示例14: CRM_Event_BAO_Participant
/**
* takes an associative array and creates a participant object
*
* the function extract all the params it needs to initialize the create a
* participant object. the params array could contain additional unused name/value
* pairs
*
* @param array $params (reference ) an assoc array of name/value pairs
* @param array $ids the array that holds all the db ids
*
* @return object CRM_Event_BAO_Participant object
* @access public
* @static
*/
static function &add(&$params)
{
require_once 'CRM/Utils/Hook.php';
if (CRM_Utils_Array::value('id', $params)) {
CRM_Utils_Hook::pre('edit', 'Participant', $params['id'], $params);
} else {
CRM_Utils_Hook::pre('create', 'Participant', null, $params);
}
// converting dates to mysql format
if (CRM_Utils_Array::value('register_date', $params)) {
$params['register_date'] = CRM_Utils_Date::isoToMysql($params['register_date']);
}
if (CRM_Utils_Array::value('participant_fee_amount', $params)) {
$params['participant_fee_amount'] = CRM_Utils_Rule::cleanMoney($params['participant_fee_amount']);
}
if (CRM_Utils_Array::value('participant_fee_amount', $params)) {
$params['fee_amount'] = CRM_Utils_Rule::cleanMoney($params['fee_amount']);
}
$participantBAO = new CRM_Event_BAO_Participant();
if (CRM_Utils_Array::value('id', $params)) {
$participantBAO->id = CRM_Utils_Array::value('id', $params);
$participantBAO->find(true);
$participantBAO->register_date = CRM_Utils_Date::isoToMysql($participantBAO->register_date);
}
$participantBAO->copyValues($params);
//CRM-6910
//1. If currency present, it should be valid one.
//2. We should have currency when amount is not null.
require_once 'CRM/Utils/Rule.php';
$currency = $participantBAO->fee_currency;
if ($currency || !CRM_Utils_System::isNull($participantBAO->fee_amount)) {
if (!CRM_Utils_Rule::currencyCode($currency)) {
$config = CRM_Core_Config::singleton();
$currency = $config->defaultCurrency;
}
}
$participantBAO->fee_currency = $currency;
$participantBAO->save();
$session =& CRM_Core_Session::singleton();
// reset the group contact cache for this group
require_once 'CRM/Contact/BAO/GroupContactCache.php';
CRM_Contact_BAO_GroupContactCache::remove();
if (CRM_Utils_Array::value('id', $params)) {
CRM_Utils_Hook::post('edit', 'Participant', $participantBAO->id, $participantBAO);
} else {
CRM_Utils_Hook::post('create', 'Participant', $participantBAO->id, $participantBAO);
}
return $participantBAO;
}
示例15: deleteCustomValue
/**
* Function to delete custom value
*
*/
static function deleteCustomValue()
{
$customValueID = CRM_Utils_Type::escape($_POST['valueID'], 'Positive');
$customGroupID = CRM_Utils_Type::escape($_POST['groupID'], 'Positive');
CRM_Core_BAO_CustomValue::deleteCustomValue($customValueID, $customGroupID);
if ($contactId = CRM_Utils_Array::value('contactId', $_POST)) {
echo CRM_Contact_BAO_Contact::getCountComponent('custom_' . $_POST['groupID'], $contactId);
}
// reset the group contact cache for this group
CRM_Contact_BAO_GroupContactCache::remove();
CRM_Utils_System::civiExit();
}