/**
  * Adds a discussion to the list (internal use only).
  * @param forum_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 forum_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 display_discussion_list_item($discussion, $groupid, $last)
 {
     global $CFG;
     $showgroups = $groupid == forum::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[] = '';
         // 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[] = $CFG->modpixpath . '/forumng/timeout.png';
     }
     if ($discussion->is_sticky()) {
         $classes .= ' forumng-sticky';
         $alts[] = get_string('alt_discussion_sticky', 'forumng');
         $icons[] = $CFG->modpixpath . '/forumng/sticky.png';
     }
     if ($discussion->is_locked()) {
         $classes .= ' forumng-locked';
         $alts[] = get_string('alt_discussion_locked', 'forumng');
         $icons[] = $CFG->pixpath . '/i/unlock.gif';
     }
     // 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
     $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) {
             $result .= "<img src='{$icon}' alt='{$alt}' title='{$alt}' /> ";
         } else {
             $result .= "<span class='accesshide'>{$alt}:</span> ";
         }
     }
     $result .= "<a href='discuss.php?" . $discussion->get_link_params(forum::PARAM_HTML) . "'>" . format_string($discussion->get_subject(), true, $courseid) . "</a></td>";
     // Author
     $poster = $discussion->get_poster();
     $result .= "<td class='forumng-startedby cell c1'>" . print_user_picture($poster, $courseid, null, 0, true) . $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();
     if (!class_exists('ouflags') || !ou_get_is_mobile()) {
         $result .= '</td>';
     }
     $num++;
     // Number of unread posts
     if ($discussion->get_forum()->can_mark_read()) {
         $unreadposts = $discussion->get_num_unread_posts();
         if (!class_exists('ouflags') || !ou_get_is_mobile()) {
             $result .= '<td class="cell forumng-unreadcount c3">';
         } else {
             $result .= '&nbsp;(';
         }
         if ($unreadposts) {
             $result .= '<a href="discuss.php?' . $discussion->get_link_params(forum::PARAM_HTML) . '#firstunread">' . $unreadposts . '</a>' . '<form method="post" action="markread.php"><div>&nbsp;&nbsp;&nbsp;' . $discussion->get_link_params(forum::PARAM_FORM) . '<input type="hidden" name="back" value="view" />' . '<input type="image" title="' . get_string('markdiscussionread', 'forumng') . '" src="' . $CFG->pixpath . '/t/clear.gif" ' . 'class="iconsmall" alt="' . get_string('markdiscussionread', 'forumng') . '" /></div></form>';
         } else {
             $result .= $unreadposts;
         }
         if (class_exists('ouflags') && ou_get_is_mobile()) {
             $result .= ')';
         }
         $result .= '</td>';
         $num = 4;
     }
     // Last post
     $last = $discussion->get_last_post_user();
     $result .= '<td class="cell c' . $num . ' lastcol forumng-lastpost">' . forum_utils::display_date($discussion->get_time_modified()) . "<br/>" . "<a href='{$CFG->wwwroot}/user/view.php?id={$last->id}&amp;" . "course={$courseid}'>" . fullname($last, has_capability('moodle/site:viewfullnames', $discussion->get_forum()->get_context())) . "</a></td>";
     $result .= "</tr>";
     return $result;
 }