Ejemplo n.º 1
0
                \mod_twf\subscriptions::subscribe_user_to_discussion($userid, $newdiscussion, $destinationctx);
            }
        } else {
            \mod_twf\subscriptions::unsubscribe_user_from_discussion($userid, $newdiscussion, $destinationctx);
        }
    }
    $params = array('context' => $destinationctx, 'objectid' => $discussion->id, 'other' => array('fromtwfid' => $twf->id, 'totwfid' => $twfto->id));
    $event = \mod_twf\event\discussion_moved::create($params);
    $event->add_record_snapshot('twf_discussions', $discussion);
    $event->add_record_snapshot('twf', $twf);
    $event->add_record_snapshot('twf', $twfto);
    $event->trigger();
    // Delete the RSS files for the 2 twfs to force regeneration of the feeds
    require_once $CFG->dirroot . '/mod/twf/rsslib.php';
    twf_rss_delete_file($twf);
    twf_rss_delete_file($twfto);
    redirect($return . '&moved=-1&sesskey=' . sesskey());
}
// Trigger discussion viewed event.
twf_discussion_view($modcontext, $twf, $discussion);
unset($SESSION->fromdiscussion);
if ($mode) {
    set_user_preference('twf_displaymode', $mode);
}
$displaymode = get_user_preferences('twf_displaymode', $CFG->twf_displaymode);
if ($parent) {
    // If flat AND parent, then force nested display this time
    if ($displaymode == FORUM_MODE_FLATOLDEST or $displaymode == FORUM_MODE_FLATNEWEST) {
        $displaymode = FORUM_MODE_NESTED;
    }
} else {
Ejemplo n.º 2
0
/**
 * Deletes a single twf 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 $twf Forum
 * @param bool $skipcompletion True to skip updating completion state if it
 *   would otherwise be updated, i.e. when deleting entire twf anyway.
 * @return bool
 */
function twf_delete_post($post, $children, $course, $cm, $twf, $skipcompletion = false)
{
    global $DB, $CFG;
    require_once $CFG->libdir . '/completionlib.php';
    $context = context_module::instance($cm->id);
    if ($children !== 'ignore' && ($childposts = $DB->get_records('twf_posts', array('parent' => $post->id)))) {
        if ($children) {
            foreach ($childposts as $childpost) {
                twf_delete_post($childpost, true, $course, $cm, $twf, $skipcompletion);
            }
        } else {
            return false;
        }
    }
    // Delete ratings.
    require_once $CFG->dirroot . '/rating/lib.php';
    $delopt = new stdClass();
    $delopt->contextid = $context->id;
    $delopt->component = 'mod_twf';
    $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_twf', 'attachment', $post->id);
    $fs->delete_area_files($context->id, 'mod_twf', 'post', $post->id);
    // Delete cached RSS feeds.
    if (!empty($CFG->enablerssfeeds)) {
        require_once $CFG->dirroot . '/mod/twf/rsslib.php';
        twf_rss_delete_file($twf);
    }
    if ($DB->delete_records("twf_posts", array("id" => $post->id))) {
        twf_tp_delete_read_records(-1, $post->id);
        // Just in case we are deleting the last post
        twf_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 && ($twf->completiondiscussions || $twf->completionreplies || $twf->completionposts)) {
                $completion->update_state($cm, COMPLETION_INCOMPLETE, $post->userid);
            }
        }
        return true;
    }
    return false;
}