Skip to content

Commit

Permalink
MDL-66893 mod_forum: update user content region in grader UI
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanwyllie committed Nov 7, 2019
1 parent 4c98e56 commit d9fedf3
Show file tree
Hide file tree
Showing 15 changed files with 488 additions and 60 deletions.
2 changes: 1 addition & 1 deletion mod/forum/amd/build/grades/grader.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mod/forum/amd/build/grades/grader.min.js.map

Large diffs are not rendered by default.

21 changes: 14 additions & 7 deletions mod/forum/amd/src/grades/grader.js
Expand Up @@ -82,18 +82,25 @@ const discussionPostMapper = (discussion) => {
const parentMap = new Map();
discussion.posts.parentposts.forEach(post => parentMap.set(post.id, post));
const userPosts = discussion.posts.userposts.map(post => {
post.subject = null;
post.readonly = true;
post.starter = !post.parentid;
post.parent = parentMap.get(post.parentid);
post.html.rating = null;
post.hasreplies = false;
post.replies = [];

const parent = post.parentid ? parentMap.get(post.parentid) : null;
if (parent) {
parent.hasreplies = false;
parent.replies = [];
parent.readonly = true;
}

return post;
return {
parent,
post
};
});

return {
id: discussion.id,
name: discussion.name,
...discussion,
posts: userPosts,
};
};
Expand Down
21 changes: 18 additions & 3 deletions mod/forum/externallib.php
Expand Up @@ -2205,16 +2205,24 @@ public static function get_discussion_posts_by_userid(int $userid = 0, int $cmid
$managerfactory = mod_forum\local\container::get_manager_factory();
$capabilitymanager = $managerfactory->get_capability_manager($forum);

$discussionvault = $vaultfactory->get_discussion_vault();
$discussions = $discussionvault->get_all_discussions_in_forum($forum, 'timemodified ASC, id ASC');
$discussionsummariesvault = $vaultfactory->get_discussions_in_forum_vault();
$discussionsummaries = $discussionsummariesvault->get_from_forum_id(
$forum->get_id(),
true,
null,
$discussionsummariesvault::SORTORDER_CREATED_ASC,
0,
0
);

$postvault = $vaultfactory->get_post_vault();

$builderfactory = mod_forum\local\container::get_builder_factory();
$postbuilder = $builderfactory->get_exported_posts_builder();

$builtdiscussions = [];
foreach ($discussions as $id => $discussion) {
foreach ($discussionsummaries as $discussionsummary) {
$discussion = $discussionsummary->get_discussion();
$posts = $postvault->get_posts_in_discussion_for_user_id(
$discussion->get_id(),
$user->id,
Expand All @@ -2239,9 +2247,14 @@ public static function get_discussion_posts_by_userid(int $userid = 0, int $cmid
);
}

$discussionauthor = $discussionsummary->get_first_post_author();
$firstpost = $discussionsummary->get_first_post();

$builtdiscussions[] = [
'name' => $discussion->get_name(),
'id' => $discussion->get_id(),
'timecreated' => $firstpost->get_time_created(),
'authorfullname' => $discussionauthor->get_full_name(),
'posts' => [
'userposts' => $postbuilder->build($user, [$forum], [$discussion], $posts),
'parentposts' => $parentposts,
Expand Down Expand Up @@ -2284,6 +2297,8 @@ public static function get_discussion_posts_by_userid_returns() {
new external_single_structure([
'name' => new external_value(PARAM_RAW, 'Name of the discussion'),
'id' => new external_value(PARAM_INT, 'ID of the discussion'),
'timecreated' => new external_value(PARAM_INT, 'Timestamp of the discussion start'),
'authorfullname' => new external_value(PARAM_RAW, 'Full name of the user that started the discussion'),
'posts' => new external_single_structure([
'userposts' => new external_multiple_structure(\mod_forum\local\exporters\post::get_read_structure()),
'parentposts' => new external_multiple_structure(\mod_forum\local\exporters\post::get_read_structure()),
Expand Down
2 changes: 2 additions & 0 deletions mod/forum/lang/en/forum.php
Expand Up @@ -195,6 +195,7 @@
$string['discussionsubscription_help'] = 'Subscribing to a discussion means you will receive notifications of new posts to that discussion.';
$string['discussions'] = 'Discussions';
$string['discussionsstartedby'] = 'Discussions started by {$a}';
$string['discussionstartedby'] = 'Discussion started by {$a}';
$string['discussionsstartedbyrecent'] = 'Discussions recently started by {$a}';
$string['discussionsstartedbyuserincourse'] = 'Discussions started by {$a->fullname} in {$a->coursename}';
$string['discussionunpin'] = 'Unpin';
Expand Down Expand Up @@ -710,6 +711,7 @@
$string['usermarksread'] = 'Manual message read marking';
$string['unpindiscussion'] = 'Unpin this discussion';
$string['viewalldiscussions'] = 'View all discussions';
$string['viewparentpost'] = 'View parent post';
$string['viewthediscussion'] = 'View the discussion';
$string['warnafter'] = 'Post threshold for warning';
$string['warnafter_help'] = 'Students can be warned as they approach the maximum number of posts allowed in a given period. This setting specifies after how many posts they are warned. Users with the capability mod/forum:postwithoutthrottling are exempt from post limits.';
Expand Down
Binary file added mod/forum/pix/no-posts.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions mod/forum/pix/no-posts.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 9 additions & 9 deletions mod/forum/templates/forum_discussion_post.mustache
Expand Up @@ -179,12 +179,12 @@
{{/isimage}}
{{/attachments}}

<div class="d-flex flex-wrap">
{{#html.rating}}
<div class="mt-2">{{{.}}}</div>
{{/html.rating}}
{{$actions}}
{{^readonly}}
{{^readonly}}
<div class="d-flex flex-wrap">
{{#html.rating}}
<div class="mt-2">{{{.}}}</div>
{{/html.rating}}
{{$actions}}
<div
class="post-actions d-flex align-self-end justify-content-end flex-wrap ml-auto"
data-region="post-actions-container"
Expand Down Expand Up @@ -303,9 +303,9 @@
{{/export}}
{{/capabilities}}
</div>
{{/readonly}}
{{/actions}}
</div>
{{/actions}}
</div>
{{/readonly}}

{{$footer}}{{/footer}}
{{/isdeleted}}
Expand Down

0 comments on commit d9fedf3

Please sign in to comment.