|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 // This file is part of Moodle - http://moodle.org/ 00003 // 00004 // Moodle is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // Moodle is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00016 00027 defined('MOODLE_INTERNAL') || die(); 00028 00029 00036 class qtype_randomsamatch_edit_form extends question_edit_form { 00037 protected function definition_inner($mform) { 00038 $questionstoselect = array(); 00039 for ($i = 2; $i <= qtype_randomsamatch::MAX_SUBQUESTIONS; $i++) { 00040 $questionstoselect[$i] = $i; 00041 } 00042 00043 $mform->addElement('select', 'choose', 00044 get_string('randomsamatchnumber', 'quiz'), $questionstoselect); 00045 $mform->setType('feedback', PARAM_RAW); 00046 00047 $mform->addElement('hidden', 'fraction', 0); 00048 $mform->setType('fraction', PARAM_RAW); 00049 } 00050 00051 protected function data_preprocessing($question) { 00052 if (empty($question->name)) { 00053 $question->name = get_string('randomsamatch', 'quiz'); 00054 } 00055 00056 if (empty($question->questiontext)) { 00057 $question->questiontext = get_string('randomsamatchintro', 'quiz'); 00058 } 00059 return $question; 00060 } 00061 00062 public function qtype() { 00063 return 'randomsamatch'; 00064 } 00065 00066 public function validation($data, $files) { 00067 global $DB; 00068 $errors = parent::validation($data, $files); 00069 if (isset($data->categorymoveto)) { 00070 list($category) = explode(',', $data['categorymoveto']); 00071 } else { 00072 list($category) = explode(',', $data['category']); 00073 } 00074 $saquestions = question_bank::get_qtype('randomsamatch')->get_sa_candidates($category); 00075 $numberavailable = count($saquestions); 00076 if ($saquestions === false) { 00077 $a = new stdClass(); 00078 $a->catname = $DB->get_field('question_categories', 'name', array('id' => $category)); 00079 $errors['choose'] = get_string('nosaincategory', 'qtype_randomsamatch', $a); 00080 00081 } else if ($numberavailable < $data['choose']) { 00082 $a = new stdClass(); 00083 $a->catname = $DB->get_field('question_categories', 'name', array('id' => $category)); 00084 $a->nosaquestions = $numberavailable; 00085 $errors['choose'] = get_string('notenoughsaincategory', 'qtype_randomsamatch', $a); 00086 } 00087 return $errors; 00088 } 00089 }