Commit b7994703 authored by totten's avatar totten

(#217) PrevNext - Migrate `getSelection()` from BAO to service interface

parent 0b8038a6
......@@ -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));
}
......
......@@ -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]);
}
......
......@@ -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} ) ";
......
......@@ -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);
......
......@@ -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);
}
/**
......
......@@ -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');
}
......@@ -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;
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment