\n";
}
}
}
/**
* Prints the discussion view screen for a forum.
*
* @param object $course The current course object.
* @param object $forum Forum to be printed.
* @param int $maxdiscussions
* @param string $displayformat The display format to use (optional).
* @param string $sort Sort arguments for database query (optional).
* @param int $currentgroup
* @param int $groupmode Group mode of the forum (optional).
* @param int $page Page mode, page to display (optional).
* @param int $perpage The maximum number of discussions per page(optional)
* @param stdClass $cm
* @deprecated since Moodle 3.7
*/
function forum_print_latest_discussions($course, $forum, $maxdiscussions = -1, $displayformat = 'plain', $sort = '',
$currentgroup = -1, $groupmode = -1, $page = -1, $perpage = 100, $cm = null) {
debugging('forum_print_latest_discussions has been deprecated.', DEBUG_DEVELOPER);
global $CFG, $USER, $OUTPUT;
require_once($CFG->dirroot . '/course/lib.php');
if (!$cm) {
if (!$cm = get_coursemodule_from_instance('forum', $forum->id, $forum->course)) {
print_error('invalidcoursemodule');
}
}
$context = context_module::instance($cm->id);
if (empty($sort)) {
$sort = forum_get_default_sort_order();
}
$olddiscussionlink = false;
// Sort out some defaults.
if ($perpage <= 0) {
$perpage = 0;
$page = -1;
}
if ($maxdiscussions == 0) {
// All discussions - backwards compatibility.
$page = -1;
$perpage = 0;
if ($displayformat == 'plain') {
$displayformat = 'header'; // Abbreviate display by default.
}
} else if ($maxdiscussions > 0) {
$page = -1;
$perpage = $maxdiscussions;
}
$fullpost = false;
if ($displayformat == 'plain') {
$fullpost = true;
}
// Decide if current user is allowed to see ALL the current discussions or not.
// First check the group stuff.
if ($currentgroup == -1 or $groupmode == -1) {
$groupmode = groups_get_activity_groupmode($cm, $course);
$currentgroup = groups_get_activity_group($cm);
}
// Cache.
$groups = array();
// If the user can post discussions, then this is a good place to put the
// button for it. We do not show the button if we are showing site news
// and the current user is a guest.
$canstart = forum_user_can_post_discussion($forum, $currentgroup, $groupmode, $cm, $context);
if (!$canstart and $forum->type !== 'news') {
if (isguestuser() or !isloggedin()) {
$canstart = true;
}
if (!is_enrolled($context) and !is_viewing($context)) {
// Allow guests and not-logged-in to see the button - they are prompted to log in after clicking the link
// normal users with temporary guest access see this button too, they are asked to enrol instead
// do not show the button to users with suspended enrolments here.
$canstart = enrol_selfenrol_available($course->id);
}
}
if ($canstart) {
switch ($forum->type) {
case 'news':
case 'blog':
$buttonadd = get_string('addanewtopic', 'forum');
break;
case 'qanda':
$buttonadd = get_string('addanewquestion', 'forum');
break;
default:
$buttonadd = get_string('addanewdiscussion', 'forum');
break;
}
$button = new single_button(new moodle_url('/mod/forum/post.php', ['forum' => $forum->id]), $buttonadd, 'get');
$button->class = 'singlebutton forumaddnew';
$button->formid = 'newdiscussionform';
echo $OUTPUT->render($button);
} else if (isguestuser() or !isloggedin() or $forum->type == 'news' or
$forum->type == 'qanda' and !has_capability('mod/forum:addquestion', $context) or
$forum->type != 'qanda' and !has_capability('mod/forum:startdiscussion', $context)) {
// No button and no info.
$ignore = true;
} else if ($groupmode and !has_capability('moodle/site:accessallgroups', $context)) {
// Inform users why they can not post new discussion.
if (!$currentgroup) {
if (!has_capability('mod/forum:canposttomygroups', $context)) {
echo $OUTPUT->notification(get_string('cannotadddiscussiongroup', 'forum'));
} else {
echo $OUTPUT->notification(get_string('cannotadddiscussionall', 'forum'));
}
} else if (!groups_is_member($currentgroup)) {
echo $OUTPUT->notification(get_string('cannotadddiscussion', 'forum'));
}
}
// Get all the recent discussions we're allowed to see.
$getuserlastmodified = ($displayformat == 'header');
$discussions = forum_get_discussions($cm, $sort, $fullpost, null, $maxdiscussions, $getuserlastmodified, $page, $perpage);
if (!$discussions) {
echo '
';
}
if ($page != -1) {
// Show the paging bar.
echo $OUTPUT->paging_bar($numdiscussions, $page, $perpage, "view.php?f=$forum->id");
}
}
/**
* Count the number of replies to the specified post.
*
* @param object $post
* @param bool $children
* @return int
* @deprecated since Moodle 3.7
* @todo MDL-65252 This will be removed in Moodle 4.1
*/
function forum_count_replies($post, $children = true) {
global $USER;
debugging('forum_count_replies has been deprecated. Please use the Post vault instead.', DEBUG_DEVELOPER);
if (!$children) {
return $DB->count_records('forum_posts', array('parent' => $post->id));
}
$entityfactory = mod_forum\local\container::get_entity_factory();
$postentity = $entityfactory->get_post_from_stdclass($post);
$vaultfactory = mod_forum\local\container::get_vault_factory();
$postvault = $vaultfactory->get_post_vault();
return $postvault->get_reply_count_for_post_id_in_discussion_id(
$USER,
$postentity->get_id(),
$postentity->get_discussion_id(),
true
);
}