delete.php 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. require_once('../../../../config.php');
  17. require_once('submission_functions.php');
  18. // Get Params to correctly load page
  19. $cmid = required_param('cmid', PARAM_INT);
  20. $subid = required_param('subid', PARAM_INT);
  21. $gradeimporterid = optional_param('id', 0, PARAM_INT);
  22. // Get course module and $course to check capability
  23. $cm = get_coursemodule_from_id('gradeimporter', $cmid, 0, false, MUST_EXIST);
  24. $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
  25. // Gets context to check capability
  26. $context = context_module::instance($cm->id);
  27. // Sets Page URL
  28. $url = new moodle_url('/mod/gradeimporter/forms/submission/delete.php', array('cmid' => $cm->id, 'subid' => $subid));
  29. if (!empty($gradeimporterid)) {
  30. $url->param('id', $gradeimporterid);
  31. }
  32. $PAGE->set_url($url);
  33. // Check if its teacher opening the page
  34. require_login ($course, false, $cm);
  35. require_capability('mod/gradeimporter:edit', $context);
  36. // Get globals
  37. global $DB;
  38. // Get submission
  39. $submission = $DB->get_record('gradeimporter_submission', array('id' => $subid, 'gradeimporterid' => $gradeimporterid));
  40. // If submission doesn't exist, throw error
  41. if (!$submission) {
  42. throw new moodle_exception(get_string('submissionnotfound', 'gradeimporter', $subid));
  43. }
  44. // Get feedbacks associated with it
  45. $feedbacks = $DB->get_records('gradeimporter_feedback', array('submissionid' => $subid));
  46. // Delete its feedbacks
  47. foreach ($feedbacks as $feedback) {
  48. // Deletes feedback from gradeimporter_feedback table and removes its associated files
  49. delete_feedback($feedback);
  50. // Recalculates gradeimporter instance grade without this feedback
  51. gradeimporter_update_grades($submission, $feedback->studentid);
  52. }
  53. // Delete submission
  54. $DB->delete_records('gradeimporter_submission', array('id' => $submission->id));
  55. // If there are no more submission that go to the gradebook, reset it for this gradeimporter instance
  56. if (!$DB->get_records('gradeimporter_submission', array('gradebook' => 1))) {
  57. gradeimporter_grade_item_update($submission, 'reset');
  58. }
  59. // Print page and redirects to submission page after 5 seconds
  60. $PAGE->set_title($submission->name);
  61. $PAGE->set_heading($course->fullname);
  62. $PAGE->set_context($context);
  63. $viewlink = new moodle_url("/mod/gradeimporter/view.php", array('id' => $cmid, 'edit' => 1));
  64. echo $OUTPUT->header("refresh:5;url=$viewlink");
  65. echo "<p>".get_string('deletesubmissiondata', 'gradeimporter', $submission->name)."</p>";
  66. echo "<p>".get_string('deletefeedbacksdata', 'gradeimporter', count($feedbacks))."</p>";
  67. echo "<p>".get_string('redirect5s', 'gradeimporter')."<a href=\"$viewlink\"> ".get_string('here', 'gradeimporter')."</p>";
  68. echo $OUTPUT->footer();