/** * Adds a discussion to the list (internal use only). * @param mod_forumng_discussion $discussion */ function add_discussion($discussion) { if ($discussion->is_sticky() && !$discussion->is_deleted()) { $this->stickydiscussions[$discussion->get_id()] = $discussion; } else { $this->normaldiscussions[$discussion->get_id()] = $discussion; } }
/** * Displays a short version (suitable for including in discussion list) * of this discussion including a link to view the discussion and to * mark it read (if enabled). * @param mod_forumng_discussion $discussion Discussion * @param int $groupid Group ID for display; may be NO_GROUPS or ALL_GROUPS * @param bool $last True if this is the last item in the list * @return string HTML code to print out for this discussion */ public function render_discussion_list_item(mod_forumng_discussion $discussion, $groupid, $last) { global $CFG, $USER; $showgroups = $groupid == mod_forumng::ALL_GROUPS; // Work out CSS classes to use for discussion $classes = ''; $alts = array(); $icons = array(); if ($discussion->is_deleted()) { $classes .= ' forumng-deleted'; $alts[] = get_string('alt_discussion_deleted', 'forumng'); $icons[] = array(); // No icon, text will be output on its own } if (!$discussion->is_within_time_period()) { $classes .= ' forumng-timeout'; $icon = 'timeout'; $alts[] = get_string('alt_discussion_timeout', 'forumng'); $icons[] = array('timeout', 'mod_forumng'); } if ($discussion->is_sticky()) { $classes .= ' forumng-sticky'; $alts[] = get_string('alt_discussion_sticky', 'forumng'); $icons[] = array('sticky', 'mod_forumng'); } if ($discussion->is_locked()) { $classes .= ' forumng-locked'; $alts[] = get_string('alt_discussion_locked', 'forumng'); $icons[] = array('i/unlock', 'moodle'); } // Classes for Moodle table styles static $rownum = 0; $classes .= ' r' . $rownum; $rownum = 1 - $rownum; if ($last) { $classes .= ' lastrow'; } $courseid = $discussion->get_forum()->get_course_id(); // Start row $canmarkread = $discussion->get_forum()->can_mark_read(); if ($canmarkread) { $unreadposts = $discussion->get_num_unread_posts(); $classes = $unreadposts ? $classes . ' forumng-discussion-unread' : $classes; } $result = "<tr id='discrow_{$discussion->get_id()}' class='forumng-discussion-short{$classes}'>"; // Get any tags. $tags = $discussion->get_tags(); $taglinks = ''; $linkparams = $discussion->get_forum()->get_link_params(mod_forumng::PARAM_HTML); if ($tags) { $taglinks = "<div class='forumng_discuss_tags'>Tags: "; // Unlist them. foreach ($tags as $key => $value) { $taglinks .= "<a href='view.php?{$linkparams}&tag={$key}'>{$value}</a>, "; } $taglinks .= "</div>"; } // Subject, with icons $result .= "<td class='forumng-subject cell c0'>"; foreach ($icons as $index => $icon) { $alt = $alts[$index]; if ($icon) { $url = $this->pix_url($icon[0], $icon[1]); $result .= "<img src='{$url}' alt='{$alt}' title='{$alt}' /> "; } else { $result .= "<span class='accesshide'>{$alt}:</span> "; } } $result .= "<a href='discuss.php?" . $discussion->get_link_params(mod_forumng::PARAM_HTML) . "'>" . format_string($discussion->get_subject(true), true, $courseid) . "</a>{$taglinks}</td>"; // Author. $result .= $this->render_discussion_list_item_author($discussion, $courseid); $num = 2; // Group if ($showgroups) { $result .= '<td class="cell c' . $num . '">' . $discussion->get_group_name() . '</td>'; $num++; } // Number of posts $result .= '<td class="cell c' . $num . '">' . $discussion->get_num_posts() . '</td>'; $num++; // Number of unread posts if ($canmarkread) { $result .= '<td class="cell forumng-unreadcount c3">'; if ($unreadposts) { $result .= '<a href="discuss.php?' . $discussion->get_link_params(mod_forumng::PARAM_HTML) . '#firstunread">' . $unreadposts . '</a>' . '<form method="post" action="markread.php"><div> ' . $discussion->get_link_params(mod_forumng::PARAM_FORM) . '<input type="hidden" name="back" value="view" />' . '<input type="image" title="' . get_string('markdiscussionread', 'forumng') . '" src="' . $this->pix_url('clear', 'mod_forumng') . '" ' . 'class="iconsmall" alt="' . get_string('markdiscussionread', 'forumng') . '" /></div></form>'; } else { $result .= $unreadposts; } $result .= '</td>'; $num = 4; } // Update last post user profile link. // Last post. $lastpostcell = $this->render_discussion_list_item_lastpost($discussion, $discussion->get_last_post_anon(), $num); $result .= $lastpostcell . "</tr>"; return $result; }
/** * Checks whether this feature should be displayed for the current user * in current disscussion. * By default, this checks the discussions's can_manage function and that * the discussion isn't deleted. * @param mod_forumng_discussion $discussion * @return bool True if this should display */ public function should_display($discussion) { return $discussion->can_manage() && !$discussion->is_deleted(); }
/** * Displays a short version (suitable for including in discussion list) * of this discussion including a link to view the discussion and to * mark it read (if enabled). * @param mod_forumng_discussion $discussion Discussion * @param int $groupid Group ID for display; may be NO_GROUPS or ALL_GROUPS * @param bool $last True if this is the last item in the list * @return string HTML code to print out for this discussion */ public function render_discussion_list_item(mod_forumng_discussion $discussion, $groupid, $last) { global $CFG; $showgroups = $groupid == mod_forumng::ALL_GROUPS; // Work out CSS classes to use for discussion $classes = ''; $alts = array(); $icons = array(); if ($discussion->is_deleted()) { $classes .= ' forumng-deleted'; $alts[] = get_string('alt_discussion_deleted', 'forumng'); $icons[] = array(); // No icon, text will be output on its own } if (!$discussion->is_within_time_period()) { $classes .= ' forumng-timeout'; $icon = 'timeout'; $alts[] = get_string('alt_discussion_timeout', 'forumng'); $icons[] = array('timeout', 'mod_forumng'); } if ($discussion->is_sticky()) { $classes .= ' forumng-sticky'; $alts[] = get_string('alt_discussion_sticky', 'forumng'); $icons[] = array('sticky', 'mod_forumng'); } if ($discussion->is_locked()) { $classes .= ' forumng-locked'; $alts[] = get_string('alt_discussion_locked', 'forumng'); $icons[] = array('i/unlock', 'moodle'); } // Classes for Moodle table styles static $rownum = 0; $classes .= ' r' . $rownum; $rownum = 1 - $rownum; if ($last) { $classes .= ' lastrow'; } $courseid = $discussion->get_forum()->get_course_id(); // Start row $canmarkread = $discussion->get_forum()->can_mark_read(); if ($canmarkread) { $unreadposts = $discussion->get_num_unread_posts(); $classes = $unreadposts ? $classes . ' forumng-discussion-unread' : $classes; } $result = "<tr class='forumng-discussion-short{$classes}'>"; // Subject, with icons $result .= "<td class='forumng-subject cell c0'>"; foreach ($icons as $index => $icon) { $alt = $alts[$index]; if ($icon) { $url = $this->pix_url($icon[0], $icon[1]); $result .= "<img src='{$url}' alt='{$alt}' title='{$alt}' /> "; } else { $result .= "<span class='accesshide'>{$alt}:</span> "; } } $result .= "<a href='discuss.php?" . $discussion->get_link_params(mod_forumng::PARAM_HTML) . "'>" . format_string($discussion->get_subject(), true, $courseid) . "</a></td>"; // Author $poster = $discussion->get_poster(); $picture = $this->user_picture($poster, array('courseid' => $courseid)); if ($discussion->get_forum()->is_shared()) { // Strip course id if shared forum. $picture = str_replace('&course=' . $courseid, '', $picture); } $result .= "<td class='forumng-startedby cell c1'>" . $picture . $discussion->get_forum()->display_user_link($poster) . "</td>"; $num = 2; // Group if ($showgroups) { $result .= '<td class="cell c' . $num . '">' . $discussion->get_group_name() . '</td>'; $num++; } // Number of posts $result .= '<td class="cell c' . $num . '">' . $discussion->get_num_posts() . '</td>'; $num++; // Number of unread posts if ($canmarkread) { $result .= '<td class="cell forumng-unreadcount c3">'; if ($unreadposts) { $result .= '<a href="discuss.php?' . $discussion->get_link_params(mod_forumng::PARAM_HTML) . '#firstunread">' . $unreadposts . '</a>' . '<form method="post" action="markread.php"><div> ' . $discussion->get_link_params(mod_forumng::PARAM_FORM) . '<input type="hidden" name="back" value="view" />' . '<input type="image" title="' . get_string('markdiscussionread', 'forumng') . '" src="' . $this->pix_url('t/clear') . '" ' . 'class="iconsmall" alt="' . get_string('markdiscussionread', 'forumng') . '" /></div></form>'; } else { $result .= $unreadposts; } $result .= '</td>'; $num = 4; } // Last post $last = $discussion->get_last_post_user(); $result .= '<td class="cell c' . $num . ' lastcol forumng-lastpost">' . mod_forumng_utils::display_date($discussion->get_time_modified()) . "<br/>" . $discussion->get_forum()->display_user_link($last) . "</td>"; $result .= "</tr>"; return $result; }