MDL-65082 core_course: Update frontpage view to use new forum API
This commit is contained in:
+14
-10
@@ -2334,10 +2334,10 @@ class core_course_renderer extends plugin_renderer_base {
|
||||
/**
|
||||
* Output news for the frontpage (extract from site-wide news forum)
|
||||
*
|
||||
* @param stdClass $newsforum record from db table 'forum' that represents the site news forum
|
||||
* @param stdClass $forum record from db table 'forum' that represents the site news forum
|
||||
* @return string
|
||||
*/
|
||||
protected function frontpage_news($newsforum) {
|
||||
protected function frontpage_news($forum) {
|
||||
global $CFG, $SITE, $SESSION, $USER;
|
||||
require_once($CFG->dirroot .'/mod/forum/lib.php');
|
||||
|
||||
@@ -2346,23 +2346,27 @@ class core_course_renderer extends plugin_renderer_base {
|
||||
if (isloggedin()) {
|
||||
$SESSION->fromdiscussion = $CFG->wwwroot;
|
||||
$subtext = '';
|
||||
if (\mod_forum\subscriptions::is_subscribed($USER->id, $newsforum)) {
|
||||
if (!\mod_forum\subscriptions::is_forcesubscribed($newsforum)) {
|
||||
if (\mod_forum\subscriptions::is_subscribed($USER->id, $forum)) {
|
||||
if (!\mod_forum\subscriptions::is_forcesubscribed($forum)) {
|
||||
$subtext = get_string('unsubscribe', 'forum');
|
||||
}
|
||||
} else {
|
||||
$subtext = get_string('subscribe', 'forum');
|
||||
}
|
||||
$suburl = new moodle_url('/mod/forum/subscribe.php', array('id' => $newsforum->id, 'sesskey' => sesskey()));
|
||||
$suburl = new moodle_url('/mod/forum/subscribe.php', array('id' => $forum->id, 'sesskey' => sesskey()));
|
||||
$output .= html_writer::tag('div', html_writer::link($suburl, $subtext), array('class' => 'subscribelink'));
|
||||
}
|
||||
|
||||
ob_start();
|
||||
forum_print_latest_discussions($SITE, $newsforum, $SITE->newsitems, 'plain', 'p.modified DESC');
|
||||
$output .= ob_get_contents();
|
||||
ob_end_clean();
|
||||
$coursemodule = get_coursemodule_from_instance('forum', $forum->id);
|
||||
$context = context_module::instance($coursemodule->id);
|
||||
|
||||
return $output;
|
||||
$entityfactory = mod_forum\local\container::get_entity_factory();
|
||||
$forumentity = $entityfactory->get_forum_from_stdclass($forum, $context, $coursemodule, $SITE);
|
||||
|
||||
$rendererfactory = mod_forum\local\container::get_renderer_factory();
|
||||
$discussionsrenderer = $rendererfactory->get_frontpage_news_discussion_list_renderer($forumentity);
|
||||
$cm = \cm_info::create($coursemodule);
|
||||
return $output . $discussionsrenderer->render($USER, $cm, null, null, 0, $SITE->newsitems);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -82,6 +82,7 @@ class forum extends exporter {
|
||||
'type' => [
|
||||
'create' => ['type' => PARAM_URL],
|
||||
'markasread' => ['type' => PARAM_URL],
|
||||
'view' => ['type' => PARAM_URL],
|
||||
],
|
||||
],
|
||||
];
|
||||
@@ -115,6 +116,7 @@ class forum extends exporter {
|
||||
'urls' => [
|
||||
'create' => $urlfactory->get_discussion_create_url($this->forum)->out(false),
|
||||
'markasread' => $urlfactory->get_mark_all_discussions_as_read_url($this->forum)->out(false),
|
||||
'view' => $urlfactory->get_forum_view_url_from_forum($this->forum)->out(false),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -368,7 +368,11 @@ class renderer {
|
||||
|
||||
switch ($forum->get_type()) {
|
||||
case 'news':
|
||||
$template = 'mod_forum/news_discussion_list';
|
||||
if (SITEID == $forum->get_course_id()) {
|
||||
$template = 'mod_forum/frontpage_news_discussion_list';
|
||||
} else {
|
||||
$template = 'mod_forum/news_discussion_list';
|
||||
}
|
||||
break;
|
||||
case 'qanda':
|
||||
$template = 'mod_forum/qanda_discussion_list';
|
||||
@@ -484,6 +488,17 @@ class renderer {
|
||||
return $this->get_detailed_discussion_list_renderer($forum, 'mod_forum/social_discussion_list');
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a discussion list renderer for the social course format.
|
||||
*
|
||||
* @param forum_entity $forum The forum that the discussions belong to
|
||||
* @return discussion_list_renderer
|
||||
*/
|
||||
public function get_frontpage_news_discussion_list_renderer(
|
||||
forum_entity $forum
|
||||
) : discussion_list_renderer {
|
||||
return $this->get_detailed_discussion_list_renderer($forum, 'mod_forum/frontpage_social_discussion_list');
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a single type discussion list renderer.
|
||||
|
||||
@@ -168,7 +168,8 @@ class discussion_list {
|
||||
$this->urlfactory->get_forum_view_url_from_forum($forum),
|
||||
true
|
||||
),
|
||||
'notifications' => $this->get_notifications($user, $groupid)
|
||||
'hasmore' => ($alldiscussionscount > $pagesize),
|
||||
'notifications' => $this->get_notifications($user, $groupid),
|
||||
];
|
||||
|
||||
if (!$discussions) {
|
||||
|
||||
@@ -50,7 +50,9 @@
|
||||
{{/forum.capabilities.create}}
|
||||
|
||||
{{#state.hasdiscussions}}
|
||||
{{{ pagination }}}
|
||||
{{$discussion_top_pagination}}
|
||||
{{{ pagination }}}
|
||||
{{/discussion_top_pagination}}
|
||||
{{$discussion_list_output}}
|
||||
<table class="table table-hover table-striped">
|
||||
{{$discussion_list_header}}
|
||||
@@ -217,9 +219,9 @@
|
||||
{{/discussion_list_body}}
|
||||
</table>
|
||||
{{/discussion_list_output}}
|
||||
{{$pagination_output}}
|
||||
{{$discussion_bottom_pagination}}
|
||||
{{{ pagination }}}
|
||||
{{/pagination_output}}
|
||||
{{/discussion_bottom_pagination}}
|
||||
{{#can_create_discussion}}
|
||||
<div class="forumaddnew">
|
||||
<a href="{{create_discussion_link}}" class="btn btn-primary">{{create_discussion_link_text}}</a>
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
{{!
|
||||
This file is part of Moodle - http://moodle.org/
|
||||
|
||||
Moodle is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Moodle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
}}
|
||||
{{!
|
||||
@template mod_forum/social_discussion_list
|
||||
|
||||
Template which defines a forum post for sending in a single-post HTML email.
|
||||
|
||||
Classes required for JS:
|
||||
* none
|
||||
|
||||
Data attributes required for JS:
|
||||
* none
|
||||
|
||||
Example context (json):
|
||||
{
|
||||
}
|
||||
}}
|
||||
{{< mod_forum/news_discussion_list }}
|
||||
{{$discussion_create_text}}
|
||||
{{#str}}addanewtopic, forum{{/str}}
|
||||
{{/discussion_create_text}}
|
||||
{{/ mod_forum/news_discussion_list }}
|
||||
@@ -0,0 +1,42 @@
|
||||
{{!
|
||||
This file is part of Moodle - http://moodle.org/
|
||||
|
||||
Moodle is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Moodle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
}}
|
||||
{{!
|
||||
@template mod_forum/frontpage_social_discussion_list
|
||||
|
||||
Template which defines a forum post for sending in a single-post HTML email.
|
||||
|
||||
Classes required for JS:
|
||||
* none
|
||||
|
||||
Data attributes required for JS:
|
||||
* none
|
||||
|
||||
Example context (json):
|
||||
{
|
||||
}
|
||||
}}
|
||||
{{< mod_forum/social_discussion_list }}
|
||||
{{$discussion_create_text}}
|
||||
{{#str}}addanewtopic, forum{{/str}}
|
||||
{{/discussion_create_text}}
|
||||
{{$discussion_top_pagination}}{{/discussion_top_pagination}}
|
||||
{{$discussion_bottom_pagination}}
|
||||
{{#hasmore}}
|
||||
<a href="{{{forum.urls.view}}}">{{#str}}oldertopics, mod_forum{{/str}}...</a>
|
||||
{{/hasmore}}
|
||||
{{/discussion_bottom_pagination}}
|
||||
{{/ mod_forum/social_discussion_list }}
|
||||
Reference in New Issue
Block a user