[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/mod/workshop/ -> mod_form.php (source)

   1  <?php
   2  
   3  // This file is part of Moodle - http://moodle.org/
   4  //
   5  // Moodle is free software: you can redistribute it and/or modify
   6  // it under the terms of the GNU General Public License as published by
   7  // the Free Software Foundation, either version 3 of the License, or
   8  // (at your option) any later version.
   9  //
  10  // Moodle is distributed in the hope that it will be useful,
  11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13  // GNU General Public License for more details.
  14  //
  15  // You should have received a copy of the GNU General Public License
  16  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  17  
  18  /**
  19   * The main workshop configuration form
  20   *
  21   * The UI mockup has been proposed in MDL-18688
  22   * It uses the standard core Moodle formslib. For more info about them, please
  23   * visit: http://docs.moodle.org/dev/lib/formslib.php
  24   *
  25   * @package    mod_workshop
  26   * @copyright  2009 David Mudrak <[email protected]>
  27   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  28   */
  29  
  30  defined('MOODLE_INTERNAL') || die();
  31  
  32  require_once($CFG->dirroot . '/course/moodleform_mod.php');
  33  require_once(dirname(__FILE__) . '/locallib.php');
  34  require_once($CFG->libdir . '/filelib.php');
  35  
  36  /**
  37   * Module settings form for Workshop instances
  38   */
  39  class mod_workshop_mod_form extends moodleform_mod {
  40  
  41      /** @var object the course this instance is part of */
  42      protected $course = null;
  43  
  44      /**
  45       * Constructor
  46       */
  47      public function __construct($current, $section, $cm, $course) {
  48          $this->course = $course;
  49          parent::__construct($current, $section, $cm, $course);
  50      }
  51  
  52      /**
  53       * Defines the workshop instance configuration form
  54       *
  55       * @return void
  56       */
  57      public function definition() {
  58          global $CFG;
  59  
  60          $workshopconfig = get_config('workshop');
  61          $mform = $this->_form;
  62  
  63          // General --------------------------------------------------------------------
  64          $mform->addElement('header', 'general', get_string('general', 'form'));
  65  
  66          // Workshop name
  67          $label = get_string('workshopname', 'workshop');
  68          $mform->addElement('text', 'name', $label, array('size'=>'64'));
  69          if (!empty($CFG->formatstringstriptags)) {
  70              $mform->setType('name', PARAM_TEXT);
  71          } else {
  72              $mform->setType('name', PARAM_CLEANHTML);
  73          }
  74          $mform->addRule('name', null, 'required', null, 'client');
  75          $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
  76  
  77          // Introduction
  78          $this->add_intro_editor(false, get_string('introduction', 'workshop'));
  79  
  80          // Grading settings -----------------------------------------------------------
  81          $mform->addElement('header', 'gradingsettings', get_string('gradingsettings', 'workshop'));
  82          $mform->setExpanded('gradingsettings');
  83  
  84          $label = get_string('strategy', 'workshop');
  85          $mform->addElement('select', 'strategy', $label, workshop::available_strategies_list());
  86          $mform->setDefault('strategy', $workshopconfig->strategy);
  87          $mform->addHelpButton('strategy', 'strategy', 'workshop');
  88  
  89          $grades = workshop::available_maxgrades_list();
  90          $gradecategories = grade_get_categories_menu($this->course->id);
  91  
  92          $label = get_string('submissiongrade', 'workshop');
  93          $mform->addGroup(array(
  94              $mform->createElement('select', 'grade', '', $grades),
  95              $mform->createElement('select', 'gradecategory', '', $gradecategories),
  96              ), 'submissiongradegroup', $label, ' ', false);
  97          $mform->setDefault('grade', $workshopconfig->grade);
  98          $mform->addHelpButton('submissiongradegroup', 'submissiongrade', 'workshop');
  99  
 100          $label = get_string('gradinggrade', 'workshop');
 101          $mform->addGroup(array(
 102              $mform->createElement('select', 'gradinggrade', '', $grades),
 103              $mform->createElement('select', 'gradinggradecategory', '', $gradecategories),
 104              ), 'gradinggradegroup', $label, ' ', false);
 105          $mform->setDefault('gradinggrade', $workshopconfig->gradinggrade);
 106          $mform->addHelpButton('gradinggradegroup', 'gradinggrade', 'workshop');
 107  
 108          $options = array();
 109          for ($i=5; $i>=0; $i--) {
 110              $options[$i] = $i;
 111          }
 112          $label = get_string('gradedecimals', 'workshop');
 113          $mform->addElement('select', 'gradedecimals', $label, $options);
 114          $mform->setDefault('gradedecimals', $workshopconfig->gradedecimals);
 115  
 116          // Submission settings --------------------------------------------------------
 117          $mform->addElement('header', 'submissionsettings', get_string('submissionsettings', 'workshop'));
 118  
 119          $label = get_string('instructauthors', 'workshop');
 120          $mform->addElement('editor', 'instructauthorseditor', $label, null,
 121                              workshop::instruction_editors_options($this->context));
 122  
 123          $options = array();
 124          for ($i=7; $i>=0; $i--) {
 125              $options[$i] = $i;
 126          }
 127          $label = get_string('nattachments', 'workshop');
 128          $mform->addElement('select', 'nattachments', $label, $options);
 129          $mform->setDefault('nattachments', 1);
 130  
 131          $options = get_max_upload_sizes($CFG->maxbytes, $this->course->maxbytes, 0, $workshopconfig->maxbytes);
 132          $mform->addElement('select', 'maxbytes', get_string('maxbytes', 'workshop'), $options);
 133          $mform->setDefault('maxbytes', $workshopconfig->maxbytes);
 134  
 135          $label = get_string('latesubmissions', 'workshop');
 136          $text = get_string('latesubmissions_desc', 'workshop');
 137          $mform->addElement('checkbox', 'latesubmissions', $label, $text);
 138          $mform->addHelpButton('latesubmissions', 'latesubmissions', 'workshop');
 139  
 140          // Assessment settings --------------------------------------------------------
 141          $mform->addElement('header', 'assessmentsettings', get_string('assessmentsettings', 'workshop'));
 142  
 143          $label = get_string('instructreviewers', 'workshop');
 144          $mform->addElement('editor', 'instructreviewerseditor', $label, null,
 145                              workshop::instruction_editors_options($this->context));
 146  
 147          $label = get_string('useselfassessment', 'workshop');
 148          $text = get_string('useselfassessment_desc', 'workshop');
 149          $mform->addElement('checkbox', 'useselfassessment', $label, $text);
 150          $mform->addHelpButton('useselfassessment', 'useselfassessment', 'workshop');
 151  
 152          // Feedback -------------------------------------------------------------------
 153          $mform->addElement('header', 'feedbacksettings', get_string('feedbacksettings', 'workshop'));
 154  
 155          $mform->addElement('select', 'overallfeedbackmode', get_string('overallfeedbackmode', 'mod_workshop'), array(
 156              0 => get_string('overallfeedbackmode_0', 'mod_workshop'),
 157              1 => get_string('overallfeedbackmode_1', 'mod_workshop'),
 158              2 => get_string('overallfeedbackmode_2', 'mod_workshop')));
 159          $mform->addHelpButton('overallfeedbackmode', 'overallfeedbackmode', 'mod_workshop');
 160          $mform->setDefault('overallfeedbackmode', 1);
 161  
 162          $options = array();
 163          for ($i = 7; $i >= 0; $i--) {
 164              $options[$i] = $i;
 165          }
 166          $mform->addElement('select', 'overallfeedbackfiles', get_string('overallfeedbackfiles', 'workshop'), $options);
 167          $mform->setDefault('overallfeedbackfiles', 0);
 168          $mform->disabledIf('overallfeedbackfiles', 'overallfeedbackmode', 'eq', 0);
 169  
 170          $options = get_max_upload_sizes($CFG->maxbytes, $this->course->maxbytes);
 171          $mform->addElement('select', 'overallfeedbackmaxbytes', get_string('overallfeedbackmaxbytes', 'workshop'), $options);
 172          $mform->setDefault('overallfeedbackmaxbytes', $workshopconfig->maxbytes);
 173          $mform->disabledIf('overallfeedbackmaxbytes', 'overallfeedbackmode', 'eq', 0);
 174          $mform->disabledIf('overallfeedbackmaxbytes', 'overallfeedbackfiles', 'eq', 0);
 175  
 176          $label = get_string('conclusion', 'workshop');
 177          $mform->addElement('editor', 'conclusioneditor', $label, null,
 178                              workshop::instruction_editors_options($this->context));
 179          $mform->addHelpButton('conclusioneditor', 'conclusion', 'workshop');
 180  
 181          // Example submissions --------------------------------------------------------
 182          $mform->addElement('header', 'examplesubmissionssettings', get_string('examplesubmissions', 'workshop'));
 183  
 184          $label = get_string('useexamples', 'workshop');
 185          $text = get_string('useexamples_desc', 'workshop');
 186          $mform->addElement('checkbox', 'useexamples', $label, $text);
 187          $mform->addHelpButton('useexamples', 'useexamples', 'workshop');
 188  
 189          $label = get_string('examplesmode', 'workshop');
 190          $options = workshop::available_example_modes_list();
 191          $mform->addElement('select', 'examplesmode', $label, $options);
 192          $mform->setDefault('examplesmode', $workshopconfig->examplesmode);
 193          $mform->disabledIf('examplesmode', 'useexamples');
 194  
 195          // Availability ---------------------------------------------------------------
 196          $mform->addElement('header', 'accesscontrol', get_string('availability', 'core'));
 197  
 198          $label = get_string('submissionstart', 'workshop');
 199          $mform->addElement('date_time_selector', 'submissionstart', $label, array('optional' => true));
 200  
 201          $label = get_string('submissionend', 'workshop');
 202          $mform->addElement('date_time_selector', 'submissionend', $label, array('optional' => true));
 203  
 204          $label = get_string('submissionendswitch', 'mod_workshop');
 205          $mform->addElement('checkbox', 'phaseswitchassessment', $label);
 206          $mform->disabledIf('phaseswitchassessment', 'submissionend[enabled]');
 207          $mform->addHelpButton('phaseswitchassessment', 'submissionendswitch', 'mod_workshop');
 208  
 209          $label = get_string('assessmentstart', 'workshop');
 210          $mform->addElement('date_time_selector', 'assessmentstart', $label, array('optional' => true));
 211  
 212          $label = get_string('assessmentend', 'workshop');
 213          $mform->addElement('date_time_selector', 'assessmentend', $label, array('optional' => true));
 214  
 215          $coursecontext = context_course::instance($this->course->id);
 216          plagiarism_get_form_elements_module($mform, $coursecontext, 'mod_workshop');
 217  
 218          // Common module settings, Restrict availability, Activity completion etc. ----
 219          $features = array('groups' => true, 'groupings' => true,
 220                  'outcomes'=>true, 'gradecat'=>false, 'idnumber'=>false);
 221  
 222          $this->standard_coursemodule_elements();
 223  
 224          // Standard buttons, common to all modules ------------------------------------
 225          $this->add_action_buttons();
 226      }
 227  
 228      /**
 229       * Prepares the form before data are set
 230       *
 231       * Additional wysiwyg editor are prepared here, the introeditor is prepared automatically by core.
 232       * Grade items are set here because the core modedit supports single grade item only.
 233       *
 234       * @param array $data to be set
 235       * @return void
 236       */
 237      public function data_preprocessing(&$data) {
 238          if ($this->current->instance) {
 239              // editing an existing workshop - let us prepare the added editor elements (intro done automatically)
 240              $draftitemid = file_get_submitted_draft_itemid('instructauthors');
 241              $data['instructauthorseditor']['text'] = file_prepare_draft_area($draftitemid, $this->context->id,
 242                                  'mod_workshop', 'instructauthors', 0,
 243                                  workshop::instruction_editors_options($this->context),
 244                                  $data['instructauthors']);
 245              $data['instructauthorseditor']['format'] = $data['instructauthorsformat'];
 246              $data['instructauthorseditor']['itemid'] = $draftitemid;
 247  
 248              $draftitemid = file_get_submitted_draft_itemid('instructreviewers');
 249              $data['instructreviewerseditor']['text'] = file_prepare_draft_area($draftitemid, $this->context->id,
 250                                  'mod_workshop', 'instructreviewers', 0,
 251                                  workshop::instruction_editors_options($this->context),
 252                                  $data['instructreviewers']);
 253              $data['instructreviewerseditor']['format'] = $data['instructreviewersformat'];
 254              $data['instructreviewerseditor']['itemid'] = $draftitemid;
 255  
 256              $draftitemid = file_get_submitted_draft_itemid('conclusion');
 257              $data['conclusioneditor']['text'] = file_prepare_draft_area($draftitemid, $this->context->id,
 258                                  'mod_workshop', 'conclusion', 0,
 259                                  workshop::instruction_editors_options($this->context),
 260                                  $data['conclusion']);
 261              $data['conclusioneditor']['format'] = $data['conclusionformat'];
 262              $data['conclusioneditor']['itemid'] = $draftitemid;
 263          } else {
 264              // adding a new workshop instance
 265              $draftitemid = file_get_submitted_draft_itemid('instructauthors');
 266              file_prepare_draft_area($draftitemid, null, 'mod_workshop', 'instructauthors', 0);    // no context yet, itemid not used
 267              $data['instructauthorseditor'] = array('text' => '', 'format' => editors_get_preferred_format(), 'itemid' => $draftitemid);
 268  
 269              $draftitemid = file_get_submitted_draft_itemid('instructreviewers');
 270              file_prepare_draft_area($draftitemid, null, 'mod_workshop', 'instructreviewers', 0);    // no context yet, itemid not used
 271              $data['instructreviewerseditor'] = array('text' => '', 'format' => editors_get_preferred_format(), 'itemid' => $draftitemid);
 272  
 273              $draftitemid = file_get_submitted_draft_itemid('conclusion');
 274              file_prepare_draft_area($draftitemid, null, 'mod_workshop', 'conclusion', 0);    // no context yet, itemid not used
 275              $data['conclusioneditor'] = array('text' => '', 'format' => editors_get_preferred_format(), 'itemid' => $draftitemid);
 276          }
 277      }
 278  
 279      /**
 280       * Set the grade item categories when editing an instance
 281       */
 282      public function definition_after_data() {
 283  
 284          $mform =& $this->_form;
 285  
 286          if ($id = $mform->getElementValue('update')) {
 287              $instance   = $mform->getElementValue('instance');
 288  
 289              $gradeitems = grade_item::fetch_all(array(
 290                  'itemtype'      => 'mod',
 291                  'itemmodule'    => 'workshop',
 292                  'iteminstance'  => $instance,
 293                  'courseid'      => $this->course->id));
 294  
 295              if (!empty($gradeitems)) {
 296                  foreach ($gradeitems as $gradeitem) {
 297                      // here comes really crappy way how to set the value of the fields
 298                      // gradecategory and gradinggradecategory - grrr QuickForms
 299                      if ($gradeitem->itemnumber == 0) {
 300                          $group = $mform->getElement('submissiongradegroup');
 301                          $elements = $group->getElements();
 302                          foreach ($elements as $element) {
 303                              if ($element->getName() == 'gradecategory') {
 304                                  $element->setValue($gradeitem->categoryid);
 305                              }
 306                          }
 307                      } else if ($gradeitem->itemnumber == 1) {
 308                          $group = $mform->getElement('gradinggradegroup');
 309                          $elements = $group->getElements();
 310                          foreach ($elements as $element) {
 311                              if ($element->getName() == 'gradinggradecategory') {
 312                                  $element->setValue($gradeitem->categoryid);
 313                              }
 314                          }
 315                      }
 316                  }
 317              }
 318          }
 319  
 320          parent::definition_after_data();
 321      }
 322  
 323      /**
 324       * Validates the form input
 325       *
 326       * @param array $data submitted data
 327       * @param array $files submitted files
 328       * @return array eventual errors indexed by the field name
 329       */
 330      public function validation($data, $files) {
 331          $errors = array();
 332  
 333          // check the phases borders are valid
 334          if ($data['submissionstart'] > 0 and $data['submissionend'] > 0 and $data['submissionstart'] >= $data['submissionend']) {
 335              $errors['submissionend'] = get_string('submissionendbeforestart', 'mod_workshop');
 336          }
 337          if ($data['assessmentstart'] > 0 and $data['assessmentend'] > 0 and $data['assessmentstart'] >= $data['assessmentend']) {
 338              $errors['assessmentend'] = get_string('assessmentendbeforestart', 'mod_workshop');
 339          }
 340  
 341          // check the phases do not overlap
 342          if (max($data['submissionstart'], $data['submissionend']) > 0 and max($data['assessmentstart'], $data['assessmentend']) > 0) {
 343              $phasesubmissionend = max($data['submissionstart'], $data['submissionend']);
 344              $phaseassessmentstart = min($data['assessmentstart'], $data['assessmentend']);
 345              if ($phaseassessmentstart == 0) {
 346                  $phaseassessmentstart = max($data['assessmentstart'], $data['assessmentend']);
 347              }
 348              if ($phasesubmissionend > 0 and $phaseassessmentstart > 0 and $phaseassessmentstart < $phasesubmissionend) {
 349                  foreach (array('submissionend', 'submissionstart', 'assessmentstart', 'assessmentend') as $f) {
 350                      if ($data[$f] > 0) {
 351                          $errors[$f] = get_string('phasesoverlap', 'mod_workshop');
 352                          break;
 353                      }
 354                  }
 355              }
 356          }
 357  
 358          return $errors;
 359      }
 360  }


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