From 7fa7c084d9fbb62c7178b95e92c059758a7676e6 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Sat, 14 Nov 2020 08:31:08 +1100 Subject: [PATCH] dev/core#2187 Allow sites to customsie the default number of rows returned from QuickForm Searches --- CRM/Activity/Selector/Activity.php | 2 +- CRM/Activity/Selector/Search.php | 2 +- CRM/Admin/Form/Setting/Search.php | 1 + CRM/Campaign/Selector/Search.php | 2 +- CRM/Case/Selector/Search.php | 2 +- CRM/Contact/Form/Search/Custom/FullText.php | 2 +- CRM/Contact/Page/DedupeException.php | 2 +- CRM/Contact/Selector.php | 2 +- CRM/Contact/Selector/Custom.php | 2 +- CRM/Contribute/Page/ContributionPage.php | 2 +- CRM/Contribute/Selector/Search.php | 2 +- CRM/Core/Selector/Controller.php | 2 +- CRM/Event/Page/ManageEvent.php | 2 +- .../ParticipantListing/NameStatusAndDate.php | 2 +- CRM/Event/Page/ParticipantListing/Simple.php | 2 +- CRM/Grant/Selector/Search.php | 2 +- CRM/Mailing/Selector/Browse.php | 2 +- CRM/Mailing/Selector/Event.php | 2 +- CRM/Mailing/Selector/Search.php | 2 +- CRM/Member/Selector/Search.php | 2 +- CRM/Pledge/Selector/Search.php | 2 +- CRM/Profile/Selector/Listings.php | 2 +- CRM/Utils/Pager.php | 19 ++++++++++++++---- settings/Search.setting.php | 20 +++++++++++++++++++ .../CRM/Contact/Page/DedupeExceptionTest.php | 2 +- 25 files changed, 58 insertions(+), 26 deletions(-) diff --git a/CRM/Activity/Selector/Activity.php b/CRM/Activity/Selector/Activity.php index 9d991924bd..fff4d57ed9 100644 --- a/CRM/Activity/Selector/Activity.php +++ b/CRM/Activity/Selector/Activity.php @@ -285,7 +285,7 @@ class CRM_Activity_Selector_Activity extends CRM_Core_Selector_Base implements C public function getPagerParams($action, &$params) { $params['status'] = ts('Activities %%StatusMessage%%'); $params['csvString'] = NULL; - $params['rowCount'] = CRM_Utils_Pager::ROWCOUNT; + $params['rowCount'] = Civi::settings()->get('default_pager_size'); $params['buttonTop'] = 'PagerTopButton'; $params['buttonBottom'] = 'PagerBottomButton'; diff --git a/CRM/Activity/Selector/Search.php b/CRM/Activity/Selector/Search.php index 10c76703c2..059da02763 100644 --- a/CRM/Activity/Selector/Search.php +++ b/CRM/Activity/Selector/Search.php @@ -174,7 +174,7 @@ class CRM_Activity_Selector_Search extends CRM_Core_Selector_Base implements CRM public function getPagerParams($action, &$params) { $params['status'] = ts('Activities %%StatusMessage%%'); $params['csvString'] = NULL; - $params['rowCount'] = CRM_Utils_Pager::ROWCOUNT; + $params['rowCount'] = Civi::settings()->get('default_pager_size'); $params['buttonTop'] = 'PagerTopButton'; $params['buttonBottom'] = 'PagerBottomButton'; } diff --git a/CRM/Admin/Form/Setting/Search.php b/CRM/Admin/Form/Setting/Search.php index 18ec5d7e8e..ee4d855af9 100644 --- a/CRM/Admin/Form/Setting/Search.php +++ b/CRM/Admin/Form/Setting/Search.php @@ -35,6 +35,7 @@ class CRM_Admin_Form_Setting_Search extends CRM_Admin_Form_Setting { 'contact_reference_options' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'search_autocomplete_count' => CRM_Core_BAO_Setting::SEARCH_PREFERENCES_NAME, 'enable_innodb_fts' => CRM_Core_BAO_Setting::SEARCH_PREFERENCES_NAME, + 'default_pager_size' => CRM_Core_BAO_Setting::SEARCH_PREFERENCES_NAME, ]; /** diff --git a/CRM/Campaign/Selector/Search.php b/CRM/Campaign/Selector/Search.php index f767a4602b..ce9a302d68 100644 --- a/CRM/Campaign/Selector/Search.php +++ b/CRM/Campaign/Selector/Search.php @@ -175,7 +175,7 @@ class CRM_Campaign_Selector_Search extends CRM_Core_Selector_Base implements CRM public function getPagerParams($action, &$params) { $params['csvString'] = NULL; $params['status'] = ts('Respondents') . ' %%StatusMessage%%'; - $params['rowCount'] = ($this->_limit) ? $this->_limit : CRM_Utils_Pager::ROWCOUNT; + $params['rowCount'] = ($this->_limit) ? $this->_limit : Civi::settings()->get('default_pager_size'); $params['buttonTop'] = 'PagerTopButton'; $params['buttonBottom'] = 'PagerBottomButton'; } diff --git a/CRM/Case/Selector/Search.php b/CRM/Case/Selector/Search.php index bcc11154a9..0f0864e208 100644 --- a/CRM/Case/Selector/Search.php +++ b/CRM/Case/Selector/Search.php @@ -234,7 +234,7 @@ class CRM_Case_Selector_Search extends CRM_Core_Selector_Base { $params['rowCount'] = $this->_limit; } else { - $params['rowCount'] = CRM_Utils_Pager::ROWCOUNT; + $params['rowCount'] = Civi::settings()->get('default_pager_size'); } $params['buttonTop'] = 'PagerTopButton'; diff --git a/CRM/Contact/Form/Search/Custom/FullText.php b/CRM/Contact/Form/Search/Custom/FullText.php index 09faca084a..c86d265af9 100644 --- a/CRM/Contact/Form/Search/Custom/FullText.php +++ b/CRM/Contact/Form/Search/Custom/FullText.php @@ -105,7 +105,7 @@ class CRM_Contact_Form_Search_Custom_FullText extends CRM_Contact_Form_Search_Cu // 1. this custom search has slightly different structure , // 2. we are in constructor right now, // we 'll use a small hack - - $rowCount = CRM_Utils_Array::value('crmRowCount', $_REQUEST, CRM_Utils_Pager::ROWCOUNT); + $rowCount = CRM_Utils_Array::value('crmRowCount', $_REQUEST, Civi::settings()->get('default_pager_size')); $pageId = CRM_Utils_Array::value('crmPID', $_REQUEST, 1); $offset = ($pageId - 1) * $rowCount; $this->_limitClause = NULL; diff --git a/CRM/Contact/Page/DedupeException.php b/CRM/Contact/Page/DedupeException.php index 31aab71756..c193120275 100644 --- a/CRM/Contact/Page/DedupeException.php +++ b/CRM/Contact/Page/DedupeException.php @@ -52,7 +52,7 @@ class CRM_Contact_Page_DedupeException extends CRM_Core_Page { $totalitems = civicrm_api3('Exception', "getcount", $params); $params = [ 'total' => $totalitems, - 'rowCount' => CRM_Utils_Pager::ROWCOUNT, + 'rowCount' => Civi::settings()->get('default_pager_size'), 'status' => ts('Dedupe Exceptions %%StatusMessage%%'), 'buttonBottom' => 'PagerBottomButton', 'buttonTop' => 'PagerTopButton', diff --git a/CRM/Contact/Selector.php b/CRM/Contact/Selector.php index 17a1155d0f..cfc35d70ef 100644 --- a/CRM/Contact/Selector.php +++ b/CRM/Contact/Selector.php @@ -324,7 +324,7 @@ class CRM_Contact_Selector extends CRM_Core_Selector_Base implements CRM_Core_Se public function getPagerParams($action, &$params) { $params['status'] = ts('Contact %%StatusMessage%%'); $params['csvString'] = NULL; - $params['rowCount'] = CRM_Utils_Pager::ROWCOUNT; + $params['rowCount'] = Civi::settings()->get('default_pager_size'); $params['buttonTop'] = 'PagerTopButton'; $params['buttonBottom'] = 'PagerBottomButton'; diff --git a/CRM/Contact/Selector/Custom.php b/CRM/Contact/Selector/Custom.php index b5ea5468bb..95507319a9 100644 --- a/CRM/Contact/Selector/Custom.php +++ b/CRM/Contact/Selector/Custom.php @@ -191,7 +191,7 @@ class CRM_Contact_Selector_Custom extends CRM_Contact_Selector { public function getPagerParams($action, &$params) { $params['status'] = ts('Contact %%StatusMessage%%'); $params['csvString'] = NULL; - $params['rowCount'] = CRM_Utils_Pager::ROWCOUNT; + $params['rowCount'] = Civi::settings()->get('default_pager_size'); $params['buttonTop'] = 'PagerTopButton'; $params['buttonBottom'] = 'PagerBottomButton'; diff --git a/CRM/Contribute/Page/ContributionPage.php b/CRM/Contribute/Page/ContributionPage.php index 835089da89..ebb64417a5 100644 --- a/CRM/Contribute/Page/ContributionPage.php +++ b/CRM/Contribute/Page/ContributionPage.php @@ -648,7 +648,7 @@ ORDER BY is_active desc, title asc $params['buttonBottom'] = 'PagerBottomButton'; $params['rowCount'] = $this->get(CRM_Utils_Pager::PAGE_ROWCOUNT); if (!$params['rowCount']) { - $params['rowCount'] = CRM_Utils_Pager::ROWCOUNT; + $params['rowCount'] = Civi::settings()->get('default_pager_size'); } $query = " diff --git a/CRM/Contribute/Selector/Search.php b/CRM/Contribute/Selector/Search.php index 4e745c54bd..c8b5a8ca18 100644 --- a/CRM/Contribute/Selector/Search.php +++ b/CRM/Contribute/Selector/Search.php @@ -248,7 +248,7 @@ class CRM_Contribute_Selector_Search extends CRM_Core_Selector_Base implements C $params['rowCount'] = $this->_limit; } else { - $params['rowCount'] = CRM_Utils_Pager::ROWCOUNT; + $params['rowCount'] = Civi::settings()->get('default_pager_size'); } $params['buttonTop'] = 'PagerTopButton'; diff --git a/CRM/Core/Selector/Controller.php b/CRM/Core/Selector/Controller.php index 0fbba210c0..533d4042a2 100644 --- a/CRM/Core/Selector/Controller.php +++ b/CRM/Core/Selector/Controller.php @@ -228,7 +228,7 @@ class CRM_Core_Selector_Controller { $params['rowCount'] = $storeRowCount; } elseif (!isset($params['rowCount'])) { - $params['rowCount'] = CRM_Utils_Pager::ROWCOUNT; + $params['rowCount'] = Civi::settings()->get('default_pager_size'); } $this->_pager = new CRM_Utils_Pager($params); diff --git a/CRM/Event/Page/ManageEvent.php b/CRM/Event/Page/ManageEvent.php index f0d05726c5..53a8f9415d 100644 --- a/CRM/Event/Page/ManageEvent.php +++ b/CRM/Event/Page/ManageEvent.php @@ -575,7 +575,7 @@ ORDER BY start_date desc $params['buttonBottom'] = 'PagerBottomButton'; $params['rowCount'] = $this->get(CRM_Utils_Pager::PAGE_ROWCOUNT); if (!$params['rowCount']) { - $params['rowCount'] = CRM_Utils_Pager::ROWCOUNT; + $params['rowCount'] = Civi::settings()->get('default_pager_size'); } $query = " diff --git a/CRM/Event/Page/ParticipantListing/NameStatusAndDate.php b/CRM/Event/Page/ParticipantListing/NameStatusAndDate.php index 43b5aff703..a9eb028d16 100644 --- a/CRM/Event/Page/ParticipantListing/NameStatusAndDate.php +++ b/CRM/Event/Page/ParticipantListing/NameStatusAndDate.php @@ -114,7 +114,7 @@ LIMIT $offset, $rowCount"; $params['buttonBottom'] = 'PagerBottomButton'; $params['rowCount'] = $this->get(CRM_Utils_Pager::PAGE_ROWCOUNT); if (!$params['rowCount']) { - $params['rowCount'] = CRM_Utils_Pager::ROWCOUNT; + $params['rowCount'] = Civi::settings()->get('default_pager_size'); } $query = " diff --git a/CRM/Event/Page/ParticipantListing/Simple.php b/CRM/Event/Page/ParticipantListing/Simple.php index 58368dce2e..5452d805dd 100644 --- a/CRM/Event/Page/ParticipantListing/Simple.php +++ b/CRM/Event/Page/ParticipantListing/Simple.php @@ -104,7 +104,7 @@ LIMIT $offset, $rowCount"; $params['buttonBottom'] = 'PagerBottomButton'; $params['rowCount'] = $this->get(CRM_Utils_Pager::PAGE_ROWCOUNT); if (!$params['rowCount']) { - $params['rowCount'] = CRM_Utils_Pager::ROWCOUNT; + $params['rowCount'] = Civi::settings()->get('default_pager_size'); } $query = " diff --git a/CRM/Grant/Selector/Search.php b/CRM/Grant/Selector/Search.php index 07a2205f8a..454ab8aaec 100644 --- a/CRM/Grant/Selector/Search.php +++ b/CRM/Grant/Selector/Search.php @@ -211,7 +211,7 @@ class CRM_Grant_Selector_Search extends CRM_Core_Selector_Base implements CRM_Co $params['rowCount'] = $this->_limit; } else { - $params['rowCount'] = CRM_Utils_Pager::ROWCOUNT; + $params['rowCount'] = Civi::settings()->get('default_pager_size'); } $params['buttonTop'] = 'PagerTopButton'; diff --git a/CRM/Mailing/Selector/Browse.php b/CRM/Mailing/Selector/Browse.php index 91ac83909b..8151febab9 100644 --- a/CRM/Mailing/Selector/Browse.php +++ b/CRM/Mailing/Selector/Browse.php @@ -62,7 +62,7 @@ class CRM_Mailing_Selector_Browse extends CRM_Core_Selector_Base implements CRM_ */ public function getPagerParams($action, &$params) { $params['csvString'] = NULL; - $params['rowCount'] = CRM_Utils_Pager::ROWCOUNT; + $params['rowCount'] = Civi::settings()->get('default_pager_size'); $params['status'] = ts('Mailings %%StatusMessage%%'); $params['buttonTop'] = 'PagerTopButton'; $params['buttonBottom'] = 'PagerBottomButton'; diff --git a/CRM/Mailing/Selector/Event.php b/CRM/Mailing/Selector/Event.php index 638125a3d1..9c5aa0cd09 100644 --- a/CRM/Mailing/Selector/Event.php +++ b/CRM/Mailing/Selector/Event.php @@ -107,7 +107,7 @@ class CRM_Mailing_Selector_Event extends CRM_Core_Selector_Base implements CRM_C */ public function getPagerParams($action, &$params) { $params['csvString'] = NULL; - $params['rowCount'] = CRM_Utils_Pager::ROWCOUNT; + $params['rowCount'] = Civi::settings()->get('default_pager_size'); $params['status'] = ts('%1 %%StatusMessage%%', [1 => $this->eventToTitle()]); $params['buttonTop'] = 'PagerTopButton'; $params['buttonBottom'] = 'PagerBottomButton'; diff --git a/CRM/Mailing/Selector/Search.php b/CRM/Mailing/Selector/Search.php index 2c2cdb7421..b37a2cc323 100644 --- a/CRM/Mailing/Selector/Search.php +++ b/CRM/Mailing/Selector/Search.php @@ -213,7 +213,7 @@ class CRM_Mailing_Selector_Search extends CRM_Core_Selector_Base implements CRM_ $params['rowCount'] = $this->_limit; } else { - $params['rowCount'] = CRM_Utils_Pager::ROWCOUNT; + $params['rowCount'] = Civi::settings()->get('default_pager_size'); } $params['buttonTop'] = 'PagerTopButton'; diff --git a/CRM/Member/Selector/Search.php b/CRM/Member/Selector/Search.php index b03cef0a63..c57491f7b9 100644 --- a/CRM/Member/Selector/Search.php +++ b/CRM/Member/Selector/Search.php @@ -262,7 +262,7 @@ class CRM_Member_Selector_Search extends CRM_Core_Selector_Base implements CRM_C $params['rowCount'] = $this->_limit; } else { - $params['rowCount'] = CRM_Utils_Pager::ROWCOUNT; + $params['rowCount'] = Civi::settings()->get('default_pager_size'); } $params['buttonTop'] = 'PagerTopButton'; diff --git a/CRM/Pledge/Selector/Search.php b/CRM/Pledge/Selector/Search.php index aef07fbcfa..c82b10c184 100644 --- a/CRM/Pledge/Selector/Search.php +++ b/CRM/Pledge/Selector/Search.php @@ -221,7 +221,7 @@ class CRM_Pledge_Selector_Search extends CRM_Core_Selector_Base { $params['rowCount'] = $this->_limit; } else { - $params['rowCount'] = CRM_Utils_Pager::ROWCOUNT; + $params['rowCount'] = Civi::settings()->get('default_pager_size'); } $params['buttonTop'] = 'PagerTopButton'; diff --git a/CRM/Profile/Selector/Listings.php b/CRM/Profile/Selector/Listings.php index 21b738998b..72cad9e97d 100644 --- a/CRM/Profile/Selector/Listings.php +++ b/CRM/Profile/Selector/Listings.php @@ -250,7 +250,7 @@ class CRM_Profile_Selector_Listings extends CRM_Core_Selector_Base implements CR $status = CRM_Utils_System::isNull($this->_multiRecordTableName) ? ts('Contact %%StatusMessage%%') : ts('Contact Multi Records %%StatusMessage%%'); $params['status'] = $status; $params['csvString'] = NULL; - $params['rowCount'] = CRM_Utils_Pager::ROWCOUNT; + $params['rowCount'] = Civi::settings()->get('default_pager_size'); $params['buttonTop'] = 'PagerTopButton'; $params['buttonBottom'] = 'PagerBottomButton'; diff --git a/CRM/Utils/Pager.php b/CRM/Utils/Pager.php index c07aa8798a..4c83bfe270 100644 --- a/CRM/Utils/Pager.php +++ b/CRM/Utils/Pager.php @@ -32,7 +32,13 @@ class CRM_Utils_Pager extends Pager_Sliding { /** * Constants for static parameters of the pager */ - const ROWCOUNT = 50, PAGE_ID = 'crmPID', PAGE_ID_TOP = 'crmPID', PAGE_ID_BOTTOM = 'crmPID_B', PAGE_ROWCOUNT = 'crmRowCount'; + const PAGE_ID = 'crmPID', PAGE_ID_TOP = 'crmPID', PAGE_ID_BOTTOM = 'crmPID_B', PAGE_ROWCOUNT = 'crmRowCount'; + + /** + * Deprecated constants that might still be used by extensions but no longer by core + * @deprecated + */ + const ROWCOUNT = 50; /** * The output of the pager. This is a name/value array with various keys @@ -198,13 +204,13 @@ class CRM_Utils_Pager extends Pager_Sliding { /** * Get the number of rows to display from either a GET / POST variable * - * @param int $defaultPageRowCount + * @param int|null $defaultPageRowCount * The default value if not set. * * @return int * the rowCount value to use */ - public function getPageRowCount($defaultPageRowCount = self::ROWCOUNT) { + public function getPageRowCount($defaultPageRowCount = NULL) { // POST has higher priority than GET vars if (isset($_POST[self::PAGE_ROWCOUNT])) { $rowCount = max((int ) @$_POST[self::PAGE_ROWCOUNT], 1); @@ -213,7 +219,12 @@ class CRM_Utils_Pager extends Pager_Sliding { $rowCount = max((int ) @$_GET[self::PAGE_ROWCOUNT], 1); } else { - $rowCount = $defaultPageRowCount; + if (empty($defaultPageRowCount)) { + $rowcount = Civi::settings()->get('default_pager_size'); + } + else { + $rowCount = $defaultPageRowCount; + } } return $rowCount; } diff --git a/settings/Search.setting.php b/settings/Search.setting.php index 876eafa43b..9766a3c9f4 100644 --- a/settings/Search.setting.php +++ b/settings/Search.setting.php @@ -228,4 +228,24 @@ return [ 'description' => ts("Which fields can be searched on in the menubar quicksearch box? Don't see your custom field here? Make sure it is marked as Searchable."), 'help_text' => NULL, ], + 'default_pager_size' => [ + 'group_name' => 'Search Preferences', + 'group' => 'Search Preferences', + 'name' => 'default_pager_size', + 'type' => 'Integer', + 'quick_form_type' => 'Element', + 'html_type' => 'text', + 'html_attributes' => [ + 'size' => 2, + 'maxlength' => 3, + ], + 'default' => 50, + 'add' => '5.39', + 'title' => ts('Default Search Pager size'), + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => ts('What is the default number of records to show on a search'), + 'help_text' => NULL, + ], + ]; diff --git a/tests/phpunit/CRM/Contact/Page/DedupeExceptionTest.php b/tests/phpunit/CRM/Contact/Page/DedupeExceptionTest.php index 1e9fd053e6..c660c05292 100644 --- a/tests/phpunit/CRM/Contact/Page/DedupeExceptionTest.php +++ b/tests/phpunit/CRM/Contact/Page/DedupeExceptionTest.php @@ -28,7 +28,7 @@ class CRM_Contact_Page_DedupeExceptionTest extends CiviUnitTestCase { $totalitems = civicrm_api3('Exception', "getcount", []); $params = [ 'total' => $totalitems, - 'rowCount' => CRM_Utils_Pager::ROWCOUNT, + 'rowCount' => Civi::settings()->get('default_pager_size'), 'status' => ts('Dedupe Exceptions %%StatusMessage%%'), 'buttonBottom' => 'PagerBottomButton', 'buttonTop' => 'PagerTopButton', -- 2.25.1