submission_form.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. // This file is part of
  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. defined('MOODLE_INTERNAL') || die();
  17. require_once("$CFG->dirroot/course/moodleform_mod.php");
  18. require_once("$CFG->libdir/formslib.php");
  19. require_once("submission_form_functions.php");
  20. class mod_gradeimporter_submission_form extends moodleform {
  21. public function definition() {
  22. global $CFG, $DB;
  23. $mform = $this->_form;
  24. // Custom data
  25. $submission = $this->_customdata['submission']; // Load fields data
  26. $filemanageroptions = $this->_customdata['filemanageroptions'];
  27. $gradeimporterid = $this->_customdata['gradeimporterid'];
  28. $cmid = $this->_customdata['cmid'];
  29. // ----------------------------------------------------------------
  30. // General information
  31. // Header
  32. $mform->addElement('header', 'newsub', get_string('newsubmission', 'gradeimporter'));
  33. // Submission name field
  34. $mform->addElement('text', 'name', get_string('submissionname', 'gradeimporter'), array('maxlength' => '256'));
  35. $mform->setType('name', PARAM_TEXT);
  36. $mform->addRule('name', null, 'required', null, 'client');
  37. $mform->addElement('editor', 'description', get_string('description'));
  38. $mform->setType('description', PARAM_TEXT);
  39. $mform->addElement('filemanager', 'submissionfiles_filemanager', get_string('submissionfiles', 'gradeimporter'),
  40. null, $filemanageroptions);
  41. $mform->addHelpButton('submissionfiles_filemanager', 'submissionfiles', 'gradeimporter');
  42. // Add button to open new subtypeform
  43. $subtypeformurl = new moodle_url("/mod/gradeimporter/forms/submissiontype/submissiontype.php",
  44. array('cmid' => $cmid, 'id' => $gradeimporterid)
  45. );
  46. $newsubtypebutton = "<div class=\"col-md-9 form-inline align-items-start felement\">
  47. <button class=\"btn btn-primary\" onclick=\"window.open('$subtypeformurl','_self')\">
  48. New type
  49. </button>
  50. </div>";
  51. $mform->addElement('html', $newsubtypebutton);
  52. // To edit
  53. $subtypes = get_types_array($gradeimporterid);
  54. if ($subtypes) {
  55. $selectvalues = array();
  56. foreach ($subtypes as $id => $type) {
  57. $selectvalues[$id] = $type->name;
  58. }
  59. } else {
  60. $selectvalues = array(-1 => 'create new type first');
  61. }
  62. $mform->addElement('select', 'type', get_string('submissiontype', 'gradeimporter'), $selectvalues);
  63. $mform->addElement('selectyesno', 'visibility', get_string('visibility', 'gradeimporter'));
  64. $mform->setDefault('visibility', array('value' => 1));
  65. $mform->addHelpButton('visibility', 'visibility', 'gradeimporter');
  66. $mform->addElement('selectyesno', 'gradebook', get_string('gradebook', 'gradeimporter'));
  67. $mform->setDefault('gradebook', array('value' => 0));
  68. $mform->addHelpButton('gradebook', 'gradebook', 'gradeimporter');
  69. // -----------------------------
  70. // Hidden fields
  71. $mform->addElement('hidden', 'id');
  72. $mform->setType('id', PARAM_INT);
  73. $mform->addElement('hidden', 'cmid');
  74. $mform->setType('cmid', PARAM_INT);
  75. // ------------------------------
  76. // Save and cancel buttons
  77. $this->add_action_buttons();
  78. // ------------------------------
  79. // Sets preloaded data to fields
  80. $this->set_data($submission);
  81. }
  82. }