[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 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/>. 16 17 /** 18 * prints the forms to choose an item-typ to create items and to choose a template to use 19 * 20 * @author Andreas Grabs 21 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License 22 * @package mod_feedback 23 */ 24 25 //It must be included from a Moodle page 26 if (!defined('MOODLE_INTERNAL')) { 27 die('Direct access to this script is forbidden.'); 28 } 29 30 require_once($CFG->libdir.'/formslib.php'); 31 32 class feedback_edit_use_template_form extends moodleform { 33 34 /** 35 * Form definition 36 */ 37 public function definition() { 38 $mform =& $this->_form; 39 40 $course = $this->_customdata['course']; 41 42 $elementgroup = array(); 43 //headline 44 $mform->addElement('header', 'using_templates', get_string('using_templates', 'feedback')); 45 // hidden elements 46 $mform->addElement('hidden', 'id'); 47 $mform->setType('id', PARAM_INT); 48 49 // visible elements 50 $templates_options = array(); 51 $owntemplates = feedback_get_template_list($course, 'own'); 52 $publictemplates = feedback_get_template_list($course, 'public'); 53 54 $options = array(); 55 if ($owntemplates or $publictemplates) { 56 $options[''] = array('' => get_string('choosedots')); 57 58 if ($owntemplates) { 59 $courseoptions = array(); 60 foreach ($owntemplates as $template) { 61 $courseoptions[$template->id] = format_string($template->name); 62 } 63 $options[get_string('course')] = $courseoptions; 64 } 65 66 if ($publictemplates) { 67 $publicoptions = array(); 68 foreach ($publictemplates as $template) { 69 $publicoptions[$template->id] = format_string($template->name); 70 } 71 $options[get_string('public', 'feedback')] = $publicoptions; 72 } 73 74 $attributes = 'onChange="M.core_formchangechecker.set_form_submitted(); this.form.submit()"'; 75 $elementgroup[] = $mform->createElement('selectgroups', 76 'templateid', 77 get_string('using_templates', 'feedback'), 78 $options, 79 $attributes); 80 81 $elementgroup[] = $mform->createElement('submit', 82 'use_template', 83 get_string('use_this_template', 'feedback'), 84 array('class' => 'hiddenifjs')); 85 86 $mform->addGroup($elementgroup, 'elementgroup', '', array(' '), false); 87 } else { 88 $mform->addElement('static', 'info', get_string('no_templates_available_yet', 'feedback')); 89 } 90 91 $this->set_data(array('id' => $this->_customdata['id'])); 92 } 93 } 94 95 class feedback_edit_create_template_form extends moodleform { 96 97 /** 98 * Form definition 99 */ 100 public function definition() { 101 $mform =& $this->_form; 102 103 // hidden elements 104 $mform->addElement('hidden', 'id'); 105 $mform->setType('id', PARAM_INT); 106 $mform->addElement('hidden', 'do_show'); 107 $mform->setType('do_show', PARAM_ALPHANUMEXT); 108 $mform->setConstant('do_show', 'templates'); 109 110 //headline 111 $mform->addElement('header', 'creating_templates', get_string('creating_templates', 'feedback')); 112 113 // visible elements 114 $elementgroup = array(); 115 116 $elementgroup[] = $mform->createElement('text', 117 'templatename', 118 get_string('name', 'feedback'), 119 array('size'=>'40', 'maxlength'=>'200')); 120 121 if (has_capability('mod/feedback:createpublictemplate', context_system::instance())) { 122 $elementgroup[] = $mform->createElement('checkbox', 123 'ispublic', 124 get_string('public', 'feedback'), 125 get_string('public', 'feedback')); 126 } 127 128 // buttons 129 $elementgroup[] = $mform->createElement('submit', 130 'create_template', 131 get_string('save_as_new_template', 'feedback')); 132 133 $mform->addGroup($elementgroup, 134 'elementgroup', 135 get_string('name', 'feedback'), 136 array(' '), 137 false); 138 139 $mform->setType('templatename', PARAM_TEXT); 140 141 $this->set_data(array('id' => $this->_customdata['id'])); 142 } 143 144 /** 145 * Form validation 146 * 147 * @param array $data array of ("fieldname"=>value) of submitted data 148 * @param array $files array of uploaded files "element_name"=>tmp_file_path 149 * @return array of "element_name"=>"error_description" if there are errors, 150 * or an empty array if everything is OK (true allowed for backwards compatibility too). 151 */ 152 public function validation($data, $files) { 153 $errors = parent::validation($data, $files); 154 if (!isset($data['templatename']) || trim(strval($data['templatename'])) === '') { 155 $errors['elementgroup'] = get_string('name_required', 'feedback'); 156 } 157 return $errors; 158 } 159 } 160
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |