MDL-59250 mod_workshop: Move assessment edition code to API function
[moodle.git] / mod / workshop / assessment.php
index a4efdc7..23d2d27 100644 (file)
@@ -118,53 +118,8 @@ if (is_null($assessment->grade) and !$assessmenteditable) {
         redirect($workshop->view_url());
     } elseif ($assessmenteditable and ($data = $mform->get_data())) {
 
-        // Let the grading strategy subplugin save its data.
-        $rawgrade = $strategy->save_assessment($assessment, $data);
-
-        // Store the data managed by the workshop core.
-        $coredata = (object)array('id' => $assessment->id);
-        if (isset($data->feedbackauthor_editor)) {
-            $coredata->feedbackauthor_editor = $data->feedbackauthor_editor;
-            $coredata = file_postupdate_standard_editor($coredata, 'feedbackauthor', $workshop->overall_feedback_content_options(),
-                $workshop->context, 'mod_workshop', 'overallfeedback_content', $assessment->id);
-            unset($coredata->feedbackauthor_editor);
-        }
-        if (isset($data->feedbackauthorattachment_filemanager)) {
-            $coredata->feedbackauthorattachment_filemanager = $data->feedbackauthorattachment_filemanager;
-            $coredata = file_postupdate_standard_filemanager($coredata, 'feedbackauthorattachment',
-                $workshop->overall_feedback_attachment_options(), $workshop->context, 'mod_workshop', 'overallfeedback_attachment',
-                $assessment->id);
-            unset($coredata->feedbackauthorattachment_filemanager);
-            if (empty($coredata->feedbackauthorattachment)) {
-                $coredata->feedbackauthorattachment = 0;
-            }
-        }
-        if (isset($data->weight) and $cansetassessmentweight) {
-            $coredata->weight = $data->weight;
-        }
-        // Update the assessment data if there is something other than just the 'id'.
-        if (count((array)$coredata) > 1 ) {
-            $DB->update_record('workshop_assessments', $coredata);
-            $params = array(
-                'relateduserid' => $submission->authorid,
-                'objectid' => $assessment->id,
-                'context' => $workshop->context,
-                'other' => array(
-                    'workshopid' => $workshop->id,
-                    'submissionid' => $assessment->submissionid
-                )
-            );
-
-            if (is_null($assessment->grade)) {
-                // All workshop_assessments are created when allocations are made. The create event is of more use located here.
-                $event = \mod_workshop\event\submission_assessed::create($params);
-                $event->trigger();
-            } else {
-                $params['other']['grade'] = $assessment->grade;
-                $event = \mod_workshop\event\submission_reassessed::create($params);
-                $event->trigger();
-            }
-        }
+        // Add or update assessment.
+        $rawgrade = $workshop->edit_assessment($assessment, $submission, $data, $strategy);
 
         // And finally redirect the user's browser.
         if (!is_null($rawgrade) and isset($data->saveandclose)) {