mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 00:12:56 +02:00
MDL-74041 quiz: use own size for paging the question bank
This commit is contained in:
parent
10e8ffe312
commit
aac5b47cea
@ -36,6 +36,8 @@ use mod_quiz\question\bank\filter\custom_category_condition;
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class custom_view extends \core_question\local\bank\view {
|
||||
/** @var int number of questions per page to show in the add from question bank modal. */
|
||||
const DEFAULT_PAGE_SIZE = 20;
|
||||
|
||||
/** @var bool $quizhasattempts whether the quiz this is used by has been attemptd. */
|
||||
protected $quizhasattempts = false;
|
||||
@ -57,6 +59,7 @@ class custom_view extends \core_question\local\bank\view {
|
||||
public function __construct($contexts, $pageurl, $course, $cm, $quiz) {
|
||||
parent::__construct($contexts, $pageurl, $course, $cm);
|
||||
$this->quiz = $quiz;
|
||||
$this->pagesize = self::DEFAULT_PAGE_SIZE;
|
||||
}
|
||||
|
||||
protected function get_question_bank_plugins(): array {
|
||||
|
@ -28,6 +28,8 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use mod_quiz\question\bank\custom_view;
|
||||
|
||||
require_once($CFG->dirroot . '/calendar/lib.php');
|
||||
|
||||
|
||||
@ -2382,14 +2384,14 @@ function mod_quiz_output_fragment_quiz_question_bank($args) {
|
||||
// Build the required resources. The $params are all cleaned as
|
||||
// part of this process.
|
||||
list($thispageurl, $contexts, $cmid, $cm, $quiz, $pagevars) =
|
||||
question_build_edit_resources('editq', '/mod/quiz/edit.php', $params);
|
||||
question_build_edit_resources('editq', '/mod/quiz/edit.php', $params, custom_view::DEFAULT_PAGE_SIZE);
|
||||
|
||||
// Get the course object and related bits.
|
||||
$course = $DB->get_record('course', array('id' => $quiz->course), '*', MUST_EXIST);
|
||||
require_capability('mod/quiz:manage', $contexts->lowest());
|
||||
|
||||
// Create quiz question bank view.
|
||||
$questionbank = new mod_quiz\question\bank\custom_view($contexts, $thispageurl, $course, $cm, $quiz);
|
||||
$questionbank = new custom_view($contexts, $thispageurl, $course, $cm, $quiz);
|
||||
$questionbank->set_quiz_has_attempts(quiz_has_attempts($quiz->id));
|
||||
|
||||
// Output.
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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());
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user