Przeglądaj źródła

feat: Submission removal correctly updates grade in gradebook
- If submission grades are going to gradebook:
-- Correctly updates each student grade for gradeimporter instance

Bernardo 2 lat temu
rodzic
commit
8a382b7342

+ 10 - 6
forms/submission/delete.php

@@ -52,11 +52,15 @@ if (!$submission) {
 
 // Get feedbacks associated with it
 $feedbacks = $DB->get_records('gradeimporter_feedback', array('submissionid' => $subid));
+
+// Delete its feedbacks
 foreach ($feedbacks as $feedback) {
-  // For each feedback, deletes its files and then delete it
-  delete_feedback_files($feedback);
-  $DB->delete_records('gradeimporter_feedback', array('id' => $feedback->id));
+  // Deletes feedback from gradeimporter_feedback table and removes its associated files
+  delete_feedback($feedback);
+  // Recalculates gradeimporter instance grade without this feedback
+  gradeimporter_update_grades($submission, $feedback->studentid);
 }
+
 // Delete submission
 $DB->delete_records('gradeimporter_submission', array('id' => $submission->id));
 
@@ -65,12 +69,12 @@ $PAGE->set_title($submission->name);
 $PAGE->set_heading($course->fullname);
 $PAGE->set_context($context);
 
-$viewlink = new moodle_url('CFG->dirroot/mod/gradeimporter/view.php', array('id' => $cmid, 'edit' => 1));
+$viewlink = new moodle_url("/mod/gradeimporter/view.php", array('id' => $cmid, 'edit' => 1));
 
-echo $OUTPUT->header("refresh:5;url=../../view.php?id=$cmid&edit=1");
+echo $OUTPUT->header("refresh:5;url=$viewlink");
 
 echo "<p>".get_string('deletesubmissiondata', 'gradeimporter', $submission->name)."</p>";
 echo "<p>".get_string('deletefeedbacksdata', 'gradeimporter', count($feedbacks))."</p>";
-echo "<p>".get_string('redirect5s', 'gradeimporter')."<a href=$viewlink>".get_string('here', 'gradeimporter')."</p>";
+echo "<p>".get_string('redirect5s', 'gradeimporter')."<a href=\"$viewlink\">".get_string('here', 'gradeimporter')."</p>";
 
 echo $OUTPUT->footer();

+ 14 - 0
forms/submission/submission_functions.php

@@ -14,6 +14,10 @@
 // You should have received a copy of the GNU General Public License
 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
 
+defined('MOODLE_INTERNAL') || die();
+
+require_once('../../lib.php');
+
 function create_submission ($data, $gradeimporterid, $userid) {
   global $DB;
   $timenow = time();
@@ -252,3 +256,13 @@ function fix_feedback ($feedback, $line) {
   }
   return $feedback;
 }
+
+
+function delete_feedback($feedback) {
+  global $DB;
+  delete_feedback_files($feedback);
+  $DB->delete_records('gradeimporter_feedback',
+                      array('submissionid' => $feedback->submissionid,
+                            'studentid' => $feedback->studentid)
+                    );
+}

+ 0 - 2
lib.php

@@ -303,11 +303,9 @@ function create_grade_item($submission) {
 
 function insert_grade_outcome($submission, $userid) {
   global $CFG, $DB, $COURSE;
-  echo "abdesg";
   if (empty($CFG->enableoutcomes)) {
     return;
   }
-  echo "abc";
   require_once("$CFG->libdir/gradelib.php");
 
   $data = array();

+ 0 - 1
libs/teacher_viewlib.php

@@ -14,7 +14,6 @@
 // You should have received a copy of the GNU General Public License
 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
 
-
 class Teacherview {
   /**
    * @property gradeimporterid used to query DB at get_submissions()