Пример #1
0
$includetext = optional_param('includetext', false, PARAM_BOOL);
$twf = $DB->get_record('twf', array('id' => $twfid), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id' => $twf->course), '*', MUST_EXIST);
$discussion = $DB->get_record('twf_discussions', array('id' => $discussionid), '*', MUST_EXIST);
$cm = get_coursemodule_from_instance('twf', $twf->id, $course->id, false, MUST_EXIST);
$context = context_module::instance($cm->id);
require_sesskey();
require_login($course, false, $cm);
require_capability('mod/twf:viewdiscussion', $context);
$return = new stdClass();
if (is_guest($context, $USER)) {
    // is_guest should be used here as this also checks whether the user is a guest in the current course.
    // Guests and visitors cannot subscribe - only enrolled users.
    throw new moodle_exception('noguestsubscribe', 'mod_twf');
}
if (!\mod_twf\subscriptions::is_subscribable($twf)) {
    // Nothing to do. We won't actually output any content here though.
    echo json_encode($return);
    die;
}
if (\mod_twf\subscriptions::is_subscribed($USER->id, $twf, $discussion->id, $cm)) {
    // The user is subscribed, unsubscribe them.
    \mod_twf\subscriptions::unsubscribe_user_from_discussion($USER->id, $discussion, $context);
} else {
    // The user is unsubscribed, subscribe them.
    \mod_twf\subscriptions::subscribe_user_to_discussion($USER->id, $discussion, $context);
}
// Now return the updated subscription icon.
$return->icon = twf_get_discussion_subscription_icon($twf, $discussion->id, null, $includetext);
echo json_encode($return);
die;
Пример #2
0
if ($node && $post->id != $discussion->firstpost) {
    $node->add(format_string($post->subject), $PAGE->url);
}
$PAGE->set_title("{$course->shortname}: " . format_string($discussion->name));
$PAGE->set_heading($course->fullname);
$PAGE->set_button($searchform);
$renderer = $PAGE->get_renderer('mod_twf');
echo $OUTPUT->header();
echo $OUTPUT->heading(format_string($twf->name), 2);
echo $OUTPUT->heading(format_string($discussion->name), 3, 'discussionname');
// is_guest should be used here as this also checks whether the user is a guest in the current course.
// Guests and visitors cannot subscribe - only enrolled users.
if (!is_guest($modcontext, $USER) && isloggedin() && has_capability('mod/twf:viewdiscussion', $modcontext)) {
    // Discussion subscription.
    if (\mod_twf\subscriptions::is_subscribable($twf)) {
        echo html_writer::div(twf_get_discussion_subscription_icon($twf, $post->discussion, null, true), 'discussionsubscription');
        echo twf_get_discussion_subscription_icon_preloaders();
    }
}
/// Check to see if groups are being used in this twf
/// If so, make sure the current person is allowed to see this discussion
/// Also, if we know they should be able to reply, then explicitly set $canreply for performance reasons
$canreply = twf_user_can_post($twf, $discussion, $USER, $cm, $course, $modcontext);
if (!$canreply and $twf->type !== 'news') {
    if (isguestuser() or !isloggedin()) {
        $canreply = true;
    }
    if (!is_enrolled($modcontext) and !is_viewing($modcontext)) {
        // allow guests and not-logged-in to see the link - they are prompted to log in after clicking the link
        // normal users with temporary guest access see this link too, they are asked to enrol instead
        $canreply = enrol_selfenrol_available($course->id);
Пример #3
0
/**
 * This function prints the overview of a discussion in the twf listing.
 * It needs some discussion information and some post information, these
 * happen to be combined for efficiency in the $post parameter by the function
 * that calls this one: twf_print_latest_discussions()
 *
 * @global object
 * @global object
 * @param object $post The post object (passed by reference for speed).
 * @param object $twf The twf object.
 * @param int $group Current group.
 * @param string $datestring Format to use for the dates.
 * @param boolean $cantrack Is tracking enabled for this twf.
 * @param boolean $twftracked Is the user tracking this twf.
 * @param boolean $canviewparticipants True if user has the viewparticipants permission for this course
 */
function twf_print_discussion_header(&$post, $twf, $group = -1, $datestring = "", $cantrack = true, $twftracked = true, $canviewparticipants = true, $modcontext = NULL)
{
    global $COURSE, $USER, $CFG, $OUTPUT;
    static $rowcount;
    static $strmarkalldread;
    if (empty($modcontext)) {
        if (!($cm = get_coursemodule_from_instance('twf', $twf->id, $twf->course))) {
            print_error('invalidcoursemodule');
        }
        $modcontext = context_module::instance($cm->id);
    }
    if (!isset($rowcount)) {
        $rowcount = 0;
        $strmarkalldread = get_string('markalldread', 'twf');
    } else {
        $rowcount = ($rowcount + 1) % 2;
    }
    $post->subject = format_string($post->subject, true);
    echo "\n\n";
    echo '<tr class="discussion r' . $rowcount . '">';
    // Topic
    echo '<td class="topic starter">';
    echo '<a href="' . $CFG->wwwroot . '/mod/twf/discuss.php?d=' . $post->discussion . '">' . $post->subject . '</a>';
    echo "</td>\n";
    // Picture
    $postuser = new stdClass();
    $postuserfields = explode(',', user_picture::fields());
    $postuser = username_load_fields_from_object($postuser, $post, null, $postuserfields);
    $postuser->id = $post->userid;
    echo '<td class="picture">';
    echo $OUTPUT->user_picture($postuser, array('courseid' => $twf->course));
    echo "</td>\n";
    // User name
    $fullname = fullname($postuser, has_capability('moodle/site:viewfullnames', $modcontext));
    echo '<td class="author">';
    echo '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $post->userid . '&amp;course=' . $twf->course . '">' . $fullname . '</a>';
    echo "</td>\n";
    // Group picture
    if ($group !== -1) {
        // Groups are active - group is a group data object or NULL
        echo '<td class="picture group">';
        if (!empty($group->picture) and empty($group->hidepicture)) {
            if ($canviewparticipants && $COURSE->groupmode) {
                $picturelink = true;
            } else {
                $picturelink = false;
            }
            print_group_picture($group, $twf->course, false, false, $picturelink);
        } else {
            if (isset($group->id)) {
                if ($canviewparticipants && $COURSE->groupmode) {
                    echo '<a href="' . $CFG->wwwroot . '/user/index.php?id=' . $twf->course . '&amp;group=' . $group->id . '">' . $group->name . '</a>';
                } else {
                    echo $group->name;
                }
            }
        }
        echo "</td>\n";
    }
    if (has_capability('mod/twf:viewdiscussion', $modcontext)) {
        // Show the column with replies
        echo '<td class="replies">';
        echo '<a href="' . $CFG->wwwroot . '/mod/twf/discuss.php?d=' . $post->discussion . '">';
        echo $post->replies . '</a>';
        echo "</td>\n";
        if ($cantrack) {
            echo '<td class="replies">';
            if ($twftracked) {
                if ($post->unread > 0) {
                    echo '<span class="unread">';
                    echo '<a href="' . $CFG->wwwroot . '/mod/twf/discuss.php?d=' . $post->discussion . '#unread">';
                    echo $post->unread;
                    echo '</a>';
                    echo '<a title="' . $strmarkalldread . '" href="' . $CFG->wwwroot . '/mod/twf/markposts.php?f=' . $twf->id . '&amp;d=' . $post->discussion . '&amp;mark=read&amp;returnpage=view.php">' . '<img src="' . $OUTPUT->pix_url('t/markasread') . '" class="iconsmall" alt="' . $strmarkalldread . '" /></a>';
                    echo '</span>';
                } else {
                    echo '<span class="read">';
                    echo $post->unread;
                    echo '</span>';
                }
            } else {
                echo '<span class="read">';
                echo '-';
                echo '</span>';
            }
            echo "</td>\n";
        }
    }
    echo '<td class="lastpost">';
    $usedate = empty($post->timemodified) ? $post->modified : $post->timemodified;
    // Just in case
    $parenturl = '';
    $usermodified = new stdClass();
    $usermodified->id = $post->usermodified;
    $usermodified = username_load_fields_from_object($usermodified, $post, 'um');
    // In QA twfs we check that the user can view participants.
    if ($twf->type !== 'qanda' || $canviewparticipants) {
        echo '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $post->usermodified . '&amp;course=' . $twf->course . '">' . fullname($usermodified) . '</a><br />';
        $parenturl = empty($post->lastpostid) ? '' : '&amp;parent=' . $post->lastpostid;
    }
    echo '<a href="' . $CFG->wwwroot . '/mod/twf/discuss.php?d=' . $post->discussion . $parenturl . '">' . userdate($usedate, $datestring) . '</a>';
    echo "</td>\n";
    // is_guest should be used here as this also checks whether the user is a guest in the current course.
    // Guests and visitors cannot subscribe - only enrolled users.
    if (!is_guest($modcontext, $USER) && isloggedin() && has_capability('mod/twf:viewdiscussion', $modcontext)) {
        // Discussion subscription.
        if (\mod_twf\subscriptions::is_subscribable($twf)) {
            echo '<td class="discussionsubscription">';
            echo twf_get_discussion_subscription_icon($twf, $post->discussion);
            echo '</td>';
        }
    }
    echo "</tr>\n\n";
}