Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/feedback/edit_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 
00025 //It must be included from a Moodle page
00026 if (!defined('MOODLE_INTERNAL')) {
00027     die('Direct access to this script is forbidden.');
00028 }
00029 
00030 require_once($CFG->libdir.'/formslib.php');
00031 
00032 class feedback_edit_add_question_form extends moodleform {
00033     public function definition() {
00034         $mform =& $this->_form;
00035 
00036         //headline
00037         $mform->addElement('header', 'general', get_string('add_items', 'feedback'));
00038         // visible elements
00039         $feedback_names_options = feedback_load_feedback_items_options();
00040 
00041         $attributes = 'onChange="this.form.submit()"';
00042         $mform->addElement('select', 'typ', '', $feedback_names_options, $attributes);
00043 
00044         // hidden elements
00045         $mform->addElement('hidden', 'cmid');
00046         $mform->setType('cmid', PARAM_INT);
00047         $mform->addElement('hidden', 'position');
00048         $mform->setType('position', PARAM_INT);
00049 
00050         // buttons
00051         $mform->addElement('submit', 'add_item', get_string('add_item', 'feedback'));
00052     }
00053 }
00054 
00055 class feedback_edit_use_template_form extends moodleform {
00056     private $feedbackdata;
00057 
00058     public function definition() {
00059         $this->feedbackdata = new stdClass();
00060         //this function can not be called, because not all data are available at this time
00061         //I use set_form_elements instead
00062     }
00063 
00064     //this function set the data used in set_form_elements()
00065     //in this form the only value have to set is course
00066     //eg: array('course' => $course)
00067     public function set_feedbackdata($data) {
00068         if (is_array($data)) {
00069             foreach ($data as $key => $val) {
00070                 $this->feedbackdata->{$key} = $val;
00071             }
00072         }
00073     }
00074 
00075     //here the elements will be set
00076     //this function have to be called manually
00077     //the advantage is that the data are already set
00078     public function set_form_elements() {
00079         $mform =& $this->_form;
00080 
00081         $elementgroup = array();
00082         //headline
00083         $mform->addElement('header', '', get_string('using_templates', 'feedback'));
00084         // hidden elements
00085         $mform->addElement('hidden', 'id');
00086         $mform->setType('id', PARAM_INT);
00087 
00088         // visible elements
00089         $templates_options = array();
00090         $owntemplates = feedback_get_template_list($this->feedbackdata->course, 'own');
00091         $publictemplates = feedback_get_template_list($this->feedbackdata->course, 'public');
00092 
00093         $options = array();
00094         if ($owntemplates or $publictemplates) {
00095             $options[''] = array('' => get_string('choose'));
00096 
00097             if ($owntemplates) {
00098                 $courseoptions = array();
00099                 foreach ($owntemplates as $template) {
00100                     $courseoptions[$template->id] = $template->name;
00101                 }
00102                 $options[get_string('course')] = $courseoptions;
00103             }
00104 
00105             if ($publictemplates) {
00106                 $publicoptions = array();
00107                 foreach ($publictemplates as $template) {
00108                     $publicoptions[$template->id] = $template->name;
00109                 }
00110                 $options[get_string('public', 'feedback')] = $publicoptions;
00111             }
00112 
00113             $attributes = 'onChange="this.form.submit()"';
00114             $elementgroup[] =& $mform->createElement('selectgroups',
00115                                                      'templateid',
00116                                                      '',
00117                                                      $options,
00118                                                      $attributes);
00119 
00120             $elementgroup[] =& $mform->createElement('submit',
00121                                                      'use_template',
00122                                                      get_string('use_this_template', 'feedback'));
00123         } else {
00124             $mform->addElement('static', 'info', get_string('no_templates_available_yet', 'feedback'));
00125         }
00126         $mform->addGroup($elementgroup, 'elementgroup', '', array(' '), false);
00127 
00128     }
00129 }
00130 
00131 class feedback_edit_create_template_form extends moodleform {
00132     private $feedbackdata;
00133 
00134     public function definition() {
00135     }
00136 
00137     public function data_preprocessing(&$default_values) {
00138         $default_values['templatename'] = '';
00139     }
00140 
00141     public function set_feedbackdata($data) {
00142         if (is_array($data)) {
00143             foreach ($data as $key => $val) {
00144                 $this->feedbackdata->{$key} = $val;
00145             }
00146         }
00147     }
00148 
00149     public function set_form_elements() {
00150         $mform =& $this->_form;
00151 
00152         // hidden elements
00153         $mform->addElement('hidden', 'id');
00154         $mform->setType('id', PARAM_INT);
00155         $mform->addElement('hidden', 'do_show');
00156         $mform->setType('do_show', PARAM_INT);
00157         $mform->addElement('hidden', 'savetemplate', 1);
00158         $mform->setType('savetemplate', PARAM_INT);
00159 
00160         //headline
00161         $mform->addElement('header', '', get_string('creating_templates', 'feedback'));
00162 
00163         // visible elements
00164         $elementgroup = array();
00165 
00166         $elementgroup[] =& $mform->createElement('static',
00167                                                  'templatenamelabel',
00168                                                  get_string('name', 'feedback'));
00169 
00170         $elementgroup[] =& $mform->createElement('text',
00171                                                  'templatename',
00172                                                  get_string('name', 'feedback'),
00173                                                  array('size'=>'40', 'maxlength'=>'200'));
00174 
00175         if (has_capability('mod/feedback:createpublictemplate', get_system_context())) {
00176             $elementgroup[] =& $mform->createElement('checkbox',
00177                                                      'ispublic',
00178                                                      get_string('public', 'feedback'),
00179                                                      get_string('public', 'feedback'));
00180         }
00181 
00182         // buttons
00183         $elementgroup[] =& $mform->createElement('submit',
00184                                                  'create_template',
00185                                                  get_string('save_as_new_template', 'feedback'));
00186 
00187         $mform->addGroup($elementgroup,
00188                          'elementgroup',
00189                          get_string('name', 'feedback'),
00190                          array(' '),
00191                          false);
00192 
00193         $mform->setType('templatename', PARAM_TEXT);
00194 
00195     }
00196 }
00197 
 All Data Structures Namespaces Files Functions Variables Enumerations