Merge branch 'MDL-65786-master' of git://github.com/rezaies/moodle

This commit is contained in:
Sara Arjona 2019-08-06 14:19:17 +08:00
commit e9fc5a7381
3 changed files with 32 additions and 2 deletions

View File

@ -481,11 +481,24 @@ class renderer {
$discussionentriesids,
$canseeanyprivatereply
);
$forumdatamapper = $this->legacydatamapperfactory->get_forum_data_mapper();
$forumrecord = $forumdatamapper->to_legacy_object($forum);
if (forum_tp_is_tracked($forumrecord, $user)) {
$discussionunreadscount = $postvault->get_unread_count_for_discussion_ids(
$user,
$discussionentriesids,
$canseeanyprivatereply
);
} else {
$discussionunreadscount = [];
}
array_walk($exportedposts['posts'], function($post) use ($discussionrepliescount) {
array_walk($exportedposts['posts'], function($post) use ($discussionrepliescount, $discussionunreadscount) {
$post->discussionrepliescount = $discussionrepliescount[$post->discussionid] ?? 0;
$post->discussionunreadscount = $discussionunreadscount[$post->discussionid] ?? 0;
// TODO: Find a better solution due to language differences when defining the singular and plural form.
$post->isreplyplural = $post->discussionrepliescount != 1 ? true : false;
$post->isunreadplural = $post->discussionunreadscount != 1 ? true : false;
});
$exportedposts['state']['hasdiscussions'] = $exportedposts['posts'] ? true : false;

View File

@ -38,7 +38,9 @@
{{< mod_forum/forum_discussion_post }}
{{$footer}}
<div class="link text-right">
<a href="{{urls.discuss}}">{{#str}}discussthistopic, forum{{/str}}</a>&nbsp;({{discussionrepliescount}}{{#isreplyplural}}{{#str}}repliesmany, forum{{/str}}{{/isreplyplural}}{{^isreplyplural}}{{#str}}repliesone, forum{{/str}}{{/isreplyplural}})
<a href="{{urls.discuss}}">{{#str}}discussthistopic, forum{{/str}}</a>&nbsp;({{#isreplyplural}}{{#str}} repliesmany, forum, {{discussionrepliescount}} {{/str}}{{/isreplyplural}}{{^isreplyplural}}{{#str}} repliesone, forum, {{discussionrepliescount}} {{/str}}{{/isreplyplural}}{{#discussionunreadscount}}
<span class="sep">/</span>
<span class="unread"><a href="{{urls.discuss}}#unread">{{#isunreadplural}}{{#str}} unreadpostsnumber, mod_forum, {{discussionunreadscount}} {{/str}}{{/isunreadplural}}{{^isunreadplural}}{{#str}} unreadpostsone, mod_forum {{/str}}{{/isunreadplural}}</a></span>{{/discussionunreadscount}})
</div>
{{/footer}}
{{$replyoutput}}{{/replyoutput}}

View File

@ -160,12 +160,27 @@ switch ($forum->get_type()) {
$orderpostsby
);
echo $discussionsrenderer->render($USER, $post, $replies);
if (!$CFG->forum_usermarksread && forum_tp_is_tracked($forumrecord, $USER)) {
$postids = array_map(function($post) {
return $post->get_id();
}, array_merge([$post], array_values($replies)));
forum_tp_mark_posts_read($USER, $postids);
}
break;
case 'blog':
$discussionsrenderer = $rendererfactory->get_blog_discussion_list_renderer($forum);
// Blog forums always show discussions newest first.
echo $discussionsrenderer->render($USER, $cm, $groupid, $discussionlistvault::SORTORDER_CREATED_DESC,
$pageno, $pagesize);
if (!$CFG->forum_usermarksread && forum_tp_is_tracked($forumrecord, $USER)) {
$discussions = mod_forum_get_discussion_summaries($forum, $USER, $groupid, null, $pageno, $pagesize);
$firstpostids = array_map(function($discussion) {
return $discussion->get_first_post()->get_id();
}, array_values($discussions));
forum_tp_mark_posts_read($USER, $firstpostids);
}
break;
default:
$discussionsrenderer = $rendererfactory->get_discussion_list_renderer($forum);