MDL-60144 mod_workshop: Move submission evaluation code to API
authorJuan Leyva <juanleyvadelgado@gmail.com>
Fri, 15 Sep 2017 14:01:34 +0000 (16:01 +0200)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Tue, 3 Oct 2017 17:28:44 +0000 (19:28 +0200)
mod/workshop/locallib.php
mod/workshop/submission.php

index 6de355d..e34a376 100644 (file)
@@ -2491,12 +2491,12 @@ class workshop {
     /**
      * Returns the mform the teachers use to put a feedback for the author on their submission
      *
-     * @param moodle_url $actionurl
+     * @mixed moodle_url|null $actionurl
      * @param stdClass $submission
      * @param array $options editable
      * @return workshop_feedbackauthor_form
      */
-    public function get_feedbackauthor_form(moodle_url $actionurl, stdclass $submission, $options=array()) {
+    public function get_feedbackauthor_form($actionurl, stdclass $submission, $options=array()) {
         global $CFG;
         require_once(__DIR__ . '/feedbackauthor_form.php');
 
@@ -3139,6 +3139,34 @@ class workshop {
         $event->trigger();
     }
 
+    /**
+     * Evaluates a submission.
+     *
+     * @param  stdClass $submission the submission
+     * @param  stdClass $data       the submission data to be updated
+     * @param  bool $canpublish     whether the user can publish the submission
+     * @param  bool $canoverride    whether the user can override the submission grade
+     * @return void
+     * @since  Moodle 3.4
+     */
+    public function evaluate_submission($submission, $data, $canpublish, $canoverride) {
+        global $DB, $USER;
+
+        $data = file_postupdate_standard_editor($data, 'feedbackauthor', array(), $this->context);
+        $record = new stdclass();
+        $record->id = $submission->id;
+        if ($canoverride) {
+            $record->gradeover = $this->raw_grade_value($data->gradeover, $this->grade);
+            $record->gradeoverby = $USER->id;
+            $record->feedbackauthor = $data->feedbackauthor;
+            $record->feedbackauthorformat = $data->feedbackauthorformat;
+        }
+        if ($canpublish) {
+            $record->published = !empty($data->published);
+        }
+        $DB->update_record('workshop_submissions', $record);
+    }
+
     ////////////////////////////////////////////////////////////////////////////////
     // Internal methods (implementation details)                                  //
     ////////////////////////////////////////////////////////////////////////////////
index 8985e04..195fc92 100644 (file)
@@ -166,19 +166,7 @@ if (!$edit and ($canoverride or $canpublish)) {
         'overridablegrade' => $canoverride);
     $feedbackform = $workshop->get_feedbackauthor_form($PAGE->url, $submission, $options);
     if ($data = $feedbackform->get_data()) {
-        $data = file_postupdate_standard_editor($data, 'feedbackauthor', array(), $workshop->context);
-        $record = new stdclass();
-        $record->id = $submission->id;
-        if ($canoverride) {
-            $record->gradeover = $workshop->raw_grade_value($data->gradeover, $workshop->grade);
-            $record->gradeoverby = $USER->id;
-            $record->feedbackauthor = $data->feedbackauthor;
-            $record->feedbackauthorformat = $data->feedbackauthorformat;
-        }
-        if ($canpublish) {
-            $record->published = !empty($data->published);
-        }
-        $DB->update_record('workshop_submissions', $record);
+        $workshop->evaluate_submission($submission, $data, $canpublish, $canoverride);
         redirect($workshop->view_url());
     }
 }