]> git.mjollnir.org Git - moodle.git/commitdiff
added function callbacks for module specific controls to question bank.
authorjamiesensei <jamiesensei>
Mon, 7 May 2007 16:57:23 +0000 (16:57 +0000)
committerjamiesensei <jamiesensei>
Mon, 7 May 2007 16:57:23 +0000 (16:57 +0000)
mod/quiz/edit.php
question/edit.php
question/editlib.php

index c9f608f72af0591c7b7a9e6a3df2b6fd454d8e25..e788e1de9ea80f5b737651aba48264d3e8603bfc 100644 (file)
     require_once("../../config.php");
     require_once($CFG->dirroot.'/mod/quiz/editlib.php');
 
-
+    /**
+     * Callback function called from question_list() function (which is called from showbank()
+     * Displays action icon as first action for each question.
+     */
+    function module_specific_actions($pageurl, $questionid, $cmid){
+        global $CFG;
+        if (has_capability("mod/quiz:manage", get_context_instance(CONTEXT_MODULE, $cmid))){
+            $straddtoquiz = get_string("addtoquiz", "quiz");
+            $out = "<a title=\"$straddtoquiz\" href=\"edit.php?".$pageurl->get_query_string()."&amp;addquestion=$questionid&amp;sesskey=".sesskey()."\"><img
+                  src=\"$CFG->pixpath/t/moveleft.gif\" alt=\"$straddtoquiz\" /></a>&nbsp;";
+            return $out;
+        } else {
+            return '';
+        }
+    }
+    /**
+     * Callback function called from question_list() function (which is called from showbank()
+     * Displays button in form with checkboxes for each question.
+     */
+    function module_specific_buttons($cmid){
+        global $THEME;
+        if (has_capability("mod/quiz:manage", get_context_instance(CONTEXT_MODULE, $cmid))){
+            $straddtoquiz = get_string("addtoquiz", "quiz");
+            $out = "<input type=\"submit\" name=\"add\" value=\"{$THEME->larrow} $straddtoquiz\" />\n";
+            $out .= '</td><td>';
+            return $out;
+        } else {
+            return '';
+        }
+    }
+    
+    
+    /**
+     * Callback function called from question_list() function (which is called from showbank()
+     * Displays button in form with checkboxes for each question.
+     */
+    function module_specific_controls($totalnumber, $recurse, $categoryid, $cmid){
+        if (has_capability("mod/quiz:manage", get_context_instance(CONTEXT_MODULE, $cmid))){
+            for ($i = 1;$i <= min(10, $totalnumber); $i++) {
+                $randomcount[$i] = $i;
+            }
+            for ($i = 20;$i <= min(100, $totalnumber); $i += 10) {
+                $randomcount[$i] = $i;
+            }
+            $out = '<br />';
+            $out .= get_string('addrandom', 'quiz', choose_from_menu($randomcount, 'randomcount', '1', '', '', '', true));
+            $out .= '<input type="hidden" name="recurse" value="'.$recurse.'" />';
+            $out .= "<input type=\"hidden\" name=\"categoryid\" value=\"$categoryid\" />";
+            $out .= ' <input type="submit" name="addrandom" value="'. get_string('add') .'" />';
+            $out .= helpbutton('random', get_string('random', 'quiz'), 'quiz', true, false, '', true);
+            return $out;
+        } else {
+            return '';
+        }
+    }       
+        
     list($thispageurl, $courseid, $cmid, $cm, $quiz, $pagevars) = question_edit_setup(true);
 
     //these params are only passed from page request to request while we stay on this page
index 790a5c5d948157cf524a000f2dfb78103a6ed4c1..1f1b0da33e4a379b1df7480e013eadbcd6503e1e 100644 (file)
@@ -10,6 +10,7 @@
 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
 * @package questionbank
 */
+
     require_once("../config.php");
     require_once("editlib.php");
 
index 904d497e788b8a45ebe8882f472b3253b5d658ec..1b28851da0d71ddd94c13c56cc34e3835bda1802 100644 (file)
@@ -191,7 +191,6 @@ function question_list($course, $pageurl, $categoryid, $cm = null,
     $straction = get_string("action");
     $strrestore = get_string('restore');
 
-    $straddtoquiz = get_string("addtoquiz", "quiz");
     $strtype = get_string("type", "quiz");
     $strcreatemultiple = get_string("createmultiple", "quiz");
     $strpreview = get_string("preview","quiz");
@@ -210,10 +209,8 @@ function question_list($course, $pageurl, $categoryid, $cm = null,
     $canedit = has_capability('moodle/question:manage', get_context_instance(CONTEXT_COURSE, $category->course));
 
     if ($cm AND $cm->modname == 'quiz') {
-        $editingquiz = has_capability("mod/quiz:manage", get_context_instance(CONTEXT_MODULE, $cm->id));
         $quizid = $cm->instance;
     } else {
-        $editingquiz = false;
         $quizid = 0;
     }
     
@@ -308,12 +305,10 @@ function question_list($course, $pageurl, $categoryid, $cm = null,
         
         echo "<tr>\n<td style=\"white-space:nowrap;\" $nameclass>\n";
         
-        // add to quiz
-        if ($editingquiz) {
-            echo "<a title=\"$straddtoquiz\" href=\"edit.php?".$pageurl->get_query_string()."&amp;addquestion=$question->id&amp;sesskey=$USER->sesskey\"><img
-                  src=\"$CFG->pixpath/t/moveleft.gif\" alt=\"$straddtoquiz\" /></a>&nbsp;";
+        if (function_exists('module_specific_actions')) {
+            echo module_specific_actions($pageurl, $question->id, $cm->id);
         }
-        
+       
         // preview
         link_to_popup_window('/question/preview.php?id=' . $question->id . '&amp;quizid=' . $quizid, 'questionpreview',
                 "<img src=\"$CFG->pixpath/t/preview.gif\" class=\"iconsmall\" alt=\"$strpreview\" />",
@@ -377,9 +372,8 @@ function question_list($course, $pageurl, $categoryid, $cm = null,
      ' <a href="javascript:deselect_all_in(\'TABLE\', null, \'categoryquestions\');">'.$strselectnone.'</a>'.
      '</td><td align="right"><b>&nbsp;'.get_string('withselected', 'quiz').':</b></td></tr><tr><td>';
 
-    if ($editingquiz) {
-        echo "<input type=\"submit\" name=\"add\" value=\"{$THEME->larrow} $straddtoquiz\" />\n";
-        echo '</td><td>';
+    if (function_exists('module_specific_buttons')) {
+        echo module_specific_buttons($cm->id);
     }
     // print delete and move selected question
     if ($canedit) {
@@ -389,20 +383,8 @@ function question_list($course, $pageurl, $categoryid, $cm = null,
     }
     echo "</td></tr></table>";
 
-    // add random question
-    if ($editingquiz) {
-        for ($i = 1;$i <= min(10, $totalnumber); $i++) {
-            $randomcount[$i] = $i;
-        }
-        for ($i = 20;$i <= min(100, $totalnumber); $i += 10) {
-            $randomcount[$i] = $i;
-        }
-        echo '<br />';
-        print_string('addrandom', 'quiz', choose_from_menu($randomcount, 'randomcount', '1', '', '', '', true));
-        echo '<input type="hidden" name="recurse" value="'.$recurse.'" />';
-        echo "<input type=\"hidden\" name=\"categoryid\" value=\"$category->id\" />";
-        echo ' <input type="submit" name="addrandom" value="'. get_string('add') .'" />';
-        helpbutton('random', get_string('random', 'quiz'), 'quiz');
+    if (function_exists('module_specific_controls')) {
+        echo module_specific_controls($totalnumber, $recurse, $category->id, $cm->id);
     }
     echo '</fieldset>';
     echo "</form>\n";