From a62c68fb5f324cc95f781a3f511cada76a747ac9 Mon Sep 17 00:00:00 2001 From: Mathew May Date: Mon, 28 Oct 2019 13:22:48 +0800 Subject: [PATCH] MDL-66074 mod_forum: Mustache and PHP documentation for grading --- mod/forum/classes/grades/forum_gradeitem.php | 12 +++++-- mod/forum/classes/local/vaults/post.php | 35 ------------------- mod/forum/db/upgrade.php | 5 ++- mod/forum/externallib.php | 2 +- .../grader/discussion/post_modal.mustache | 6 ++-- .../grades/grader/discussion/posts.mustache | 2 +- .../templates/local/grades/grader.mustache | 18 ++++++---- .../grades/local/grader/content.mustache | 6 ++-- .../local/grader/grade_placeholder.mustache | 6 ++-- .../grades/local/grader/grading.mustache | 8 +++-- .../local/grader/gradingpanel/error.mustache | 9 +++-- .../grades/local/grader/navigation.mustache | 10 ++++-- .../grades/local/grader/user_picker.mustache | 10 ++++-- .../local/grader/user_picker/user.mustache | 14 ++++++-- .../grader/user_picker_placeholder.mustache | 6 ++-- mod/forum/tests/vaults_post_test.php | 35 ------------------- 16 files changed, 74 insertions(+), 110 deletions(-) diff --git a/mod/forum/classes/grades/forum_gradeitem.php b/mod/forum/classes/grades/forum_gradeitem.php index 37f477d85c1..bd1b5264016 100644 --- a/mod/forum/classes/grades/forum_gradeitem.php +++ b/mod/forum/classes/grades/forum_gradeitem.php @@ -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; diff --git a/mod/forum/classes/local/vaults/post.php b/mod/forum/classes/local/vaults/post.php index b8a7b3211d9..da0ad2981cb 100644 --- a/mod/forum/classes/local/vaults/post.php +++ b/mod/forum/classes/local/vaults/post.php @@ -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. * diff --git a/mod/forum/db/upgrade.php b/mod/forum/db/upgrade.php index e4cdeeffa5e..ac6f468bb4c 100644 --- a/mod/forum/db/upgrade.php +++ b/mod/forum/db/upgrade.php @@ -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'); diff --git a/mod/forum/externallib.php b/mod/forum/externallib.php index 47f5bc346bc..418972e06dd 100644 --- a/mod/forum/externallib.php +++ b/mod/forum/externallib.php @@ -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(); diff --git a/mod/forum/templates/grades/grader/discussion/post_modal.mustache b/mod/forum/templates/grades/grader/discussion/post_modal.mustache index ab2b4ff77a6..44c2a0424ca 100644 --- a/mod/forum/templates/grades/grader/discussion/post_modal.mustache +++ b/mod/forum/templates/grades/grader/discussion/post_modal.mustache @@ -23,14 +23,14 @@ * none Data attributes required for JS: - * none + * data-region="posts-modal" Example context (json): { } }}
- {{#posts}} + {{#.}} {{> mod_forum/forum_discussion_modern_post_reply }} - {{/posts}} + {{/.}}
diff --git a/mod/forum/templates/grades/grader/discussion/posts.mustache b/mod/forum/templates/grades/grader/discussion/posts.mustache index 05f9d39ab97..16b7df80e19 100644 --- a/mod/forum/templates/grades/grader/discussion/posts.mustache +++ b/mod/forum/templates/grades/grader/discussion/posts.mustache @@ -23,7 +23,7 @@ * none Data attributes required for JS: - * none + * data-region="posts" Example context (json): { diff --git a/mod/forum/templates/local/grades/grader.mustache b/mod/forum/templates/local/grades/grader.mustache index bb1dc2351b4..f0c1d069b52 100644 --- a/mod/forum/templates/local/grades/grader.mustache +++ b/mod/forum/templates/local/grades/grader.mustache @@ -21,20 +21,24 @@ * 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 } }} -
+
{{> mod_forum/local/grades/local/grader/navigation }}
diff --git a/mod/forum/templates/local/grades/local/grader/content.mustache b/mod/forum/templates/local/grades/local/grader/content.mustache index 313e57bc2cd..d1e92b8b173 100644 --- a/mod/forum/templates/local/grades/local/grader/content.mustache +++ b/mod/forum/templates/local/grades/local/grader/content.mustache @@ -18,13 +18,13 @@ @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): { diff --git a/mod/forum/templates/local/grades/local/grader/grade_placeholder.mustache b/mod/forum/templates/local/grades/local/grader/grade_placeholder.mustache index 04428dbc82b..7431ede1a3a 100644 --- a/mod/forum/templates/local/grades/local/grader/grade_placeholder.mustache +++ b/mod/forum/templates/local/grades/local/grader/grade_placeholder.mustache @@ -18,13 +18,13 @@ @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): { diff --git a/mod/forum/templates/local/grades/local/grader/grading.mustache b/mod/forum/templates/local/grades/local/grader/grading.mustache index fab4025f714..2d038bcf2dc 100644 --- a/mod/forum/templates/local/grades/local/grader/grading.mustache +++ b/mod/forum/templates/local/grades/local/grader/grading.mustache @@ -18,13 +18,15 @@ @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): { diff --git a/mod/forum/templates/local/grades/local/grader/gradingpanel/error.mustache b/mod/forum/templates/local/grades/local/grader/gradingpanel/error.mustache index c6396e094e5..220564f5fd4 100644 --- a/mod/forum/templates/local/grades/local/grader/gradingpanel/error.mustache +++ b/mod/forum/templates/local/grades/local/grader/gradingpanel/error.mustache @@ -18,16 +18,19 @@ @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" + } } }}
diff --git a/mod/forum/templates/local/grades/local/grader/navigation.mustache b/mod/forum/templates/local/grades/local/grader/navigation.mustache index a99a0251c21..e4c43301dc4 100644 --- a/mod/forum/templates/local/grades/local/grader/navigation.mustache +++ b/mod/forum/templates/local/grades/local/grader/navigation.mustache @@ -18,16 +18,20 @@ @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" } }}
diff --git a/mod/forum/templates/local/grades/local/grader/user_picker.mustache b/mod/forum/templates/local/grades/local/grader/user_picker.mustache index 998462b33d3..c281e10c91d 100644 --- a/mod/forum/templates/local/grades/local/grader/user_picker.mustache +++ b/mod/forum/templates/local/grades/local/grader/user_picker.mustache @@ -18,13 +18,17 @@ @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): { diff --git a/mod/forum/templates/local/grades/local/grader/user_picker/user.mustache b/mod/forum/templates/local/grades/local/grader/user_picker/user.mustache index 178cf9a133e..3fb917b9702 100644 --- a/mod/forum/templates/local/grades/local/grader/user_picker/user.mustache +++ b/mod/forum/templates/local/grades/local/grader/user_picker/user.mustache @@ -18,16 +18,24 @@ @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 } }}
{{fullname}}
diff --git a/mod/forum/templates/local/grades/local/grader/user_picker_placeholder.mustache b/mod/forum/templates/local/grades/local/grader/user_picker_placeholder.mustache index 0146ba687e8..af03054b440 100644 --- a/mod/forum/templates/local/grades/local/grader/user_picker_placeholder.mustache +++ b/mod/forum/templates/local/grades/local/grader/user_picker_placeholder.mustache @@ -18,13 +18,13 @@ @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): { diff --git a/mod/forum/tests/vaults_post_test.php b/mod/forum/tests/vaults_post_test.php index f3c096addb5..de7838c0dd2 100644 --- a/mod/forum/tests/vaults_post_test.php +++ b/mod/forum/tests/vaults_post_test.php @@ -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); - } }