MDL-67165 core_grade: Add the grader name to webservices
authorMathew May <mathewm@hotmail.co.nz>
Wed, 13 Nov 2019 04:13:00 +0000 (12:13 +0800)
committerMathew May <mathewm@hotmail.co.nz>
Tue, 17 Dec 2019 02:46:02 +0000 (10:46 +0800)
16 files changed:
grade/classes/grades/grader/gradingpanel/point/external/fetch.php
grade/classes/grades/grader/gradingpanel/point/external/store.php
grade/classes/grades/grader/gradingpanel/scale/external/fetch.php
grade/classes/grades/grader/gradingpanel/scale/external/store.php
grade/grading/form/guide/classes/grades/grader/gradingpanel/external/fetch.php
grade/grading/form/guide/tests/grades_grader_gradingpanel_guide_external_fetch_test.php
grade/grading/form/guide/tests/grades_grader_gradingpanel_guide_external_store_test.php
grade/grading/form/rubric/classes/grades/grader/gradingpanel/external/fetch.php
grade/grading/form/rubric/tests/grades_grader_gradingpanel_rubric_external_fetch_test.php
grade/grading/form/rubric/tests/grades_grader_gradingpanel_rubric_external_store_test.php
grade/tests/grades_grader_gradingpanel_point_external_fetch_test.php
grade/tests/grades_grader_gradingpanel_point_external_store_test.php
grade/tests/grades_grader_gradingpanel_scale_external_fetch_test.php
grade/tests/grades_grader_gradingpanel_scale_external_store_test.php
mod/forum/lang/en/forum.php
mod/forum/templates/local/grades/view_grade.mustache

index 5feb55d..458b64f 100644 (file)
@@ -97,8 +97,8 @@ class fetch extends external_api {
      * @since Moodle 3.8
      */
     public static function execute(string $component, int $contextid, string $itemname, int $gradeduserid): array {
-        global $USER;
-
+        global $USER, $CFG;
+        require_once("{$CFG->libdir}/gradelib.php");
         [
             'component' => $component,
             'contextid' => $contextid,
@@ -131,9 +131,13 @@ class fetch extends external_api {
         $gradeduser = \core_user::get_user($gradeduserid);
         $hasgrade = $gradeitem->user_has_grade($gradeduser);
         $grade = $gradeitem->get_grade_for_user($gradeduser, $USER);
+
+        // Set up some items we need to return on other interfaces.
+        $gradegrade = \grade_grade::fetch(['itemid' => $gradeitem->get_grade_item()->id, 'userid' => $gradeduser->id]);
+        $gradername = $gradegrade ? fullname(\core_user::get_user($gradegrade->usermodified)) : null;
         $maxgrade = (int) $gradeitem->get_grade_item()->grademax;
 
-        return self::get_fetch_data($grade, $hasgrade, $maxgrade);
+        return self::get_fetch_data($grade, $hasgrade, $maxgrade, $gradername);
     }
 
     /**
@@ -142,9 +146,10 @@ class fetch extends external_api {
      * @param stdClass $grade
      * @param bool $hasgrade
      * @param int $maxgrade
+     * @param string|null $gradername
      * @return array
      */
-    public static function get_fetch_data(stdClass $grade, bool $hasgrade, int $maxgrade): array {
+    public static function get_fetch_data(stdClass $grade, bool $hasgrade, int $maxgrade, ?string $gradername): array {
         return [
             'templatename' => 'core_grades/grades/grader/gradingpanel/point',
             'hasgrade' => $hasgrade,
@@ -152,6 +157,7 @@ class fetch extends external_api {
                 'grade' => $grade->grade,
                 'usergrade' => $grade->grade,
                 'maxgrade' => $maxgrade,
+                'gradedby' => $gradername,
                 'timecreated' => $grade->timecreated,
                 'timemodified' => $grade->timemodified,
             ],
@@ -173,6 +179,7 @@ class fetch extends external_api {
                 'grade' => new external_value(PARAM_FLOAT, 'The numeric grade'),
                 'usergrade' => new external_value(PARAM_RAW, 'Current user grade'),
                 'maxgrade' => new external_value(PARAM_RAW, 'Max possible grade'),
+                'gradedby' => new external_value(PARAM_RAW, 'The assumed grader of this grading instance'),
                 'timecreated' => new external_value(PARAM_INT, 'The time that the grade was created'),
                 'timemodified' => new external_value(PARAM_INT, 'The time that the grade was last updated'),
             ]),
index 6ca3f99..5488027 100644 (file)
@@ -110,8 +110,8 @@ class store extends external_api {
      */
     public static function execute(string $component, int $contextid, string $itemname, int $gradeduserid,
             bool $notifyuser, string $formdata): array {
-        global $USER;
-
+        global $USER, $CFG;
+        require_once("{$CFG->libdir}/gradelib.php");
         [
             'component' => $component,
             'contextid' => $contextid,
@@ -172,7 +172,11 @@ class store extends external_api {
         // Fetch the updated grade back out.
         $grade = $gradeitem->get_grade_for_user($gradeduser, $USER);
 
-        return fetch::get_fetch_data($grade, $hasgrade, 0);
+        $gradegrade = \grade_grade::fetch(['itemid' => $gradeitem->get_grade_item()->id, 'userid' => $gradeduser->id]);
+        $gradername = $gradegrade ? fullname(\core_user::get_user($gradegrade->usermodified)) : null;
+        $maxgrade = (int) $gradeitem->get_grade_item()->grademax;
+
+        return fetch::get_fetch_data($grade, $hasgrade, $maxgrade, $gradername);
     }
 
     /**
index 6d2e12b..8f3bb48 100644 (file)
@@ -97,8 +97,8 @@ class fetch extends external_api {
      * @since Moodle 3.8
      */
     public static function execute(string $component, int $contextid, string $itemname, int $gradeduserid): array {
-        global $USER;
-
+        global $USER, $CFG;
+        require_once("{$CFG->libdir}/gradelib.php");
         [
             'component' => $component,
             'contextid' => $contextid,
@@ -129,9 +129,12 @@ class fetch extends external_api {
 
         $gradeduser = \core_user::get_user($gradeduserid);
 
+        // Set up some items we need to return on other interfaces.
+        $gradegrade = \grade_grade::fetch(['itemid' => $gradeitem->get_grade_item()->id, 'userid' => $gradeduser->id]);
+        $gradername = $gradegrade ? fullname(\core_user::get_user($gradegrade->usermodified)) : null;
         $maxgrade = (int) $gradeitem->get_grade_item()->grademax;
 
-        return self::get_fetch_data($gradeitem, $gradeduser, $maxgrade);
+        return self::get_fetch_data($gradeitem, $gradeduser, $maxgrade, $gradername);
     }
 
     /**
@@ -140,9 +143,10 @@ class fetch extends external_api {
      * @param gradeitem $gradeitem
      * @param stdClass $gradeduser
      * @param int $maxgrade
+     * @param string|null $gradername
      * @return array
      */
-    public static function get_fetch_data(gradeitem $gradeitem, stdClass $gradeduser, int $maxgrade): array {
+    public static function get_fetch_data(gradeitem $gradeitem, stdClass $gradeduser, int $maxgrade, ?string $gradername): array {
         global $USER;
 
         $hasgrade = $gradeitem->user_has_grade($gradeduser);
@@ -165,6 +169,7 @@ class fetch extends external_api {
                 'options' => $values,
                 'usergrade' => $grade->grade,
                 'maxgrade' => $maxgrade,
+                'gradedby' => $gradername,
                 'timecreated' => $grade->timecreated,
                 'timemodified' => $grade->timemodified,
             ],
@@ -193,6 +198,7 @@ class fetch extends external_api {
                 ),
                 'usergrade' => new external_value(PARAM_RAW, 'Current user grade'),
                 'maxgrade' => new external_value(PARAM_RAW, 'Max possible grade'),
+                'gradedby' => new external_value(PARAM_RAW, 'The assumed grader of this grading instance'),
                 'timecreated' => new external_value(PARAM_INT, 'The time that the grade was created'),
                 'timemodified' => new external_value(PARAM_INT, 'The time that the grade was last updated'),
             ]),
index 41d2b52..751017b 100644 (file)
@@ -107,8 +107,8 @@ class store extends external_api {
      */
     public static function execute(string $component, int $contextid, string $itemname, int $gradeduserid,
             bool $notifyuser, string $formdata): array {
-        global $USER;
-
+        global $USER, $CFG;
+        require_once("{$CFG->libdir}/gradelib.php");
         [
             'component' => $component,
             'contextid' => $contextid,
@@ -165,7 +165,11 @@ class store extends external_api {
             $gradeitem->send_student_notification($gradeduser, $USER);
         }
 
-        return fetch::get_fetch_data($gradeitem, $gradeduser, 0);
+        $gradegrade = \grade_grade::fetch(['itemid' => $gradeitem->get_grade_item()->id, 'userid' => $gradeduser->id]);
+        $gradername = $gradegrade ? fullname(\core_user::get_user($gradegrade->usermodified)) : null;
+        $maxgrade = (int) $gradeitem->get_grade_item()->grademax;
+
+        return fetch::get_fetch_data($gradeitem, $gradeduser, $maxgrade, $gradername);
     }
 
     /**
index 6fe6008..f1f0f5d 100644 (file)
@@ -100,8 +100,8 @@ class fetch extends external_api {
      * @since Moodle 3.8
      */
     public static function execute(string $component, int $contextid, string $itemname, int $gradeduserid): array {
-        global $USER;
-
+        global $CFG;
+        require_once("{$CFG->libdir}/gradelib.php");
         [
             'component' => $component,
             'contextid' => $contextid,
@@ -156,6 +156,10 @@ class fetch extends external_api {
         $fillings = $instance->get_guide_filling();
         $context = $controller->get_context();
         $definitionid = (int) $definition->id;
+
+        // Set up some items we need to return on other interfaces.
+        $gradegrade = \grade_grade::fetch(['itemid' => $gradeitem->get_grade_item()->id, 'userid' => $gradeduser->id]);
+        $gradername = $gradegrade ? fullname(\core_user::get_user($gradegrade->usermodified)) : null;
         $maxgrade = max(array_keys($controller->get_grade_range()));
 
         $criterion = [];
@@ -227,6 +231,7 @@ class fetch extends external_api {
                 'comments' => $comments,
                 'usergrade' => $grade->grade,
                 'maxgrade' => $maxgrade,
+                'gradedby' => $gradername,
                 'timecreated' => $grade->timecreated,
                 'timemodified' => $grade->timemodified,
             ],
@@ -269,6 +274,7 @@ class fetch extends external_api {
                 ),
                 'usergrade' => new external_value(PARAM_RAW, 'Current user grade'),
                 'maxgrade' => new external_value(PARAM_RAW, 'Max possible grade'),
+                'gradedby' => new external_value(PARAM_RAW, 'The assumed grader of this grading instance'),
                 'timecreated' => new external_value(PARAM_INT, 'The time that the grade was created'),
                 'timemodified' => new external_value(PARAM_INT, 'The time that the grade was last updated'),
             ]),
index bee39c5..50ec39b 100644 (file)
@@ -123,16 +123,27 @@ class fetch_test extends advanced_testcase {
 
         $this->assertEquals('gradingform_guide/grades/grader/gradingpanel', $result['templatename']);
 
+        $this->assertArrayHasKey('warnings', $result);
+        $this->assertIsArray($result['warnings']);
+        $this->assertEmpty($result['warnings']);
+
+        // Test the grade array items.
         $this->assertArrayHasKey('grade', $result);
         $this->assertIsArray($result['grade']);
-
         $this->assertIsInt($result['grade']['timecreated']);
+
         $this->assertArrayHasKey('timemodified', $result['grade']);
         $this->assertIsInt($result['grade']['timemodified']);
 
-        $this->assertArrayHasKey('warnings', $result);
-        $this->assertIsArray($result['warnings']);
-        $this->assertEmpty($result['warnings']);
+        $this->assertArrayHasKey('usergrade', $result['grade']);
+        $this->assertEquals(0, $result['grade']['usergrade']);
+
+        $this->assertArrayHasKey('maxgrade', $result['grade']);
+        $this->assertIsInt($result['grade']['maxgrade']);
+        $this->assertEquals(100, $result['grade']['maxgrade']);
+
+        $this->assertArrayHasKey('gradedby', $result['grade']);
+        $this->assertEquals(null, $result['grade']['gradedby']);
 
         $this->assertArrayHasKey('criterion', $result['grade']);
         $criteria = $result['grade']['criterion'];
@@ -193,7 +204,7 @@ class fetch_test extends advanced_testcase {
             'instanceid' => $instance->get_id(),
             'advancedgrading' => $submissiondata,
         ]);
-
+        // Set up some items we need to return on other interfaces.
         $result = fetch::execute('mod_forum', (int) $forum->get_context()->id, 'forum', (int) $student->id);
         $result = external_api::clean_returnvalue(fetch::execute_returns(), $result);
 
@@ -202,16 +213,27 @@ class fetch_test extends advanced_testcase {
 
         $this->assertEquals('gradingform_guide/grades/grader/gradingpanel', $result['templatename']);
 
+        $this->assertArrayHasKey('warnings', $result);
+        $this->assertIsArray($result['warnings']);
+        $this->assertEmpty($result['warnings']);
+
+        // Test the grade array items.
         $this->assertArrayHasKey('grade', $result);
         $this->assertIsArray($result['grade']);
-
         $this->assertIsInt($result['grade']['timecreated']);
+
         $this->assertArrayHasKey('timemodified', $result['grade']);
         $this->assertIsInt($result['grade']['timemodified']);
 
-        $this->assertArrayHasKey('warnings', $result);
-        $this->assertIsArray($result['warnings']);
-        $this->assertEmpty($result['warnings']);
+        $this->assertArrayHasKey('usergrade', $result['grade']);
+        $this->assertEquals(25, $result['grade']['usergrade']);
+
+        $this->assertArrayHasKey('maxgrade', $result['grade']);
+        $this->assertIsInt($result['grade']['maxgrade']);
+        $this->assertEquals(100, $result['grade']['maxgrade']);
+
+        $this->assertArrayHasKey('gradedby', $result['grade']);
+        $this->assertEquals(fullname($teacher), $result['grade']['gradedby']);
 
         $this->assertArrayHasKey('criterion', $result['grade']);
         $criteria = $result['grade']['criterion'];
@@ -254,7 +276,7 @@ class fetch_test extends advanced_testcase {
 
         $datagenerator = $this->getDataGenerator();
         $course = $datagenerator->create_course();
-        $forum = $datagenerator->create_module('forum', array_merge($config, ['course' => $course->id]));
+        $forum = $datagenerator->create_module('forum', array_merge($config, ['course' => $course->id, 'grade_forum' => 100]));
 
         $vaultfactory = \mod_forum\local\container::get_vault_factory();
         $vault = $vaultfactory->get_forum_vault();
@@ -284,7 +306,20 @@ class fetch_test extends advanced_testcase {
         $controller = $guidegenerator->get_test_guide($forum->get_context(), 'forum', 'forum');
         $definition = $controller->get_definition();
 
-        $DB->set_field('forum', 'grade_forum', count($definition->guide_criteria), ['id' => $forum->get_id()]);
+        // In the situation of mod_forum this would be the id from forum_grades.
+        $itemid = 1;
+        $instance = $controller->create_instance($student->id, $itemid);
+
+        $data = $this->get_test_form_data(
+            $controller,
+            $itemid,
+            5, 'This user made several mistakes.',
+            10, 'This user has two pictures.'
+        );
+
+        // Update this instance with data.
+        $instance->update($data);
+
         return [
             'forum' => $forum,
             'controller' => $controller,
@@ -293,4 +328,36 @@ class fetch_test extends advanced_testcase {
             'teacher' => $teacher,
         ];
     }
+
+    /**
+     * Fetch a set of sample data.
+     *
+     * @param \gradingform_guide_controller $controller
+     * @param int $itemid
+     * @param float $spellingscore
+     * @param string $spellingremark
+     * @param float $picturescore
+     * @param string $pictureremark
+     * @return array
+     */
+    protected function get_test_form_data(
+        \gradingform_guide_controller $controller,
+        int $itemid,
+        float $spellingscore,
+        string $spellingremark,
+        float $picturescore,
+        string $pictureremark
+    ): array {
+        $generator = \testing_util::get_data_generator();
+        $guidegenerator = $generator->get_plugin_generator('gradingform_guide');
+
+        return $guidegenerator->get_test_form_data(
+            $controller,
+            $itemid,
+            $spellingscore,
+            $spellingremark,
+            $picturescore,
+            $pictureremark
+        );
+    }
 }
index cc0a6b6..89296fe 100644 (file)
@@ -155,16 +155,27 @@ class store_test extends advanced_testcase {
 
         $this->assertEquals('gradingform_guide/grades/grader/gradingpanel', $result['templatename']);
 
+        $this->assertArrayHasKey('warnings', $result);
+        $this->assertIsArray($result['warnings']);
+        $this->assertEmpty($result['warnings']);
+
+        // Test the grade array items.
         $this->assertArrayHasKey('grade', $result);
         $this->assertIsArray($result['grade']);
-
         $this->assertIsInt($result['grade']['timecreated']);
+
         $this->assertArrayHasKey('timemodified', $result['grade']);
         $this->assertIsInt($result['grade']['timemodified']);
 
-        $this->assertArrayHasKey('warnings', $result);
-        $this->assertIsArray($result['warnings']);
-        $this->assertEmpty($result['warnings']);
+        $this->assertArrayHasKey('usergrade', $result['grade']);
+        $this->assertEquals(0.5, $result['grade']['usergrade']);
+
+        $this->assertArrayHasKey('maxgrade', $result['grade']);
+        $this->assertIsInt($result['grade']['maxgrade']);
+        $this->assertEquals(2, $result['grade']['maxgrade']);
+
+        $this->assertArrayHasKey('gradedby', $result['grade']);
+        $this->assertEquals(fullname($teacher), $result['grade']['gradedby']);
 
         $this->assertArrayHasKey('criterion', $result['grade']);
         $criteria = $result['grade']['criterion'];
index 5c18346..3632c7a 100644 (file)
@@ -93,6 +93,8 @@ class fetch extends external_api {
      * @since Moodle 3.8
      */
     public static function execute(string $component, int $contextid, string $itemname, int $gradeduserid): array {
+        global $CFG;
+        require_once("{$CFG->libdir}/gradelib.php");
         [
             'component' => $component,
             'contextid' => $contextid,
@@ -138,7 +140,6 @@ class fetch extends external_api {
      */
     public static function get_fetch_data(gradeitem $gradeitem, stdClass $gradeduser): array {
         global $USER;
-
         // Set up all the controllers etc that we'll be needing.
         $hasgrade = $gradeitem->user_has_grade($gradeduser);
         $grade = $gradeitem->get_grade_for_user($gradeduser, $USER);
@@ -148,7 +149,12 @@ class fetch extends external_api {
         $fillings = $instance->get_rubric_filling();
         $context = $controller->get_context();
         $definitionid = (int) $definition->id;
+
+        // Set up some items we need to return on other interfaces.
+        $gradegrade = \grade_grade::fetch(['itemid' => $gradeitem->get_grade_item()->id, 'userid' => $gradeduser->id]);
+        $gradername = $gradegrade ? fullname(\core_user::get_user($gradegrade->usermodified)) : null;
         $maxgrade = max(array_keys($controller->get_grade_range()));
+
         $teacherdescription = self::get_formatted_text(
             $context,
             $definitionid,
@@ -239,6 +245,7 @@ class fetch extends external_api {
                 'canedit' => false,
                 'usergrade' => $grade->grade,
                 'maxgrade' => $maxgrade,
+                'gradedby' => $gradername,
                 'timecreated' => $grade->timecreated,
                 'timemodified' => $grade->timemodified,
             ],
@@ -277,6 +284,7 @@ class fetch extends external_api {
                 'timecreated' => new external_value(PARAM_INT, 'The time that the grade was created'),
                 'usergrade' => new external_value(PARAM_RAW, 'Current user grade'),
                 'maxgrade' => new external_value(PARAM_RAW, 'Max possible grade'),
+                'gradedby' => new external_value(PARAM_RAW, 'The assumed grader of this grading instance'),
                 'timemodified' => new external_value(PARAM_INT, 'The time that the grade was last updated'),
             ]),
             'warnings' => new external_warnings(),
index ec1ac94..2f7525e 100644 (file)
@@ -30,6 +30,7 @@ namespace gradingform_rubric\grades\grader\gradingpanel\external;
 use advanced_testcase;
 use coding_exception;
 use core_grades\component_gradeitem;
+use core_grades\component_gradeitems;
 use external_api;
 use mod_forum\local\entities\forum as forum_entity;
 use moodle_exception;
@@ -123,16 +124,27 @@ class fetch_test extends advanced_testcase {
 
         $this->assertEquals('gradingform_rubric/grades/grader/gradingpanel', $result['templatename']);
 
+        $this->assertArrayHasKey('warnings', $result);
+        $this->assertIsArray($result['warnings']);
+        $this->assertEmpty($result['warnings']);
+
+        // Test the grade array items.
         $this->assertArrayHasKey('grade', $result);
         $this->assertIsArray($result['grade']);
-
         $this->assertIsInt($result['grade']['timecreated']);
+
         $this->assertArrayHasKey('timemodified', $result['grade']);
         $this->assertIsInt($result['grade']['timemodified']);
 
-        $this->assertArrayHasKey('warnings', $result);
-        $this->assertIsArray($result['warnings']);
-        $this->assertEmpty($result['warnings']);
+        $this->assertArrayHasKey('usergrade', $result['grade']);
+        $this->assertEquals(0, $result['grade']['usergrade']);
+
+        $this->assertArrayHasKey('maxgrade', $result['grade']);
+        $this->assertIsInt($result['grade']['maxgrade']);
+        $this->assertEquals(100, $result['grade']['maxgrade']);
+
+        $this->assertArrayHasKey('gradedby', $result['grade']);
+        $this->assertEquals(null, $result['grade']['gradedby']);
 
         $this->assertArrayHasKey('criteria', $result['grade']);
         $criteria = $result['grade']['criteria'];
@@ -209,16 +221,27 @@ class fetch_test extends advanced_testcase {
 
         $this->assertEquals('gradingform_rubric/grades/grader/gradingpanel', $result['templatename']);
 
+        $this->assertArrayHasKey('warnings', $result);
+        $this->assertIsArray($result['warnings']);
+        $this->assertEmpty($result['warnings']);
+
+        // Test the grade array items.
         $this->assertArrayHasKey('grade', $result);
         $this->assertIsArray($result['grade']);
-
         $this->assertIsInt($result['grade']['timecreated']);
+
         $this->assertArrayHasKey('timemodified', $result['grade']);
         $this->assertIsInt($result['grade']['timemodified']);
 
-        $this->assertArrayHasKey('warnings', $result);
-        $this->assertIsArray($result['warnings']);
-        $this->assertEmpty($result['warnings']);
+        $this->assertArrayHasKey('usergrade', $result['grade']);
+        $this->assertEquals(50, $result['grade']['usergrade']);
+
+        $this->assertArrayHasKey('maxgrade', $result['grade']);
+        $this->assertIsInt($result['grade']['maxgrade']);
+        $this->assertEquals(100, $result['grade']['maxgrade']);
+
+        $this->assertArrayHasKey('gradedby', $result['grade']);
+        $this->assertEquals(fullname($teacher), $result['grade']['gradedby']);
 
         $this->assertArrayHasKey('criteria', $result['grade']);
         $criteria = $result['grade']['criteria'];
@@ -274,7 +297,7 @@ class fetch_test extends advanced_testcase {
 
         $datagenerator = $this->getDataGenerator();
         $course = $datagenerator->create_course();
-        $forum = $datagenerator->create_module('forum', array_merge($config, ['course' => $course->id]));
+        $forum = $datagenerator->create_module('forum', array_merge($config, ['course' => $course->id, 'grade_forum' => 100]));
 
         $vaultfactory = \mod_forum\local\container::get_vault_factory();
         $vault = $vaultfactory->get_forum_vault();
@@ -301,10 +324,24 @@ class fetch_test extends advanced_testcase {
         $student = $this->getDataGenerator()->create_and_enrol($course, 'student');
 
         $this->setUser($teacher);
+
         $controller = $rubricgenerator->get_test_rubric($forum->get_context(), 'forum', 'forum');
         $definition = $controller->get_definition();
 
-        $DB->set_field('forum', 'grade_forum', count($definition->rubric_criteria), ['id' => $forum->get_id()]);
+        // In the situation of mod_forum this would be the id from forum_grades.
+        $itemid = 1;
+        $instance = $controller->create_instance($student->id, $itemid);
+
+        $data = $this->get_test_form_data(
+            $controller,
+            $itemid,
+            1, 'This user made several mistakes.',
+            0, 'Please add more pictures.'
+        );
+
+        // Update this instance with data.
+        $instance->update($data);
+
         return [
             'forum' => $forum,
             'controller' => $controller,
@@ -313,4 +350,35 @@ class fetch_test extends advanced_testcase {
             'teacher' => $teacher,
         ];
     }
+    /**
+     * Fetch a set of sample data.
+     *
+     * @param \gradingform_rubric_controller $controller
+     * @param int $itemid
+     * @param float $spellingscore
+     * @param string $spellingremark
+     * @param float $picturescore
+     * @param string $pictureremark
+     * @return array
+     */
+    protected function get_test_form_data(
+        \gradingform_rubric_controller $controller,
+        int $itemid,
+        float $spellingscore,
+        string $spellingremark,
+        float $picturescore,
+        string $pictureremark
+    ): array {
+        $generator = \testing_util::get_data_generator();
+        $rubricgenerator = $generator->get_plugin_generator('gradingform_rubric');
+
+        return $rubricgenerator->get_test_form_data(
+            $controller,
+            $itemid,
+            $spellingscore,
+            $spellingremark,
+            $picturescore,
+            $pictureremark
+        );
+    }
 }
index cd720f6..e7b8aaf 100644 (file)
@@ -154,16 +154,27 @@ class store_test extends advanced_testcase {
 
         $this->assertEquals('gradingform_rubric/grades/grader/gradingpanel', $result['templatename']);
 
+        $this->assertArrayHasKey('warnings', $result);
+        $this->assertIsArray($result['warnings']);
+        $this->assertEmpty($result['warnings']);
+
+        // Test the grade array items.
         $this->assertArrayHasKey('grade', $result);
         $this->assertIsArray($result['grade']);
-
         $this->assertIsInt($result['grade']['timecreated']);
+
         $this->assertArrayHasKey('timemodified', $result['grade']);
         $this->assertIsInt($result['grade']['timemodified']);
 
-        $this->assertArrayHasKey('warnings', $result);
-        $this->assertIsArray($result['warnings']);
-        $this->assertEmpty($result['warnings']);
+        $this->assertArrayHasKey('usergrade', $result['grade']);
+        $this->assertEquals(1, $result['grade']['usergrade']);
+
+        $this->assertArrayHasKey('maxgrade', $result['grade']);
+        $this->assertIsInt($result['grade']['maxgrade']);
+        $this->assertEquals(2, $result['grade']['maxgrade']);
+
+        $this->assertArrayHasKey('gradedby', $result['grade']);
+        $this->assertEquals(fullname($teacher), $result['grade']['gradedby']);
 
         $this->assertArrayHasKey('criteria', $result['grade']);
         $criteria = $result['grade']['criteria'];
index 66db17e..6e61d5d 100644 (file)
@@ -122,18 +122,30 @@ class fetch_test extends advanced_testcase {
 
         $this->assertEquals('core_grades/grades/grader/gradingpanel/point', $result['templatename']);
 
+        $this->assertArrayHasKey('warnings', $result);
+        $this->assertIsArray($result['warnings']);
+        $this->assertEmpty($result['warnings']);
+
+        // Test the grade array items.
         $this->assertArrayHasKey('grade', $result);
         $this->assertIsArray($result['grade']);
+
         $this->assertArrayHasKey('grade', $result['grade']);
         $this->assertEmpty($result['grade']['grade']);
-        $this->assertArrayHasKey('timecreated', $result['grade']);
+
         $this->assertIsInt($result['grade']['timecreated']);
         $this->assertArrayHasKey('timemodified', $result['grade']);
         $this->assertIsInt($result['grade']['timemodified']);
 
-        $this->assertArrayHasKey('warnings', $result);
-        $this->assertIsArray($result['warnings']);
-        $this->assertEmpty($result['warnings']);
+        $this->assertArrayHasKey('usergrade', $result['grade']);
+        $this->assertEquals(0, $result['grade']['usergrade']);
+
+        $this->assertArrayHasKey('maxgrade', $result['grade']);
+        $this->assertIsInt($result['grade']['maxgrade']);
+        $this->assertEquals(5, $result['grade']['maxgrade']);
+
+        $this->assertArrayHasKey('gradedby', $result['grade']);
+        $this->assertEquals(null, $result['grade']['gradedby']);
     }
 
     /**
@@ -164,19 +176,31 @@ class fetch_test extends advanced_testcase {
 
         $this->assertEquals('core_grades/grades/grader/gradingpanel/point', $result['templatename']);
 
+        $this->assertArrayHasKey('warnings', $result);
+        $this->assertIsArray($result['warnings']);
+        $this->assertEmpty($result['warnings']);
+
+        // Test the grade array items.
         $this->assertArrayHasKey('grade', $result);
         $this->assertIsArray($result['grade']);
+
         $this->assertArrayHasKey('grade', $result['grade']);
         $this->assertIsFloat($result['grade']['grade']);
         $this->assertEquals(grade_floatval(unformat_float(4)), $result['grade']['grade']);
-        $this->assertArrayHasKey('timecreated', $result['grade']);
+
         $this->assertIsInt($result['grade']['timecreated']);
         $this->assertArrayHasKey('timemodified', $result['grade']);
         $this->assertIsInt($result['grade']['timemodified']);
 
-        $this->assertArrayHasKey('warnings', $result);
-        $this->assertIsArray($result['warnings']);
-        $this->assertEmpty($result['warnings']);
+        $this->assertArrayHasKey('usergrade', $result['grade']);
+        $this->assertEquals(4, $result['grade']['usergrade']);
+
+        $this->assertArrayHasKey('maxgrade', $result['grade']);
+        $this->assertIsInt($result['grade']['maxgrade']);
+        $this->assertEquals(5, $result['grade']['maxgrade']);
+
+        $this->assertArrayHasKey('gradedby', $result['grade']);
+        $this->assertEquals(fullname($teacher), $result['grade']['gradedby']);
     }
 
     /**
index 00695ce..5c8a50b 100644 (file)
@@ -162,6 +162,27 @@ class store_test extends advanced_testcase {
         $this->assertIsArray($result['warnings']);
         $this->assertEmpty($result['warnings']);
 
+        // Test the grade array items.
+        $this->assertArrayHasKey('grade', $result);
+        $this->assertIsArray($result['grade']);
+
+        $this->assertArrayHasKey('grade', $result['grade']);
+        $this->assertEquals(null, $result['grade']['grade']);
+
+        $this->assertIsInt($result['grade']['timecreated']);
+        $this->assertArrayHasKey('timemodified', $result['grade']);
+        $this->assertIsInt($result['grade']['timemodified']);
+
+        $this->assertArrayHasKey('usergrade', $result['grade']);
+        $this->assertEquals(null, $result['grade']['usergrade']);
+
+        $this->assertArrayHasKey('maxgrade', $result['grade']);
+        $this->assertIsInt($result['grade']['maxgrade']);
+        $this->assertEquals(5, $result['grade']['maxgrade']);
+
+        $this->assertArrayHasKey('gradedby', $result['grade']);
+        $this->assertEquals(fullname($teacher), $result['grade']['gradedby']);
+
         // Compare against the grade stored in the database.
         $storedgradeitem = grade_item::fetch([
             'courseid' => $forum->get_course_id(),
@@ -210,18 +231,30 @@ class store_test extends advanced_testcase {
 
         $this->assertEquals('core_grades/grades/grader/gradingpanel/point', $result['templatename']);
 
+        $this->assertArrayHasKey('warnings', $result);
+        $this->assertIsArray($result['warnings']);
+        $this->assertEmpty($result['warnings']);
+
+        // Test the grade array items.
         $this->assertArrayHasKey('grade', $result);
         $this->assertIsArray($result['grade']);
+
         $this->assertArrayHasKey('grade', $result['grade']);
         $this->assertEquals($formattedvalue, $result['grade']['grade']);
-        $this->assertArrayHasKey('timecreated', $result['grade']);
+
         $this->assertIsInt($result['grade']['timecreated']);
         $this->assertArrayHasKey('timemodified', $result['grade']);
         $this->assertIsInt($result['grade']['timemodified']);
 
-        $this->assertArrayHasKey('warnings', $result);
-        $this->assertIsArray($result['warnings']);
-        $this->assertEmpty($result['warnings']);
+        $this->assertArrayHasKey('usergrade', $result['grade']);
+        $this->assertEquals($formattedvalue, $result['grade']['usergrade']);
+
+        $this->assertArrayHasKey('maxgrade', $result['grade']);
+        $this->assertIsInt($result['grade']['maxgrade']);
+        $this->assertEquals(5, $result['grade']['maxgrade']);
+
+        $this->assertArrayHasKey('gradedby', $result['grade']);
+        $this->assertEquals(fullname($teacher), $result['grade']['gradedby']);
 
         // Compare against the grade stored in the database.
         $storedgradeitem = grade_item::fetch([
index 4b64859..cd5de19 100644 (file)
@@ -129,9 +129,28 @@ class fetch_test extends advanced_testcase {
 
         $this->assertEquals('core_grades/grades/grader/gradingpanel/scale', $result['templatename']);
 
+        $this->assertArrayHasKey('warnings', $result);
+        $this->assertIsArray($result['warnings']);
+        $this->assertEmpty($result['warnings']);
+
+        // Test the grade array items.
         $this->assertArrayHasKey('grade', $result);
         $this->assertIsArray($result['grade']);
 
+        $this->assertIsInt($result['grade']['timecreated']);
+        $this->assertArrayHasKey('timemodified', $result['grade']);
+        $this->assertIsInt($result['grade']['timemodified']);
+
+        $this->assertArrayHasKey('usergrade', $result['grade']);
+        $this->assertEquals(0, $result['grade']['usergrade']);
+
+        $this->assertArrayHasKey('maxgrade', $result['grade']);
+        $this->assertIsInt($result['grade']['maxgrade']);
+        $this->assertEquals(3, $result['grade']['maxgrade']);
+
+        $this->assertArrayHasKey('gradedby', $result['grade']);
+        $this->assertEquals(null, $result['grade']['gradedby']);
+
         $this->assertArrayHasKey('options', $result['grade']);
         $this->assertCount(count($options), $result['grade']['options']);
         rsort($options);
@@ -148,14 +167,6 @@ class fetch_test extends advanced_testcase {
             $this->assertArrayHasKey('selected', $returnedoption);
             $this->assertFalse($returnedoption['selected']);
         }
-
-        $this->assertIsInt($result['grade']['timecreated']);
-        $this->assertArrayHasKey('timemodified', $result['grade']);
-        $this->assertIsInt($result['grade']['timemodified']);
-
-        $this->assertArrayHasKey('warnings', $result);
-        $this->assertIsArray($result['warnings']);
-        $this->assertEmpty($result['warnings']);
     }
 
     /**
@@ -201,9 +212,28 @@ class fetch_test extends advanced_testcase {
 
         $this->assertEquals('core_grades/grades/grader/gradingpanel/scale', $result['templatename']);
 
+        $this->assertArrayHasKey('warnings', $result);
+        $this->assertIsArray($result['warnings']);
+        $this->assertEmpty($result['warnings']);
+
+        // Test the grade array items.
         $this->assertArrayHasKey('grade', $result);
         $this->assertIsArray($result['grade']);
 
+        $this->assertIsInt($result['grade']['timecreated']);
+        $this->assertArrayHasKey('timemodified', $result['grade']);
+        $this->assertIsInt($result['grade']['timemodified']);
+
+        $this->assertArrayHasKey('usergrade', $result['grade']);
+        $this->assertEquals(2, $result['grade']['usergrade']);
+
+        $this->assertArrayHasKey('maxgrade', $result['grade']);
+        $this->assertIsInt($result['grade']['maxgrade']);
+        $this->assertEquals(3, $result['grade']['maxgrade']);
+
+        $this->assertArrayHasKey('gradedby', $result['grade']);
+        $this->assertEquals(fullname($teacher), $result['grade']['gradedby']);
+
         $this->assertArrayHasKey('options', $result['grade']);
         $this->assertCount(count($options), $result['grade']['options']);
         rsort($options);
@@ -224,14 +254,6 @@ class fetch_test extends advanced_testcase {
         $this->assertFalse($result['grade']['options'][0]['selected']);
         $this->assertTrue($result['grade']['options'][1]['selected']);
         $this->assertFalse($result['grade']['options'][2]['selected']);
-
-        $this->assertIsInt($result['grade']['timecreated']);
-        $this->assertArrayHasKey('timemodified', $result['grade']);
-        $this->assertIsInt($result['grade']['timemodified']);
-
-        $this->assertArrayHasKey('warnings', $result);
-        $this->assertIsArray($result['warnings']);
-        $this->assertEmpty($result['warnings']);
     }
 
     /**
index 71c46a1..b389b07 100644 (file)
@@ -147,8 +147,28 @@ class store_test extends advanced_testcase {
 
         $this->assertEquals('core_grades/grades/grader/gradingpanel/scale', $result['templatename']);
 
+        $this->assertArrayHasKey('warnings', $result);
+        $this->assertIsArray($result['warnings']);
+        $this->assertEmpty($result['warnings']);
+
+        // Test the grade array items.
         $this->assertArrayHasKey('grade', $result);
         $this->assertIsArray($result['grade']);
+
+        $this->assertIsInt($result['grade']['timecreated']);
+        $this->assertArrayHasKey('timemodified', $result['grade']);
+        $this->assertIsInt($result['grade']['timemodified']);
+
+        $this->assertArrayHasKey('usergrade', $result['grade']);
+        $this->assertEquals(0, $result['grade']['usergrade']);
+
+        $this->assertArrayHasKey('maxgrade', $result['grade']);
+        $this->assertIsInt($result['grade']['maxgrade']);
+        $this->assertEquals(3, $result['grade']['maxgrade']);
+
+        $this->assertArrayHasKey('gradedby', $result['grade']);
+        $this->assertEquals(fullname($teacher), $result['grade']['gradedby']);
+
         $this->assertArrayHasKey('options', $result['grade']);
         $this->assertCount(count($options), $result['grade']['options']);
         rsort($options);
@@ -166,14 +186,6 @@ class store_test extends advanced_testcase {
             $this->assertFalse($returnedoption['selected']);
         }
 
-        $this->assertIsInt($result['grade']['timecreated']);
-        $this->assertArrayHasKey('timemodified', $result['grade']);
-        $this->assertIsInt($result['grade']['timemodified']);
-
-        $this->assertArrayHasKey('warnings', $result);
-        $this->assertIsArray($result['warnings']);
-        $this->assertEmpty($result['warnings']);
-
         // Compare against the grade stored in the database.
         $storedgradeitem = grade_item::fetch([
             'courseid' => $forum->get_course_id(),
@@ -219,8 +231,28 @@ class store_test extends advanced_testcase {
 
         $this->assertEquals('core_grades/grades/grader/gradingpanel/scale', $result['templatename']);
 
+        $this->assertArrayHasKey('warnings', $result);
+        $this->assertIsArray($result['warnings']);
+        $this->assertEmpty($result['warnings']);
+
+        // Test the grade array items.
         $this->assertArrayHasKey('grade', $result);
         $this->assertIsArray($result['grade']);
+
+        $this->assertIsInt($result['grade']['timecreated']);
+        $this->assertArrayHasKey('timemodified', $result['grade']);
+        $this->assertIsInt($result['grade']['timemodified']);
+
+        $this->assertArrayHasKey('usergrade', $result['grade']);
+        $this->assertEquals(-1, $result['grade']['usergrade']);
+
+        $this->assertArrayHasKey('maxgrade', $result['grade']);
+        $this->assertIsInt($result['grade']['maxgrade']);
+        $this->assertEquals(3, $result['grade']['maxgrade']);
+
+        $this->assertArrayHasKey('gradedby', $result['grade']);
+        $this->assertEquals(null, $result['grade']['gradedby']);
+
         $this->assertArrayHasKey('options', $result['grade']);
         $this->assertCount(count($options), $result['grade']['options']);
         rsort($options);
@@ -238,14 +270,6 @@ class store_test extends advanced_testcase {
             $this->assertFalse($returnedoption['selected']);
         }
 
-        $this->assertIsInt($result['grade']['timecreated']);
-        $this->assertArrayHasKey('timemodified', $result['grade']);
-        $this->assertIsInt($result['grade']['timemodified']);
-
-        $this->assertArrayHasKey('warnings', $result);
-        $this->assertIsArray($result['warnings']);
-        $this->assertEmpty($result['warnings']);
-
         // Compare against the grade stored in the database.
         $storedgradeitem = grade_item::fetch([
             'courseid' => $forum->get_course_id(),
@@ -294,8 +318,28 @@ class store_test extends advanced_testcase {
 
         $this->assertEquals('core_grades/grades/grader/gradingpanel/scale', $result['templatename']);
 
+        $this->assertArrayHasKey('warnings', $result);
+        $this->assertIsArray($result['warnings']);
+        $this->assertEmpty($result['warnings']);
+
+        // Test the grade array items.
         $this->assertArrayHasKey('grade', $result);
         $this->assertIsArray($result['grade']);
+
+        $this->assertIsInt($result['grade']['timecreated']);
+        $this->assertArrayHasKey('timemodified', $result['grade']);
+        $this->assertIsInt($result['grade']['timemodified']);
+
+        $this->assertArrayHasKey('usergrade', $result['grade']);
+        $this->assertEquals(2, $result['grade']['usergrade']);
+
+        $this->assertArrayHasKey('maxgrade', $result['grade']);
+        $this->assertIsInt($result['grade']['maxgrade']);
+        $this->assertEquals(3, $result['grade']['maxgrade']);
+
+        $this->assertArrayHasKey('gradedby', $result['grade']);
+        $this->assertEquals(fullname($teacher), $result['grade']['gradedby']);
+
         $this->assertArrayHasKey('options', $result['grade']);
         $this->assertCount(count($options), $result['grade']['options']);
         rsort($options);
@@ -312,19 +356,6 @@ class store_test extends advanced_testcase {
             $this->assertArrayHasKey('selected', $returnedoption);
         }
 
-        // The grade was 2, which relates to the middle option.
-        $this->assertFalse($result['grade']['options'][0]['selected']);
-        $this->assertTrue($result['grade']['options'][1]['selected']);
-        $this->assertFalse($result['grade']['options'][2]['selected']);
-
-        $this->assertIsInt($result['grade']['timecreated']);
-        $this->assertArrayHasKey('timemodified', $result['grade']);
-        $this->assertIsInt($result['grade']['timemodified']);
-
-        $this->assertArrayHasKey('warnings', $result);
-        $this->assertIsArray($result['warnings']);
-        $this->assertEmpty($result['warnings']);
-
         // Compare against the grade stored in the database.
         $storedgradeitem = grade_item::fetch([
             'courseid' => $forum->get_course_id(),
@@ -340,6 +371,11 @@ class store_test extends advanced_testcase {
 
         $this->assertEquals($formattedvalue, $storedgrade->rawgrade);
         $this->assertEquals($scale->id, $storedgrade->rawscaleid);
+
+        // The grade was 2, which relates to the middle option.
+        $this->assertFalse($result['grade']['options'][0]['selected']);
+        $this->assertTrue($result['grade']['options'][1]['selected']);
+        $this->assertFalse($result['grade']['options'][2]['selected']);
     }
 
     /**
index a1fa7ba..50a2094 100644 (file)
@@ -745,6 +745,8 @@ $string['grade_forum_title'] = 'Grade';
 $string['grade_rating_name'] = 'Rating';
 $string['gradeusers'] = 'Grade users';
 $string['graded'] = 'Graded';
+$string['gradedby'] = 'Graded by';
+$string['notgraded'] = 'Not graded';
 $string['gradeforrating'] = 'Grade for rating: {$a->str_long_grade}';
 $string['gradeforratinghidden'] = 'Grade for rating hidden';
 $string['gradeforwholeforum'] = 'Grade for forum: {$a->str_long_grade}';
index 9b4e953..920556c 100644 (file)
             <h5 class="font-weight-bold description">{{#str}}grade{{/str}}:</h5>
             <p class="ml-auto">{{usergrade}} / {{maxgrade}}</p>
         </div>
+        <div class="row-fluid px-3">
+            <h5 class="font-weight-bold description">{{#str}}gradedby, forum{{/str}}:</h5>
+            <p class="ml-auto">
+                {{#gradedby}}
+                    {{gradedby}}
+                {{/gradedby}}
+                {{^gradedby}}
+                    -
+                {{/gradedby}}
+            </p>
+        </div>
         <div class="row-fluid px-3">
             <h5 class="font-weight-bold description">{{#str}}date{{/str}}:</h5>
             <p class="ml-auto">{{#userdate}}{{timemodified}}, {{#str}} strftimedate, langconfig {{/str}}{{/userdate}}</p>