Skip to content

Commit

Permalink
MDL-34810 question bank: user prefs for some display options
Browse files Browse the repository at this point in the history
The options that are remembered persistently are
* Also show questions from sub-categories
* Also show old questions
* Show question text in the question list
* Number of questions per page
  • Loading branch information
timhunt committed Aug 16, 2012
1 parent c92d6f4 commit be77e9b
Showing 1 changed file with 33 additions and 27 deletions.
60 changes: 33 additions & 27 deletions question/editlib.php
Expand Up @@ -1642,12 +1642,8 @@ function question_edit_setup($edittab, $baseurl, $requirecmid = false, $requirec
$pagevars['qpage'] = 0; $pagevars['qpage'] = 0;
} }


$pagevars['qperpage'] = optional_param('qperpage', -1, PARAM_INT); $pagevars['qperpage'] = question_get_display_preference(
if ($pagevars['qperpage'] > -1) { 'qperpage', DEFAULT_QUESTIONS_PER_PAGE, PARAM_INT, $thispageurl);
$thispageurl->param('qperpage', $pagevars['qperpage']);
} else {
$pagevars['qperpage'] = DEFAULT_QUESTIONS_PER_PAGE;
}


for ($i = 1; $i <= question_bank_view::MAX_SORTS; $i++) { for ($i = 1; $i <= question_bank_view::MAX_SORTS; $i++) {
$param = 'qbs' . $i; $param = 'qbs' . $i;
Expand Down Expand Up @@ -1675,28 +1671,12 @@ function question_edit_setup($edittab, $baseurl, $requirecmid = false, $requirec
$pagevars['cat'] = "$category->id,$category->contextid"; $pagevars['cat'] = "$category->id,$category->contextid";
} }


if(($recurse = optional_param('recurse', -1, PARAM_BOOL)) != -1) { // Display options.
$pagevars['recurse'] = $recurse; $pagevars['recurse'] = question_get_display_preference('recurse', 1, PARAM_BOOL, $thispageurl);
$thispageurl->param('recurse', $recurse); $pagevars['showhidden'] = question_get_display_preference('showhidden', 0, PARAM_BOOL, $thispageurl);
} else { $pagevars['qbshowtext'] = question_get_display_preference('qbshowtext', 0, PARAM_BOOL, $thispageurl);
$pagevars['recurse'] = 1;
}


if(($showhidden = optional_param('showhidden', -1, PARAM_BOOL)) != -1) { // Category list page.
$pagevars['showhidden'] = $showhidden;
$thispageurl->param('showhidden', $showhidden);
} else {
$pagevars['showhidden'] = 0;
}

if(($showquestiontext = optional_param('qbshowtext', -1, PARAM_BOOL)) != -1) {
$pagevars['qbshowtext'] = $showquestiontext;
$thispageurl->param('qbshowtext', $showquestiontext);
} else {
$pagevars['qbshowtext'] = 0;
}

//category list page
$pagevars['cpage'] = optional_param('cpage', 1, PARAM_INT); $pagevars['cpage'] = optional_param('cpage', 1, PARAM_INT);
if ($pagevars['cpage'] != 1){ if ($pagevars['cpage'] != 1){
$thispageurl->param('cpage', $pagevars['cpage']); $thispageurl->param('cpage', $pagevars['cpage']);
Expand All @@ -1705,6 +1685,32 @@ function question_edit_setup($edittab, $baseurl, $requirecmid = false, $requirec
return array($thispageurl, $contexts, $cmid, $cm, $module, $pagevars); return array($thispageurl, $contexts, $cmid, $cm, $module, $pagevars);
} }


/**
* Get a particular question preference that is also stored as a user preference.
* If the the value is given in the GET/POST request, then that value is used,
* and the user preference is updated to that value. Otherwise, the last set
* value of the user preference is used, or if it has never been set the default
* passed to this function.
*
* @param string $param the param name. The URL parameter set, and the GET/POST
* parameter read. The user_preference name is 'question_bank_' . $param.
* @param mixed $default The default value to use, if not otherwise set.
* @param int $type one of the PARAM_... constants.
* @param moodle_url $thispageurl if the value has been explicitly set, we add
* it to this URL.
* @return mixed the parameter value to use.
*/
function question_get_display_preference($param, $default, $type, $thispageurl) {
$submittedvalue = optional_param($param, null, $type);
if (is_null($submittedvalue)) {
return get_user_preferences('question_bank_' . $param, $default);
}

set_user_preference('question_bank_' . $param, $submittedvalue);
$thispageurl->param($param, $submittedvalue);
return $submittedvalue;
}

/** /**
* Make sure user is logged in as required in this context. * Make sure user is logged in as required in this context.
*/ */
Expand Down

0 comments on commit be77e9b

Please sign in to comment.