From 17b4648aafeee3ddd9b4c9a5fd3e997a185330a7 Mon Sep 17 00:00:00 2001 From: Civiware Solutions Date: Sun, 30 Sep 2018 14:47:11 +0100 Subject: [PATCH] fixed contact toggling --- CRM/ConstituentsOnly/BAO/ConstituentsOnly.php | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/CRM/ConstituentsOnly/BAO/ConstituentsOnly.php b/CRM/ConstituentsOnly/BAO/ConstituentsOnly.php index 10e1210..7d6fedd 100644 --- a/CRM/ConstituentsOnly/BAO/ConstituentsOnly.php +++ b/CRM/ConstituentsOnly/BAO/ConstituentsOnly.php @@ -161,9 +161,11 @@ class CRM_ConstituentsOnly_BAO_ConstituentsOnly { $url = CRM_Utils_Array::value('q', $_GET); $returnProperties = NULL; $request = $_REQUEST; + + $qfKey = $_REQUEST['qfKey']; + $cache = "CRM_Contact_Controller_Search_{$qfKey}"; if (!empty($_REQUEST['has_js'])) { - $qfKey = $_REQUEST['qfKey']; - $formValuesFromSession = CRM_Core_Session::singleton()->get("CRM_Contact_Controller_Search_{$qfKey}"); + $formValuesFromSession = CRM_Core_Session::singleton()->get($cache); if (!empty($formValuesFromSession['formValues'])) { $request = $formValuesFromSession['formValues']; } @@ -192,6 +194,32 @@ class CRM_ConstituentsOnly_BAO_ConstituentsOnly { } $newRows[$cid]['sort_name'] .= "({$rows[$ogContactId]['sort_name']})"; $rows[$ogContactId] = $newRows[$cid]; + $prevCacheKey = "civicrm search {$qfKey}"; + $exists = CRM_Core_DAO::singleValueQuery( + "SELECT count(id) FROM civicrm_prevnext_cache + WHERE ( + entity_id1 = %1 OR entity_id2 = %1 + ) + AND cacheKey = %2 + AND entity_table = 'civicrm_contact' + ", + [ + 1 => [$cid, 'Integer'], + 2 => [$prevCacheKey, 'String'], + ] + ); + + if (!$exists) { + $prevCache = [ + "('civicrm_contact'", + "'{$cid}'", + "'{$cid}'", + "'{$prevCacheKey}'", + "'" . $newRows[$cid]['sort_name'] . "')", + ]; + CRM_Core_BAO_PrevNextCache::setItem($prevCache); + } + CRM_Core_BAO_PrevNextCache::deleteItem($ogContactId, $prevCacheKey); } } return $rows;