PageRenderTime 39ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/mod/workshop/submission_form.php

https://bitbucket.org/moodle/moodle
PHP | 90 lines | 48 code | 21 blank | 21 comment | 9 complexity | c783037c31d0fe8f4dbea2c75db42975 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.1, BSD-3-Clause, MIT, GPL-3.0
  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. * Submit an assignment or edit the already submitted work
  18. *
  19. * @package mod_workshop
  20. * @copyright 2009 David Mudrak <david.mudrak@gmail.com>
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22. */
  23. defined('MOODLE_INTERNAL') || die();
  24. require_once($CFG->dirroot . '/lib/formslib.php');
  25. class workshop_submission_form extends moodleform {
  26. function definition() {
  27. $mform = $this->_form;
  28. $current = $this->_customdata['current'];
  29. $workshop = $this->_customdata['workshop'];
  30. $contentopts = $this->_customdata['contentopts'];
  31. $attachmentopts = $this->_customdata['attachmentopts'];
  32. $mform->addElement('header', 'general', get_string('submission', 'workshop'));
  33. $mform->addElement('text', 'title', get_string('submissiontitle', 'workshop'));
  34. $mform->setType('title', PARAM_TEXT);
  35. $mform->addRule('title', null, 'required', null, 'client');
  36. $mform->addRule('title', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
  37. if ($workshop->submissiontypetext != WORKSHOP_SUBMISSION_TYPE_DISABLED) {
  38. $mform->addElement('editor', 'content_editor', get_string('submissioncontent', 'workshop'), null, $contentopts);
  39. $mform->setType('content_editor', PARAM_RAW);
  40. if ($workshop->submissiontypetext == WORKSHOP_SUBMISSION_TYPE_REQUIRED) {
  41. $mform->addRule('content_editor', null, 'required', null, 'client');
  42. }
  43. }
  44. if ($workshop->submissiontypefile != WORKSHOP_SUBMISSION_TYPE_DISABLED) {
  45. $mform->addElement('static', 'filemanagerinfo', get_string('nattachments', 'workshop'), $workshop->nattachments);
  46. $mform->addElement('filemanager', 'attachment_filemanager', get_string('submissionattachment', 'workshop'),
  47. null, $attachmentopts);
  48. if ($workshop->submissiontypefile == WORKSHOP_SUBMISSION_TYPE_REQUIRED) {
  49. $mform->addRule('attachment_filemanager', null, 'required', null, 'client');
  50. }
  51. }
  52. $mform->addElement('hidden', 'id', $current->id);
  53. $mform->setType('id', PARAM_INT);
  54. $mform->addElement('hidden', 'cmid', $workshop->cm->id);
  55. $mform->setType('cmid', PARAM_INT);
  56. $mform->addElement('hidden', 'edit', 1);
  57. $mform->setType('edit', PARAM_INT);
  58. $mform->addElement('hidden', 'example', 0);
  59. $mform->setType('example', PARAM_INT);
  60. $this->add_action_buttons();
  61. $this->set_data($current);
  62. }
  63. function validation($data, $files) {
  64. global $CFG, $USER, $DB;
  65. $errors = parent::validation($data, $files);
  66. $errors += $this->_customdata['workshop']->validate_submission_data($data);
  67. return $errors;
  68. }
  69. }