예제 #1
0
파일: lib.php 프로젝트: Jtgadbois/Pedadida
/**
 * Deletes a single forum post.
 *
 * @global object
 * @param object $post Forum post object
 * @param mixed $children Whether to delete children. If false, returns false
 *   if there are any children (without deleting the post). If true,
 *   recursively deletes all children. If set to special value 'ignore', deletes
 *   post regardless of children (this is for use only when deleting all posts
 *   in a disussion).
 * @param object $course Course
 * @param object $cm Course-module
 * @param object $forum Forum
 * @param bool $skipcompletion True to skip updating completion state if it
 *   would otherwise be updated, i.e. when deleting entire forum anyway.
 * @return bool
 */
function forum_delete_post($post, $children, $course, $cm, $forum, $skipcompletion=false) {
    global $DB, $CFG;
    require_once($CFG->libdir.'/completionlib.php');

    $context = context_module::instance($cm->id);

    if ($children !== 'ignore' && ($childposts = $DB->get_records('forum_posts', array('parent'=>$post->id)))) {
       if ($children) {
           foreach ($childposts as $childpost) {
               forum_delete_post($childpost, true, $course, $cm, $forum, $skipcompletion);
           }
       } else {
           return false;
       }
    }

    //delete ratings
    require_once($CFG->dirroot.'/rating/lib.php');
    $delopt = new stdClass;
    $delopt->contextid = $context->id;
    $delopt->component = 'mod_forum';
    $delopt->ratingarea = 'post';
    $delopt->itemid = $post->id;
    $rm = new rating_manager();
    $rm->delete_ratings($delopt);

    //delete attachments
    $fs = get_file_storage();
    $fs->delete_area_files($context->id, 'mod_forum', 'attachment', $post->id);
    $fs->delete_area_files($context->id, 'mod_forum', 'post', $post->id);

    if ($DB->delete_records("forum_posts", array("id" => $post->id))) {

        forum_tp_delete_read_records(-1, $post->id);

    // Just in case we are deleting the last post
        forum_discussion_update_last_post($post->discussion);

        // Update completion state if we are tracking completion based on number of posts
        // But don't bother when deleting whole thing

        if (!$skipcompletion) {
            $completion = new completion_info($course);
            if ($completion->is_enabled($cm) == COMPLETION_TRACKING_AUTOMATIC &&
               ($forum->completiondiscussions || $forum->completionreplies || $forum->completionposts)) {
                $completion->update_state($cm, COMPLETION_INCOMPLETE, $post->userid);
            }
        }

        return true;
    }
    return false;
}
예제 #2
0
    /**
     * Function to create a dummy post.
     *
     * @param array|stdClass $record
     * @return stdClass the post object
     */
    public function create_forum_post($record = null) {
        global $DB;

        // Increment the forum post count.
        $this->forumpostcount++;

        // Variable to store time.
        $time = time() + $this->forumpostcount;

        $record = (array) $record;

        if (!isset($record['discussion'])) {
            throw new coding_exception('discussion must be present in phpunit_util::create_forum_post() $record');
        }

        if (!isset($record['userid'])) {
            throw new coding_exception('userid must be present in phpunit_util::create_forum_post() $record');
        }

        if (!isset($record['parent'])) {
            $record['parent'] = 0;
        }

        if (!isset($record['subject'])) {
            $record['subject'] = 'Forum post subject ' . $this->forumpostcount;
        }

        if (!isset($record['message'])) {
            $record['message'] = html_writer::tag('p', 'Forum message post ' . $this->forumpostcount);
        }

        if (!isset($record['created'])) {
            $record['created'] = $time;
        }

        if (!isset($record['modified'])) {
            $record['modified'] = $time;
        }

        $record = (object) $record;

        // Add the post.
        $record->id = $DB->insert_record('forum_posts', $record);

        // Update the last post.
        forum_discussion_update_last_post($record->discussion);

        return $record;
    }
예제 #3
0
파일: post.php 프로젝트: njorth/marginalia
     $newdiscussion->userid = $discussion->userid;
     $newdiscussion->groupid = $discussion->groupid;
     $newdiscussion->assessed = $discussion->assessed;
     $newdiscussion->usermodified = $post->userid;
     $newdiscussion->timestart = $discussion->timestart;
     $newdiscussion->timeend = $discussion->timeend;
     $newid = $DB->insert_record('forum_discussions', $newdiscussion);
     $newpost = new stdClass();
     $newpost->id = $post->id;
     $newpost->parent = 0;
     $newpost->subject = $name;
     $DB->update_record("forum_posts", $newpost);
     forum_change_discussionid($post->id, $newid);
     // update last post in each discussion
     forum_discussion_update_last_post($discussion->id);
     forum_discussion_update_last_post($newid);
     add_to_log($discussion->course, "forum", "prune post", "discuss.php?d={$newid}", "{$post->id}", $cm->id);
     redirect(forum_go_back_to("discuss.php?d={$newid}"));
 } else {
     // User just asked to prune something
     $course = $DB->get_record('course', array('id' => $forum->course));
     $PAGE->set_cm($cm);
     $PAGE->set_context($modcontext);
     $PAGE->navbar->add(format_string($post->subject, true), new moodle_url('/mod/forum/discuss.php', array('d' => $discussion->id)));
     $PAGE->navbar->add(get_string("prune", "forum"));
     $PAGE->set_title(format_string($discussion->name) . ": " . format_string($post->subject));
     $PAGE->set_heading($course->fullname);
     echo $OUTPUT->header();
     echo $OUTPUT->heading(get_string('pruneheading', 'forum'));
     echo '<center>';
     include 'prune.html';
예제 #4
0
파일: lib.php 프로젝트: rezaies/moodle
/**
 * Deletes a single forum post.
 *
 * @global object
 * @param object $post Forum post object
 * @param mixed $children Whether to delete children. If false, returns false
 *   if there are any children (without deleting the post). If true,
 *   recursively deletes all children. If set to special value 'ignore', deletes
 *   post regardless of children (this is for use only when deleting all posts
 *   in a disussion).
 * @param object $course Course
 * @param object $cm Course-module
 * @param object $forum Forum
 * @param bool $skipcompletion True to skip updating completion state if it
 *   would otherwise be updated, i.e. when deleting entire forum anyway.
 * @return bool
 */
function forum_delete_post($post, $children, $course, $cm, $forum, $skipcompletion = false)
{
    global $DB, $CFG, $USER;
    require_once $CFG->libdir . '/completionlib.php';
    $context = context_module::instance($cm->id);
    if ($children !== 'ignore' && ($childposts = $DB->get_records('forum_posts', array('parent' => $post->id)))) {
        if ($children) {
            foreach ($childposts as $childpost) {
                forum_delete_post($childpost, true, $course, $cm, $forum, $skipcompletion);
            }
        } else {
            return false;
        }
    }
    // Delete ratings.
    require_once $CFG->dirroot . '/rating/lib.php';
    $delopt = new stdClass();
    $delopt->contextid = $context->id;
    $delopt->component = 'mod_forum';
    $delopt->ratingarea = 'post';
    $delopt->itemid = $post->id;
    $rm = new rating_manager();
    $rm->delete_ratings($delopt);
    // Delete attachments.
    $fs = get_file_storage();
    $fs->delete_area_files($context->id, 'mod_forum', 'attachment', $post->id);
    $fs->delete_area_files($context->id, 'mod_forum', 'post', $post->id);
    // Delete cached RSS feeds.
    if (!empty($CFG->enablerssfeeds)) {
        require_once $CFG->dirroot . '/mod/forum/rsslib.php';
        forum_rss_delete_file($forum);
    }
    if ($DB->delete_records("forum_posts", array("id" => $post->id))) {
        forum_tp_delete_read_records(-1, $post->id);
        // Just in case we are deleting the last post
        forum_discussion_update_last_post($post->discussion);
        // Update completion state if we are tracking completion based on number of posts
        // But don't bother when deleting whole thing
        if (!$skipcompletion) {
            $completion = new completion_info($course);
            if ($completion->is_enabled($cm) == COMPLETION_TRACKING_AUTOMATIC && ($forum->completiondiscussions || $forum->completionreplies || $forum->completionposts)) {
                $completion->update_state($cm, COMPLETION_INCOMPLETE, $post->userid);
            }
        }
        $params = array('context' => $context, 'objectid' => $post->id, 'other' => array('discussionid' => $post->discussion, 'forumid' => $forum->id, 'forumtype' => $forum->type));
        if ($post->userid !== $USER->id) {
            $params['relateduserid'] = $post->userid;
        }
        $event = \mod_forum\event\post_deleted::create($params);
        $event->add_record_snapshot('forum_posts', $post);
        $event->trigger();
        return true;
    }
    return false;
}
예제 #5
0
파일: lib.php 프로젝트: r007/PMoodle
/**
 *
 */
function forum_delete_post($post, $children = false)
{
    if ($childposts = get_records('forum_posts', 'parent', $post->id)) {
        if ($children) {
            foreach ($childposts as $childpost) {
                forum_delete_post($childpost, true);
            }
        } else {
            return false;
        }
    }
    if (delete_records("forum_posts", "id", $post->id)) {
        delete_records("forum_ratings", "post", $post->id);
        // Just in case
        forum_tp_delete_read_records(-1, $post->id);
        if ($post->attachment) {
            $discussion = get_record("forum_discussions", "id", $post->discussion);
            $post->course = $discussion->course;
            $post->forum = $discussion->forum;
            forum_delete_old_attachments($post);
        }
        // Just in case we are deleting the last post
        forum_discussion_update_last_post($post->discussion);
        return true;
    }
    return false;
}
예제 #6
0
/**
 * Deletes a single forum post.
 * @param object $post Forum post object
 * @param mixed $children Whether to delete children. If false, returns false
 *   if there are any children (without deleting the post). If true,
 *   recursively deletes all children. If set to special value 'ignore', deletes
 *   post regardless of children (this is for use only when deleting all posts
 *   in a disussion).
 * @param object $course Course
 * @param object $cm Course-module
 * @param object $forum Forum
 * @param bool $skipcompletion True to skip updating completion state if it
 *   would otherwise be updated, i.e. when deleting entire forum anyway.
 */
function forum_delete_post($post, $children, $course, $cm, $forum, $skipcompletion = false)
{
    global $DB;
    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
    if ($children != 'ignore' && ($childposts = $DB->get_records('forum_posts', array('parent' => $post->id)))) {
        if ($children) {
            foreach ($childposts as $childpost) {
                forum_delete_post($childpost, true, $course, $cm, $forum, $skipcompletion);
            }
        } else {
            return false;
        }
    }
    //delete ratings
    $DB->delete_records("forum_ratings", array("post" => $post->id));
    //delete attachments
    $fs = get_file_storage();
    $fs->delete_area_files($context->id, 'forum_attachment', $post->id);
    if ($DB->delete_records("forum_posts", array("id" => $post->id))) {
        forum_tp_delete_read_records(-1, $post->id);
        // Just in case we are deleting the last post
        forum_discussion_update_last_post($post->discussion);
        // Update completion state if we are tracking completion based on number of posts
        // But don't bother when deleting whole thing
        if (!$skipcompletion) {
            $completion = new completion_info($course);
            if ($completion->is_enabled($cm) == COMPLETION_TRACKING_AUTOMATIC && ($forum->completiondiscussions || $forum->completionreplies || $forum->completionposts)) {
                $completion->update_state($cm, COMPLETION_INCOMPLETE, $post->userid);
            }
        }
        return true;
    }
    return false;
}