MDL-15250 "Adding a new function quiz_question_action_icons that outputs a string...
authorjamiesensei <jamiesensei>
Sun, 15 Jun 2008 11:52:07 +0000 (11:52 +0000)
committerjamiesensei <jamiesensei>
Sun, 15 Jun 2008 11:52:07 +0000 (11:52 +0000)
mod/quiz/editlib.php
mod/quiz/locallib.php

index aeee04b52e1bffd041574a1766b4fc4d00b042a7..db2937a87c61c80c6047594b947d0e174859db88 100644 (file)
@@ -142,8 +142,6 @@ function quiz_print_question_list($quiz, $pageurl, $allowdelete=true, $showbreak
     $strquestionname = get_string("questionname", "quiz");
     $strgrade = get_string("grade");
     $strremove = get_string('remove', 'quiz');
-    $stredit = get_string("edit");
-    $strview = get_string("view");
     $straction = get_string("action");
     $strmoveup = get_string("moveup");
     $strmovedown = get_string("movedown");
@@ -286,20 +284,7 @@ function quiz_print_question_list($quiz, $pageurl, $allowdelete=true, $showbreak
              '" tabindex="'.($lastindex+$qno).'" />';
         }
         echo '</td><td align="center">';
-
-        if (($question->qtype != 'random')){
-            echo quiz_question_preview_button($quiz, $question);
-        }
-        $returnurl = $pageurl->out();
-        $questionparams = array('returnurl' => $returnurl, 'cmid'=>$quiz->cmid, 'id' => $question->id);
-        $questionurl = new moodle_url("$CFG->wwwroot/question/question.php", $questionparams);
-        if (question_has_capability_on($question, 'edit', $question->category) || question_has_capability_on($question, 'move', $question->category)) {
-            echo "<a title=\"$stredit\" href=\"".$questionurl->out()."\">
-                    <img src=\"$CFG->pixpath/t/edit.gif\" class=\"iconsmall\" alt=\"$stredit\" /></a>";
-        } elseif (question_has_capability_on($question, 'view', $question->category)){
-            echo "<a title=\"$strview\" href=\"".$questionurl->out(false, array('id'=>$question->id))."\"><img
-                    src=\"$CFG->pixpath/i/info.gif\" alt=\"$strview\" /></a>&nbsp;";
-        }
+        echo quiz_question_action_icons($quiz, $quiz->cmid, $question, $pageurl->out());
         if ($allowdelete && question_has_capability_on($question, 'use', $question->category)) { // remove from quiz, not question delete.
             echo "<a title=\"$strremove\" href=\"".$pageurl->out_action(array('delete'=>$count))."\">
                     <img src=\"$CFG->pixpath/t/$movearrow\" class=\"iconsmall\" alt=\"$strremove\" /></a>";
index 238c1bed3fee588d9065524e43474cd4d593630d..dd09695cdc7e35b246a5d86ff2664fa0311faf0f 100644 (file)
@@ -710,6 +710,39 @@ function quiz_upgrade_states($attempt) {
         }
     }
 }
+/**
+ * Function that can be used in various parts of the quiz code.
+ * @param object $quiz
+ * @param integer $cmid
+ * @param object $question
+ * @param string $returnurl url to return to after action is done.
+ * @return string html for a number of icons linked to action pages for a
+ * question - preview and edit / view icons depending on user capabilities.
+ */
+function quiz_question_action_icons($quiz, $cmid, $question, $returnurl){
+    global $CFG;
+    static $stredit = null;
+    static $strview = null;
+    if ($stredit === null){
+        $stredit = get_string('edit');
+        $strview = get_string('view');
+    }
+    $html =''; 
+    if (($question->qtype != 'random')){
+        $html .= quiz_question_preview_button($quiz, $question);
+    }
+    $questionparams = array('returnurl' => $returnurl, 'cmid'=>$cmid, 'id' => $question->id);
+    $questionurl = new moodle_url("$CFG->wwwroot/question/question.php", $questionparams);
+    if (question_has_capability_on($question, 'edit', $question->category) || question_has_capability_on($question, 'move', $question->category)) {
+        $html .= "<a title=\"$stredit\" href=\"".$questionurl->out()."\">
+                <img src=\"$CFG->pixpath/t/edit.gif\" class=\"iconsmall\" alt=\"$stredit\" /></a>";
+    } elseif (question_has_capability_on($question, 'view', $question->category)){
+        $html .= "<a title=\"$strview\" href=\"".$questionurl->out(false, array('id'=>$question->id))."\"><img
+                src=\"$CFG->pixpath/i/info.gif\" alt=\"$strview\" /></a>&nbsp;";
+    }
+    return $html;
+}
+
 
 /**
  * @param object $quiz the quiz