/**
 * Displays the view page (usually showing a list of discussions).
 * @param mod_forumng $forum Forum
 * @param int $groupid Group ID
 */
function print_view_page($forum, $groupid)
{
    global $PAGE;
    $out = mod_forumng_utils::get_renderer();
    $forumngid = $forum->get_id();
    $baseurl = 'list.php?' . $forum->get_link_params(mod_forumng::PARAM_PLAIN);
    $sortorder = optional_param('sort', '', PARAM_ALPHA);
    if (!$sortorder) {
        $sortlink = optional_param('sortlink', '', PARAM_ALPHA);
        if ($sortlink) {
            $sortorder = $sortlink;
        } else {
            $sortorder = 'd';
        }
    }
    $page = optional_param('page', 0, PARAM_INT);
    if (!$page) {
        $page = 1;
    }
    $baseurl .= '&page=' . $page;
    $sortchar = substr($sortorder, 0, 1);
    if (strlen($sortorder) == 2) {
        $sortreverse = substr($sortorder, 1, 1) == 'r' ? true : false;
    } else {
        $sortreverse = false;
    }
    $baseurl .= '&sort=' . $sortchar;
    $baseurl .= $sortreverse ? 'r' : '';
    $sort = mod_forumng::get_sort_code($sortchar);
    $list = $forum->get_discussion_list($groupid, $forum->can_view_hidden(), $page, $sort, $sortreverse);
    $normal = $list->get_normal_discussions();
    $fg = new forumngtype_general();
    // Remove discussions from list if the forumtype thinks we can't see them or they are not deleted.
    foreach ($normal as $key => $value) {
        if (!$fg->can_view_discussion($value) || !$value->is_deleted()) {
            unset($normal[$key]);
        }
    }
    $pagecount = get_page_count(count($normal), $page);
    // Intro.
    print $out->render_intro($forum);
    print display_paging_bar($baseurl, $pagecount, $page);
    if (count($normal) > 0) {
        print $out->render_discussion_list_start($forum, $groupid, $baseurl, $sort, $sortreverse);
        foreach ($normal as $discussion) {
            if ($discussion->is_deleted()) {
                print $out->render_discussion_list_item($discussion, $groupid, $discussion == end($normal));
            }
        }
        print $out->render_discussion_list_end($forum, $groupid);
    } else {
        print '<p class="forumng-nodiscussions">' . get_string('nodeleteddiscussions', 'forumngfeature_deletedposts') . '</p>';
    }
    print display_paging_bar($baseurl, $pagecount, $page);
}
Пример #2
0
 /**
  * Display tag filter as a link or dropdown
  * @param array $taglist is array of tags
  * @param mod_forumng $forum
  * @param string $selectid of tag if selected
  * @return string for printing out
  */
 public function render_tag_filter($taglist, $forum, $selectid = null)
 {
     $baseurl = 'view.php?' . $forum->get_link_params(mod_forumng::PARAM_HTML);
     if (isset($selectid)) {
         $tagname = htmlspecialchars($taglist[$selectid]->displayname);
         $taglink = get_string('removefiltering', 'forumng', $tagname);
         $taglink .= '&nbsp;(';
         $taglink .= html_writer::tag('a', get_string('show_all', 'forumng'), array('href' => $baseurl));
         $taglink .= ')';
         $out = html_writer::tag('div', $taglink, array('class' => 'forumng_discuss_tagfilter'));
     } else {
         // Display dropdown.
         foreach ($taglist as $tag) {
             $options[$tag->id] = htmlspecialchars($tag->displayname) . '  (' . $tag->count . ')';
         }
         $tagurl = new moodle_url('/mod/forumng/view.php?', $forum->get_link_params_array(mod_forumng::PARAM_PLAIN));
         $select = new single_select($tagurl, 'tag', $options, '');
         $select->label = get_string('filterdiscussions', 'forumng');
         $select->set_help_icon('forumngdiscusstagfilter', 'forumng');
         $output = $this->render($select);
         $out = '<div class="forumng_discuss_tagfilter">' . $output . '</div>';
     }
     return $out;
 }
 /**
  * Displays the view page (usually showing a list of discussions).
  * @param mod_forumng $forum Forum
  * @param int $groupid Group ID
  */
 public function print_view_page($forum, $groupid)
 {
     global $SESSION, $PAGE, $USER;
     $out = mod_forumng_utils::get_renderer();
     $forumngid = $forum->get_id();
     $baseurl = 'view.php?' . $forum->get_link_params(mod_forumng::PARAM_PLAIN);
     if (isset($SESSION->forumng_discussionlist[$forumngid]) && property_exists($SESSION->forumng_discussionlist[$forumngid], 'groupid') && $SESSION->forumng_discussionlist[$forumngid]->groupid != $groupid) {
         unset($SESSION->forumng_discussionlist[$forumngid]->page);
         unset($SESSION->forumng_discussionlist[$forumngid]->groupid);
     }
     // Remember the sort order and page number in session variables
     // Unset the page session variable when the sort links are clicked
     // or groupid has been changed (using the group dropdown box)
     $sortorder = optional_param('sort', '', PARAM_ALPHA);
     if (!$sortorder) {
         if (isset($SESSION->forumng_discussionlist[$forumngid]->sort)) {
             $sortorder = $SESSION->forumng_discussionlist[$forumngid]->sort;
         } else {
             $sortorder = 'd';
         }
     } else {
         if (optional_param('sortlink', '', PARAM_ALPHA)) {
             if (!isset($SESSION->forumng_discussionlist[$forumngid])) {
                 $SESSION->forumng_discussionlist[$forumngid] = new stdClass();
             }
             $SESSION->forumng_discussionlist[$forumngid]->sort = $sortorder;
             unset($SESSION->forumng_discussionlist[$forumngid]->page);
         }
     }
     $page = optional_param('page', 0, PARAM_INT);
     if (!$page) {
         if (isset($SESSION->forumng_discussionlist[$forumngid]->page)) {
             $page = $SESSION->forumng_discussionlist[$forumngid]->page;
         } else {
             $page = 1;
         }
     } else {
         if (!isset($SESSION->forumng_discussionlist[$forumngid])) {
             $SESSION->forumng_discussionlist[$forumngid] = new stdClass();
         }
         $SESSION->forumng_discussionlist[$forumngid]->page = $page;
         $SESSION->forumng_discussionlist[$forumngid]->groupid = $groupid;
     }
     $baseurl .= '&page=' . $page;
     $sortchar = substr($sortorder, 0, 1);
     if (strlen($sortorder) == 2) {
         $sortreverse = substr($sortorder, 1, 1) == 'r' ? true : false;
     } else {
         $sortreverse = false;
     }
     $baseurl .= '&sort=' . $sortchar;
     $baseurl .= $sortreverse ? 'r' : '';
     $sort = mod_forumng::get_sort_code($sortchar);
     // Get tagid if used.
     $tag = optional_param('tag', null, PARAM_ALPHANUM);
     $list = $forum->get_discussion_list($groupid, $forum->can_view_hidden(), $page, $sort, $sortreverse, 0, true, $tag);
     $sticky = $list->get_sticky_discussions();
     $normal = $list->get_normal_discussions();
     // Remove discussions from list if the forumtype thinks we can't see
     // them
     foreach ($sticky as $key => $value) {
         if (!$this->can_view_discussion($value)) {
             unset($sticky[$key]);
         }
     }
     foreach ($normal as $key => $value) {
         if (!$this->can_view_discussion($value)) {
             unset($normal[$key]);
         }
     }
     // Intro
     print $out->render_intro($forum);
     // Flagged posts skip link.
     $flaggedposts = $forum->get_flagged_posts();
     $flagdiscussions = $forum->get_flagged_discussions();
     $flaggeddiscussions = array();
     // Need to loop through flagged discussions removing any that can not be viewed by user.
     foreach ($flagdiscussions as $discussion) {
         if ($discussion->can_view($USER->id)) {
             // Add to flagged discussions.
             array_push($flaggeddiscussions, $discussion);
         }
     }
     if (count($flaggedposts) + count($flaggeddiscussions) > 0) {
         $output = html_writer::start_tag('div', array('class' => 'forumng-flagged-link'));
         $output .= $out->render_flagged_list_link($flaggeddiscussions, true);
         $output .= $out->render_flagged_list_link($flaggedposts);
         $output .= html_writer::end_tag('div');
         echo $output;
     }
     // Draft posts
     $drafts = $forum->get_drafts();
     if (count($drafts) > 0) {
         print $out->render_draft_list_start();
         foreach ($drafts as $draft) {
             print $out->render_draft_list_item($forum, $draft, $draft == end($drafts));
         }
         print $out->render_draft_list_end();
     }
     // Print info about the start and end dates of the forum from the form setting
     $stringend = has_capability('mod/forumng:ignorepostlimits', $forum->get_context()) ? 'capable' : '';
     $startdate = $forum->get_postingfrom();
     $enddate = $forum->get_postinguntil();
     // Before start date
     if (time() < $startdate) {
         $message = get_string('beforestartdate' . $stringend, 'forumng', mod_forumng_utils::display_date($startdate));
         print "<div class='forumng-show-dates'>{$message}</div>";
     } else {
         if (time() < $enddate) {
             $message = get_string('beforeenddate' . $stringend, 'forumng', mod_forumng_utils::display_date($enddate));
             print "<div class='forumng-show-dates'>{$message}</div>";
         }
     }
     // After end date
     if ($enddate && time() >= $enddate) {
         $message = get_string('afterenddate' . $stringend, 'forumng', mod_forumng_utils::display_date($enddate));
         print "<div class='forumng-show-dates'>{$message}</div>";
     }
     // Show Alert info.
     if ($forum->has_reporting_email()) {
         print $out->box(get_string('alert_intro', 'forumng'), 'generalbox', 'forumng-reportingon');
     }
     // Post button - temporarily disabled when in all-groups mode
     print $groupid == null ? '' : $forum->display_post_button($groupid);
     if ($taglist = $forum->get_tags_used($groupid)) {
         print $out->render_tag_filter($taglist, $forum, $tag);
     }
     // Provide link to skip sticky discussions.
     if (count($sticky) > 0 && count($normal) > 0) {
         print $out->render_skip_link(key($normal));
     }
     print $list->display_paging_bar($baseurl);
     if (count($sticky) + count($normal) > 0) {
         print $out->render_discussion_list_start($forum, $groupid, $baseurl, $sort, $sortreverse);
         foreach ($sticky as $discussion) {
             print $out->render_discussion_list_item($discussion, $groupid, count($normal) == 0 && $discussion == end($sticky));
         }
         if (count($sticky) > 0 && count($normal) > 0) {
             print $out->render_discussion_list_divider($forum, $groupid);
         }
         foreach ($normal as $discussion) {
             print $out->render_discussion_list_item($discussion, $groupid, $discussion == end($normal));
         }
         print $out->render_discussion_list_end($forum, $groupid);
     } else {
         print '<p class="forumng-nodiscussions">' . $this->get_string($forum, 'nodiscussions') . '</p>';
     }
     print $list->display_paging_bar($baseurl);
     print $forum->display_forumngfeature_discussion_lists($groupid);
     // Flagged discussions.
     if (count($flaggeddiscussions) > 0) {
         print $out->render_flagged_list_start(true);
         foreach ($flaggeddiscussions as $discussion) {
             print $out->render_flagged_discuss_list_item($discussion, $discussion === end($flaggeddiscussions));
         }
         print $out->render_flagged_list_end();
     }
     // Flagged posts.
     if (count($flaggedposts) > 0) {
         print $out->render_flagged_list_start();
         foreach ($flaggedposts as $post) {
             print $out->render_flagged_list_item($post, $post === end($flaggedposts));
         }
         print $out->render_flagged_list_end();
     }
     // Subscribe and view subscribers links
     print $forum->display_subscribe_options();
     // Atom/RSS links
     print $forum->display_feed_links($groupid);
     // display the warning message for invalid archive setting
     print $forum->display_archive_warning();
     // Display sharing information
     print $forum->display_sharing_info();
 }
 /**
  * Updates the in-memory digest records to add a new post to the given
  * user's digests.
  * @param object $user User object (must include special ->emailtype, etc)
  * @param array $userdigests Array of user id => digest information object
  * @param mod_forumng_post $post Post object
  * @param mod_forumng_post $inreplyto Parent post
  * @param mod_forumng_discussion $discussion Discus
  * @param mod_forumng $forum
  * @param object $cm
  * @param object $course
  * @param object $context
  */
 private static function digest_add_post_for_user(&$user, &$userdigests, &$post, &$inreplyto, &$discussion, &$forum, &$cm, &$course, &$context)
 {
     global $CFG;
     // Set up digest for user if required
     if (!array_key_exists($user->id, $userdigests)) {
         $userdigests[$user->id] = new StdClass();
         $userdigests[$user->id]->discussionid = -1;
         // So we do header next
         $userdigests[$user->id]->user = $user;
         $userdigests[$user->id]->forumngid = -1;
         // Get header text
         $headerdata = new object();
         $headerdata->sitename = format_string($course->fullname, true);
         $headerdata->userprefs = $CFG->wwwroot . '/user/edit.php?id=' . $user->id . '&amp;course=' . $course->id;
         $userdigests[$user->id]->text = get_string('digestmailheader', 'forumng', $headerdata) . "\n\n";
         // Get header HTML
         $html = "<body id='forumng-email'>\n";
         $headerdata->userprefs = '<a target="_blank" href="' . $headerdata->userprefs . '">' . get_string('digestmailprefs', 'forumng') . '</a>';
         $html .= '<div class="forumng-emailheader"><p>' . get_string('digestmailheader', 'forumng', $headerdata) . '</p></div><hr size="1" noshade="noshade" />';
         $userdigests[$user->id]->html = $html;
         // Get email subject
         $userdigests[$user->id]->subject = get_string('digestmailsubject', 'forumng', format_string($course->shortname, true));
     }
     // New forum?
     if ($userdigests[$user->id]->forumngid != $forum->get_id()) {
         $userdigests[$user->id]->forumngid = $forum->get_id();
     }
     // Is this a new discussion?
     if ($userdigests[$user->id]->discussionid != $discussion->get_id()) {
         $strforums = get_string('forums', 'forumng');
         // Per-discussion header (text mode)
         $text = "\n \n";
         $text .= '=====================================================================';
         $text .= "\n \n";
         $text .= "{$course->shortname} -> {$strforums} -> " . format_string($forum->get_name(), true);
         if ($discussion->get_subject(false) !== $forum->get_name()) {
             $text .= " -> " . format_string($discussion->get_subject(false), true);
         }
         $text .= "\n";
         // HTML mode
         $html = '<hr size="1" noshade="noshade" />';
         $html .= "<div class='forumng-breadcrumbs'>" . "<a target='_blank' href='{$CFG->wwwroot}/course/view.php?" . "id={$course->id}'>{$course->shortname}</a> -> " . "<a target='_blank' href='{$CFG->wwwroot}/mod/forumng/index.php?" . "id={$course->id}'>{$strforums}</a> -> " . "<a target='_blank' href='{$CFG->wwwroot}/mod/forumng/view.php?" . $forum->get_link_params(mod_forumng::PARAM_HTML) . "'>" . format_string($forum->get_name(), true) . "</a>";
         if ($discussion->get_subject(false) !== $forum->get_name()) {
             $html .= " -> <a target='_blank' href='{$CFG->wwwroot}/mod/forumng/discuss.php?" . $discussion->get_link_params(mod_forumng::PARAM_HTML) . "'>" . format_string($discussion->get_subject(false), true) . "</a>";
         }
         $html .= '</div>';
         $userdigests[$user->id]->text .= $text;
         $userdigests[$user->id]->html .= $html;
         $userdigests[$user->id]->discussionid = $discussion->get_id();
     }
     // Get both plaintext and html versions (and subject).
     // The html version will be blank if set to
     // plain text mode.
     $post->build_email($inreplyto, $subject, $text, $html, $user->emailtype & 1, $user->emailtype & 2, $user->emailtype & 4, $user->lang, $user->timezone, true);
     $userdigests[$user->id]->text .= $text;
     $userdigests[$user->id]->html .= $html;
 }
Пример #5
0
 /**
  * Display subscribe options.
  * @param mod_forumng $forum Forum
  * @param string $text Textual note
  * @param int $subscribed
  * @param bool $button True if subscribe/unsubscribe button should be shown
  * @param bool $viewlink True if 'view subscribers' link should be shown
  * @return string HTML code for this area
  */
 public function render_subscribe_options($forum, $text, $subscribed, $button, $viewlink)
 {
     $out = '<div class="forumng-subscribe-options">' . '<h3>' . get_string('subscription', 'forumng') . '</h3>' . '<p>' . $text . '</p>';
     $cm = $forum->get_course_module();
     if ($button) {
         $outsubmit = '';
         $currentgroupid = mod_forumng::get_activity_group($cm, true);
         if ($currentgroupid == mod_forumng::NO_GROUPS) {
             $currentgroupid = 0;
         }
         if ($subscribed == mod_forumng::FULLY_SUBSCRIBED || $subscribed == mod_forumng::FULLY_SUBSCRIBED_GROUPMODE) {
             $outsubmit .= '<input type="submit" name="submitunsubscribe" value="' . get_string('unsubscribeshort', 'forumng') . '" />';
         } else {
             if ($subscribed == mod_forumng::PARTIALLY_SUBSCRIBED) {
                 //print both subscribe button and unsubscribe button
                 $outsubmit .= '<input type="submit" name="submitsubscribe" value="' . get_string('subscribelong', 'forumng') . '" />' . '<input type="submit" name="submitunsubscribe" value="' . get_string('unsubscribelong', 'forumng') . '" />';
             } else {
                 if ($subscribed == mod_forumng::NOT_SUBSCRIBED) {
                     //default unsubscribed, print subscribe button
                     $outsubmit .= '<input type="submit" name="submitsubscribe" value="' . get_string('subscribeshort', 'forumng') . '" />';
                 } else {
                     if ($subscribed == mod_forumng::THIS_GROUP_PARTIALLY_SUBSCRIBED) {
                         $outsubmit .= '<input type="submit" name="submitsubscribe_thisgroup" value="' . get_string('subscribegroup', 'forumng') . '" />' . '<input type="submit" name="submitunsubscribe_thisgroup" value="' . get_string('unsubscribegroup_partial', 'forumng') . '" />' . '<input type="hidden" name="g" value="' . $currentgroupid . '" />';
                     } else {
                         if ($subscribed == mod_forumng::THIS_GROUP_SUBSCRIBED) {
                             $outsubmit .= '<input type="submit" name="submitunsubscribe_thisgroup" value="' . get_string('unsubscribegroup', 'forumng') . '" />' . '<input type="hidden" name="g" value="' . $currentgroupid . '" />';
                         } else {
                             if ($subscribed == mod_forumng::THIS_GROUP_NOT_SUBSCRIBED) {
                                 $outsubmit .= '<input type="submit" name="submitsubscribe_thisgroup" value="' . get_string('subscribegroup', 'forumng') . '" />' . '<input type="hidden" name="g" value="' . $currentgroupid . '" />';
                             }
                         }
                     }
                 }
             }
         }
         $out .= '&nbsp;<form action="subscribe.php" method="post"><div>' . $forum->get_link_params(mod_forumng::PARAM_FORM) . '<input type="hidden" name="back" value="view" />' . $outsubmit . '</div></form>';
     }
     if ($viewlink) {
         $out .= ' <div class="forumng-subscribe-admin">' . '<a href="subscribers.php?' . $forum->get_link_params(mod_forumng::PARAM_HTML) . '">' . get_string('viewsubscribers', 'forumng') . '</a></div>';
     }
     $out .= '</div>';
     return $out;
 }