MDL-8978 - Regression from MDL-6386. Merged from MOODLE_16_STABLE.
[moodle.git] / question / type / randomsamatch / edit_randomsamatch_form.php
CommitLineData
08224df1 1<?php
2/**
3 * Defines the editing form for the randomsamatch question type.
4 *
5 * @copyright &copy; 2007 Jamie Pratt
6 * @author Jamie Pratt me@jamiep.org
7 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
8 * @package questions
9 */
10
11/**
12 * randomsamatch editing form definition.
13 */
14class question_edit_randomsamatch_form extends question_edit_form {
15 /**
16 * Add question-type specific form fields.
17 *
18 * @param MoodleQuickForm $mform the form being built.
19 */
20 function definition_inner(&$mform) {
21 $mform->removeElement('image');
22
23 $questionstoselect = array();
24 for ($i=2; $i<=QUESTION_NUMANS; $i++){
25 $questionstoselect[$i] = $i;
26 }
27
28 $mform->addElement('select', 'choose', get_string("randomsamatchnumber", "quiz"), $questionstoselect);
29 $mform->setType('feedback', PARAM_RAW);
30
31 $mform->addElement('hidden', 'fraction', 0);
32 }
33
32db0d42 34 function set_data($question) {
08224df1 35 if (empty($question->name)) {
36 $question->name = get_string("randomsamatch", "quiz");
37 }
38
39 if (empty($question->questiontext)) {
40 $question->questiontext = get_string("randomsamatchintro", "quiz");
41 }
32db0d42 42 parent::set_data($question);
08224df1 43 }
44
45 function qtype() {
46 return 'randomsamatch';
47 }
48
49 function validation($data){
50 global $QTYPES;
51 $errors = array();
52 $saquestions = $QTYPES['randomsamatch']->get_sa_candidates($data['category']);
53 $numberavailable = count($saquestions);
54 if ($saquestions === false){
55 $a = new object();
56 $a->catname = get_field('question_categories', 'name', 'id', $data['category']);
57 $errors['choose'] = get_string('nosaincategory', 'qtype_randomsamatch', $a);
58
59 } elseif ($numberavailable < $data['choose']){
60 $a = new object();
61 $a->catname = get_field('question_categories', 'name', 'id', $data['category']);
62 $a->nosaquestions = $numberavailable;
63 $errors['choose'] = get_string('notenoughsaincategory', 'qtype_randomsamatch', $a);
64 }
65 return $errors;
66
67 }
68
69}
70?>