1
0

submission_form.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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_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. // Description
  38. $mform->addElement('editor', 'intro', get_string('submissionintro', 'gradeimporter'));
  39. $mform->setType('intro', PARAM_RAW);
  40. $mform->addElement('filemanager', 'submissionfiles_filemanager', get_string('submissionfiles', 'gradeimporter'),
  41. null, $filemanageroptions);
  42. $mform->addHelpButton('submissionfiles_filemanager', 'submissionfiles', 'gradeimporter');
  43. // Add button to open new subtypeform
  44. $subtypeformurl = new moodle_url("/mod/gradeimporter/forms/submissiontype/submissiontype.php",
  45. array('cmid' => $cmid, 'id' => $gradeimporterid)
  46. );
  47. $newsubtypebutton = "<div class=\"col-md-9 form-inline align-items-start felement\">
  48. <button class=\"btn btn-primary\" onclick=\"window.open('$subtypeformurl','_self')\">
  49. New type
  50. </button>
  51. </div>";
  52. $mform->addElement('html', $newsubtypebutton);
  53. // To edit
  54. $subtypes = get_types_array($gradeimporterid);
  55. if ($subtypes) {
  56. $selectvalues = array();
  57. foreach ($subtypes as $id => $type) {
  58. $selectvalues[$id] = $type->name;
  59. }
  60. } else {
  61. $selectvalues = array(-1 => 'create new type first');
  62. }
  63. $mform->addElement('select', 'type', get_string('submissiontype', 'gradeimporter'), $selectvalues);
  64. $mform->addElement('selectyesno', 'visibility', get_string('visibility', 'gradeimporter'));
  65. $mform->setDefault('visibility', array('value' => 1));
  66. $mform->addHelpButton('visibility', 'visibility', 'gradeimporter');
  67. $mform->addElement('selectyesno', 'gradebook', get_string('gradebook', 'gradeimporter'));
  68. $mform->setDefault('gradebook', array('value' => 0));
  69. $mform->addHelpButton('gradebook', 'gradebook', 'gradeimporter');
  70. $mform->addElement('text', 'maxgrade', get_string('maxgrade', 'gradeimporter'), array('type' => 'number', 'value' => 100));
  71. $mform->setType('maxgrade', PARAM_INT);
  72. $mform->hideIf('maxgrade', 'gradebook', 'eq', 0);
  73. // -----------------------------
  74. // Hidden fields
  75. $mform->addElement('hidden', 'id');
  76. $mform->setType('id', PARAM_INT);
  77. $mform->addElement('hidden', 'cmid');
  78. $mform->setType('cmid', PARAM_INT);
  79. // ------------------------------
  80. // Save and cancel buttons
  81. $this->add_action_buttons();
  82. // ------------------------------
  83. // Sets preloaded data to fields
  84. $this->set_data($submission);
  85. }
  86. }