Example #1
0
$PAGE->set_heading($course->fullname);
$renderer = $PAGE->get_renderer('mod_hsuforum');
$PAGE->requires->js_init_call('M.mod_hsuforum.init', null, false, $renderer->get_js_module());
echo $OUTPUT->header();
echo $OUTPUT->heading(format_string($forum->name), 2);
// checkup
if (!empty($parent) && !hsuforum_user_can_see_post($forum, $discussion, $post, null, $cm)) {
    print_error('cannotreply', 'hsuforum');
}
if (!empty($parent) && !empty($parent->privatereply)) {
    print_error('cannotreply', 'hsuforum');
}
if (empty($parent) && empty($edit) && !hsuforum_user_can_post_discussion($forum, $groupid, -1, $cm, $modcontext)) {
    print_error('cannotcreatediscussion', 'hsuforum');
}
if ($forum->type == 'qanda' && !has_capability('mod/hsuforum:viewqandawithoutposting', $modcontext) && !empty($discussion->id) && !hsuforum_user_has_posted($forum->id, $discussion->id, $USER->id)) {
    echo $OUTPUT->notification(get_string('qandanotify', 'hsuforum'));
}
// If there is a warning message and we are not editing a post we need to handle the warning.
if (!empty($thresholdwarning) && !$edit) {
    // Here we want to throw an exception if they are no longer allowed to post.
    hsuforum_check_blocking_threshold($thresholdwarning);
}
if (!empty($parent)) {
    if (!($discussion = $DB->get_record('hsuforum_discussions', array('id' => $parent->discussion)))) {
        print_error('notpartofdiscussion', 'hsuforum');
    }
    echo $renderer->svg_sprite();
    // We don't have the valid unread status. Set to read so we don't see
    // the unread tag.
    $parent->postread = true;
Example #2
0
/**
 * Prints the discussion view screen for a forum.
 *
 * @global object
 * @global object
 * @param object $course The current course object.
 * @param object $forum Forum to be printed.
 * @param int $maxdiscussions .
 * @param string $sort Sort arguments for database query (optional).
 * @param int $groupmode Group mode of the forum (optional).
 * @param void $unused (originally current group)
 * @param int $page Page mode, page to display (optional).
 * @param int $perpage The maximum number of discussions per page(optional)
 *
 */
function hsuforum_print_latest_discussions($course, $forum, $maxdiscussions = -1, $sort = '', $currentgroup = -1, $groupmode = -1, $page = -1, $perpage = 100, $cm = NULL)
{
    global $CFG, $USER, $OUTPUT, $PAGE;
    require_once $CFG->dirroot . '/rating/lib.php';
    if (!$cm) {
        if (!($cm = get_coursemodule_from_instance('hsuforum', $forum->id, $forum->course))) {
            print_error('invalidcoursemodule');
        }
    }
    $context = context_module::instance($cm->id);
    if (empty($sort)) {
        $sort = "d.timemodified DESC";
    }
    $olddiscussionlink = false;
    // Sort out some defaults
    if ($perpage <= 0) {
        $perpage = 0;
        $page = -1;
    }
    if ($maxdiscussions == 0) {
        // all discussions - backwards compatibility
        $page = -1;
        $perpage = 0;
    } else {
        if ($maxdiscussions > 0) {
            $page = -1;
            $perpage = $maxdiscussions;
        }
    }
    $renderer = $PAGE->get_renderer('mod_hsuforum');
    $PAGE->requires->js_init_call('M.mod_hsuforum.init', null, false, $renderer->get_js_module());
    $fullpost = true;
    // Decide if current user is allowed to see ALL the current discussions or not
    // First check the group stuff
    if ($currentgroup == -1 or $groupmode == -1) {
        $groupmode = groups_get_activity_groupmode($cm, $course);
        $currentgroup = groups_get_activity_group($cm);
    }
    $groups = array();
    //cache
    // If the user can post discussions, then this is a good place to put the
    // button for it. We do not show the button if we are showing site news
    // and the current user is a guest.
    $canstart = hsuforum_user_can_post_discussion($forum, $currentgroup, $groupmode, $cm, $context);
    if (!$canstart and $forum->type !== 'news') {
        if (isguestuser() or !isloggedin()) {
            $canstart = true;
        }
        if (!is_enrolled($context) and !is_viewing($context)) {
            // allow guests and not-logged-in to see the button - they are prompted to log in after clicking the link
            // normal users with temporary guest access see this button too, they are asked to enrol instead
            // do not show the button to users with suspended enrolments here
            $canstart = enrol_selfenrol_available($course->id);
        }
    }
    // Get all the recent discussions we're allowed to see
    $getuserlastmodified = true;
    $discussions = hsuforum_get_discussions($cm, $sort, $fullpost, $maxdiscussions, $getuserlastmodified, $page, $perpage, false);
    // If we want paging
    $numdiscussions = null;
    if ($page != -1) {
        // Get the number of discussions found.
        $numdiscussions = hsuforum_get_discussions_count($cm);
    } else {
        if ($maxdiscussions > 0 and $maxdiscussions <= count($discussions)) {
            $olddiscussionlink = true;
        }
    }
    // TODO - Can we just delete this first if?
    if (!$canstart && (isguestuser() or !isloggedin() or $forum->type == 'news' or $forum->type == 'qanda' and !has_capability('mod/hsuforum:addquestion', $context) or $forum->type != 'qanda' and !has_capability('mod/hsuforum:startdiscussion', $context))) {
        // no button and no info
    } else {
        if (!$canstart && $groupmode and !has_capability('moodle/site:accessallgroups', $context)) {
            // inform users why they can not post new discussion
            if (!$currentgroup) {
                echo $OUTPUT->notification(get_string('cannotadddiscussionall', 'hsuforum'), 'notifyproblem hsuforum-cannot-post');
            } else {
                if (!groups_is_member($currentgroup)) {
                    echo $OUTPUT->notification(get_string('cannotadddiscussion', 'hsuforum'), 'notifyproblem hsuforum-cannot-post');
                }
            }
        }
    }
    if ($discussions) {
        echo "<h3 class='hsuforum-discussion-count' data-count='{$numdiscussions}'>" . get_string('xdiscussions', 'hsuforum', $numdiscussions) . "</h3>";
    }
    // lots of echo instead of building up and printing - bad
    echo '<div id="hsuforum-menu">';
    if ($canstart) {
        echo '<form class="hsuforum-add-discussion" id="newdiscussionform" method="get" action="' . $CFG->wwwroot . '/mod/hsuforum/post.php">
        <div>
        <input type="hidden" name="forum" value="' . $forum->id . '" />
        <input type="submit" value="' . get_string('addanewtopic', 'hsuforum') . '" />
        </div>
        </form>';
    }
    echo hsuforum_search_form($course, $forum->id);
    // Sort/Filter options
    $urlmenu = new moodle_url('/mod/hsuforum/view.php', array('id' => $cm->id));
    $groupselect = groups_print_activity_menu($cm, $urlmenu, true);
    $sortselect = '';
    if ($discussions && $forum->type != 'single' && $numdiscussions > 1) {
        require_once __DIR__ . '/lib/discussion/sort.php';
        $dsort = hsuforum_lib_discussion_sort::get_from_session($forum, $context);
        $dsort->set_key(optional_param('dsortkey', $dsort->get_key(), PARAM_ALPHA));
        $dsort->set_direction(optional_param('dsortdirection', $dsort->get_direction(), PARAM_ALPHA));
        hsuforum_lib_discussion_sort::set_to_session($dsort);
        $sortselect = $renderer->discussion_sorting($cm, $dsort);
    }
    if ($groupselect || $sortselect) {
        echo "<div id='hsuforum-filter-options'>";
        echo $groupselect;
        echo $sortselect;
        echo "</div>";
    }
    echo "</div><!-- end hsuforum-menu -->";
    // When there are no threads, return;
    if (!$discussions) {
        // in an empty forum, if the user can start a thread this div is where the js puts it
        if ($canstart) {
            echo '<div class="mod-hsuforum-posts-container article">';
            echo $renderer->discussions($cm, array(), array('total' => 0, 'page' => $page, 'perpage' => $perpage));
            echo "</div>";
        }
        return;
    }
    if ($forum->assessed != RATING_AGGREGATE_NONE) {
        $ratingoptions = new stdClass();
        $ratingoptions->context = $context;
        $ratingoptions->component = 'mod_hsuforum';
        $ratingoptions->ratingarea = 'post';
        $ratingoptions->items = $discussions;
        $ratingoptions->aggregate = $forum->assessed;
        $ratingoptions->scaleid = $forum->scale;
        $ratingoptions->userid = $USER->id;
        $ratingoptions->returnurl = "{$CFG->wwwroot}/mod/hsuforum/view.php?id={$cm->id}";
        $ratingoptions->assesstimestart = $forum->assesstimestart;
        $ratingoptions->assesstimefinish = $forum->assesstimefinish;
        $rm = new rating_manager();
        $discussions = $rm->get_ratings($ratingoptions);
    }
    $canviewparticipants = has_capability('moodle/course:viewparticipants', $context);
    $strdatestring = get_string('strftimerecentfull');
    echo '<div class="mod-hsuforum-posts-container article">';
    // Can be used by some output formats.
    $discussionlist = array();
    foreach ($discussions as $discussion) {
        if ($forum->type == 'qanda' && !has_capability('mod/hsuforum:viewqandawithoutposting', $context) && !hsuforum_user_has_posted($forum->id, $discussion->discussion, $USER->id)) {
            $canviewparticipants = false;
        }
        if (empty($discussion->replies)) {
            $discussion->replies = 0;
        }
        if (empty($discussion->lastpostid)) {
            $discussion->lastpostid = 0;
        }
        // SPECIAL CASE: The front page can display a news item post to non-logged in users.
        // All posts are read in this case.
        if (empty($USER)) {
            $discussion->unread = 0;
        } else {
            if (empty($discussion->unread)) {
                $discussion->unread = 0;
            }
        }
        if (isloggedin()) {
            $ownpost = $discussion->userid == $USER->id;
        } else {
            $ownpost = false;
        }
        // Use discussion name instead of subject of first post
        $discussion->subject = $discussion->name;
        $disc = hsuforum_extract_discussion($discussion, $forum);
        $discussionlist[$disc->id] = array($disc, $discussion);
    }
    echo $renderer->discussions($cm, $discussionlist, array('total' => $numdiscussions, 'page' => $page, 'perpage' => $perpage));
    if ($olddiscussionlink) {
        if ($forum->type == 'news') {
            $strolder = get_string('oldertopics', 'hsuforum');
        } else {
            $strolder = get_string('olderdiscussions', 'hsuforum');
        }
        echo '<div class="forumolddiscuss">';
        echo '<a href="' . $CFG->wwwroot . '/mod/hsuforum/view.php?f=' . $forum->id . '&amp;showall=1">';
        echo $strolder . '</a> ...</div>';
    }
    echo "</div>";
    // End mod-hsuforum-posts-container
    if ($page != -1) {
        echo $OUTPUT->paging_bar($numdiscussions, $page, $perpage, "view.php?f={$forum->id}");
    }
}