From 26a29b1ab5516f330b43faac6980eb30ed3b99e5 Mon Sep 17 00:00:00 2001 From: jamiesensei Date: Sun, 15 Jun 2008 11:52:07 +0000 Subject: [PATCH] MDL-15250 "Adding a new function quiz_question_action_icons that outputs a string of html" --- mod/quiz/editlib.php | 17 +---------------- mod/quiz/locallib.php | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/mod/quiz/editlib.php b/mod/quiz/editlib.php index aeee04b52e..db2937a87c 100644 --- a/mod/quiz/editlib.php +++ b/mod/quiz/editlib.php @@ -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 ''; - - 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 "out()."\"> - pixpath/t/edit.gif\" class=\"iconsmall\" alt=\"$stredit\" />"; - } elseif (question_has_capability_on($question, 'view', $question->category)){ - echo "out(false, array('id'=>$question->id))."\">pixpath/i/info.gif\" alt=\"$strview\" /> "; - } + 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 "out_action(array('delete'=>$count))."\"> pixpath/t/$movearrow\" class=\"iconsmall\" alt=\"$strremove\" />"; diff --git a/mod/quiz/locallib.php b/mod/quiz/locallib.php index 238c1bed3f..dd09695cdc 100644 --- a/mod/quiz/locallib.php +++ b/mod/quiz/locallib.php @@ -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 .= "out()."\"> + pixpath/t/edit.gif\" class=\"iconsmall\" alt=\"$stredit\" />"; + } elseif (question_has_capability_on($question, 'view', $question->category)){ + $html .= "out(false, array('id'=>$question->id))."\">pixpath/i/info.gif\" alt=\"$strview\" /> "; + } + return $html; +} + /** * @param object $quiz the quiz -- 2.39.5