Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
   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   * Submit an assignment or edit the already submitted work
  20   *
  21   * @package    mod_workshop
  22   * @copyright  2009 David Mudrak <david.mudrak@gmail.com>
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  require_once($CFG->dirroot . '/lib/formslib.php');
  29  
  30  class workshop_submission_form extends moodleform {
  31  
  32      function definition() {
  33          $mform = $this->_form;
  34  
  35          $current        = $this->_customdata['current'];
  36          $workshop       = $this->_customdata['workshop'];
  37          $contentopts    = $this->_customdata['contentopts'];
  38          $attachmentopts = $this->_customdata['attachmentopts'];
  39  
  40          $mform->addElement('header', 'general', get_string('submission', 'workshop'));
  41  
  42          $mform->addElement('text', 'title', get_string('submissiontitle', 'workshop'));
  43          $mform->setType('title', PARAM_TEXT);
  44          $mform->addRule('title', null, 'required', null, 'client');
  45          $mform->addRule('title', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
  46  
  47          if ($workshop->submissiontypetext != WORKSHOP_SUBMISSION_TYPE_DISABLED) {
  48              $mform->addElement('editor', 'content_editor', get_string('submissioncontent', 'workshop'), null, $contentopts);
  49              $mform->setType('content_editor', PARAM_RAW);
  50              if ($workshop->submissiontypetext == WORKSHOP_SUBMISSION_TYPE_REQUIRED) {
  51                  $mform->addRule('content_editor', null, 'required', null, 'client');
  52              }
  53          }
  54  
  55          if ($workshop->submissiontypefile != WORKSHOP_SUBMISSION_TYPE_DISABLED) {
  56              $mform->addElement('static', 'filemanagerinfo', get_string('nattachments', 'workshop'), $workshop->nattachments);
  57              $mform->addElement('filemanager', 'attachment_filemanager', get_string('submissionattachment', 'workshop'),
  58                                  null, $attachmentopts);
  59              if ($workshop->submissiontypefile == WORKSHOP_SUBMISSION_TYPE_REQUIRED) {
  60                  $mform->addRule('attachment_filemanager', null, 'required', null, 'client');
  61              }
  62          }
  63  
  64          $mform->addElement('hidden', 'id', $current->id);
  65          $mform->setType('id', PARAM_INT);
  66  
  67          $mform->addElement('hidden', 'cmid', $workshop->cm->id);
  68          $mform->setType('cmid', PARAM_INT);
  69  
  70          $mform->addElement('hidden', 'edit', 1);
  71          $mform->setType('edit', PARAM_INT);
  72  
  73          $mform->addElement('hidden', 'example', 0);
  74          $mform->setType('example', PARAM_INT);
  75  
  76          $this->add_action_buttons();
  77  
  78          $this->set_data($current);
  79      }
  80  
  81      function validation($data, $files) {
  82          global $CFG, $USER, $DB;
  83  
  84          $errors = parent::validation($data, $files);
  85  
  86          $errors += $this->_customdata['workshop']->validate_submission_data($data);
  87  
  88          return $errors;
  89      }
  90  }