1<?php 2// This file is part of Moodle - http://moodle.org/ 3// 4// Moodle is free software: you can redistribute it and/or modify 5// it under the terms of the GNU General Public License as published by 6// the Free Software Foundation, either version 3 of the License, or 7// (at your option) any later version. 8// 9// Moodle is distributed in the hope that it will be useful, 10// but WITHOUT ANY WARRANTY; without even the implied warranty of 11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12// GNU General Public License for more details. 13// 14// You should have received a copy of the GNU General Public License 15// along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17/** 18 * Course format featuring social forum. 19 * 20 * @package format_social 21 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25defined('MOODLE_INTERNAL') || die(); 26 27$pageno = optional_param('p', 0, PARAM_INT); 28 29require_once($CFG->dirroot.'/mod/forum/lib.php'); 30 31$forum = forum_get_course_forum($course->id, 'social'); 32if (empty($forum)) { 33 echo $OUTPUT->notification('Could not find or create a social forum here'); 34} 35 36$coursemodule = get_coursemodule_from_instance('forum', $forum->id); 37$modcontext = context_module::instance($coursemodule->id); 38 39$entityfactory = mod_forum\local\container::get_entity_factory(); 40$forumentity = $entityfactory->get_forum_from_stdclass($forum, $modcontext, $coursemodule, $course); 41 42// Print forum intro above posts MDL-18483. 43if (trim($forum->intro) != '') { 44 $options = (object) [ 45 'para' => false, 46 ]; 47 $introcontent = format_module_intro('forum', $forum, $coursemodule->id); 48 49 if ($PAGE->user_is_editing() && has_capability('moodle/course:update', $modcontext)) { 50 $streditsummary = get_string('editsummary'); 51 $introcontent .= html_writer::start_div('editinglink'); 52 $introcontent .= html_writer::link( 53 new moodle_url('/course/modedit.php', [ 54 'update' => $coursemodule->id, 55 'sesskey' => sesskey(), 56 ]), 57 $OUTPUT->pix_icon('t/edit', $streditsummary), 58 [ 59 'title' => $streditsummary, 60 ] 61 ); 62 $introcontent .= html_writer::end_div(); 63 } 64 echo $OUTPUT->box($introcontent, 'generalbox', 'intro'); 65} 66 67echo html_writer::div(forum_get_subscribe_link($forum, $modcontext), 'subscribelink'); 68 69$numdiscussions = course_get_format($course)->get_course()->numdiscussions; 70if ($numdiscussions < 1) { 71 // Make sure that the value is at least one. 72 $numdiscussions = 1; 73} 74 75$rendererfactory = mod_forum\local\container::get_renderer_factory(); 76$discussionsrenderer = $rendererfactory->get_social_discussion_list_renderer($forumentity); 77$cm = \cm_info::create($coursemodule); 78echo $discussionsrenderer->render($USER, $cm, null, null, $pageno, $numdiscussions); 79