/**
  * Convenience function for subclasses. Returns HTML code suitable to
  * use for a button in this area.
  * @param mod_forumng_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
  * @param bool $selector If true, adds a selector class to the form (indicating that the
  *   JavaScript post selector should be used)
  * @return string HTML code for button
  */
 protected static function get_button($discussion, $name, $script, $post = false, $options = array(), $extrahtml = '', $highlight = false, $selector = 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 = 'forumng-highlight';
     }
     if ($selector) {
         $class .= ' forumng-selectorbutton';
     }
     if ($class !== '') {
         $class = ' class="' . trim($class) . '"';
     }
     return "<form method='{$method}' action='{$script}' {$class}><div>" . "{$optionshtml}<input type='submit' value='{$name}' />" . "{$extrahtml}</div></form>";
 }
 /**
  * Merges the contents of this discussion into another discussion.
  * @param mod_forumng_discussion $targetdiscussion Target discussion
  * @param int $userid User ID (0 = current)
  * @param bool $log True to log this action
  */
 public function merge_into($targetdiscussion, $userid = 0, $log = true)
 {
     global $DB;
     $transaction = $DB->start_delegated_transaction();
     // Delete search data for the source discussion
     $this->ismakingsearchchange = true;
     $root = $this->get_root_post();
     $root->search_update();
     $root->search_update_children();
     $this->ismakingsearchchange = false;
     // Update parent post id of root post
     $record = new stdClass();
     $record->id = $this->discussionfields->postid;
     $record->parentpostid = $targetdiscussion->discussionfields->postid;
     $DB->update_record('forumng_posts', $record);
     // Move all posts into new discussion
     $DB->execute("UPDATE {forumng_posts} SET discussionid = ? WHERE discussionid = ?", array($targetdiscussion->get_id(), $this->get_id()));
     // Delete this discussion
     $DB->delete_records('forumng_discussions', array('id' => $this->discussionfields->id));
     // Attachments are OK because they are still in the same context, postid
     // etc (note this would NOT be the case if we allowed merging between
     // forums).
     if ($this->get_forum()->get_id() != $targetdiscussion->get_forum()->get_id()) {
         throw new coding_exception('Cannot merge into different forum');
     }
     // Merging the discussion into another might cause completion changes
     // (if there was a requirement for discussions and this is no longer
     // a discussion in its own right).
     $this->update_completion(false);
     // Update the search data for the target discussion after the merge
     $newroot = $targetdiscussion->get_root_post();
     $newroot->search_update();
     $newroot->search_update_children();
     if ($log) {
         $this->log('merge discussion', 'd' . $this->get_id() . ' into d' . $targetdiscussion->get_id());
     }
     $transaction->allow_commit();
     $this->uncache();
     $targetdiscussion->uncache();
 }
Ejemplo n.º 3
0
 /**
  * Display subscribe option for discussions.
  * @param mod_forumng_discussion $discussion Forum
  * @param string $text Textual note
  * @param bool $subscribe True if user can subscribe, False if user can unsubscribe
  * @return string HTML code for this area
  */
 public function render_discussion_subscribe_option($discussion, $subscribe)
 {
     global $USER;
     $info = '';
     if ($subscribe) {
         $status = get_string('subscribestate_discussionunsubscribed', 'forumng');
         $submit = 'submitsubscribe';
         $button = get_string('subscribediscussion', 'forumng');
     } else {
         $status = get_string('subscribestate_discussionsubscribed', 'forumng', '<strong>' . $USER->email . '</strong>');
         $submit = 'submitunsubscribe';
         $button = get_string('unsubscribediscussion', 'forumng');
         $info = $this->render_subscribe_info($discussion->get_forum()->get_context());
     }
     return '<div class="clearfix"></div><div class="forumng-subscribe-options" id="forumng-subscribe-options">' . '<h3>' . get_string('subscription', 'forumng') . '</h3>' . '<p>' . $status . '</p>' . '&nbsp;<form action="subscribe.php" method="post"><div>' . $discussion->get_link_params(mod_forumng::PARAM_FORM) . '<input type="hidden" name="back" value="discuss" />' . '<input type="submit" name="' . $submit . '" value="' . $button . '" /></div></form></div>' . $info;
 }
Ejemplo n.º 4
0
 /**
  * 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('&amp;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>&nbsp;&nbsp;&nbsp;' . $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;
 }