2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * Defines the editing form for the randomsamatch question type.
21 * @subpackage randomsamatch
22 * @copyright 2007 Jamie Pratt me@jamiep.org
23 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
27 defined('MOODLE_INTERNAL') ||
die();
31 * randomsamatch editing form definition.
33 * @copyright 2007 Jamie Pratt me@jamiep.org
34 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
36 class qtype_randomsamatch_edit_form
extends question_edit_form
{
37 protected function definition_inner($mform) {
38 $questionstoselect = array();
39 for ($i = 2; $i <= qtype_randomsamatch
::MAX_SUBQUESTIONS
; $i++
) {
40 $questionstoselect[$i] = $i;
43 $mform->addElement('select', 'choose',
44 get_string('randomsamatchnumber', 'quiz'), $questionstoselect);
45 $mform->setType('feedback', PARAM_RAW
);
47 $mform->addElement('hidden', 'fraction', 0);
48 $mform->setType('fraction', PARAM_RAW
);
51 protected function data_preprocessing($question) {
52 if (empty($question->name
)) {
53 $question->name
= get_string('randomsamatch', 'quiz');
56 if (empty($question->questiontext
)) {
57 $question->questiontext
= get_string('randomsamatchintro', 'quiz');
62 public function qtype() {
63 return 'randomsamatch';
66 public function validation($data, $files) {
68 $errors = parent
::validation($data, $files);
69 if (isset($data->categorymoveto
)) {
70 list($category) = explode(',', $data['categorymoveto']);
72 list($category) = explode(',', $data['category']);
74 $saquestions = question_bank
::get_qtype('randomsamatch')->get_sa_candidates($category);
75 $numberavailable = count($saquestions);
76 if ($saquestions === false) {
78 $a->catname
= $DB->get_field('question_categories', 'name', array('id' => $category));
79 $errors['choose'] = get_string('nosaincategory', 'qtype_randomsamatch', $a);
81 } else if ($numberavailable < $data['choose']) {
83 $a->catname
= $DB->get_field('question_categories', 'name', array('id' => $category));
84 $a->nosaquestions
= $numberavailable;
85 $errors['choose'] = get_string('notenoughsaincategory', 'qtype_randomsamatch', $a);