/** * Deletes a single quora 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 $quora Forum * @param bool $skipcompletion True to skip updating completion state if it * would otherwise be updated, i.e. when deleting entire quora anyway. * @return bool */ function quora_delete_post($post, $children, $course, $cm, $quora, $skipcompletion = false) { global $DB, $CFG; require_once $CFG->libdir . '/completionlib.php'; $context = context_module::instance($cm->id); if ($children !== 'ignore' && ($childposts = $DB->get_records('quora_posts', array('parent' => $post->id)))) { if ($children) { foreach ($childposts as $childpost) { quora_delete_post($childpost, true, $course, $cm, $quora, $skipcompletion); } } else { return false; } } // Delete ratings. require_once $CFG->dirroot . '/rating/lib.php'; $delopt = new stdClass(); $delopt->contextid = $context->id; $delopt->component = 'mod_quora'; $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_quora', 'attachment', $post->id); $fs->delete_area_files($context->id, 'mod_quora', 'post', $post->id); // Delete cached RSS feeds. if (!empty($CFG->enablerssfeeds)) { require_once $CFG->dirroot . '/mod/quora/rsslib.php'; quora_rss_delete_file($quora); } if ($DB->delete_records("quora_posts", array("id" => $post->id))) { quora_tp_delete_read_records(-1, $post->id); // Just in case we are deleting the last post quora_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 && ($quora->completiondiscussions || $quora->completionreplies || $quora->completionposts)) { $completion->update_state($cm, COMPLETION_INCOMPLETE, $post->userid); } } return true; } return false; }
\mod_quora\subscriptions::subscribe_user_to_discussion($userid, $newdiscussion, $destinationctx); } } else { \mod_quora\subscriptions::unsubscribe_user_from_discussion($userid, $newdiscussion, $destinationctx); } } $params = array('context' => $destinationctx, 'objectid' => $discussion->id, 'other' => array('fromquoraid' => $quora->id, 'toquoraid' => $quorato->id)); $event = \mod_quora\event\discussion_moved::create($params); $event->add_record_snapshot('quora_discussions', $discussion); $event->add_record_snapshot('quora', $quora); $event->add_record_snapshot('quora', $quorato); $event->trigger(); // Delete the RSS files for the 2 quoras to force regeneration of the feeds require_once $CFG->dirroot . '/mod/quora/rsslib.php'; quora_rss_delete_file($quora); quora_rss_delete_file($quorato); redirect($return . '&moved=-1&sesskey=' . sesskey()); } // Trigger discussion viewed event. quora_discussion_view($modcontext, $quora, $discussion); unset($SESSION->fromdiscussion); if ($mode) { set_user_preference('quora_displaymode', $mode); } $displaymode = get_user_preferences('quora_displaymode', $CFG->quora_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 {