[ 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 Moodle forum used to add random questions to the quiz. 19 * 20 * @package mod_quiz 21 * @copyright 2008 Olli Savolainen 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 26 defined('MOODLE_INTERNAL') || die(); 27 28 require_once($CFG->libdir.'/formslib.php'); 29 30 31 /** 32 * The add random questions form. 33 * 34 * @copyright 1999 onwards Martin Dougiamas and others {@link http://moodle.com} 35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 36 */ 37 class quiz_add_random_form extends moodleform { 38 39 protected function definition() { 40 global $CFG, $DB; 41 $mform =& $this->_form; 42 $mform->setDisableShortforms(); 43 44 $contexts = $this->_customdata['contexts']; 45 $usablecontexts = $contexts->having_cap('moodle/question:useall'); 46 47 // Random from existing category section. 48 $mform->addElement('header', 'categoryheader', 49 get_string('randomfromexistingcategory', 'quiz')); 50 51 $mform->addElement('questioncategory', 'category', get_string('category'), 52 array('contexts' => $usablecontexts, 'top' => false)); 53 $mform->setDefault('category', $this->_customdata['cat']); 54 55 $mform->addElement('checkbox', 'includesubcategories', '', get_string('recurse', 'quiz')); 56 57 $mform->addElement('select', 'numbertoadd', get_string('randomnumber', 'quiz'), 58 $this->get_number_of_questions_to_add_choices()); 59 60 $mform->addElement('submit', 'existingcategory', get_string('addrandomquestion', 'quiz')); 61 62 // Random from a new category section. 63 $mform->addElement('header', 'categoryheader', 64 get_string('randomquestionusinganewcategory', 'quiz')); 65 66 $mform->addElement('text', 'name', get_string('name'), 'maxlength="254" size="50"'); 67 $mform->setType('name', PARAM_TEXT); 68 69 $mform->addElement('questioncategory', 'parent', get_string('parentcategory', 'question'), 70 array('contexts' => $usablecontexts, 'top' => true)); 71 $mform->addHelpButton('parent', 'parentcategory', 'question'); 72 73 $mform->addElement('submit', 'newcategory', 74 get_string('createcategoryandaddrandomquestion', 'quiz')); 75 76 // Cancel button. 77 $mform->addElement('cancel'); 78 $mform->closeHeaderBefore('cancel'); 79 80 $mform->addElement('hidden', 'addonpage', 0, 'id="rform_qpage"'); 81 $mform->setType('addonpage', PARAM_SEQUENCE); 82 $mform->addElement('hidden', 'cmid', 0); 83 $mform->setType('cmid', PARAM_INT); 84 $mform->addElement('hidden', 'returnurl', 0); 85 $mform->setType('returnurl', PARAM_LOCALURL); 86 } 87 88 public function validation($fromform, $files) { 89 $errors = parent::validation($fromform, $files); 90 91 if (!empty($fromform['newcategory']) && trim($fromform['name']) == '') { 92 $errors['name'] = get_string('categorynamecantbeblank', 'question'); 93 } 94 95 return $errors; 96 } 97 98 /** 99 * Return an arbitrary array for the dropdown menu 100 * @return array of integers array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100) 101 */ 102 private function get_number_of_questions_to_add_choices() { 103 $maxrand = 100; 104 $randomcount = array(); 105 for ($i = 1; $i <= min(10, $maxrand); $i++) { 106 $randomcount[$i] = $i; 107 } 108 for ($i = 20; $i <= min(100, $maxrand); $i += 10) { 109 $randomcount[$i] = $i; 110 } 111 return $randomcount; 112 } 113 }
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 |