]> git.mjollnir.org Git - moodle.git/commitdiff
quiz: MDL-6085 when editing a question from various places like a preview attempt...
authortjhunt <tjhunt>
Wed, 10 Dec 2008 06:26:47 +0000 (06:26 +0000)
committertjhunt <tjhunt>
Wed, 10 Dec 2008 06:26:47 +0000 (06:26 +0000)
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!

mod/quiz/attempt.php
mod/quiz/attemptlib.php
mod/quiz/report/grading/report.php
mod/quiz/review.php
mod/quiz/reviewquestion.php
question/preview.php
question/type/description/questiontype.php
question/type/question.html
question/type/questiontype.php

index efb7dd14e75c15ebc70a48a823eaabe88c21c035..28bc9e5f5003981389f5c6259741c46c60f3879e 100644 (file)
 
 /// 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.
index aaf94cb1d5832a56bdf0e8ca7da79a4446ec51b7..9a04eb040c877f5209f3d29116b1818971ab457f 100644 (file)
@@ -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 '</div>';
     }
 
-    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);
     }
index f18673dec1ee7c321d5f8e54e0df09ba28bb2a44..da9be0362fbb076d94211b8d4d1f693005350615 100644 (file)
@@ -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.
index 130f79ec7518b5a3e53aa548469aa36756ac000e..7c619274dd5244f9c21e6fb20b85997c08a1000c 100644 (file)
         $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.
index 12b5c07daa558ea31541da22b3a5692a78c9d00d..7f0bdebfa586727d95bb334110ccc21a69fbfe9f 100644 (file)
         $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() . '&amp;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() .
-                '&amp;question=' . $questionid);
+        $attemptlist = $attemptobj->links_to_other_attempts($baseurl);
         if ($attemptlist) {
             $rows[] = '<tr><th scope="row" class="cell">' . get_string('attempts', 'quiz') .
                     '</th><td class="cell">' . $attemptlist . '</td></tr>';
     }
 
 /// Print the question in the requested state.
-    $attemptobj->print_question($questionid);
+    if ($stateid) {
+        $baseurl .= '&amp;state=' . $stateid;
+    }
+    $attemptobj->print_question($questionid, true, $baseurl);
 
 /// Finish the page
     print_footer();
index b8610110a417221ca16e893258a64057ecfcd2c4..e1f48459f975ae1d37ab7136251be1e828b5d7ef 100644 (file)
 
     // 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) {
index 36acbdd4693cbce50886df844803e0a14a0f2d32..dd948045c7fb7d1f62f0c0865273d4f6be252576 100644 (file)
@@ -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 = '&amp;cmid='.$cm->id;
-        } else if (!empty($cmoptions->course)) {
-            $cmorcourseid = '&amp;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 = '<img src="'.$CFG->pixpath.'/t/edit.gif" alt="'.$stredit.'" />';
-            $editlink = link_to_popup_window('/question/question.php?inpopup=1&amp;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);
index 12154dc84e58ccf6ef64968db25b4708acb58899..13e19ab160f79f53d05fd5a80d2a37197e601554 100644 (file)
@@ -3,7 +3,7 @@
  * print_question() method.
  */
 ?>
-<div id="q<?php echo $question->id; ?>" class="que <?php echo $question->qtype; ?> clearfix">
+<div id="q<?php echo $actualquestionid; ?>" class="que <?php echo $question->qtype; ?> clearfix">
   <div class="info">
     <h2 class="no"><span class="accesshide">Question </span><?php echo $number;
     if ($editlink) { ?>
index 8b5f11e7dd82701996a1042794f154d9735da232..811e93d79481b1918cc906abf9c0018a0422080d 100644 (file)
@@ -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 = '&amp;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 = '&amp;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 = '<img src="'.$CFG->pixpath.'/t/edit.gif" alt="'.$stredit.'" />';
-            $editlink = link_to_popup_window('/question/question.php?inpopup=1&amp;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 = '<div class="commentlink">'.link_to_popup_window ($options->questioncommentlink.'?attempt='.$state->attempt.'&amp;question='.$question_to_comment,
-                             'commentquestion', $strcomment, 450, 650, $strcomment, 'none', true).'</div>';
+            $commentlink = link_to_popup_window($options->questioncommentlink .
+                    '?attempt=' . $state->attempt . '&amp;question=' . $actualquestionid,
+                    'commentquestion', $strcomment, 450, 650, $strcomment, 'none', true);
+            $commentlink = '<div class="commentlink">'. $commentlink .'</div>';
         }
 
         $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 .= '&amp;cmid=' . $cmoptions->id;
+        } else if (!empty($cmoptions->course)) {
+            $linkurl .= '&amp;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 = '<img src="' . $CFG->pixpath . '/t/edit.gif" alt="' . $stredit . '" />';
+
+        if (!empty($cmoptions->thispageurl)) {
+        /// The module allow editing in the same window, print an ordinary link.
+            return '<a href="' . $CFG->wwwroot . $linkurl . '&amp;returnurl=' . urlencode($cmoptions->thispageurl) .
+                    '" title="' . $stredit . '">' . $linktext . '</a>';
+        } else {
+        /// We have to edit in a pop-up.
+            return link_to_popup_window($linkurl . '&amp;inpopup=1', 'editquestion',
+                    $linktext, false, false, $stredit, '', true);
+        }
+    }
+
     /**
      * Print history of responses
      *