/** * Convenience function for subclasses. Returns HTML code suitable to * use for a button in this area. * @param forum_discussion $discussion * @param string $name Text of button * @param string $script Name/path of .php script (relative to mod/forumng) * @param bool $post If true, makes the button send a POST request * @param array $options If included, passes these options as well as 'd' * @param string $extrahtml If specified, adds this HTML at end of (just * inside) the form * @param bool $highlight If true, adds a highlight class to the form * @return string HTML code for button */ protected static function get_button($discussion, $name, $script, $post = false, $options = array(), $extrahtml = '', $highlight = false) { $method = $post ? 'post' : 'get'; $optionshtml = ''; $options['d'] = $discussion->get_id(); if ($discussion->get_forum()->is_shared()) { $options['clone'] = $discussion->get_forum()->get_course_module_id(); } if ($post) { $options['sesskey'] = sesskey(); } foreach ($options as $key => $value) { $optionshtml .= '<input type="hidden" name="' . $key . '" value="' . $value . '" />'; } $class = ''; if ($highlight) { $class = ' class="forumng-highlight"'; } return "<form method='{$method}' action='{$script}' {$class}><div>" . "{$optionshtml}<input type='submit' value='{$name}' />" . "{$extrahtml}</div></form>"; }
/** * 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 .= ' ('; } if ($unreadposts) { $result .= '<a href="discuss.php?' . $discussion->get_link_params(forum::PARAM_HTML) . '#firstunread">' . $unreadposts . '</a>' . '<form method="post" action="markread.php"><div> ' . $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}&" . "course={$courseid}'>" . fullname($last, has_capability('moodle/site:viewfullnames', $discussion->get_forum()->get_context())) . "</a></td>"; $result .= "</tr>"; return $result; }