[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Defines the custom question bank view used on the Edit quiz page. 19 * 20 * @package mod_quiz 21 * @category question 22 * @copyright 1999 onwards Martin Dougiamas and others {@link http://moodle.com} 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 namespace mod_quiz\question\bank; 27 defined('MOODLE_INTERNAL') || die(); 28 29 30 /** 31 * Subclass to customise the view of the question bank for the quiz editing screen. 32 * 33 * @copyright 2009 Tim Hunt 34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 35 */ 36 class custom_view extends \core_question\bank\view { 37 /** @var bool whether the quiz this is used by has been attemptd. */ 38 protected $quizhasattempts = false; 39 /** @var \stdClass the quiz settings. */ 40 protected $quiz = false; 41 /** @var int The maximum displayed length of the category info. */ 42 const MAX_TEXT_LENGTH = 200; 43 44 /** 45 * Constructor 46 * @param \question_edit_contexts $contexts 47 * @param \moodle_url $pageurl 48 * @param \stdClass $course course settings 49 * @param \stdClass $cm activity settings. 50 * @param \stdClass $quiz quiz settings. 51 */ 52 public function __construct($contexts, $pageurl, $course, $cm, $quiz) { 53 parent::__construct($contexts, $pageurl, $course, $cm); 54 $this->quiz = $quiz; 55 } 56 57 protected function wanted_columns() { 58 global $CFG; 59 60 if (empty($CFG->quizquestionbankcolumns)) { 61 $quizquestionbankcolumns = array( 62 'add_action_column', 63 'checkbox_column', 64 'question_type_column', 65 'question_name_text_column', 66 'preview_action_column', 67 ); 68 } else { 69 $quizquestionbankcolumns = explode(',', $CFG->quizquestionbankcolumns); 70 } 71 72 foreach ($quizquestionbankcolumns as $fullname) { 73 if (!class_exists($fullname)) { 74 if (class_exists('mod_quiz\\question\\bank\\' . $fullname)) { 75 $fullname = 'mod_quiz\\question\\bank\\' . $fullname; 76 } else if (class_exists('core_question\\bank\\' . $fullname)) { 77 $fullname = 'core_question\\bank\\' . $fullname; 78 } else if (class_exists('question_bank_' . $fullname)) { 79 debugging('Legacy question bank column class question_bank_' . 80 $fullname . ' should be renamed to mod_quiz\\question\\bank\\' . 81 $fullname, DEBUG_DEVELOPER); 82 $fullname = 'question_bank_' . $fullname; 83 } else { 84 throw new coding_exception("No such class exists: $fullname"); 85 } 86 } 87 $this->requiredcolumns[$fullname] = new $fullname($this); 88 } 89 return $this->requiredcolumns; 90 } 91 92 /** 93 * Specify the column heading 94 * 95 * @return string Column name for the heading 96 */ 97 protected function heading_column() { 98 return 'mod_quiz\\question\\bank\\question_name_text_column'; 99 } 100 101 protected function default_sort() { 102 return array( 103 'core_question\\bank\\question_type_column' => 1, 104 'mod_quiz\\question\\bank\\question_name_text_column' => 1, 105 ); 106 } 107 108 /** 109 * Let the question bank display know whether the quiz has been attempted, 110 * hence whether some bits of UI, like the add this question to the quiz icon, 111 * should be displayed. 112 * @param bool $quizhasattempts whether the quiz has attempts. 113 */ 114 public function set_quiz_has_attempts($quizhasattempts) { 115 $this->quizhasattempts = $quizhasattempts; 116 if ($quizhasattempts && isset($this->visiblecolumns['addtoquizaction'])) { 117 unset($this->visiblecolumns['addtoquizaction']); 118 } 119 } 120 121 public function preview_question_url($question) { 122 return quiz_question_preview_url($this->quiz, $question); 123 } 124 125 public function add_to_quiz_url($questionid) { 126 global $CFG; 127 $params = $this->baseurl->params(); 128 $params['addquestion'] = $questionid; 129 $params['sesskey'] = sesskey(); 130 return new \moodle_url('/mod/quiz/edit.php', $params); 131 } 132 133 /** 134 * Renders the html question bank (same as display, but returns the result). 135 * 136 * Note that you can only output this rendered result once per page, as 137 * it contains IDs which must be unique. 138 * 139 * @return string HTML code for the form 140 */ 141 public function render($tabname, $page, $perpage, $cat, $recurse, $showhidden, $showquestiontext) { 142 ob_start(); 143 $this->display($tabname, $page, $perpage, $cat, $recurse, $showhidden, $showquestiontext); 144 $out = ob_get_contents(); 145 ob_end_clean(); 146 return $out; 147 } 148 149 /** 150 * Display the controls at the bottom of the list of questions. 151 * @param int $totalnumber Total number of questions that might be shown (if it was not for paging). 152 * @param bool $recurse Whether to include subcategories. 153 * @param \stdClass $category The question_category row from the database. 154 * @param \context $catcontext The context of the category being displayed. 155 * @param array $addcontexts contexts where the user is allowed to add new questions. 156 */ 157 protected function display_bottom_controls($totalnumber, $recurse, $category, \context $catcontext, array $addcontexts) { 158 $cmoptions = new \stdClass(); 159 $cmoptions->hasattempts = !empty($this->quizhasattempts); 160 161 $canuseall = has_capability('moodle/question:useall', $catcontext); 162 163 echo '<div class="modulespecificbuttonscontainer">'; 164 if ($canuseall) { 165 166 // Add selected questions to the quiz. 167 $params = array( 168 'type' => 'submit', 169 'name' => 'add', 170 'value' => get_string('addselectedquestionstoquiz', 'quiz'), 171 ); 172 if ($cmoptions->hasattempts) { 173 $params['disabled'] = 'disabled'; 174 } 175 echo \html_writer::empty_tag('input', $params); 176 } 177 echo "</div>\n"; 178 } 179 180 /** 181 * Prints a form to choose categories. 182 * @param string $categoryandcontext 'categoryID,contextID'. 183 * @deprecated since Moodle 2.6 MDL-40313. 184 * @see \core_question\bank\search\category_condition 185 * @todo MDL-41978 This will be deleted in Moodle 2.8 186 */ 187 protected function print_choose_category_message($categoryandcontext) { 188 global $OUTPUT; 189 debugging('print_choose_category_message() is deprecated, ' . 190 'please use \core_question\bank\search\category_condition instead.', DEBUG_DEVELOPER); 191 echo $OUTPUT->box_start('generalbox questionbank'); 192 $this->display_category_form($this->contexts->having_one_edit_tab_cap('edit'), 193 $this->baseurl, $categoryandcontext); 194 echo "<p style=\"text-align:center;\"><b>"; 195 print_string('selectcategoryabove', 'question'); 196 echo "</b></p>"; 197 echo $OUTPUT->box_end(); 198 } 199 200 protected function display_options_form($showquestiontext, $scriptpath = '/mod/quiz/edit.php', 201 $showtextoption = false) { 202 // Overridden just to change the default values of the arguments. 203 parent::display_options_form($showquestiontext, $scriptpath, $showtextoption); 204 } 205 206 protected function print_category_info($category) { 207 $formatoptions = new stdClass(); 208 $formatoptions->noclean = true; 209 $strcategory = get_string('category', 'quiz'); 210 echo '<div class="categoryinfo"><div class="categorynamefieldcontainer">' . 211 $strcategory; 212 echo ': <span class="categorynamefield">'; 213 echo shorten_text(strip_tags(format_string($category->name)), 60); 214 echo '</span></div><div class="categoryinfofieldcontainer">' . 215 '<span class="categoryinfofield">'; 216 echo shorten_text(strip_tags(format_text($category->info, $category->infoformat, 217 $formatoptions, $this->course->id)), 200); 218 echo '</span></div></div>'; 219 } 220 221 protected function display_options($recurse, $showhidden, $showquestiontext) { 222 debugging('display_options() is deprecated, see display_options_form() instead.', DEBUG_DEVELOPER); 223 echo '<form method="get" action="edit.php" id="displayoptions">'; 224 echo "<fieldset class='invisiblefieldset'>"; 225 echo \html_writer::input_hidden_params($this->baseurl, 226 array('recurse', 'showhidden', 'qbshowtext')); 227 $this->display_category_form_checkbox('recurse', $recurse, 228 get_string('includesubcategories', 'question')); 229 $this->display_category_form_checkbox('showhidden', $showhidden, 230 get_string('showhidden', 'question')); 231 echo '<noscript><div class="centerpara"><input type="submit" value="' . 232 get_string('go') . '" />'; 233 echo '</div></noscript></fieldset></form>'; 234 } 235 236 protected function create_new_question_form($category, $canadd) { 237 // Don't display this. 238 } 239 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |