/mod/workshop/submission_form.php

https://bitbucket.org/synergylearning/campusconnect · PHP · 94 lines · 49 code · 22 blank · 23 comment · 4 complexity · dbe9702c00e11853987d18c101468622 MD5 · raw file

  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
  20. * @subpackage workshop
  21. * @copyright 2009 David Mudrak <david.mudrak@gmail.com>
  22. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23. */
  24. defined('MOODLE_INTERNAL') || die();
  25. require_once($CFG->dirroot . '/lib/formslib.php');
  26. class workshop_submission_form extends moodleform {
  27. function definition() {
  28. $mform = $this->_form;
  29. $current = $this->_customdata['current'];
  30. $workshop = $this->_customdata['workshop'];
  31. $contentopts = $this->_customdata['contentopts'];
  32. $attachmentopts = $this->_customdata['attachmentopts'];
  33. $mform->addElement('header', 'general', get_string('submission', 'workshop'));
  34. $mform->addElement('text', 'title', get_string('submissiontitle', 'workshop'));
  35. $mform->setType('title', PARAM_TEXT);
  36. $mform->addRule('title', null, 'required', null, 'client');
  37. $mform->addElement('editor', 'content_editor', get_string('submissioncontent', 'workshop'), null, $contentopts);
  38. $mform->setType('content', PARAM_RAW);
  39. if ($workshop->nattachments > 0) {
  40. $mform->addElement('static', 'filemanagerinfo', get_string('nattachments', 'workshop'), $workshop->nattachments);
  41. $mform->addElement('filemanager', 'attachment_filemanager', get_string('submissionattachment', 'workshop'),
  42. null, $attachmentopts);
  43. }
  44. $mform->addElement('hidden', 'id', $current->id);
  45. $mform->setType('id', PARAM_INT);
  46. $mform->addElement('hidden', 'cmid', $workshop->cm->id);
  47. $mform->setType('cmid', PARAM_INT);
  48. $mform->addElement('hidden', 'edit', 1);
  49. $mform->setType('edit', PARAM_INT);
  50. $mform->addElement('hidden', 'example', 0);
  51. $mform->setType('example', PARAM_INT);
  52. $this->add_action_buttons();
  53. $this->set_data($current);
  54. }
  55. function validation($data, $files) {
  56. global $CFG, $USER, $DB;
  57. $errors = parent::validation($data, $files);
  58. if (empty($data['id']) and empty($data['example'])) {
  59. // make sure there is no submission saved meanwhile from another browser window
  60. $sql = "SELECT COUNT(s.id)
  61. FROM {workshop_submissions} s
  62. JOIN {workshop} w ON (s.workshopid = w.id)
  63. JOIN {course_modules} cm ON (w.id = cm.instance)
  64. JOIN {modules} m ON (m.name = 'workshop' AND m.id = cm.module)
  65. WHERE cm.id = ? AND s.authorid = ? AND s.example = 0";
  66. if ($DB->count_records_sql($sql, array($data['cmid'], $USER->id))) {
  67. $errors['title'] = get_string('err_multiplesubmissions', 'mod_workshop');
  68. }
  69. }
  70. return $errors;
  71. }
  72. }