MDL-20636 Fix @package names and PHPdoc layout.
[moodle.git] / question / type / randomsamatch / edit_randomsamatch_form.php
CommitLineData
aeb15530 1<?php
d3603157
TH
2
3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17
08224df1 18/**
19 * Defines the editing form for the randomsamatch question type.
20 *
b04a4319
TH
21 * @package qtype
22 * @subpackage randomsamatch
23 * @copyright 2007 Jamie Pratt me@jamiep.org
24 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
08224df1 25 */
26
d3603157 27
08224df1 28/**
29 * randomsamatch editing form definition.
b04a4319
TH
30 *
31 * @copyright 2007 Jamie Pratt me@jamiep.org
32 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
08224df1 33 */
34class question_edit_randomsamatch_form extends question_edit_form {
35 /**
36 * Add question-type specific form fields.
37 *
38 * @param MoodleQuickForm $mform the form being built.
39 */
40 function definition_inner(&$mform) {
08224df1 41 $questionstoselect = array();
42 for ($i=2; $i<=QUESTION_NUMANS; $i++){
43 $questionstoselect[$i] = $i;
44 }
45
46 $mform->addElement('select', 'choose', get_string("randomsamatchnumber", "quiz"), $questionstoselect);
47 $mform->setType('feedback', PARAM_RAW);
48
49 $mform->addElement('hidden', 'fraction', 0);
d18e0fe6 50 $mform->setType('fraction', PARAM_RAW);
08224df1 51 }
52
fe6ce234 53 function data_preprocessing($question) {
08224df1 54 if (empty($question->name)) {
55 $question->name = get_string("randomsamatch", "quiz");
56 }
57
58 if (empty($question->questiontext)) {
fe6ce234 59 $question->questiontext = get_string("randomsamatchintro", "quiz");
08224df1 60 }
fe6ce234 61 return $question;
08224df1 62 }
63
64 function qtype() {
65 return 'randomsamatch';
66 }
67
a78890d5 68 function validation($data, $files) {
f34488b2 69 global $QTYPES, $DB;
fe93ba83 70 $errors = parent::validation($data, $files);
5e581dd4 71 if (isset($data->categorymoveto)) {
72 list($category) = explode(',', $data['categorymoveto']);
73 } else {
74 list($category) = explode(',', $data['category']);
c958ac93 75 }
c958ac93 76 $saquestions = $QTYPES['randomsamatch']->get_sa_candidates($category);
08224df1 77 $numberavailable = count($saquestions);
78 if ($saquestions === false){
7f389342 79 $a = new stdClass();
f34488b2 80 $a->catname = $DB->get_field('question_categories', 'name', array('id' => $category));
08224df1 81 $errors['choose'] = get_string('nosaincategory', 'qtype_randomsamatch', $a);
82
83 } elseif ($numberavailable < $data['choose']){
7f389342 84 $a = new stdClass();
f34488b2 85 $a->catname = $DB->get_field('question_categories', 'name', array('id' => $category));
08224df1 86 $a->nosaquestions = $numberavailable;
87 $errors['choose'] = get_string('notenoughsaincategory', 'qtype_randomsamatch', $a);
88 }
89 return $errors;
08224df1 90 }
08224df1 91}