MDL-20636 Fix new stdClass -> stdClass(), and trailing whitespace.
[moodle.git] / question / type / randomsamatch / edit_randomsamatch_form.php
CommitLineData
aeb15530 1<?php
08224df1 2/**
3 * Defines the editing form for the randomsamatch question type.
4 *
b04a4319
TH
5 * @package qtype
6 * @subpackage randomsamatch
7 * @copyright 2007 Jamie Pratt me@jamiep.org
8 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
08224df1 9 */
10
11/**
12 * randomsamatch editing form definition.
b04a4319
TH
13 *
14 * @copyright 2007 Jamie Pratt me@jamiep.org
15 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
08224df1 16 */
17class question_edit_randomsamatch_form extends question_edit_form {
18 /**
19 * Add question-type specific form fields.
20 *
21 * @param MoodleQuickForm $mform the form being built.
22 */
23 function definition_inner(&$mform) {
08224df1 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);
d18e0fe6 33 $mform->setType('fraction', PARAM_RAW);
08224df1 34 }
35
fe6ce234 36 function data_preprocessing($question) {
08224df1 37 if (empty($question->name)) {
38 $question->name = get_string("randomsamatch", "quiz");
39 }
40
41 if (empty($question->questiontext)) {
fe6ce234 42 $question->questiontext = get_string("randomsamatchintro", "quiz");
08224df1 43 }
fe6ce234 44 return $question;
08224df1 45 }
46
47 function qtype() {
48 return 'randomsamatch';
49 }
50
a78890d5 51 function validation($data, $files) {
f34488b2 52 global $QTYPES, $DB;
fe93ba83 53 $errors = parent::validation($data, $files);
5e581dd4 54 if (isset($data->categorymoveto)) {
55 list($category) = explode(',', $data['categorymoveto']);
56 } else {
57 list($category) = explode(',', $data['category']);
c958ac93 58 }
c958ac93 59 $saquestions = $QTYPES['randomsamatch']->get_sa_candidates($category);
08224df1 60 $numberavailable = count($saquestions);
61 if ($saquestions === false){
7f389342 62 $a = new stdClass();
f34488b2 63 $a->catname = $DB->get_field('question_categories', 'name', array('id' => $category));
08224df1 64 $errors['choose'] = get_string('nosaincategory', 'qtype_randomsamatch', $a);
65
66 } elseif ($numberavailable < $data['choose']){
7f389342 67 $a = new stdClass();
f34488b2 68 $a->catname = $DB->get_field('question_categories', 'name', array('id' => $category));
08224df1 69 $a->nosaquestions = $numberavailable;
70 $errors['choose'] = get_string('notenoughsaincategory', 'qtype_randomsamatch', $a);
71 }
72 return $errors;
08224df1 73 }
08224df1 74}