From: tjhunt Date: Wed, 10 Dec 2008 06:26:47 +0000 (+0000) Subject: quiz: MDL-6085 when editing a question from various places like a preview attempt... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=aafdb447bf6af9676faea67bd3e4e77de4e26324;p=moodle.git quiz: MDL-6085 when editing a question from various places like a preview attempt or review screen, don't use a popup, instead take advantage of the fact that question.php now takes a returnurl. Merged from MOODLE_19_STABLE. And MDL-17568 minor niggles with new queston navigation: * The bit that scrolls down to the question you just submitted in adaptive mode was not working with random questions. * Teachers reviewing an open attempt were shown the qusetions as editable, not read only! --- diff --git a/mod/quiz/attempt.php b/mod/quiz/attempt.php index efb7dd14e7..28bc9e5f50 100644 --- a/mod/quiz/attempt.php +++ b/mod/quiz/attempt.php @@ -138,7 +138,7 @@ /// Print all the questions foreach ($attemptobj->get_question_ids($page) as $id) { - $attemptobj->print_question($id); + $attemptobj->print_question($id, false, $attemptobj->attempt_url($id, $page)); } /// Print a link to the next page. diff --git a/mod/quiz/attemptlib.php b/mod/quiz/attemptlib.php index aaf94cb1d5..9a04eb040c 100644 --- a/mod/quiz/attemptlib.php +++ b/mod/quiz/attemptlib.php @@ -470,7 +470,7 @@ class quiz_attempt extends quiz { return $this->attempt->userid; } - /** @return boolean whether this attemp has been finished (true) or is still in progress (false). */ + /** @return boolean whether this attempt has been finished (true) or is still in progress (false). */ public function is_finished() { return $this->attempt->timefinish != 0; } @@ -641,6 +641,10 @@ class quiz_attempt extends quiz { $this->page_and_question_fragment($questionid, $page, $showall); } + public function set_this_page_url($url) { + $this->quiz->thispageurl = $url; + } + // Bits of content ===================================================================== public function get_html_head_contributions($page = 'all') { return get_html_head_contributions($this->get_question_ids($page), @@ -660,12 +664,24 @@ class quiz_attempt extends quiz { echo ''; } - public function print_question($id) { - if ($this->is_finished()) { + /** + * Wrapper round print_question from lib/questionlib.php. + * + * @param integer $id the id of a question in this quiz attempt. + * @param boolean $reviewing is the being printed on an attempt or a review page. + * @param string $thispageurl the URL of the page this question is being printed on. + */ + public function print_question($id, $reviewing, $thispageurl = '') { + if ($reviewing) { $options = $this->get_review_options(); } else { $options = $this->get_render_options($this->states[$id]); } + if ($thispageurl) { + $this->quiz->thispageurl = $thispageurl; + } else { + unset($thispageurl); + } print_question($this->questions[$id], $this->states[$id], $this->questions[$id]->_number, $this->quiz, $options); } diff --git a/mod/quiz/report/grading/report.php b/mod/quiz/report/grading/report.php index f18673dec1..da9be0362f 100644 --- a/mod/quiz/report/grading/report.php +++ b/mod/quiz/report/grading/report.php @@ -408,6 +408,7 @@ class quiz_grading_report extends quiz_default_report { // Print the question, without showing any previous comment. $copy = $state->manualcomment; $state->manualcomment = ''; + $options->noeditlink = true; print_question($question, $state, '', $quiz, $options); // The print the comment and grade fields, putting back the previous comment. diff --git a/mod/quiz/review.php b/mod/quiz/review.php index 130f79ec75..7c619274dd 100644 --- a/mod/quiz/review.php +++ b/mod/quiz/review.php @@ -224,7 +224,7 @@ $lastpage = $attemptobj->is_last_page($page); } foreach ($attemptobj->get_question_ids($thispage) as $id) { - $attemptobj->print_question($id); + $attemptobj->print_question($id, true, $attemptobj->review_url($id, $page, $showall)); } /// Close form if we opened it. diff --git a/mod/quiz/reviewquestion.php b/mod/quiz/reviewquestion.php index 12b5c07daa..7f0bdebfa5 100644 --- a/mod/quiz/reviewquestion.php +++ b/mod/quiz/reviewquestion.php @@ -50,6 +50,10 @@ $attemptobj->load_specific_question_state($questionid, $stateid); } +/// Work out the base URL of this page. + $baseurl = $CFG->wwwroot . '/mod/quiz/reviewquestion.php?attempt=' . + $attemptobj->get_attemptid() . '&question=' . $questionid; + /// Log this review. add_to_log($attemptobj->get_courseid(), 'quiz', 'review', 'reviewquestion.php?attempt=' . $attemptobj->get_attemptid() . '&question=' . $questionid . @@ -86,9 +90,7 @@ /// Other attempts at the quiz. if ($attemptobj->has_capability('mod/quiz:viewreports')) { - $attemptlist = $attemptobj->links_to_other_attempts( - 'reviewquestion.php?attempt=' . $attemptobj->get_attemptid() . - '&question=' . $questionid); + $attemptlist = $attemptobj->links_to_other_attempts($baseurl); if ($attemptlist) { $rows[] = '' . get_string('attempts', 'quiz') . '' . $attemptlist . ''; @@ -110,7 +112,10 @@ } /// Print the question in the requested state. - $attemptobj->print_question($questionid); + if ($stateid) { + $baseurl .= '&state=' . $stateid; + } + $attemptobj->print_question($questionid, true, $baseurl); /// Finish the page print_footer(); diff --git a/question/preview.php b/question/preview.php index b8610110a4..e1f48459f9 100644 --- a/question/preview.php +++ b/question/preview.php @@ -189,6 +189,7 @@ // TODO: should not use quiz-specific function here $options = quiz_get_renderoptions($quiz, $attempt, $context, $curstate); + $options->noeditlink = true; // Fill in the correct responses (unless the question is in readonly mode) if ($fillcorrect && !$options->readonly) { diff --git a/question/type/description/questiontype.php b/question/type/description/questiontype.php index 36acbdd469..dd948045c7 100644 --- a/question/type/description/questiontype.php +++ b/question/type/description/questiontype.php @@ -45,24 +45,8 @@ class description_qtype extends default_questiontype { global $CFG; $isfinished = question_state_is_graded($state->last_graded) || $state->event == QUESTION_EVENTCLOSE; - if (!empty($cmoptions->id)) { - $cm = get_coursemodule_from_instance('quiz', $cmoptions->id); - $cmorcourseid = '&cmid='.$cm->id; - } else if (!empty($cmoptions->course)) { - $cmorcourseid = '&courseid='.$cmoptions->course; - } else { - print_error('missingcourseorcmid', 'question'); - } - // For editing teachers print a link to an editing popup window - $editlink = ''; - if (question_has_capability_on($question, 'edit')) { - $stredit = get_string('edit'); - $linktext = ''.$stredit.''; - $editlink = link_to_popup_window('/question/question.php?inpopup=1&id=' . - $question->id . $cmorcourseid, 'editquestion', - $linktext, false, false, $stredit, '', true); - } + $editlink = $this->get_question_edit_link($question, $cmoptions, $options); $questiontext = $this->format_text($question->questiontext, $question->questiontextformat, $cmoptions); $image = get_question_image($question); diff --git a/question/type/question.html b/question/type/question.html index 12154dc84e..13e19ab160 100644 --- a/question/type/question.html +++ b/question/type/question.html @@ -3,7 +3,7 @@ * print_question() method. */ ?> -
+

Question diff --git a/question/type/questiontype.php b/question/type/questiontype.php index 8b5f11e7dd..811e93d794 100644 --- a/question/type/questiontype.php +++ b/question/type/questiontype.php @@ -892,29 +892,24 @@ class default_questiontype { global $CFG; $isgraded = question_state_is_graded($state->last_graded); - // get the context so we can determine whether some extra links - // should be shown. + // Get the context we should use to check permissions. if (!empty($cmoptions->id)) { - $cm = get_coursemodule_from_instance('quiz', $cmoptions->id); - $context = get_context_instance(CONTEXT_MODULE, $cm->id); - $cmorcourseid = '&cmid='.$cm->id; + $context = get_context_instance(CONTEXT_MODULE, $cmoptions->id); } else if (!empty($cmoptions->course)) { $context = get_context_instance(CONTEXT_COURSE, $cmoptions->course); - $cmorcourseid = '&courseid='.$cmoptions->course; } else { - print_error('missingcourseorcmid', 'question'); + $context = null; } - // For editing teachers print a link to an editing popup window - $editlink = ''; - if (question_has_capability_on($question, 'edit')) { - $stredit = get_string('edit'); - $linktext = ''.$stredit.''; - $editlink = link_to_popup_window('/question/question.php?inpopup=1&id=' . - $question->id . $cmorcourseid, 'editquestion', - $linktext, false, false, $stredit, '', true); + if (isset($question->randomquestionid)) { + $actualquestionid = $question->randomquestionid; + } else { + $actualquestionid = $question->id; } + // For editing teachers print a link to an editing popup window + $editlink = $this->get_question_edit_link($question, $cmoptions, $options); + $generalfeedback = ''; if ($isgraded && $options->generalfeedback) { $generalfeedback = $this->format_text($question->generalfeedback, @@ -936,11 +931,12 @@ class default_questiontype { $comment = $state->manualcomment; $commentlink = ''; - if (isset($options->questioncommentlink) && $context && has_capability('mod/quiz:grade', $context)) { + if (!empty($options->questioncommentlink)) { $strcomment = get_string('commentorgrade', 'quiz'); - $question_to_comment = isset($question->randomquestionid) ? $question->randomquestionid : $question->id; - $commentlink = ''; + $commentlink = link_to_popup_window($options->questioncommentlink . + '?attempt=' . $state->attempt . '&question=' . $actualquestionid, + 'commentquestion', $strcomment, 450, 650, $strcomment, 'none', true); + $commentlink = ''; } $history = $this->history($question, $state, $number, $cmoptions, $options); @@ -1009,6 +1005,49 @@ class default_questiontype { '" alt="' . get_string('flagthisquestion', 'question') . '" />'; } + /** + * Get a link to an edit icon for this question, if the current user is allowed + * to edit it. + * + * @param object $question the question object. + * @param object $cmoptions the options from the module. If $cmoptions->thispageurl is set + * then the link will be to edit the question in this browser window, then return to + * $cmoptions->thispageurl. Otherwise the link will be to edit in a popup. + * @return string the HTML of the link, or nothing it the currenty user is not allowed to edit. + */ + function get_question_edit_link($question, $cmoptions, $options) { + global $CFG; + + /// Is this user allowed to edit this question? + if (!empty($options->noeditlink) || !question_has_capability_on($question, 'edit')) { + return ''; + } + + /// Work out the right URL. + $linkurl = '/question/question.php?id=' . $question->id; + if (!empty($cmoptions->id)) { + $linkurl .= '&cmid=' . $cmoptions->id; + } else if (!empty($cmoptions->course)) { + $linkurl .= '&courseid=' . $cmoptions->course; + } else { + error('Need to provide courseid or cmid to get_question_edit_link.'); + } + + /// Work out the contents of the link. + $stredit = get_string('edit'); + $linktext = '' . $stredit . ''; + + if (!empty($cmoptions->thispageurl)) { + /// The module allow editing in the same window, print an ordinary link. + return '' . $linktext . ''; + } else { + /// We have to edit in a pop-up. + return link_to_popup_window($linkurl . '&inpopup=1', 'editquestion', + $linktext, false, false, $stredit, '', true); + } + } + /** * Print history of responses *