Merge branch 'MDL-27675_master' of git://github.com/grabs/moodle
[moodle.git] / mod / feedback / item / numeric / numeric_form.php
CommitLineData
6ee09cfe 1<?php
9c5bc7a5
AG
2// This file is part of Moodle - http://moodle.org/
3//
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.
8//
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.
13//
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/>.
6ee09cfe 16
a627a9c1 17require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_form_class.php');
6ee09cfe 18
a627a9c1 19class feedback_numeric_form extends feedback_item_form {
9c5bc7a5
AG
20 protected $type = "numeric";
21
22 public function definition() {
1adbd2c3 23
271fdd62
AG
24 $item = $this->_customdata['item'];
25 $common = $this->_customdata['common'];
26 $positionlist = $this->_customdata['positionlist'];
27 $position = $this->_customdata['position'];
9c5bc7a5 28
6ee09cfe 29 $mform =& $this->_form;
1adbd2c3 30
6ee09cfe 31 $mform->addElement('header', 'general', get_string($this->type, 'feedback'));
271fdd62 32 $mform->addElement('checkbox', 'required', get_string('required', 'feedback'));
1adbd2c3 33
af26e345
AG
34 $mform->addElement('text',
35 'name',
36 get_string('item_name', 'feedback'),
37 array('size'=>FEEDBACK_ITEM_NAME_TEXTBOX_SIZE, 'maxlength'=>255));
38 $mform->addElement('text',
39 'label',
40 get_string('item_label', 'feedback'),
41 array('size'=>FEEDBACK_ITEM_LABEL_TEXTBOX_SIZE, 'maxlength'=>255));
42
43 $mform->addElement('text',
44 'rangefrom',
45 get_string('numeric_range_from', 'feedback'),
46 array('size'=>10, 'maxlength'=>10));
47
48 $mform->addElement('text',
49 'rangeto',
50 get_string('numeric_range_to', 'feedback'),
9c5bc7a5 51 array('size'=>10, 'maxlength'=>10));
6ee09cfe 52
5e97c34d 53 parent::definition();
271fdd62 54 $this->set_data($item);
51859310 55
6ee09cfe 56 }
271fdd62 57
9c5bc7a5
AG
58 public function get_data() {
59 if (!$item = parent::get_data()) {
271fdd62
AG
60 return false;
61 }
9c5bc7a5 62
271fdd62
AG
63 $itemobj = new feedback_item_numeric();
64
65 $num1 = str_replace($itemobj->sep_dec, FEEDBACK_DECIMAL, $item->rangefrom);
9c5bc7a5 66 if (is_numeric($num1)) {
271fdd62 67 $num1 = floatval($num1);
9c5bc7a5 68 } else {
271fdd62
AG
69 $num1 = '-';
70 }
71
72 $num2 = str_replace($itemobj->sep_dec, FEEDBACK_DECIMAL, $item->rangeto);
9c5bc7a5 73 if (is_numeric($num2)) {
271fdd62 74 $num2 = floatval($num2);
9c5bc7a5 75 } else {
271fdd62
AG
76 $num2 = '-';
77 }
78
9c5bc7a5 79 if ($num1 === '-' OR $num2 === '-') {
271fdd62
AG
80 $item->presentation = $num1 . '|'. $num2;
81 return $item;
82 }
83
9c5bc7a5 84 if ($num1 > $num2) {
271fdd62 85 $item->presentation = $num2 . '|'. $num1;
9c5bc7a5 86 } else {
271fdd62
AG
87 $item->presentation = $num1 . '|'. $num2;
88 }
89 return $item;
90 }
91
6ee09cfe 92}