MDL-37148 assign: Fix missing parameter for submit_for_grading webservice.
authorDamyon Wiese <damyon@moodle.com>
Mon, 16 Sep 2013 01:17:42 +0000 (09:17 +0800)
committerDamyon Wiese <damyon@moodle.com>
Mon, 16 Sep 2013 01:34:32 +0000 (09:34 +0800)
It is required to specify if the user has accepted the submission statement
to make sure it goes in the log/event.

mod/assign/externallib.php
mod/assign/locallib.php
mod/assign/tests/externallib_test.php

index 4a679d9..8aa0a35 100644 (file)
@@ -1223,14 +1223,15 @@ class mod_assign_external extends external_api {
     }
 
     /**
-     * Describes the parameters for unlock_submissions
+     * Describes the parameters for submit_for_grading
      * @return external_external_function_parameters
      * @since  Moodle 2.6
      */
     public static function submit_for_grading_parameters() {
         return new external_function_parameters(
             array(
-                'assignmentid' => new external_value(PARAM_INT, 'The assignment id to operate on')
+                'assignmentid' => new external_value(PARAM_INT, 'The assignment id to operate on'),
+                'acceptsubmissionstatement' => new external_value(PARAM_BOOL, 'Accept the assignment submission statement')
             )
         );
     }
@@ -1242,12 +1243,13 @@ class mod_assign_external extends external_api {
      * @return array of warnings to indicate any errors.
      * @since Moodle 2.6
      */
-    public static function submit_for_grading($assignmentid) {
+    public static function submit_for_grading($assignmentid, $acceptsubmissionstatement) {
         global $CFG, $USER;
         require_once("$CFG->dirroot/mod/assign/locallib.php");
 
         $params = self::validate_parameters(self::submit_for_grading_parameters(),
-                                            array('assignmentid' => $assignmentid));
+                                            array('assignmentid' => $assignmentid,
+                                                  'acceptsubmissionstatement' => $acceptsubmissionstatement));
 
         $cm = get_coursemodule_from_instance('assign', $assignmentid, 0, false, MUST_EXIST);
         $context = context_module::instance($cm->id);
@@ -1255,7 +1257,10 @@ class mod_assign_external extends external_api {
         $assignment = new assign($context, $cm, null);
 
         $warnings = array();
-        if (!$assignment->submit_for_grading()) {
+        $data = new stdClass();
+        $data->submissionstatement = $acceptsubmissionstatement;
+
+        if (!$assignment->submit_for_grading($data)) {
             $detail = 'User id: ' . $USER->id . ', Assignment id: ' . $assignmentid;
             $warnings[] = self::generate_warning($assignmentid,
                                                  'couldnotsubmitforgrading',
index 5ef2ccd..3cbccaf 100644 (file)
@@ -4472,7 +4472,7 @@ class assign {
      *
      * @return bool Return false if the submission was not submitted.
      */
-    public function submit_for_grading() {
+    public function submit_for_grading($data) {
         global $USER;
 
         // Need submit permission to submit an assignment.
@@ -4490,6 +4490,10 @@ class assign {
             return false;
         }
 
+        if ($instance->requiresubmissionstatement && !$data->submissionstatement) {
+            return false;
+        }
+
         if ($submission->status != ASSIGN_SUBMISSION_STATUS_SUBMITTED) {
             // Give each submission plugin a chance to process the submission.
             $plugins = $this->get_submission_plugins();
@@ -4506,7 +4510,7 @@ class assign {
                 $completion->update_state($this->get_course_module(), COMPLETION_COMPLETE, $USER->id);
             }
 
-            if (isset($data->submissionstatement)) {
+            if (!empty($data->submissionstatement)) {
                 $logmessage = get_string('submissionstatementacceptedlog',
                                          'mod_assign',
                                          fullname($USER));
@@ -4571,7 +4575,7 @@ class assign {
             if ($mform->get_data() == false) {
                 return false;
             }
-            return $this->submit_for_grading();
+            return $this->submit_for_grading($data);
         }
         return true;
     }
index aeb0cb3..eebc750 100644 (file)
@@ -584,6 +584,7 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
         $params['assignsubmission_onlinetext_enabled'] = 1;
         $params['submissiondrafts'] = 1;
         $params['sendnotifications'] = 0;
+        $params['requiresubmissionstatement'] = 1;
         $instance = $generator->create_instance($params);
         $cm = get_coursemodule_from_instance('assign', $instance->id);
         $context = context_module::instance($cm->id);
@@ -607,7 +608,12 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
         $plugin = $assign->get_submission_plugin_by_type('onlinetext');
         $plugin->save($submission, $data);
 
-        $result = mod_assign_external::submit_for_grading($instance->id);
+        $result = mod_assign_external::submit_for_grading($instance->id, false);
+
+        // Should be 1 fail because the submission statement was not aceptted.
+        $this->assertEquals(1, count($result));
+
+        $result = mod_assign_external::submit_for_grading($instance->id, true);
 
         // Check for 0 warnings.
         $this->assertEquals(0, count($result));
@@ -657,7 +663,7 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
                                               $studentrole->id);
 
         $this->setUser($student1);
-        $result = mod_assign_external::submit_for_grading($instance->id);
+        $result = mod_assign_external::submit_for_grading($instance->id, true);
 
         // Check for 0 warnings.
         $this->assertEquals(1, count($result));
@@ -675,7 +681,7 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
         $this->assertEquals(0, count($result));
 
         $this->setUser($student1);
-        $result = mod_assign_external::submit_for_grading($instance->id);
+        $result = mod_assign_external::submit_for_grading($instance->id, true);
         $this->assertEquals(0, count($result));
 
         $this->setUser($student1);
@@ -783,7 +789,7 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
         // Create a student1 with an online text submission.
         // Simulate a submission.
         $this->setUser($student1);
-        $result = mod_assign_external::submit_for_grading($instance->id);
+        $result = mod_assign_external::submit_for_grading($instance->id, true);
         $this->assertEquals(0, count($result));
 
         // Ready to test.