MDL-74041 quiz: use own size for paging the question bank

This commit is contained in:
Tim Hunt 2022-03-03 12:33:03 +00:00
parent 10e8ffe312
commit aac5b47cea
4 changed files with 29 additions and 12 deletions

View file

@ -113,6 +113,11 @@ class view {
*/
protected $sort;
/**
* @var int page size to use (when we are not showing all questions).
*/
protected $pagesize = DEFAULT_QUESTIONS_PER_PAGE;
/**
* @var int|null id of the a question to highlight in the list (if present).
*/
@ -934,11 +939,11 @@ class view {
* @param string $categoryandcontext 'categoryID,contextID'.
* @param int $recurse Whether to include subcategories.
* @param int $page The number of the page to be displayed
* @param int $perpage Number of questions to show per page
* @param int|null $perpage Number of questions to show per page
* @param array $addcontexts contexts where the user is allowed to add new questions.
*/
protected function display_question_list($pageurl, $categoryandcontext, $recurse = 1, $page = 0,
$perpage = 100, $addcontexts = []): void {
$perpage = null, $addcontexts = []): void {
global $OUTPUT;
// This function can be moderately slow with large question counts and may time out.
// We probably do not want to raise it to unlimited, so randomly picking 5 minutes.
@ -946,6 +951,7 @@ class view {
\core_php_time_limit::raise(300);
$category = $this->get_current_category($categoryandcontext);
$perpage = $perpage ?? $this->pagesize;
list($categoryid, $contextid) = explode(',', $categoryandcontext);
$catcontext = \context::instance_by_id($contextid);
@ -1021,9 +1027,9 @@ class view {
'pagination' => $pagination,
'biggertotal' => true,
);
if ($totalnumber > DEFAULT_QUESTIONS_PER_PAGE) {
if ($totalnumber > $this->pagesize) {
$displaydata['showall'] = true;
if ($perpage == DEFAULT_QUESTIONS_PER_PAGE) {
if ($perpage == $this->pagesize) {
$url = new \moodle_url($pageurl, array_merge($pageurl->params(),
['qpage' => 0, 'qperpage' => MAXIMUM_QUESTIONS_PER_PAGE]));
if ($totalnumber > MAXIMUM_QUESTIONS_PER_PAGE) {
@ -1034,8 +1040,8 @@ class view {
}
} else {
$url = new \moodle_url($pageurl, array_merge($pageurl->params(),
['qperpage' => DEFAULT_QUESTIONS_PER_PAGE]));
$displaydata['totalnumber'] = DEFAULT_QUESTIONS_PER_PAGE;
['qperpage' => $this->pagesize]));
$displaydata['totalnumber'] = $this->pagesize;
}
$displaydata['showallurl'] = $url;
}

View file

@ -252,10 +252,12 @@ function question_edit_setup($edittab, $baseurl, $requirecmid = false, $unused =
* @param string $edittab Code for this edit tab
* @param string $baseurl The name of the script calling this funciton. For examle 'qusetion/edit.php'.
* @param array $params The provided parameters to construct the resources with.
* @param int $defaultquestionsperpage number of questions per page, if not given in the URL.
* @return array $thispageurl, $contexts, $cmid, $cm, $module, $pagevars
*/
function question_build_edit_resources($edittab, $baseurl, $params) {
global $DB, $PAGE, $CFG;
function question_build_edit_resources($edittab, $baseurl, $params,
$defaultquestionsperpage = DEFAULT_QUESTIONS_PER_PAGE) {
global $DB;
$thispageurl = new moodle_url($baseurl);
$thispageurl->remove_all_params(); // We are going to explicity add back everything important - this avoids unwanted params from being retained.
@ -372,8 +374,12 @@ function question_build_edit_resources($edittab, $baseurl, $params) {
$pagevars['qpage'] = 0;
}
$pagevars['qperpage'] = question_set_or_get_user_preference(
'qperpage', $qperpage, DEFAULT_QUESTIONS_PER_PAGE, $thispageurl);
if ($defaultquestionsperpage == DEFAULT_QUESTIONS_PER_PAGE) {
$pagevars['qperpage'] = question_set_or_get_user_preference(
'qperpage', $qperpage, DEFAULT_QUESTIONS_PER_PAGE, $thispageurl);
} else {
$pagevars['qperpage'] = $qperpage ?? $defaultquestionsperpage;
}
$defaultcategory = question_make_default_categories($contexts->all());