MDL-59243 mod_workshop: Return creation status in create_submission WS
authorJuan Leyva <juanleyvadelgado@gmail.com>
Wed, 13 Sep 2017 09:41:28 +0000 (11:41 +0200)
committerJuan Leyva <juanleyvadelgado@gmail.com>
Wed, 13 Sep 2017 09:41:28 +0000 (11:41 +0200)
mod/workshop/classes/external.php
mod/workshop/tests/external_test.php

index 30585b9..5d2c7df 100644 (file)
@@ -508,14 +508,18 @@ class mod_workshop_external extends external_api {
                     'message' => s($message)
                 );
             }
+            return array(
+                'status' => false,
+                'warnings' => $warnings
+            );
         } else {
             $submission->id = $workshop->edit_submission($submission);
+            return array(
+                'status' => true,
+                'submissionid' => $submission->id,
+                'warnings' => $warnings
+            );
         }
-
-        return array(
-            'submissionid' => $submission->id,
-            'warnings' => $warnings
-        );
     }
 
     /**
@@ -526,7 +530,8 @@ class mod_workshop_external extends external_api {
      */
     public static function add_submission_returns() {
         return new external_single_structure(array(
-            'submissionid' => new external_value(PARAM_INT, 'New workshop submission id (0 if it wasn\'t created).'),
+            'status' => new external_value(PARAM_BOOL, 'True if the submission was created false otherwise.'),
+            'submissionid' => new external_value(PARAM_INT, 'New workshop submission id.', VALUE_OPTIONAL),
             'warnings' => new external_warnings()
         ));
     }
index d97e783..3247e78 100644 (file)
@@ -461,6 +461,7 @@ class mod_workshop_external_testcase extends externallib_advanced_testcase {
 
         // Check submission created.
         $submission = $workshop->get_submission_by_author($this->student->id);
+        $this->assertTrue($result['status']);
         $this->assertEquals($result['submissionid'], $submission->id);
         $this->assertEquals($title, $submission->title);
         $this->assertEquals($content, $submission->content);
@@ -527,7 +528,8 @@ class mod_workshop_external_testcase extends externallib_advanced_testcase {
         // Try to create it again.
         $result = mod_workshop_external::add_submission($this->workshop->id, 'My submission');
         $result = external_api::clean_returnvalue(mod_workshop_external::add_submission_returns(), $result);
-        $this->assertEquals(0, $result['submissionid']);
+        $this->assertFalse($result['status']);
+        $this->assertArrayNotHasKey('submissionid', $result);
         $this->assertCount(2, $result['warnings']);
         $this->assertEquals('fielderror', $result['warnings'][0]['warningcode']);
         $this->assertEquals('content_editor', $result['warnings'][0]['item']);