(dev/core#217) PrevNext - Migrate `getSelection()` from BAO to service interface
authorTim Otten <totten@civicrm.org>
Mon, 2 Jul 2018 19:54:54 +0000 (12:54 -0700)
committerTim Otten <totten@civicrm.org>
Wed, 25 Jul 2018 00:31:11 +0000 (17:31 -0700)
CRM/Campaign/Form/Task.php
CRM/Contact/Form/Search.php
CRM/Contact/Form/Task.php
CRM/Contact/Page/AJAX.php
CRM/Core/BAO/PrevNextCache.php
CRM/Core/PrevNextCache/Interface.php
CRM/Core/PrevNextCache/Sql.php

index a7e464ad83a7b6d7547cabed44f25b618e29516b..5ad1593f13d4f13c4372f52fb5b23c2060590979 100644 (file)
@@ -65,7 +65,7 @@ class CRM_Campaign_Form_Task extends CRM_Core_Form_Task {
     else {
       $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this);
       $cacheKey = "civicrm search {$qfKey}";
-      $allCids = CRM_Core_BAO_PrevNextCache::getSelection($cacheKey, "getall");
+      $allCids = Civi::service('prevnext')->getSelection($cacheKey, "getall");
       $ids = array_keys($allCids[$cacheKey]);
       $this->assign('totalSelectedVoters', count($ids));
     }
index 5b9a2079dd6441351d4cceba97b553723a600240..eadf418b4d015b245773ba27f6e98f025d5e3ff4 100644 (file)
@@ -497,7 +497,7 @@ class CRM_Contact_Form_Search extends CRM_Core_Form_Search {
     if ($qfKeyParam && ($this->get('component_mode') <= CRM_Contact_BAO_Query::MODE_CONTACTS || $this->get('component_mode') == CRM_Contact_BAO_Query::MODE_CONTACTSRELATED)) {
       $this->addClass('crm-ajax-selection-form');
       $qfKeyParam = "civicrm search {$qfKeyParam}";
-      $selectedContactIdsArr = CRM_Core_BAO_PrevNextCache::getSelection($qfKeyParam);
+      $selectedContactIdsArr = Civi::service('prevnext')->getSelection($qfKeyParam);
       $selectedContactIds = array_keys($selectedContactIdsArr[$qfKeyParam]);
     }
 
index 2d6e7637bf7a46a75acda0ea7cd8d3eaf0c5f462..5cacbcc77b9619b5548120ad19edefc74e352a27 100644 (file)
@@ -172,7 +172,7 @@ class CRM_Contact_Form_Task extends CRM_Core_Form_Task {
       // rather than prevnext cache table for most of the task actions except export where we rebuild query to fetch
       // final result set
       if ($useTable) {
-        $allCids = CRM_Core_BAO_PrevNextCache::getSelection($cacheKey, "getall");
+        $allCids = Civi::service('prevnext')->getSelection($cacheKey, "getall");
       }
       else {
         $allCids[$cacheKey] = self::getContactIds($form);
@@ -233,7 +233,7 @@ class CRM_Contact_Form_Task extends CRM_Core_Form_Task {
       }
       else {
         // fetching selected contact ids of passed cache key
-        $selectedCids = CRM_Core_BAO_PrevNextCache::getSelection($cacheKey);
+        $selectedCids = Civi::service('prevnext')->getSelection($cacheKey);
         foreach ($selectedCids[$cacheKey] as $selectedCid => $ignore) {
           if ($useTable) {
             $insertString[] = " ( {$selectedCid} ) ";
index 031e04fb6990f51f62a732fdb56e40f6901396a5..8270d7b753a2d8b1d923197e2d797c4b1db49818 100644 (file)
@@ -978,7 +978,7 @@ LIMIT {$offset}, {$rowCount}
       $action = ($state == 'checked') ? 'select' : 'unselect';
       Civi::service('prevnext')->markSelection($cacheKey, $action, $cId);
     }
-    $contactIds = CRM_Core_BAO_PrevNextCache::getSelection($cacheKey);
+    $contactIds = Civi::service('prevnext')->getSelection($cacheKey);
     $countSelectionCids = count($contactIds[$cacheKey]);
 
     $arrRet = array('getCount' => $countSelectionCids);
index 3c330ef4189dfadacbc99c9c94accee742ba7f0b..95b90b8e9d6439e0fcd01ee7cc5849f7dacab8d4 100644 (file)
@@ -438,47 +438,18 @@ AND        c.created_date < date_sub( NOW( ), INTERVAL %2 day )
     CRM_Core_DAO::executeQuery($sql, $params);
   }
 
+
   /**
    * Get the selections.
    *
-   * @param string $cacheKey
-   *   Cache key.
-   * @param string $action
-   *   Action.
-   *  $action : get - get only selection records
-   *            getall - get all the records of the specified cache key
-   * @param string $entity_table
-   *   Entity table.
+   * NOTE: This stub has been preserved because one extension in `universe`
+   * was referencing the function.
    *
-   * @return array|NULL
+   * @deprecated
+   * @see CRM_Core_PrevNextCache_Sql::getSelection()
    */
   public static function getSelection($cacheKey, $action = 'get', $entity_table = 'civicrm_contact') {
-    if (!$cacheKey) {
-      return NULL;
-    }
-    $params = array();
-
-    $entity_whereClause = " AND entity_table = '{$entity_table}'";
-    if ($cacheKey && ($action == 'get' || $action == 'getall')) {
-      $actionGet = ($action == "get") ? " AND is_selected = 1 " : "";
-      $sql = "
-SELECT entity_id1, entity_id2 FROM civicrm_prevnext_cache
-WHERE cacheKey LIKE %1
-      $actionGet
-      $entity_whereClause
-ORDER BY id
-";
-      $params[1] = array("{$cacheKey}%", 'String');
-
-      $contactIds = array($cacheKey => array());
-      $cIdDao = CRM_Core_DAO::executeQuery($sql, $params);
-      while ($cIdDao->fetch()) {
-        if ($cIdDao->entity_id1 == $cIdDao->entity_id2) {
-          $contactIds[$cacheKey][$cIdDao->entity_id1] = 1;
-        }
-      }
-      return $contactIds;
-    }
+    return Civi::service('prevnext')->getSelection($cacheKey, $action, $entity_table);
   }
 
   /**
index fbc937b8cef47e5d18c8bafa96224a09c47c6948..161120ca00b8b82802f3c3942ab492deae9df81e 100644 (file)
@@ -72,4 +72,20 @@ interface CRM_Core_PrevNextCache_Interface {
    */
   public function markSelection($cacheKey, $action = 'unselect', $cIds = NULL, $entity_table = 'civicrm_contact');
 
+  /**
+   * Get the selections.
+   *
+   * @param string $cacheKey
+   *   Cache key.
+   * @param string $action
+   *   Action.
+   *  $action : get - get only selection records
+   *            getall - get all the records of the specified cache key
+   * @param string $entity_table
+   *   Entity table.
+   *
+   * @return array|NULL
+   */
+  public function getSelection($cacheKey, $action = 'get', $entity_table = 'civicrm_contact');
+
 }
index 1f3e0a2c31a5c7d6646f13ecf1b52e8dd00df1c9..2bf5242fc37db56f76536bcbd70b0167e449c457 100644 (file)
@@ -132,4 +132,47 @@ WHERE  cacheKey LIKE %1 AND is_selected = 1
     CRM_Core_DAO::executeQuery($sql, $params);
   }
 
+  /**
+   * Get the selections.
+   *
+   * @param string $cacheKey
+   *   Cache key.
+   * @param string $action
+   *   Action.
+   *  $action : get - get only selection records
+   *            getall - get all the records of the specified cache key
+   * @param string $entity_table
+   *   Entity table.
+   *
+   * @return array|NULL
+   */
+  public function getSelection($cacheKey, $action = 'get', $entity_table = 'civicrm_contact') {
+    if (!$cacheKey) {
+      return NULL;
+    }
+    $params = array();
+
+    $entity_whereClause = " AND entity_table = '{$entity_table}'";
+    if ($cacheKey && ($action == 'get' || $action == 'getall')) {
+      $actionGet = ($action == "get") ? " AND is_selected = 1 " : "";
+      $sql = "
+SELECT entity_id1, entity_id2 FROM civicrm_prevnext_cache
+WHERE cacheKey LIKE %1
+      $actionGet
+      $entity_whereClause
+ORDER BY id
+";
+      $params[1] = array("{$cacheKey}%", 'String');
+
+      $contactIds = array($cacheKey => array());
+      $cIdDao = CRM_Core_DAO::executeQuery($sql, $params);
+      while ($cIdDao->fetch()) {
+        if ($cIdDao->entity_id1 == $cIdDao->entity_id2) {
+          $contactIds[$cacheKey][$cIdDao->entity_id1] = 1;
+        }
+      }
+      return $contactIds;
+    }
+  }
+
 }