* Check to see if we have cache entries for this group
* if not, regenerate, else return
*
- * @param $groupIDs
- *
- * @internal param int $groupID groupID of group that we are checking against
+ * @param $groupIDs of group that we are checking against
*
* @return boolean true if we did not regenerate, false if we did
*/
}
/**
- * @param $groupID
+ * FIXME: This function should not be needed, because the cache table should not be getting truncated
+ */
+ static function fillIfEmpty() {
+ if (!CRM_Core_DAO::singleValueQuery("SELECT COUNT(id) FROM civicrm_group_contact_cache")) {
+ self::loadAll();
+ }
+ }
+
+ /**
+ * @param int $groupID
*/
static function add($groupID) {
// first delete the current cache
}
/**
- * @param $groupID
+ * @param int $groupID
* @param $values
*/
static function store(&$groupID, &$values) {
}
/**
- * load the smart group cache for a saved search
+ * Removes one or more contacts from the smart group cache
+ * @param int|array $cid
+ * @param int $groupId
+ * @return bool - true if successful
+ */
+ static function removeContact($cid, $groupId = NULL) {
+ $cids = array();
+ // sanitize input
+ foreach ((array) $cid as $c) {
+ $cids[] = CRM_Utils_Type::escape($c, 'Integer');
+ }
+ if ($cids) {
+ $condition = count($cids) == 1 ? "= {$cids[0]}" : "IN (" . implode(',', $cids) . ")";
+ if ($groupId) {
+ $condition .= " AND group_id = " . CRM_Utils_Type::escape($groupId, 'Integer');
+ }
+ $sql = "DELETE FROM civicrm_group_contact_cache WHERE contact_id $condition";
+ CRM_Core_DAO::executeQuery($sql);
+ return TRUE;
+ }
+ return FALSE;
+ }
+
+ /**
+ * Load the smart group cache for a saved search
*
* @param object $group - the smart group that needs to be loaded
* @param boolean $force - should we force a search through