/**
* 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');
* 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 {
* @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;
* @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;
/**
* 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;
*
* @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;
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.
*
// 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');
// 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');
]);
$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();
* 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>
* none
Data attributes required for JS:
- * none
+ * data-region="posts"
Example context (json):
{
* 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>
@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):
{
@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):
{
@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):
{
@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}}">
@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">
@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):
{
@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>
@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):
{
$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);
- }
}