예제 #1
0
        }
        if ($cansub && $cm->visible == 0 && !has_capability('mod/hsuforum:managesubscriptions', $modcontext)) {
            $cansub = false;
        }
        if (!hsuforum_is_forcesubscribed($forum)) {
            $subscribed = hsuforum_is_subscribed($USER->id, $forum);
            if ((has_capability('moodle/course:manageactivities', $coursecontext, $USER->id) || $forum->forcesubscribe != HSUFORUM_DISALLOWSUBSCRIBE) && $subscribe && !$subscribed && $cansub) {
                hsuforum_subscribe($USER->id, $forumid, $modcontext);
            } else {
                if (!$subscribe && $subscribed) {
                    hsuforum_unsubscribe($USER->id, $forumid, $modcontext);
                }
            }
        }
    }
    $returnto = hsuforum_go_back_to("index.php?id={$course->id}");
    $shortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id)));
    if ($subscribe) {
        redirect($returnto, get_string('nowallsubscribed', 'hsuforum', $shortname), 1);
    } else {
        redirect($returnto, get_string('nowallunsubscribed', 'hsuforum', $shortname), 1);
    }
}
/// First, let's process the general forums and build up a display
if ($generalforums) {
    foreach ($generalforums as $forum) {
        $cm = $modinfo->instances['hsuforum'][$forum->id];
        $context = context_module::instance($cm->id);
        $count = hsuforum_count_discussions($forum, $cm, $course);
        if ($unread = hsuforum_count_forum_unread_posts($cm, $course)) {
            $unreadlink = '<span class="unread"><a href="view.php?f=' . $forum->id . '">' . $unread . '</a>';
예제 #2
0
                if ($fromform->mailnow) {
                    $message .= get_string("postmailnow", "hsuforum");
                    $timemessage = 4;
                } else {
                    $message .= '<p>' . get_string("postaddedsuccess", "hsuforum") . '</p>';
                    $message .= '<p>' . get_string("postaddedtimeleft", "hsuforum", format_time($CFG->maxeditingtime)) . '</p>';
                }
                if ($subscribemessage = hsuforum_post_subscription($discussion, $forum)) {
                    $timemessage = 6;
                }
                // Update completion status
                $completion = new completion_info($course);
                if ($completion->is_enabled($cm) && ($forum->completiondiscussions || $forum->completionposts)) {
                    $completion->update_state($cm, COMPLETION_COMPLETE);
                }
                redirect(hsuforum_go_back_to("view.php?f={$fromform->forum}"), $message . $subscribemessage, $timemessage);
            } else {
                print_error("couldnotadd", "hsuforum", $errordestination);
            }
            exit;
        }
    }
}
// To get here they need to edit a post, and the $post
// variable will be loaded with all the particulars,
// so bring up the form.
// $course, $forum are defined.  $discussion is for edit and reply only.
if ($post->discussion) {
    if (!($toppost = $DB->get_record("hsuforum_posts", array("discussion" => $post->discussion, "parent" => 0)))) {
        print_error('cannotfindparentpost', 'hsuforum', '', $post->id);
    }
예제 #3
0
/**
 * Verify and delete the post.  The post can be a discussion post.
 *
 * @param object $course
 * @param object $cm
 * @param object $forum
 * @param context_module $modcontext
 * @param object $discussion
 * @param object $post
 * @return string The URL to redirect to
 */
function hsuforum_verify_and_delete_post($course, $cm, $forum, $modcontext, $discussion, $post)
{
    global $CFG, $USER;
    // Check user capability to delete post.
    $timepassed = time() - $post->created;
    if ($timepassed > $CFG->maxeditingtime && !has_capability('mod/hsuforum:deleteanypost', $modcontext)) {
        print_error("cannotdeletepost", "hsuforum", hsuforum_go_back_to("discuss.php?d={$post->discussion}"));
    }
    if ($post->totalscore) {
        print_error('couldnotdeleteratings', 'rating', hsuforum_go_back_to("discuss.php?d={$post->discussion}"));
    }
    if (hsuforum_count_replies($post) && !has_capability('mod/hsuforum:deleteanypost', $modcontext)) {
        print_error("couldnotdeletereplies", "hsuforum", hsuforum_go_back_to("discuss.php?d={$post->discussion}"));
    }
    if (!$post->parent) {
        // post is a discussion topic as well, so delete discussion
        if ($forum->type == 'single') {
            print_error('cannnotdeletesinglediscussion', 'hsuforum', hsuforum_go_back_to("discuss.php?d={$post->discussion}"));
        }
        hsuforum_delete_discussion($discussion, false, $course, $cm, $forum);
        $params = array('objectid' => $discussion->id, 'context' => $modcontext, 'other' => array('forumid' => $forum->id));
        $event = \mod_hsuforum\event\discussion_deleted::create($params);
        $event->add_record_snapshot('hsuforum_discussions', $discussion);
        $event->trigger();
        return $CFG->wwwroot . "/mod/hsuforum/view.php?id={$cm->id}";
    }
    if (!hsuforum_delete_post($post, has_capability('mod/hsuforum:deleteanypost', $modcontext), $course, $cm, $forum)) {
        print_error('errorwhiledelete', 'hsuforum');
    }
    if ($forum->type == 'single') {
        // Single discussion forums are an exception. We show
        // the forum itself since it only has one discussion
        // thread.
        $discussionurl = "view.php?f={$forum->id}";
    } else {
        $discussionurl = "discuss.php?d={$post->discussion}";
    }
    $params = array('context' => $modcontext, 'objectid' => $post->id, 'other' => array('discussionid' => $discussion->id, 'forumid' => $forum->id, 'forumtype' => $forum->type));
    if ($post->userid !== $USER->id) {
        $params['relateduserid'] = $post->userid;
    }
    $event = \mod_hsuforum\event\post_deleted::create($params);
    $event->add_record_snapshot('hsuforum_posts', $post);
    $event->add_record_snapshot('hsuforum_discussions', $discussion);
    $event->trigger();
    return hsuforum_go_back_to($discussionurl);
}