[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/mod/feedback/ -> edit_form.php (source)

   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_add_question_form extends moodleform {
  33      public function definition() {
  34          $mform = $this->_form;
  35  
  36          //headline
  37          $mform->addElement('header', 'general', get_string('content'));
  38          // visible elements
  39          $feedback_names_options = feedback_load_feedback_items_options();
  40  
  41          $attributes = 'onChange="M.core_formchangechecker.set_form_submitted(); this.form.submit()"';
  42          $mform->addElement('select', 'typ', '', $feedback_names_options, $attributes);
  43  
  44          // hidden elements
  45          $mform->addElement('hidden', 'cmid');
  46          $mform->setType('cmid', PARAM_INT);
  47          $mform->addElement('hidden', 'position');
  48          $mform->setType('position', PARAM_INT);
  49  
  50          // buttons
  51          $mform->addElement('submit', 'add_item', get_string('add_item', 'feedback'), array('class' => 'hiddenifjs'));
  52      }
  53  }
  54  
  55  class feedback_edit_use_template_form extends moodleform {
  56      private $feedbackdata;
  57  
  58      public function definition() {
  59          $this->feedbackdata = new stdClass();
  60          //this function can not be called, because not all data are available at this time
  61          //I use set_form_elements instead
  62      }
  63  
  64      //this function set the data used in set_form_elements()
  65      //in this form the only value have to set is course
  66      //eg: array('course' => $course)
  67      public function set_feedbackdata($data) {
  68          if (is_array($data)) {
  69              if (!isset($this->feedbackdata)) {
  70                  $this->feedbackdata = new stdClass();
  71              }
  72              foreach ($data as $key => $val) {
  73                  $this->feedbackdata->{$key} = $val;
  74              }
  75          }
  76      }
  77  
  78      //here the elements will be set
  79      //this function have to be called manually
  80      //the advantage is that the data are already set
  81      public function set_form_elements() {
  82          $mform =& $this->_form;
  83  
  84          $elementgroup = array();
  85          //headline
  86          $mform->addElement('header', 'using_templates', get_string('using_templates', 'feedback'));
  87          // hidden elements
  88          $mform->addElement('hidden', 'id');
  89          $mform->setType('id', PARAM_INT);
  90  
  91          // visible elements
  92          $templates_options = array();
  93          $owntemplates = feedback_get_template_list($this->feedbackdata->course, 'own');
  94          $publictemplates = feedback_get_template_list($this->feedbackdata->course, 'public');
  95  
  96          $options = array();
  97          if ($owntemplates or $publictemplates) {
  98              $options[''] = array('' => get_string('choose'));
  99  
 100              if ($owntemplates) {
 101                  $courseoptions = array();
 102                  foreach ($owntemplates as $template) {
 103                      $courseoptions[$template->id] = $template->name;
 104                  }
 105                  $options[get_string('course')] = $courseoptions;
 106              }
 107  
 108              if ($publictemplates) {
 109                  $publicoptions = array();
 110                  foreach ($publictemplates as $template) {
 111                      $publicoptions[$template->id] = $template->name;
 112                  }
 113                  $options[get_string('public', 'feedback')] = $publicoptions;
 114              }
 115  
 116              $attributes = 'onChange="M.core_formchangechecker.set_form_submitted(); this.form.submit()"';
 117              $elementgroup[] = $mform->createElement('selectgroups',
 118                                                       'templateid',
 119                                                       '',
 120                                                       $options,
 121                                                       $attributes);
 122  
 123              $elementgroup[] = $mform->createElement('submit',
 124                                                       'use_template',
 125                                                       get_string('use_this_template', 'feedback'));
 126  
 127              $mform->addGroup($elementgroup, 'elementgroup', '', array(' '), false);
 128          } else {
 129              $mform->addElement('static', 'info', get_string('no_templates_available_yet', 'feedback'));
 130          }
 131      }
 132  }
 133  
 134  class feedback_edit_create_template_form extends moodleform {
 135      private $feedbackdata;
 136  
 137      public function definition() {
 138      }
 139  
 140      public function data_preprocessing(&$default_values) {
 141          $default_values['templatename'] = '';
 142      }
 143  
 144      public function set_feedbackdata($data) {
 145          if (is_array($data)) {
 146              if (!isset($this->feedbackdata)) {
 147                  $this->feedbackdata = new stdClass();
 148              }
 149              foreach ($data as $key => $val) {
 150                  $this->feedbackdata->{$key} = $val;
 151              }
 152          }
 153      }
 154  
 155      public function set_form_elements() {
 156          $mform =& $this->_form;
 157  
 158          // hidden elements
 159          $mform->addElement('hidden', 'id');
 160          $mform->setType('id', PARAM_INT);
 161          $mform->addElement('hidden', 'do_show');
 162          $mform->setType('do_show', PARAM_INT);
 163          $mform->addElement('hidden', 'savetemplate', 1);
 164          $mform->setType('savetemplate', PARAM_INT);
 165  
 166          //headline
 167          $mform->addElement('header', 'creating_templates', get_string('creating_templates', 'feedback'));
 168  
 169          // visible elements
 170          $elementgroup = array();
 171  
 172          $elementgroup[] = $mform->createElement('static',
 173                                                   'templatenamelabel',
 174                                                   get_string('name', 'feedback'));
 175  
 176          $elementgroup[] = $mform->createElement('text',
 177                                                   'templatename',
 178                                                   get_string('name', 'feedback'),
 179                                                   array('size'=>'40', 'maxlength'=>'200'));
 180  
 181          if (has_capability('mod/feedback:createpublictemplate', context_system::instance())) {
 182              $elementgroup[] = $mform->createElement('checkbox',
 183                                                       'ispublic',
 184                                                       get_string('public', 'feedback'),
 185                                                       get_string('public', 'feedback'));
 186          }
 187  
 188          // buttons
 189          $elementgroup[] = $mform->createElement('submit',
 190                                                   'create_template',
 191                                                   get_string('save_as_new_template', 'feedback'));
 192  
 193          $mform->addGroup($elementgroup,
 194                           'elementgroup',
 195                           get_string('name', 'feedback'),
 196                           array(' '),
 197                           false);
 198  
 199          $mform->setType('templatename', PARAM_TEXT);
 200  
 201      }
 202  }
 203  


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1