submission_form.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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'));
  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. var_dump ($subtypes);
  55. if ($subtypes) {
  56. $selectvalues = array();
  57. foreach ($subtypes as $id => $type) {
  58. $selectvalues[$id] = $type->name;
  59. }
  60. } else {
  61. $selectvalues = array('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. // -----------------------------
  71. // Hidden fields
  72. $mform->addElement('hidden', 'id');
  73. $mform->setType('id', PARAM_INT);
  74. $mform->addElement('hidden', 'cmid');
  75. $mform->setType('cmid', PARAM_INT);
  76. // ------------------------------
  77. // Save and cancel buttons
  78. $this->add_action_buttons();
  79. // ------------------------------
  80. // Sets preloaded data to fields
  81. $this->set_data($submission);
  82. }
  83. }