|
Moodle
2.2.1
http://www.collinsharper.com
|
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_multichoice_form extends feedback_item_form { 00020 protected $type = "multichoice"; 00021 00022 public function definition() { 00023 $item = $this->_customdata['item']; 00024 $common = $this->_customdata['common']; 00025 $positionlist = $this->_customdata['positionlist']; 00026 $position = $this->_customdata['position']; 00027 00028 $mform =& $this->_form; 00029 00030 $mform->addElement('header', 'general', get_string($this->type, 'feedback')); 00031 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, 00038 'maxlength' => 255)); 00039 00040 $mform->addElement('text', 00041 'label', 00042 get_string('item_label', 'feedback'), 00043 array('size' => FEEDBACK_ITEM_LABEL_TEXTBOX_SIZE, 00044 'maxlength' => 255)); 00045 00046 $mform->addElement('select', 00047 'horizontal', 00048 get_string('adjustment', 'feedback').' ', 00049 array(0 => get_string('vertical', 'feedback'), 00050 1 => get_string('horizontal', 'feedback'))); 00051 00052 $mform->addElement('select', 00053 'subtype', 00054 get_string('multichoicetype', 'feedback').' ', 00055 array('r'=>get_string('radio', 'feedback'), 00056 'c'=>get_string('check', 'feedback'), 00057 'd'=>get_string('dropdown', 'feedback'))); 00058 00059 $mform->addElement('selectyesno', 00060 'ignoreempty', 00061 get_string('do_not_analyse_empty_submits', 'feedback')); 00062 00063 $mform->addElement('selectyesno', 00064 'hidenoselect', 00065 get_string('hide_no_select_option', 'feedback')); 00066 00067 $mform->addElement('static', 00068 'hint', 00069 get_string('multichoice_values', 'feedback'), 00070 get_string('use_one_line_for_each_value', 'feedback')); 00071 00072 $mform->addElement('textarea', 'values', '', 'wrap="virtual" rows="10" cols="65"'); 00073 00074 parent::definition(); 00075 $this->set_data($item); 00076 00077 } 00078 00079 public function set_data($item) { 00080 $info = $this->_customdata['info']; 00081 00082 $item->horizontal = $info->horizontal; 00083 00084 $item->subtype = $info->subtype; 00085 00086 $itemvalues = str_replace(FEEDBACK_MULTICHOICE_LINE_SEP, "\n", $info->presentation); 00087 $itemvalues = str_replace("\n\n", "\n", $itemvalues); 00088 $item->values = $itemvalues; 00089 00090 return parent::set_data($item); 00091 } 00092 00093 public function get_data() { 00094 if (!$item = parent::get_data()) { 00095 return false; 00096 } 00097 00098 $presentation = str_replace("\n", FEEDBACK_MULTICHOICE_LINE_SEP, trim($item->values)); 00099 if (!isset($item->subtype)) { 00100 $subtype = 'r'; 00101 } else { 00102 $subtype = substr($item->subtype, 0, 1); 00103 } 00104 if (isset($item->horizontal) AND $item->horizontal == 1 AND $subtype != 'd') { 00105 $presentation .= FEEDBACK_MULTICHOICE_ADJUST_SEP.'1'; 00106 } 00107 00108 $item->presentation = $subtype.FEEDBACK_MULTICHOICE_TYPE_SEP.$presentation; 00109 return $item; 00110 } 00111 }