From 647bcd41299a215fe0c06ac65f6c6cd9854b74f7 Mon Sep 17 00:00:00 2001 From: tjhunt Date: Wed, 23 Aug 2006 18:37:38 +0000 Subject: [PATCH] Fix getting the context. It did not work during question preview from the question bank when there was no quiz in sight. --- question/type/questiontype.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/question/type/questiontype.php b/question/type/questiontype.php index 096d6cc0b3..e02f0c1de1 100644 --- a/question/type/questiontype.php +++ b/question/type/questiontype.php @@ -501,12 +501,19 @@ class default_questiontype { global $CFG; $isgraded = question_state_is_graded($state->last_graded); + // If this question is being shown in the context of a quiz + // get the context so we can determine whether some extra links + // should be shown. (Don't show these links during question preview.) $cm = get_coursemodule_from_instance('quiz', $cmoptions->id); - $context = get_context_instance(CONTEXT_MODULE, $cm->id); + if (!empty($cm->id)) { + $context = get_context_instance(CONTEXT_MODULE, $cm->id); + } else { + $context = false; + } // For editing teachers print a link to an editing popup window $editlink = ''; - if (has_capability('mod/quiz:manage', $context)) { + if ($context && has_capability('mod/quiz:manage', $context)) { $stredit = get_string('edit'); $linktext = ''.$stredit.''; $editlink = link_to_popup_window('/question/question.php?id='.$question->id, $stredit, $linktext, 450, 550, $stredit, '', true); @@ -529,7 +536,7 @@ class default_questiontype { $comment = stripslashes($state->comment); $commentlink = ''; - if (isset($options->questioncommentlink) && has_capability('mod/quiz:grade', $context)) { + if (isset($options->questioncommentlink) && $context && has_capability('mod/quiz:grade', $context)) { $strcomment = get_string('commentorgrade', 'quiz'); $commentlink = ''; -- 2.39.5