Skip to content
Snippets Groups Projects
Commit ea178a7d authored by Chris Sangwin's avatar Chris Sangwin
Browse files

Do not set moodle context inside functions (WIP).

parent 10043290
No related branches found
No related tags found
No related merge requests found
......@@ -124,7 +124,7 @@ if (data_submitted() && optional_param('includes', false, PARAM_BOOL)) {
if (isset($q->compiledcache['includes']) && (
(isset($q->compiledcache['includes']['keyval']) && count($q->compiledcache['includes']['keyval']) > 0) ||
(isset($q->compiledcache['includes']['castext']) && count($q->compiledcache['includes']['castext']) > 0))) {
list($context, $seed, $urlparams) = qtype_stack_setup_question_test_page($q, false);
list($context, $seed, $urlparams) = qtype_stack_setup_question_test_page($q);
if (stack_determine_moodle_version() < 400) {
$qurl = question_preview_url($item->questionid, null, null, null, null, $context);
} else {
......@@ -190,7 +190,7 @@ if (data_submitted() && optional_param('jsxgraphs', false, PARAM_BOOL)) {
}
// Confirm that it does have these.
if ($block || $filter || $other) {
list($context, $seed, $urlparams) = qtype_stack_setup_question_test_page($q, false);
list($context, $seed, $urlparams) = qtype_stack_setup_question_test_page($q);
if (stack_determine_moodle_version() < 400) {
$qurl = question_preview_url($item->questionid, null, null, null, null, $context);
} else {
......@@ -217,7 +217,7 @@ if (data_submitted() && optional_param('script', false, PARAM_BOOL)) {
// Load the whole question, simpler to get the contexts correct that way.
foreach ($qs as $item) {
$q = question_bank::load_question($item->questionid);
list($context, $seed, $urlparams) = qtype_stack_setup_question_test_page($q, false);
list($context, $seed, $urlparams) = qtype_stack_setup_question_test_page($q);
if (stack_determine_moodle_version() < 400) {
$qurl = question_preview_url($item->questionid, null, null, null, null, $context);
} else {
......@@ -242,7 +242,7 @@ if (data_submitted() && optional_param('PLUGINFILE', false, PARAM_BOOL)) {
// Load the whole question, simpler to get the contexts correct that way.
foreach ($qs as $item) {
$q = question_bank::load_question($item->questionid);
list($context, $seed, $urlparams) = qtype_stack_setup_question_test_page($q, false);
list($context, $seed, $urlparams) = qtype_stack_setup_question_test_page($q);
if (stack_determine_moodle_version() < 400) {
$qurl = question_preview_url($item->questionid, null, null, null, null, $context);
} else {
......@@ -267,7 +267,7 @@ if (data_submitted() && optional_param('langs', false, PARAM_BOOL)) {
// Load the whole question, simpler to get the contexts correct that way.
foreach ($qs as $item) {
$q = question_bank::load_question($item->questionid);
list($context, $seed, $urlparams) = qtype_stack_setup_question_test_page($q, false);
list($context, $seed, $urlparams) = qtype_stack_setup_question_test_page($q);
if (stack_determine_moodle_version() < 400) {
$qurl = question_preview_url($item->questionid, null, null, null, null, $context);
} else {
......
......@@ -36,6 +36,7 @@ $question = question_bank::load_question($questionid);
// Process any other URL parameters, and do require_login.
list($context, $seed, $urlparams) = qtype_stack_setup_question_test_page($question);
$PAGE->set_context($context);
// Check permissions.
question_require_capability_on($questiondata, 'edit');
......
......@@ -207,9 +207,7 @@ function stack_string_sanitise($str) {
* that is needed on all of them.
* @return array page context, selected seed (or null), and URL parameters.
*/
function qtype_stack_setup_question_test_page($question, $setcontext = true) {
global $PAGE;
function qtype_stack_setup_question_test_page($question) {
$seed = optional_param('seed', null, PARAM_INT);
$urlparams = array('questionid' => $question->id);
if (!is_null($seed) && $question->has_random_variants()) {
......@@ -238,11 +236,6 @@ function qtype_stack_setup_question_test_page($question, $setcontext = true) {
} else {
$urlparams['courseid'] = SITEID;
}
if ($setcontext) {
require_login();
$PAGE->set_context($context);
}
// Note that in the other cases, require_login will set the correct page context.
}
return array($context, $seed, $urlparams);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment