MDL-15094 fixed stats
[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
830e47a8 8 * @package questionbank
9 * @subpackage questiontypes
08224df1 10 */
11
12/**
13 * randomsamatch editing form definition.
14 */
15class question_edit_randomsamatch_form extends question_edit_form {
16 /**
17 * Add question-type specific form fields.
18 *
19 * @param MoodleQuickForm $mform the form being built.
20 */
21 function definition_inner(&$mform) {
22 $mform->removeElement('image');
23
24 $questionstoselect = array();
25 for ($i=2; $i<=QUESTION_NUMANS; $i++){
26 $questionstoselect[$i] = $i;
27 }
28
29 $mform->addElement('select', 'choose', get_string("randomsamatchnumber", "quiz"), $questionstoselect);
30 $mform->setType('feedback', PARAM_RAW);
31
32 $mform->addElement('hidden', 'fraction', 0);
33 }
34
32db0d42 35 function set_data($question) {
08224df1 36 if (empty($question->name)) {
37 $question->name = get_string("randomsamatch", "quiz");
38 }
39
40 if (empty($question->questiontext)) {
41 $question->questiontext = get_string("randomsamatchintro", "quiz");
42 }
32db0d42 43 parent::set_data($question);
08224df1 44 }
45
46 function qtype() {
47 return 'randomsamatch';
48 }
49
a78890d5 50 function validation($data, $files) {
08224df1 51 global $QTYPES;
fe93ba83 52 $errors = parent::validation($data, $files);
c958ac93 53 if (isset($data['usecurrentcat'])){
54 $category = $data['category'];
55 }else{
56 $category = $data['categorymoveto'];
57 }
58
59 $saquestions = $QTYPES['randomsamatch']->get_sa_candidates($category);
08224df1 60 $numberavailable = count($saquestions);
61 if ($saquestions === false){
62 $a = new object();
c958ac93 63 $a->catname = get_field('question_categories', 'name', 'id', $category);
08224df1 64 $errors['choose'] = get_string('nosaincategory', 'qtype_randomsamatch', $a);
65
66 } elseif ($numberavailable < $data['choose']){
67 $a = new object();
c958ac93 68 $a->catname = get_field('question_categories', 'name', 'id', $category);
08224df1 69 $a->nosaquestions = $numberavailable;
70 $errors['choose'] = get_string('notenoughsaincategory', 'qtype_randomsamatch', $a);
71 }
72 return $errors;
73
74 }
75
76}
77?>