Skip to content

Commit

Permalink
dev/core#2187 Allow sites to customsie the default number of rows ret…
Browse files Browse the repository at this point in the history
…urned from QuickForm Searches
  • Loading branch information
seamuslee001 committed Nov 13, 2020
1 parent d1eed91 commit 0a2c919
Show file tree
Hide file tree
Showing 25 changed files with 58 additions and 26 deletions.
2 changes: 1 addition & 1 deletion CRM/Activity/Selector/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public static function actionLinks(
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';
Expand Down
2 changes: 1 addition & 1 deletion CRM/Activity/Selector/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public function __construct(
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';
}
Expand Down
1 change: 1 addition & 0 deletions CRM/Admin/Form/Setting/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];

/**
Expand Down
2 changes: 1 addition & 1 deletion CRM/Campaign/Selector/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public static function &links() {
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';
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Case/Selector/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public function getPagerParams($action, &$params) {
$params['rowCount'] = $this->_limit;
}
else {
$params['rowCount'] = CRM_Utils_Pager::ROWCOUNT;
$params['rowCount'] = Civi::settings()->get('default_pager_size');
}

$params['buttonTop'] = 'PagerTopButton';
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contact/Form/Search/Custom/FullText.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function __construct(&$formValues) {
// 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;
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contact/Page/DedupeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected function initializePager() {
$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',
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contact/Selector.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ public static function &links() {
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';
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contact/Selector/Custom.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public static function &links() {
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';
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contribute/Page/ContributionPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ public function pager($whereClause, $whereParams) {
$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 = "
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contribute/Selector/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public function getPagerParams($action, &$params) {
$params['rowCount'] = $this->_limit;
}
else {
$params['rowCount'] = CRM_Utils_Pager::ROWCOUNT;
$params['rowCount'] = Civi::settings()->get('default_pager_size');
}

$params['buttonTop'] = 'PagerTopButton';
Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/Selector/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public function __construct($object, $pageID, $sortID, $action, $store = NULL, $
$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);
Expand Down
2 changes: 1 addition & 1 deletion CRM/Event/Page/ManageEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ public function pager($whereClause, $whereParams) {
$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 = "
Expand Down
2 changes: 1 addition & 1 deletion CRM/Event/Page/ParticipantListing/NameStatusAndDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function pager($fromClause, $whereClause, $whereParams) {
$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 = "
Expand Down
2 changes: 1 addition & 1 deletion CRM/Event/Page/ParticipantListing/Simple.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function pager($fromClause, $whereClause, $whereParams) {
$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 = "
Expand Down
2 changes: 1 addition & 1 deletion CRM/Grant/Selector/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public function getPagerParams($action, &$params) {
$params['rowCount'] = $this->_limit;
}
else {
$params['rowCount'] = CRM_Utils_Pager::ROWCOUNT;
$params['rowCount'] = Civi::settings()->get('default_pager_size');
}

$params['buttonTop'] = 'PagerTopButton';
Expand Down
2 changes: 1 addition & 1 deletion CRM/Mailing/Selector/Browse.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static function &links() {
*/
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';
Expand Down
2 changes: 1 addition & 1 deletion CRM/Mailing/Selector/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static function &links() {
*/
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';
Expand Down
2 changes: 1 addition & 1 deletion CRM/Mailing/Selector/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public function getPagerParams($action, &$params) {
$params['rowCount'] = $this->_limit;
}
else {
$params['rowCount'] = CRM_Utils_Pager::ROWCOUNT;
$params['rowCount'] = Civi::settings()->get('default_pager_size');
}

$params['buttonTop'] = 'PagerTopButton';
Expand Down
2 changes: 1 addition & 1 deletion CRM/Member/Selector/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public function getPagerParams($action, &$params) {
$params['rowCount'] = $this->_limit;
}
else {
$params['rowCount'] = CRM_Utils_Pager::ROWCOUNT;
$params['rowCount'] = Civi::settings()->get('default_pager_size');
}

$params['buttonTop'] = 'PagerTopButton';
Expand Down
2 changes: 1 addition & 1 deletion CRM/Pledge/Selector/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public function getPagerParams($action, &$params) {
$params['rowCount'] = $this->_limit;
}
else {
$params['rowCount'] = CRM_Utils_Pager::ROWCOUNT;
$params['rowCount'] = Civi::settings()->get('default_pager_size');
}

$params['buttonTop'] = 'PagerTopButton';
Expand Down
2 changes: 1 addition & 1 deletion CRM/Profile/Selector/Listings.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public function getPagerParams($action, &$params) {
$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';
Expand Down
19 changes: 15 additions & 4 deletions CRM/Utils/Pager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -198,13 +204,13 @@ public function getPageID($defaultPageId = 1, &$params) {
/**
* 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);
Expand All @@ -213,7 +219,12 @@ public function getPageRowCount($defaultPageRowCount = self::ROWCOUNT) {
$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;
}
Expand Down
20 changes: 20 additions & 0 deletions settings/Search.setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,24 @@
'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.33',
'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' => ts('Set this to show a specific number of records'),
],

];
2 changes: 1 addition & 1 deletion tests/phpunit/CRM/Contact/Page/DedupeExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function testGetDedupeExceptions() {
$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',
Expand Down

0 comments on commit 0a2c919

Please sign in to comment.