diff --git a/course/format/social/format.php b/course/format/social/format.php
index 4fcd31398d4..bde97091021 100644
--- a/course/format/social/format.php
+++ b/course/format/social/format.php
@@ -1,42 +1,78 @@
.
- require_once($CFG->dirroot.'/mod/forum/lib.php');
+/**
+ * Course format featuring social forum.
+ *
+ * @package format_social
+ * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
- $strgroups = get_string('groups');
- $strgroupmy = get_string('groupmy');
- $editing = $PAGE->user_is_editing();
+defined('MOODLE_INTERNAL') || die();
- if ($forum = forum_get_course_forum($course->id, 'social')) {
+$pageno = optional_param('p', 0, PARAM_INT);
- $cm = get_coursemodule_from_instance('forum', $forum->id);
- $modcontext = context_module::instance($cm->id);
+require_once($CFG->dirroot.'/mod/forum/lib.php');
- /// Print forum intro above posts MDL-18483
- if (trim($forum->intro) != '') {
- $options = new stdClass();
- $options->para = false;
- $introcontent = format_module_intro('forum', $forum, $cm->id);
+$forum = forum_get_course_forum($course->id, 'social');
+if (empty($forum)) {
+ echo $OUTPUT->notification('Could not find or create a social forum here');
+}
- if ($PAGE->user_is_editing() && has_capability('moodle/course:update', $modcontext)) {
- $streditsummary = get_string('editsummary');
- $introcontent .= '
';
- }
- echo $OUTPUT->box($introcontent, 'generalbox', 'intro');
- }
+$coursemodule = get_coursemodule_from_instance('forum', $forum->id);
+$modcontext = context_module::instance($coursemodule->id);
- echo '', forum_get_subscribe_link($forum, $modcontext), '
';
+$entityfactory = mod_forum\local\container::get_entity_factory();
+$forumentity = $entityfactory->get_forum_from_stdclass($forum, $modcontext, $coursemodule, $course);
- $numdiscussions = course_get_format($course)->get_course()->numdiscussions;
- if ($numdiscussions < 1) {
- // Make sure that the value is at least one.
- $numdiscussions = 1;
- }
- forum_print_latest_discussions($course, $forum, $numdiscussions, 'plain', '', false);
+// Print forum intro above posts MDL-18483.
+if (trim($forum->intro) != '') {
+ $options = (object) [
+ 'para' => false,
+ ];
+ $introcontent = format_module_intro('forum', $forum, $coursemodule->id);
- } else {
- echo $OUTPUT->notification('Could not find or create a social forum here');
+ if ($PAGE->user_is_editing() && has_capability('moodle/course:update', $modcontext)) {
+ $streditsummary = get_string('editsummary');
+ $introcontent .= html_writer::start_div('editinglink');
+ $introcontent .= html_writer::link(
+ new moodle_url('/modedit.php', [
+ 'update' => $coursemodule->id,
+ 'sesskey' => sesskey(),
+ ]),
+ $OUTPUT->pix_icon('t/edit', $streditsummary),
+ [
+ 'title' => $streditsummary,
+ ]
+ );
+ $introcontent .= html_writer::end_div();
}
+ echo $OUTPUT->box($introcontent, 'generalbox', 'intro');
+}
+
+echo html_writer::div(forum_get_subscribe_link($forum, $modcontext), 'subscribelink');
+
+$numdiscussions = course_get_format($course)->get_course()->numdiscussions;
+if ($numdiscussions < 1) {
+ // Make sure that the value is at least one.
+ $numdiscussions = 1;
+}
+
+$rendererfactory = mod_forum\local\container::get_renderer_factory();
+$discussionsrenderer = $rendererfactory->get_social_discussion_list_renderer($forumentity);
+$cm = \cm_info::create($coursemodule);
+echo $discussionsrenderer->render($USER, $cm, null, null, $pageno, $numdiscussions);
diff --git a/course/format/social/tests/behat/social_adjust_discussion_count.feature b/course/format/social/tests/behat/social_adjust_discussion_count.feature
index a0a709ed5ab..830ad4ecd2d 100644
--- a/course/format/social/tests/behat/social_adjust_discussion_count.feature
+++ b/course/format/social/tests/behat/social_adjust_discussion_count.feature
@@ -4,124 +4,122 @@ Feature: Change number of discussions displayed
As a teacher
I need to edit the course and change the number of sections displayed.
-# Uncomment these tests when the forum_print_latest_discussions function is
-# deprecated in MDL-65082.
-# Background:
-# Given the following "users" exist:
-# | username | firstname | lastname | email |
-# | teacher1 | Teacher | 1 | teacher1@example.com |
-# And the following "courses" exist:
-# | fullname | shortname | category | format |
-# | Course 1 | C1 | 0 | social |
-# And the following "course enrolments" exist:
-# | user | course | role |
-# | teacher1 | C1 | editingteacher |
-# And I log in as "teacher1"
-# And I am on "Course 1" course homepage
-# And I press "Add a new discussion topic"
-# And I set the following fields to these values:
-# | Subject | Forum Post 10 |
-# | Message | This is forum post ten |
-# And I press "Post to forum"
-# And I wait to be redirected
-# And I am on "Course 1" course homepage
-# And I wait "1" seconds
-# And I press "Add a new discussion topic"
-# And I set the following fields to these values:
-# | Subject | Forum Post 9 |
-# | Message | This is forum post nine |
-# And I press "Post to forum"
-# And I wait to be redirected
-# And I am on "Course 1" course homepage
-# And I wait "1" seconds
-# And I press "Add a new discussion topic"
-# And I set the following fields to these values:
-# | Subject | Forum Post 8 |
-# | Message | This is forum post eight |
-# And I press "Post to forum"
-# And I wait to be redirected
-# And I am on "Course 1" course homepage
-# And I wait "1" seconds
-# And I press "Add a new discussion topic"
-# And I set the following fields to these values:
-# | Subject | Forum Post 7 |
-# | Message | This is forum post seven |
-# And I press "Post to forum"
-# And I wait to be redirected
-# And I am on "Course 1" course homepage
-# And I wait "1" seconds
-# And I press "Add a new discussion topic"
-# And I set the following fields to these values:
-# | Subject | Forum Post 6 |
-# | Message | This is forum post six |
-# And I press "Post to forum"
-# And I wait to be redirected
-# And I am on "Course 1" course homepage
-# And I wait "1" seconds
-# And I press "Add a new discussion topic"
-# And I set the following fields to these values:
-# | Subject | Forum Post 5 |
-# | Message | This is forum post five |
-# And I press "Post to forum"
-# And I wait to be redirected
-# And I am on "Course 1" course homepage
-# And I wait "1" seconds
-# And I press "Add a new discussion topic"
-# And I set the following fields to these values:
-# | Subject | Forum Post 4 |
-# | Message | This is forum post four |
-# And I press "Post to forum"
-# And I wait to be redirected
-# And I am on "Course 1" course homepage
-# And I wait "1" seconds
-# And I press "Add a new discussion topic"
-# And I set the following fields to these values:
-# | Subject | Forum Post 3 |
-# | Message | This is forum post three |
-# And I press "Post to forum"
-# And I wait to be redirected
-# And I am on "Course 1" course homepage
-# And I wait "1" seconds
-# And I press "Add a new discussion topic"
-# And I set the following fields to these values:
-# | Subject | Forum Post 2 |
-# | Message | This is forum post two |
-# And I press "Post to forum"
-# And I wait to be redirected
-# And I am on "Course 1" course homepage
-# And I wait "1" seconds
-# And I press "Add a new discussion topic"
-# And I set the following fields to these values:
-# | Subject | Forum Post 1 |
-# | Message | This is forum post one |
-# And I press "Post to forum"
-# And I wait to be redirected
-# And I am on "Course 1" course homepage
-#
-# Scenario: When number of discussions is decreased fewer discussions appear
-# Given I navigate to "Edit settings" in current page administration
-# And I set the following fields to these values:
-# | numdiscussions | 5 |
-# When I press "Save and display"
-# Then I should see "This is forum post one"
-# And I should see "This is forum post five"
-# And I should not see "This is forum post six"
-#
-# Scenario: When number of discussions is decreased to less than 1 only 1 discussion should appear
-# Given I navigate to "Edit settings" in current page administration
-# And I set the following fields to these values:
-# | numdiscussions | -1 |
-# When I press "Save and display"
-# Then I should see "This is forum post one"
-# And I should not see "This is forum post two"
-# And I should not see "This is forum post ten"
-#
-# Scenario: When number of discussions is increased more discussions appear
-# Given I navigate to "Edit settings" in current page administration
-# And I set the following fields to these values:
-# | numdiscussions | 9 |
-# When I press "Save and display"
-# Then I should see "This is forum post one"
-# And I should see "This is forum post five"
-# And I should see "This is forum post nine"
-# And I should not see "This is forum post ten"
+ Background:
+ Given the following "users" exist:
+ | username | firstname | lastname | email |
+ | teacher1 | Teacher | 1 | teacher1@example.com |
+ And the following "courses" exist:
+ | fullname | shortname | category | format |
+ | Course 1 | C1 | 0 | social |
+ And the following "course enrolments" exist:
+ | user | course | role |
+ | teacher1 | C1 | editingteacher |
+ And I log in as "teacher1"
+ And I am on "Course 1" course homepage
+ And I follow "Add a new discussion topic"
+ And I set the following fields to these values:
+ | Subject | Forum Post 10 |
+ | Message | This is forum post ten |
+ And I press "Post to forum"
+ And I wait to be redirected
+ And I am on "Course 1" course homepage
+ And I wait "1" seconds
+ And I follow "Add a new discussion topic"
+ And I set the following fields to these values:
+ | Subject | Forum Post 9 |
+ | Message | This is forum post nine |
+ And I press "Post to forum"
+ And I wait to be redirected
+ And I am on "Course 1" course homepage
+ And I wait "1" seconds
+ And I follow "Add a new discussion topic"
+ And I set the following fields to these values:
+ | Subject | Forum Post 8 |
+ | Message | This is forum post eight |
+ And I press "Post to forum"
+ And I wait to be redirected
+ And I am on "Course 1" course homepage
+ And I wait "1" seconds
+ And I follow "Add a new discussion topic"
+ And I set the following fields to these values:
+ | Subject | Forum Post 7 |
+ | Message | This is forum post seven |
+ And I press "Post to forum"
+ And I wait to be redirected
+ And I am on "Course 1" course homepage
+ And I wait "1" seconds
+ And I follow "Add a new discussion topic"
+ And I set the following fields to these values:
+ | Subject | Forum Post 6 |
+ | Message | This is forum post six |
+ And I press "Post to forum"
+ And I wait to be redirected
+ And I am on "Course 1" course homepage
+ And I wait "1" seconds
+ And I follow "Add a new discussion topic"
+ And I set the following fields to these values:
+ | Subject | Forum Post 5 |
+ | Message | This is forum post five |
+ And I press "Post to forum"
+ And I wait to be redirected
+ And I am on "Course 1" course homepage
+ And I wait "1" seconds
+ And I follow "Add a new discussion topic"
+ And I set the following fields to these values:
+ | Subject | Forum Post 4 |
+ | Message | This is forum post four |
+ And I press "Post to forum"
+ And I wait to be redirected
+ And I am on "Course 1" course homepage
+ And I wait "1" seconds
+ And I follow "Add a new discussion topic"
+ And I set the following fields to these values:
+ | Subject | Forum Post 3 |
+ | Message | This is forum post three |
+ And I press "Post to forum"
+ And I wait to be redirected
+ And I am on "Course 1" course homepage
+ And I wait "1" seconds
+ And I follow "Add a new discussion topic"
+ And I set the following fields to these values:
+ | Subject | Forum Post 2 |
+ | Message | This is forum post two |
+ And I press "Post to forum"
+ And I wait to be redirected
+ And I am on "Course 1" course homepage
+ And I wait "1" seconds
+ And I follow "Add a new discussion topic"
+ And I set the following fields to these values:
+ | Subject | Forum Post 1 |
+ | Message | This is forum post one |
+ And I press "Post to forum"
+ And I wait to be redirected
+ And I am on "Course 1" course homepage
+
+ Scenario: When number of discussions is decreased fewer discussions appear
+ Given I navigate to "Edit settings" in current page administration
+ And I set the following fields to these values:
+ | numdiscussions | 5 |
+ When I press "Save and display"
+ Then I should see "This is forum post one"
+ And I should see "This is forum post five"
+ And I should not see "This is forum post six"
+
+ Scenario: When number of discussions is decreased to less than 1 only 1 discussion should appear
+ Given I navigate to "Edit settings" in current page administration
+ And I set the following fields to these values:
+ | numdiscussions | -1 |
+ When I press "Save and display"
+ Then I should see "This is forum post one"
+ And I should not see "This is forum post two"
+ And I should not see "This is forum post ten"
+
+ Scenario: When number of discussions is increased more discussions appear
+ Given I navigate to "Edit settings" in current page administration
+ And I set the following fields to these values:
+ | numdiscussions | 9 |
+ When I press "Save and display"
+ Then I should see "This is forum post one"
+ And I should see "This is forum post five"
+ And I should see "This is forum post nine"
+ And I should not see "This is forum post ten"
diff --git a/mod/forum/classes/local/factories/renderer.php b/mod/forum/classes/local/factories/renderer.php
index 467f5dff605..b0b02bb01ce 100644
--- a/mod/forum/classes/local/factories/renderer.php
+++ b/mod/forum/classes/local/factories/renderer.php
@@ -469,10 +469,22 @@ class renderer {
public function get_blog_discussion_list_renderer(
forum_entity $forum
) : discussion_list_renderer {
-
return $this->get_detailed_discussion_list_renderer($forum, 'mod_forum/blog_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_social_discussion_list_renderer(
+ forum_entity $forum
+ ) : discussion_list_renderer {
+ return $this->get_detailed_discussion_list_renderer($forum, 'mod_forum/social_discussion_list');
+ }
+
+
/**
* Create a single type discussion list renderer.
*
diff --git a/mod/forum/view.php b/mod/forum/view.php
index 4de4e125e7f..7a9a38f9c67 100644
--- a/mod/forum/view.php
+++ b/mod/forum/view.php
@@ -45,9 +45,16 @@ if (!$cmid && !$forumid) {
print_error('missingparameter');
}
-$forum = $forumid ? $forumvault->get_from_id($forumid) : $forumvault->get_from_course_module_id($cmid);
-if (!$forum) {
- throw new \moodle_exception('Unable to find forum with id ' . $forumid);
+if ($cmid) {
+ $forum = $forumvault->get_from_course_module_id($cmid);
+ if (empty($forum)) {
+ throw new \moodle_exception('Unable to find forum with cmid ' . $cmid);
+ }
+} else {
+ $forum = $forumvault->get_from_id($forumid);
+ if (empty($forum)) {
+ throw new \moodle_exception('Unable to find forum with id ' . $forumid);
+ }
}
if (!empty($showall)) {