Merge pull request #4724 from atif-shaikh/CRM-15598
[civicrm-core.git] / CRM / Contact / BAO / GroupContactCache.php
index a88d317325675d0aa44f7623b0036b4d1ed86331..bd0115dc10fcd4013a82122a0107e7559dd5c276 100644 (file)
@@ -40,9 +40,7 @@ class CRM_Contact_BAO_GroupContactCache extends CRM_Contact_DAO_GroupContactCach
    * 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
    */
@@ -200,7 +198,7 @@ AND    g.refresh_date IS NULL
   }
 
   /**
-   * @param $groupID
+   * @param int $groupID
    */
   static function add($groupID) {
     // first delete the current cache
@@ -218,7 +216,7 @@ AND    g.refresh_date IS NULL
   }
 
   /**
-   * @param $groupID
+   * @param int $groupID
    * @param $values
    */
   static function store(&$groupID, &$values) {
@@ -387,7 +385,31 @@ WHERE  id = %1
   }
 
   /**
-   * 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