Skip to content

Commit

Permalink
MDL-78328 mod_forum: Deprecate forum_print_discussion_header
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed May 22, 2023
1 parent 2e1c6fd commit 656433d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 171 deletions.
12 changes: 12 additions & 0 deletions mod/forum/deprecatedlib.php
Expand Up @@ -512,3 +512,15 @@ function forum_update_subscriptions_button($courseid, $forumid): string {

return $subscribers;
}

/**
* This function prints the overview of a discussion in the forum listing.
* It needs some discussion information and some post information, these
* happen to be combined for efficiency in the $post parameter by the function
* that calls this one: forum_print_latest_discussions()
*
* @deprecated since Moodle 4.3
*/
function forum_print_discussion_header() {
throw new \coding_exception('forum_print_discussion_header has been deprecated');
}
171 changes: 0 additions & 171 deletions mod/forum/lib.php
Expand Up @@ -2309,177 +2309,6 @@ function mod_forum_rating_can_see_item_ratings($params) {
return true;
}

/**
* This function prints the overview of a discussion in the forum listing.
* It needs some discussion information and some post information, these
* happen to be combined for efficiency in the $post parameter by the function
* that calls this one: forum_print_latest_discussions()
*
* @global object
* @global object
* @param object $post The post object (passed by reference for speed).
* @param object $forum The forum object.
* @param int $group Current group.
* @param string $datestring Format to use for the dates.
* @param boolean $cantrack Is tracking enabled for this forum.
* @param boolean $forumtracked Is the user tracking this forum.
* @param boolean $canviewparticipants True if user has the viewparticipants permission for this course
* @param boolean $canviewhiddentimedposts True if user has the viewhiddentimedposts permission for this forum
*/
function forum_print_discussion_header(&$post, $forum, $group = -1, $datestring = "",
$cantrack = true, $forumtracked = true, $canviewparticipants = true, $modcontext = null,
$canviewhiddentimedposts = false) {

global $COURSE, $USER, $CFG, $OUTPUT, $PAGE;

static $rowcount;
static $strmarkalldread;

if (empty($modcontext)) {
if (!$cm = get_coursemodule_from_instance('forum', $forum->id, $forum->course)) {
throw new \moodle_exception('invalidcoursemodule');
}
$modcontext = context_module::instance($cm->id);
}

if (!isset($rowcount)) {
$rowcount = 0;
$strmarkalldread = get_string('markalldread', 'forum');
} else {
$rowcount = ($rowcount + 1) % 2;
}

$post->subject = format_string($post->subject,true);

$canviewfullnames = has_capability('moodle/site:viewfullnames', $modcontext);
$timeddiscussion = !empty($CFG->forum_enabletimedposts) && ($post->timestart || $post->timeend);
$timedoutsidewindow = '';
if ($timeddiscussion && ($post->timestart > time() || ($post->timeend != 0 && $post->timeend < time()))) {
$timedoutsidewindow = ' dimmed_text';
}

echo "\n\n";
echo '<tr class="discussion r'.$rowcount.$timedoutsidewindow.'">';

$topicclass = 'topic starter';
if (FORUM_DISCUSSION_PINNED == $post->pinned) {
$topicclass .= ' pinned';
}
echo '<td class="'.$topicclass.'">';
if (FORUM_DISCUSSION_PINNED == $post->pinned) {
echo $OUTPUT->pix_icon('i/pinned', get_string('discussionpinned', 'forum'), 'mod_forum');
}
$canalwaysseetimedpost = $USER->id == $post->userid || $canviewhiddentimedposts;
if ($timeddiscussion && $canalwaysseetimedpost) {
echo $PAGE->get_renderer('mod_forum')->timed_discussion_tooltip($post, empty($timedoutsidewindow));
}

echo '<a href="'.$CFG->wwwroot.'/mod/forum/discuss.php?d='.$post->discussion.'">'.$post->subject.'</a>';
echo "</td>\n";

// Picture
$postuser = new stdClass();
$postuserfields = explode(',', implode(',', \core_user\fields::get_picture_fields()));
$postuser = username_load_fields_from_object($postuser, $post, null, $postuserfields);
$postuser->id = $post->userid;
echo '<td class="author">';
echo '<div class="media">';
echo '<span class="float-left">';
echo $OUTPUT->user_picture($postuser, array('courseid'=>$forum->course));
echo '</span>';
// User name
echo '<div class="media-body">';
$fullname = fullname($postuser, $canviewfullnames);
echo '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$post->userid.'&amp;course='.$forum->course.'">'.$fullname.'</a>';
echo '</div>';
echo '</div>';
echo "</td>\n";

// Group picture
if ($group !== -1) { // Groups are active - group is a group data object or NULL
echo '<td class="picture group">';
if (!empty($group->picture)) {
if ($canviewparticipants && $COURSE->groupmode) {
$picturelink = true;
} else {
$picturelink = false;
}
print_group_picture($group, $forum->course, false, false, $picturelink);
} else if (isset($group->id)) {
if ($canviewparticipants && $COURSE->groupmode) {
echo '<a href="'.$CFG->wwwroot.'/user/index.php?id='.$forum->course.'&amp;group='.$group->id.'">'.$group->name.'</a>';
} else {
echo $group->name;
}
}
echo "</td>\n";
}

if (has_capability('mod/forum:viewdiscussion', $modcontext)) { // Show the column with replies
echo '<td class="replies">';
echo '<a href="'.$CFG->wwwroot.'/mod/forum/discuss.php?d='.$post->discussion.'">';
echo $post->replies.'</a>';
echo "</td>\n";

if ($cantrack) {
echo '<td class="replies">';
if ($forumtracked) {
if ($post->unread > 0) {
echo '<span class="unread">';
echo '<a href="'.$CFG->wwwroot.'/mod/forum/discuss.php?d='.$post->discussion.'#unread">';
echo $post->unread;
echo '</a>';
echo '<a title="'.$strmarkalldread.'" href="'.$CFG->wwwroot.'/mod/forum/markposts.php?f='.
$forum->id.'&amp;d='.$post->discussion.'&amp;mark=read&amp;return=/mod/forum/view.php&amp;sesskey=' .
sesskey() . '">' . $OUTPUT->pix_icon('t/markasread', $strmarkalldread) . '</a>';
echo '</span>';
} else {
echo '<span class="read">';
echo $post->unread;
echo '</span>';
}
} else {
echo '<span class="read">';
echo '-';
echo '</span>';
}
echo "</td>\n";
}
}

echo '<td class="lastpost">';
$usedate = (empty($post->timemodified)) ? $post->created : $post->timemodified;
$parenturl = '';
$usermodified = new stdClass();
$usermodified->id = $post->usermodified;
$usermodified = username_load_fields_from_object($usermodified, $post, 'um');

// In QA forums we check that the user can view participants.
if ($forum->type !== 'qanda' || $canviewparticipants) {
echo '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$post->usermodified.'&amp;course='.$forum->course.'">'.
fullname($usermodified, $canviewfullnames).'</a><br />';
$parenturl = (empty($post->lastpostid)) ? '' : '&amp;parent='.$post->lastpostid;
}

echo '<a href="'.$CFG->wwwroot.'/mod/forum/discuss.php?d='.$post->discussion.$parenturl.'">'.
userdate_htmltime($usedate, $datestring).'</a>';
echo "</td>\n";

// is_guest should be used here as this also checks whether the user is a guest in the current course.
// Guests and visitors cannot subscribe - only enrolled users.
if ((!is_guest($modcontext, $USER) && isloggedin()) && has_capability('mod/forum:viewdiscussion', $modcontext)) {
// Discussion subscription.
if (\mod_forum\subscriptions::is_subscribable($forum)) {
echo '<td class="discussionsubscription">';
echo forum_get_discussion_subscription_icon($forum, $post->discussion);
echo '</td>';
}
}

echo "</tr>\n\n";

}

/**
* Return the markup for the discussion subscription toggling icon.
*
Expand Down
4 changes: 4 additions & 0 deletions mod/forum/upgrade.txt
@@ -1,6 +1,10 @@
This files describes API changes in /mod/forum/*,
information provided here is intended especially for developers.

=== 4.3 ===

* The forum_print_discussion_header function has been deprecated and will not be replaced.

=== 4.1 ===

* The following code, previously used (exclusively) by upgrade steps is not available anymore
Expand Down

0 comments on commit 656433d

Please sign in to comment.