Пример #1
0
/**
 * Prints the discussion view screen for a quora.
 *
 * @global object
 * @global object
 * @param object $course The current course object.
 * @param object $quora Forum to be printed.
 * @param int $maxdiscussions .
 * @param string $displayformat The display format to use (optional).
 * @param string $sort Sort arguments for database query (optional).
 * @param int $groupmode Group mode of the quora (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)
 * @param boolean $subscriptionstatus Whether the user is currently subscribed to the discussion in some fashion.
 *
 */
function quora_print_latest_discussions($course, $quora, $maxdiscussions = -1, $displayformat = 'plain', $sort = '', $currentgroup = -1, $groupmode = -1, $page = -1, $perpage = 100, $cm = null)
{
    global $CFG, $USER, $OUTPUT;
    if (!$cm) {
        if (!($cm = get_coursemodule_from_instance('quora', $quora->id, $quora->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;
        if ($displayformat == 'plain') {
            $displayformat = 'header';
            // Abbreviate display by default
        }
    } else {
        if ($maxdiscussions > 0) {
            $page = -1;
            $perpage = $maxdiscussions;
        }
    }
    $fullpost = false;
    if ($displayformat == 'plain') {
        $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 = quora_user_can_post_discussion($quora, $currentgroup, $groupmode, $cm, $context);
    if (!$canstart and $quora->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);
        }
    }
    if ($canstart) {
        echo '<div class="singlebutton quoraaddnew">';
        echo "<form id=\"newdiscussionform\" method=\"get\" action=\"{$CFG->wwwroot}/mod/quora/post.php\">";
        echo '<div>';
        echo "<input type=\"hidden\" name=\"quora\" value=\"{$quora->id}\" />";
        switch ($quora->type) {
            case 'news':
            case 'blog':
                $buttonadd = get_string('addanewtopic', 'quora');
                break;
            case 'qanda':
                $buttonadd = get_string('addanewquestion', 'quora');
                break;
            default:
                $buttonadd = get_string('addanewdiscussion', 'quora');
                break;
        }
        echo '<input type="submit" value="' . $buttonadd . '" />';
        echo '</div>';
        echo '</form>';
        echo "</div>\n";
    } else {
        if (isguestuser() or !isloggedin() or $quora->type == 'news' or $quora->type == 'qanda' and !has_capability('mod/quora:addquestion', $context) or $quora->type != 'qanda' and !has_capability('mod/quora:startdiscussion', $context)) {
            // no button and no info
        } else {
            if ($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', 'quora'));
                } else {
                    if (!groups_is_member($currentgroup)) {
                        echo $OUTPUT->notification(get_string('cannotadddiscussion', 'quora'));
                    }
                }
            }
        }
    }
    // Get all the recent discussions we're allowed to see
    $getuserlastmodified = $displayformat == 'header';
    if (!($discussions = quora_get_discussions($cm, $sort, $fullpost, null, $maxdiscussions, $getuserlastmodified, $page, $perpage))) {
        echo '<div class="quoranodiscuss">';
        if ($quora->type == 'news') {
            echo '(' . get_string('nonews', 'quora') . ')';
        } else {
            if ($quora->type == 'qanda') {
                echo '(' . get_string('noquestions', 'quora') . ')';
            } else {
                echo '(' . get_string('nodiscussions', 'quora') . ')';
            }
        }
        echo "</div>\n";
        return;
    }
    // If we want paging
    if ($page != -1) {
        ///Get the number of discussions found
        $numdiscussions = quora_get_discussions_count($cm);
        ///Show the paging bar
        echo $OUTPUT->paging_bar($numdiscussions, $page, $perpage, "view.php?f={$quora->id}");
        if ($numdiscussions > 1000) {
            // saves some memory on sites with very large quoras
            $replies = quora_count_discussion_replies($quora->id, $sort, $maxdiscussions, $page, $perpage);
        } else {
            $replies = quora_count_discussion_replies($quora->id);
        }
    } else {
        $replies = quora_count_discussion_replies($quora->id);
        if ($maxdiscussions > 0 and $maxdiscussions <= count($discussions)) {
            $olddiscussionlink = true;
        }
    }
    $canviewparticipants = has_capability('moodle/course:viewparticipants', $context);
    $strdatestring = get_string('strftimerecentfull');
    // Check if the quora is tracked.
    if ($cantrack = quora_tp_can_track_quoras($quora)) {
        $quoratracked = quora_tp_is_tracked($quora);
    } else {
        $quoratracked = false;
    }
    if ($quoratracked) {
        $unreads = quora_get_discussions_unread($cm);
    } else {
        $unreads = array();
    }
    if ($displayformat == 'header') {
        echo '<table cellspacing="0" class="forumheaderlist">';
        echo '<thead>';
        echo '<tr>';
        echo '<th class="header topic" scope="col">' . get_string('discussion', 'quora') . '</th>';
        echo '<th class="header author" colspan="2" scope="col">' . get_string('startedby', 'quora') . '</th>';
        if ($groupmode > 0) {
            echo '<th class="header group" scope="col">' . get_string('group') . '</th>';
        }
        if (has_capability('mod/quora:viewdiscussion', $context)) {
            echo '<th class="header replies" scope="col">' . get_string('replies', 'quora') . '</th>';
            // If the quora can be tracked, display the unread column.
            if ($cantrack) {
                echo '<th class="header replies" scope="col">' . get_string('unread', 'quora');
                if ($quoratracked) {
                    echo '<a title="' . get_string('markallread', 'quora') . '" href="' . $CFG->wwwroot . '/mod/quora/markposts.php?f=' . $quora->id . '&amp;mark=read&amp;returnpage=view.php">' . '<img src="' . $OUTPUT->pix_url('t/markasread') . '" class="iconsmall" alt="' . get_string('markallread', 'quora') . '" /></a>';
                }
                echo '</th>';
            }
        }
        echo '<th class="header lastpost" scope="col">' . get_string('lastpost', 'quora') . '</th>';
        if (!is_guest($context, $USER) && isloggedin() && has_capability('mod/quora:viewdiscussion', $context)) {
            if (\mod_quora\subscriptions::is_subscribable($quora)) {
                echo '<th class="header discussionsubscription" scope="col">';
                echo quora_get_discussion_subscription_icon_preloaders();
                echo '</th>';
            }
        }
        echo '</tr>';
        echo '</thead>';
        echo '<tbody>';
    }
    foreach ($discussions as $discussion) {
        if ($quora->type == 'qanda' && !has_capability('mod/quora:viewqandawithoutposting', $context) && !quora_user_has_posted($quora->id, $discussion->discussion, $USER->id)) {
            $canviewparticipants = false;
        }
        if (!empty($replies[$discussion->discussion])) {
            $discussion->replies = $replies[$discussion->discussion]->replies;
            $discussion->lastpostid = $replies[$discussion->discussion]->lastpostid;
        } else {
            $discussion->replies = 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 (!$quoratracked) {
            $discussion->unread = '-';
        } else {
            if (empty($USER)) {
                $discussion->unread = 0;
            } else {
                if (empty($unreads[$discussion->discussion])) {
                    $discussion->unread = 0;
                } else {
                    $discussion->unread = $unreads[$discussion->discussion];
                }
            }
        }
        if (isloggedin()) {
            $ownpost = $discussion->userid == $USER->id;
        } else {
            $ownpost = false;
        }
        // Use discussion name instead of subject of first post
        $discussion->subject = $discussion->name;
        switch ($displayformat) {
            case 'header':
                if ($groupmode > 0) {
                    if (isset($groups[$discussion->groupid])) {
                        $group = $groups[$discussion->groupid];
                    } else {
                        $group = $groups[$discussion->groupid] = groups_get_group($discussion->groupid);
                    }
                } else {
                    $group = -1;
                }
                quora_print_discussion_header($discussion, $quora, $group, $strdatestring, $cantrack, $quoratracked, $canviewparticipants, $context);
                break;
            default:
                $link = false;
                if ($discussion->replies) {
                    $link = true;
                } else {
                    $modcontext = context_module::instance($cm->id);
                    $link = quora_user_can_see_discussion($quora, $discussion, $modcontext, $USER);
                }
                $discussion->quora = $quora->id;
                quora_print_post($discussion, $discussion, $quora, $cm, $course, $ownpost, 0, $link, false, '', null, true, $quoratracked);
                break;
        }
    }
    if ($displayformat == "header") {
        echo '</tbody>';
        echo '</table>';
    }
    if ($olddiscussionlink) {
        if ($quora->type == 'news') {
            $strolder = get_string('oldertopics', 'quora');
        } else {
            $strolder = get_string('olderdiscussions', 'quora');
        }
        echo '<div class="quoraolddiscuss">';
        echo '<a href="' . $CFG->wwwroot . '/mod/quora/view.php?f=' . $quora->id . '&amp;showall=1">';
        echo $strolder . '</a> ...</div>';
    }
    if ($page != -1) {
        ///Show the paging bar
        echo $OUTPUT->paging_bar($numdiscussions, $page, $perpage, "view.php?f={$quora->id}");
    }
}
Пример #2
0
            }
        }
        if (!empty($quoramenu)) {
            echo '<div class="movediscussionoption">';
            $select = new url_select($quoramenu, '', array('' => get_string("movethisdiscussionto", "quora")), 'quoramenu', get_string('move'));
            echo $OUTPUT->render($select);
            echo "</div>";
        }
    }
    echo "</div>";
}
echo '<div class="clearfloat">&nbsp;</div>';
echo "</div>";
if (!empty($quora->blockafter) && !empty($quora->blockperiod)) {
    $a = new stdClass();
    $a->blockafter = $quora->blockafter;
    $a->blockperiod = get_string('secondstotime' . $quora->blockperiod);
    echo $OUTPUT->notification(get_string('thisquoraisthrottled', 'quora', $a));
}
if ($quora->type == 'qanda' && !has_capability('mod/quora:viewqandawithoutposting', $modcontext) && !quora_user_has_posted($quora->id, $discussion->id, $USER->id)) {
    echo $OUTPUT->notification(get_string('qandanotify', 'quora'));
}
if ($move == -1 and confirm_sesskey()) {
    echo $OUTPUT->notification(get_string('discussionmoved', 'quora', format_string($quora->name, true)));
}
$canrate = has_capability('mod/quora:rate', $modcontext);
quora_print_discussion($course, $cm, $quora, $discussion, $post, $displaymode, $canreply, $canrate, $is_assessed);
echo $neighbourlinks;
// Add the subscription toggle JS.
$PAGE->requires->yui_module('moodle-mod_quora-subscriptiontoggle', 'Y.M.mod_quora.subscriptiontoggle.init');
echo $OUTPUT->footer();