Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/feedback/item/numeric/numeric_form.php
Go to the documentation of this file.
00001 <?php
00002 // This file is part of Moodle - http://moodle.org/
00003 //
00004 // Moodle is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // Moodle is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_form_class.php');
00018 
00019 class feedback_numeric_form extends feedback_item_form {
00020     protected $type = "numeric";
00021 
00022     public function definition() {
00023 
00024         $item = $this->_customdata['item'];
00025         $common = $this->_customdata['common'];
00026         $positionlist = $this->_customdata['positionlist'];
00027         $position = $this->_customdata['position'];
00028 
00029         $mform =& $this->_form;
00030 
00031         $mform->addElement('header', 'general', get_string($this->type, 'feedback'));
00032         $mform->addElement('checkbox', 'required', get_string('required', 'feedback'));
00033 
00034         $mform->addElement('text',
00035                             'name',
00036                             get_string('item_name', 'feedback'),
00037                             array('size'=>FEEDBACK_ITEM_NAME_TEXTBOX_SIZE, 'maxlength'=>255));
00038         $mform->addElement('text',
00039                             'label',
00040                             get_string('item_label', 'feedback'),
00041                             array('size'=>FEEDBACK_ITEM_LABEL_TEXTBOX_SIZE, 'maxlength'=>255));
00042 
00043         $mform->addElement('text',
00044                             'rangefrom',
00045                             get_string('numeric_range_from', 'feedback'),
00046                             array('size'=>10, 'maxlength'=>10));
00047 
00048         $mform->addElement('text',
00049                             'rangeto',
00050                             get_string('numeric_range_to', 'feedback'),
00051                             array('size'=>10, 'maxlength'=>10));
00052 
00053         parent::definition();
00054         $this->set_data($item);
00055 
00056     }
00057 
00058     public function get_data() {
00059         if (!$item = parent::get_data()) {
00060             return false;
00061         }
00062 
00063         $itemobj = new feedback_item_numeric();
00064 
00065         $num1 = str_replace($itemobj->sep_dec, FEEDBACK_DECIMAL, $item->rangefrom);
00066         if (is_numeric($num1)) {
00067             $num1 = floatval($num1);
00068         } else {
00069             $num1 = '-';
00070         }
00071 
00072         $num2 = str_replace($itemobj->sep_dec, FEEDBACK_DECIMAL, $item->rangeto);
00073         if (is_numeric($num2)) {
00074             $num2 = floatval($num2);
00075         } else {
00076             $num2 = '-';
00077         }
00078 
00079         if ($num1 === '-' OR $num2 === '-') {
00080             $item->presentation = $num1 . '|'. $num2;
00081             return $item;
00082         }
00083 
00084         if ($num1 > $num2) {
00085             $item->presentation =  $num2 . '|'. $num1;
00086         } else {
00087             $item->presentation = $num1 . '|'. $num2;
00088         }
00089         return $item;
00090     }
00091 
00092 }
 All Data Structures Namespaces Files Functions Variables Enumerations