MDL-66074 mod_forum: Mustache and PHP documentation for grading
authorMathew May <mathewm@hotmail.co.nz>
Mon, 28 Oct 2019 05:22:48 +0000 (13:22 +0800)
committerMathew May <mathewm@hotmail.co.nz>
Wed, 30 Oct 2019 05:03:59 +0000 (13:03 +0800)
16 files changed:
mod/forum/classes/grades/forum_gradeitem.php
mod/forum/classes/local/vaults/post.php
mod/forum/db/upgrade.php
mod/forum/externallib.php
mod/forum/templates/grades/grader/discussion/post_modal.mustache
mod/forum/templates/grades/grader/discussion/posts.mustache
mod/forum/templates/local/grades/grader.mustache
mod/forum/templates/local/grades/local/grader/content.mustache
mod/forum/templates/local/grades/local/grader/grade_placeholder.mustache
mod/forum/templates/local/grades/local/grader/grading.mustache
mod/forum/templates/local/grades/local/grader/gradingpanel/error.mustache
mod/forum/templates/local/grades/local/grader/navigation.mustache
mod/forum/templates/local/grades/local/grader/user_picker.mustache
mod/forum/templates/local/grades/local/grader/user_picker/user.mustache
mod/forum/templates/local/grades/local/grader/user_picker_placeholder.mustache
mod/forum/tests/vaults_post_test.php

index 37f477d..bd1b526 100644 (file)
@@ -65,7 +65,9 @@ class forum_gradeitem extends component_gradeitem {
     /**
      * Return an instance using the forum_entity instance.
      *
-     * @param context $context
+     * @param forum_entity $forum
+     *
+     * @return forum_gradeitem
      */
     public static function load_from_forum_entity(forum_entity $forum): self {
         $instance = new static('mod_forum', $forum->get_context(), 'forum');
@@ -124,7 +126,6 @@ class forum_gradeitem extends component_gradeitem {
      * Get the grade value for this instance.
      * The itemname is translated to the relevant grade field on the forum entity.
      *
-     * @param string $itemname
      * @return int
      */
     protected function get_gradeitem_value(): int {
@@ -139,6 +140,7 @@ class forum_gradeitem extends component_gradeitem {
      * @param stdClass $gradeduser The user being graded
      * @param stdClass $grader The user who is grading
      * @return stdClass The newly created grade record
+     * @throws \dml_exception
      */
     public function create_empty_grade(stdClass $gradeduser, stdClass $grader): stdClass {
         global $DB;
@@ -162,6 +164,7 @@ class forum_gradeitem extends component_gradeitem {
      * @param stdClass $gradeduser The user being graded
      * @param stdClass $grader The user who is grading
      * @return stdClass The grade value
+     * @throws \dml_exception
      */
     public function get_grade_for_user(stdClass $gradeduser, stdClass $grader = null): ?stdClass {
         global $DB;
@@ -184,8 +187,8 @@ class forum_gradeitem extends component_gradeitem {
     /**
      * Get grades for all users for the specified gradeitem.
      *
-     * @param int $itemnumber The specific grade item to fetch for the user
      * @return stdClass[] The grades
+     * @throws \dml_exception
      */
     public function get_all_grades(): array {
         global $DB;
@@ -201,6 +204,9 @@ class forum_gradeitem extends component_gradeitem {
      *
      * @param stdClass $grade
      * @return bool Success
+     * @throws \dml_exception
+     * @throws \moodle_exception
+     * @throws coding_exception
      */
     protected function store_grade(stdClass $grade): bool {
         global $CFG, $DB;
index b8a7b32..da0ad29 100644 (file)
@@ -513,41 +513,6 @@ class post extends db_table_vault {
         return $this->transform_db_records_to_entities($records);
     }
 
-    /**
-     * Get the posts for the given user.
-     *
-     * @param int[] $discussionids The list of discussions to fetch posts for
-     * @param int $userid
-     * @param bool $canseeprivatereplies Whether this user can see all private replies or not
-     * @param string $orderby Order the results
-     * @return post_entity[]
-     */
-    public function get_posts_in_forum_for_user_id(
-        array $discussionids,
-        int $userid,
-        bool $canseeprivatereplies,
-        string $orderby = 'created ASC'
-    ): array {
-        $user = $this->get_db()->get_record('user', ['id' => (int)$userid], '*', IGNORE_MISSING);
-        list($insql, $params) = $this->get_db()->get_in_or_equal($discussionids, SQL_PARAMS_NAMED);
-
-        $alias = $this->get_table_alias();
-        [
-            'where' => $privatewhere,
-            'params' => $privateparams,
-        ] = $this->get_private_reply_sql($user, $canseeprivatereplies);
-
-        $wheresql = "{$alias}.userid = :authorid {$privatewhere}";
-        $orderbysql = $alias . '.' . $orderby;
-
-        $sql = $this->generate_get_records_sql($wheresql, $orderbysql);
-        $records = $this->get_db()->get_records_sql($sql, array_merge([
-            'authorid' => $userid,
-        ], $privateparams));
-
-        return $this->transform_db_records_to_entities($records);
-    }
-
     /**
      * Get the posts for the given user.
      *
index e4cdeef..ac6f468 100644 (file)
@@ -195,7 +195,8 @@ function xmldb_forum_upgrade($oldversion) {
         // Main savepoint reached.
         upgrade_mod_savepoint(true, 2019071902, 'forum');
     }
-    if ($oldversion < 2019071902) {
+
+    if ($oldversion < 2019081100) {
 
         // Define field grade_forum to be added to forum.
         $table = new xmldb_table('forum');
@@ -209,6 +210,8 @@ function xmldb_forum_upgrade($oldversion) {
         // Forum savepoint reached.
         upgrade_mod_savepoint(true, 2019081100, 'forum');
 
+    }
+
     if ($oldversion < 2019100100) {
         // Define table forum_grades to be created.
         $table = new xmldb_table('forum_grades');
index 47f5bc3..418972e 100644 (file)
@@ -2176,7 +2176,7 @@ class mod_forum_external extends external_api {
         ]);
         $warnings = [];
 
-        $user = $DB->get_record('user', ['id' => (int)$params['userid']], '*', IGNORE_MISSING);
+        $user = core_user::get_user($params['userid']);
 
         $vaultfactory = mod_forum\local\container::get_vault_factory();
 
index ab2b4ff..44c2a04 100644 (file)
     * none
 
     Data attributes required for JS:
-    * none
+    * data-region="posts-modal"
 
     Example context (json):
     {
     }
 }}
 <div data-region="posts-modal">
-    {{#posts}}
+    {{#.}}
         {{> mod_forum/forum_discussion_modern_post_reply }}
-    {{/posts}}
+    {{/.}}
 </div>
index 05f9d39..16b7df8 100644 (file)
@@ -23,7 +23,7 @@
     * none
 
     Data attributes required for JS:
-    * none
+    * data-region="posts"
 
     Example context (json):
     {
index bb1dc23..f0c1d06 100644 (file)
     * TODO
 
     Data attributes required for JS:
-    * TODO
+    * data-first-userid="350"
+    * data-cmid="1337"
 
     Context variables required for this template:
-    * TODO
+    * userid: ID of the first user to jump to
+    * cmid: ID of the course module we want to grade
 
     Example context (json):
     {
+        "userid": 350,
+        "cmid": 1337
     }
 }}
-<div class="container-fluid" {{!
-    }}data-region="unified-grader" {{!
-    }}{{#userid}}data-first-userid="{{userid}}"{{/userid}} {{!
-    }}data-cmid="{{cmid}}" {{!
-    }}>
+<div class="container-fluid"
+    data-region="unified-grader"
+    {{#userid}}data-first-userid="{{userid}}"{{/userid}}
+    data-cmid="{{cmid}}"
+    >
     <div class="row-fluid">
         {{> mod_forum/local/grades/local/grader/navigation }}
     </div>
index 313e57b..d1e92b8 100644 (file)
     @template mod_forum/local/grades/local/grader/content
 
     Classes required for JS:
-    * TODO
+    * none
 
     Data attributes required for JS:
-    * TODO
+    * none
 
     Context variables required for this template:
-    * TODO
+    * none
 
     Example context (json):
     {
index 04428db..7431ede 100644 (file)
     @template mod_forum/local/grades/local/grader/grade_placeholder
 
     Classes required for JS:
-    * TODO
+    * none
 
     Data attributes required for JS:
-    * TODO
+    * none
 
     Context variables required for this template:
-    * TODO
+    * none
 
     Example context (json):
     {
index fab4025..2d038bc 100644 (file)
     @template mod_forum/local/grades/local/grader/grading
 
     Classes required for JS:
-    * TODO
+    * none
 
     Data attributes required for JS:
-    * TODO
+    * data-region="user_picker"
+    * data-region="grade"
+    * data-region="grade-errors"
 
     Context variables required for this template:
-    * TODO
+    * none
 
     Example context (json):
     {
index c6396e0..220564f 100644 (file)
     @template mod_forum/local/grades/local/grader/gradingpanel/error
 
     Classes required for JS:
-    * TODO
+    * none
 
     Data attributes required for JS:
-    * TODO
+    * none
 
     Context variables required for this template:
-    * TODO
+    * error.message: The returned message on error
 
     Example context (json):
     {
+        "error": {
+            "message": "The item (Safe) in (magic school bus trips) does not exist"
+        }
     }
 }}
 <div class="col-md-12 bg-danger text-white rounded pt-3 pb-3" id="gradingpanel-error-{{uniqid}}">
index a99a025..e4c4330 100644 (file)
     @template mod_forum/local/grades/local/grader/navigation
 
     Classes required for JS:
-    * TODO
+    * none
 
     Data attributes required for JS:
-    * TODO
+    * data-action="togglefullscreen"
+    * data-action="closegrader"
+    * data-action="savegrade"
+    * data-action="expandgrader"
 
     Context variables required for this template:
-    * TODO
+    * moduleName: The name of the module this grading interface is for i.e. "Chef the Forum"
 
     Example context (json):
     {
+        "moduleName": "Chef the Forum"
     }
 }}
 <div class="grader-grading_navigation col-sm-12">
index 998462b..c281e10 100644 (file)
     @template mod_forum/local/grades/local/grader/user_picker
 
     Classes required for JS:
-    * TODO
+    * none
 
     Data attributes required for JS:
-    * TODO
+    * data-region="user_picker/user"
+    * data-action="change-user"
+    * data-direction="-1"
+    * data-direction="1"
+    * data-action="search-user"
 
     Context variables required for this template:
-    * TODO
+    * none
 
     Example context (json):
     {
index 178cf9a..3fb917b 100644 (file)
     @template mod_forum/local/grades/local/grader/user_picker/user
 
     Classes required for JS:
-    * TODO
+    * none
 
     Data attributes required for JS:
-    * TODO
+    * data-userid="42"
+    * data-region="index"
 
     Context variables required for this template:
-    * TODO
+    * id: The ID of the user
+    * fullname: The user's full name
+    * displayIndex: The index of the user in the userpicker array + 1
+    * total: The length of the user array in the userpicker
 
     Example context (json):
     {
+        "id": 4,
+        "fullname": "Phillip J. Fry",
+        "displayIndex": 3,
+        "total": 7
     }
 }}
 <div class="d-block font-weight-bold" data-region="name" data-userid="{{id}}">{{fullname}}</div>
index 0146ba6..af03054 100644 (file)
     @template mod_forum/local/grades/local/grader/user_picker_placeholder
 
     Classes required for JS:
-    * TODO
+    * none
 
     Data attributes required for JS:
-    * TODO
+    * none
 
     Context variables required for this template:
-    * TODO
+    * none
 
     Example context (json):
     {
index f3c096a..de7838c 100644 (file)
@@ -1129,39 +1129,4 @@ class mod_forum_vaults_post_testcase extends advanced_testcase {
         $this->assertArrayHasKey($otherpost->id, $entities);
 
     }
-
-    /**
-     * Test get_from_user_id.
-     *
-     * @covers ::get_posts_in_forum_for_user_id
-     */
-    public function test_get_from_user_id() {
-        $this->resetAfterTest();
-
-        $datagenerator = $this->getDataGenerator();
-        $user = $datagenerator->create_user();
-        $course = $datagenerator->create_course();
-        $forum = $datagenerator->create_module('forum', ['course' => $course->id]);
-
-        $vaultfactory = mod_forum\local\container::get_vault_factory();
-
-        $forumvault = $vaultfactory->get_forum_vault();
-        $forumentity = $forumvault->get_from_course_module_id($forum->cmid);
-
-        $managerfactory = mod_forum\local\container::get_manager_factory();
-        $capabilitymanager = $managerfactory->get_capability_manager($forumentity);
-        [$discussion1, $post1] = $this->helper_post_to_forum($forum, $user);
-        $post2 = $this->helper_reply_to_post($post1, $user);
-        $post3 = $this->helper_reply_to_post($post1, $user);
-        [$discussion2, $post4] = $this->helper_post_to_forum($forum, $user);
-        $discussionkeys = [$discussion1->id, $discussion2->id];
-
-        $viewhidden = $capabilitymanager->can_view_any_private_reply($user);
-        $entities = $this->vault->get_posts_in_forum_for_user_id($discussionkeys, $user->id, $viewhidden, 'modified DESC');
-        $this->assertCount(4, $entities);
-        $this->assertArrayHasKey($post1->id, $entities); // Order is not guaranteed, so just verify element existence.
-        $this->assertArrayHasKey($post2->id, $entities);
-        $this->assertArrayHasKey($post3->id, $entities);
-        $this->assertArrayHasKey($post4->id, $entities);
-    }
 }