$timepassed = time() - $post->created; if ($timepassed > $CFG->maxeditingtime && !has_capability('mod/twf:deleteanypost', $modcontext)) { print_error("cannotdeletepost", "twf", twf_go_back_to("discuss.php?d={$post->discussion}")); } if ($post->totalscore) { notice(get_string('couldnotdeleteratings', 'rating'), twf_go_back_to("discuss.php?d={$post->discussion}")); } else { if ($replycount && !has_capability('mod/twf:deleteanypost', $modcontext)) { print_error("couldnotdeletereplies", "twf", twf_go_back_to("discuss.php?d={$post->discussion}")); } else { if (!$post->parent) { // post is a discussion topic as well, so delete discussion if ($twf->type == 'single') { notice("Sorry, but you are not allowed to delete that discussion!", twf_go_back_to("discuss.php?d={$post->discussion}")); } twf_delete_discussion($discussion, false, $course, $cm, $twf); $params = array('objectid' => $discussion->id, 'context' => $modcontext, 'other' => array('twfid' => $twf->id)); $event = \mod_twf\event\discussion_deleted::create($params); $event->add_record_snapshot('twf_discussions', $discussion); $event->trigger(); redirect("view.php?f={$discussion->twf}"); } else { if (twf_delete_post($post, has_capability('mod/twf:deleteanypost', $modcontext), $course, $cm, $twf)) { if ($twf->type == 'single') { // Single discussion twfs are an exception. We show // the twf itself since it only has one discussion // thread. $discussionurl = "view.php?f={$twf->id}"; } else { $discussionurl = "discuss.php?d={$post->discussion}"; }
/** * Given an ID of an instance of this module, * this function will permanently delete the instance * and any data that depends on it. * * @global object * @param int $id twf instance id * @return bool success */ function twf_delete_instance($id) { global $DB; if (!($twf = $DB->get_record('twf', array('id' => $id)))) { return false; } if (!($cm = get_coursemodule_from_instance('twf', $twf->id))) { return false; } if (!($course = $DB->get_record('course', array('id' => $cm->course)))) { return false; } $context = context_module::instance($cm->id); // now get rid of all files $fs = get_file_storage(); $fs->delete_area_files($context->id); $result = true; // Delete digest and subscription preferences. $DB->delete_records('twf_digests', array('twf' => $twf->id)); $DB->delete_records('twf_subscriptions', array('twf' => $twf->id)); $DB->delete_records('twf_discussion_subs', array('twf' => $twf->id)); if ($discussions = $DB->get_records('twf_discussions', array('twf' => $twf->id))) { foreach ($discussions as $discussion) { if (!twf_delete_discussion($discussion, true, $course, $cm, $twf)) { $result = false; } } } twf_tp_delete_read_records(-1, -1, -1, $twf->id); if (!$DB->delete_records('twf', array('id' => $twf->id))) { $result = false; } twf_grade_item_delete($twf); return $result; }