submission_form.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. // This file is part of LInE contributions to Free Education, Private Data
  3. // LInE (Laboratory of Informatics in Education)
  4. // www.usp.br/line
  5. //
  6. // Moodle is free software: you can redistribute it and/or modify
  7. // it under the terms of the GNU General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // Moodle is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU General Public License
  17. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  18. defined('MOODLE_INTERNAL') || die();
  19. require_once($CFG->dirroot . "/course/moodleform_mod.php");
  20. require_once($CFG->libdir . "/formslib.php");
  21. require_once("submission_form_functions.php");
  22. class mod_gradeimporter_submission_form extends moodleform {
  23. public function definition () {
  24. global $CFG, $DB;
  25. $mform = $this->_form;
  26. // Custom data
  27. $submission = $this->_customdata['submission']; // Load fields data
  28. $filemanageroptions = $this->_customdata['filemanageroptions'];
  29. $gradeimporterid = $this->_customdata['gradeimporterid'];
  30. $cmid = $this->_customdata['cmid'];
  31. // ----------------------------------------------------------------
  32. // General information
  33. // Header
  34. $mform->addElement('header', 'newsub', get_string('newsubmission', 'gradeimporter'));
  35. // Submission name field
  36. $mform->addElement('text', 'name', get_string('submissionname', 'gradeimporter'));
  37. $mform->setType('name', PARAM_TEXT);
  38. $mform->addRule('name', null, 'required', null, 'client');
  39. $mform->addElement('editor', 'description', get_string('description'));
  40. $mform->setType('description', PARAM_TEXT);
  41. $mform->addElement('filemanager', 'submissionfiles_filemanager', get_string('submissionfiles', 'gradeimporter'), 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", array('cmid' => $cmid, 'id' => $gradeimporterid));
  45. $newsubtypebutton = "<div class=\"col-md-9 form-inline align-items-start felement\">
  46. <button class=\"btn btn-primary\" onclick=\"window.open('" . $subtypeformurl . "','_self')\">New type</button>
  47. </div>\n";
  48. $mform->addElement('html', $newsubtypebutton);
  49. // To edit
  50. $subtypes = get_types_array($gradeimporterid);
  51. var_dump ($subtypes);
  52. if ($subtypes) {
  53. $selectvalues = array();
  54. foreach ($subtypes as $id => $type) {
  55. $selectvalues[$id] = $type->name;
  56. }
  57. }
  58. else {
  59. $selectvalues = array('create new type first');
  60. }
  61. $mform->addElement('select', 'type', get_string('submissiontype', 'gradeimporter'), $selectvalues);
  62. $mform->addElement('selectyesno', 'visibility', get_string('visibility', 'gradeimporter'));
  63. $mform->setDefault('visibility', array('value' => 1));
  64. $mform->addHelpButton('visibility', 'visibility', 'gradeimporter');
  65. $mform->addElement('selectyesno', 'gradebook', get_string('gradebook', 'gradeimporter'));
  66. $mform->setDefault('gradebook', array('value' => 0));
  67. $mform->addHelpButton('gradebook', 'gradebook', 'gradeimporter');
  68. // -----------------------------
  69. // Hidden fields
  70. $mform->addElement('hidden', 'id');
  71. $mform->setType('id', PARAM_INT);
  72. $mform->addElement('hidden', 'cmid');
  73. $mform->setType('cmid', PARAM_INT);
  74. // ------------------------------
  75. // Save and cancel buttons
  76. $this->add_action_buttons();
  77. // ------------------------------
  78. // Sets preloaded data to fields
  79. $this->set_data($submission);
  80. } // public function definition()
  81. } // class mod_gradeimporter_submission_form extends moodleform