-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathdeleteepisode.php
More file actions
155 lines (133 loc) · 5.61 KB
/
Copy pathdeleteepisode.php
File metadata and controls
155 lines (133 loc) · 5.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Page for deleting pcast episodes
*
* @package mod_pcast
* @copyright 2010 Stephen Bourget
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(dirname(__FILE__) . '/../../config.php');
require_once(dirname(__FILE__) . '/lib.php');
$id = required_param('id', PARAM_INT); // Course module ID.
$confirm = optional_param('confirm', 0, PARAM_INT); // Commit the operation?
$episode = optional_param('episode', 0, PARAM_INT); // Episode id.
$prevmode = required_param('prevmode', PARAM_ALPHANUM); // Display mode.
$hook = optional_param('hook', '', PARAM_ALPHANUM); // Alphabet bar filter.
$url = new moodle_url('/mod/pcast/deleteepisode.php', ['id' => $id, 'prevmode' => $prevmode]);
if ($confirm !== 0) {
$url->param('confirm', $confirm);
}
if ($episode !== 0) {
$url->param('episode', $episode);
}
if ($hook !== '') {
$url->param('hook', $hook);
} else {
$hook = 'ALL';
}
$strpcast = get_string("modulename", "pcast");
$strglossaries = get_string("modulenameplural", "pcast");
$stredit = get_string("edit");
$episodedeleted = get_string("episodedeleted", "pcast");
if ($id) {
$cm = get_coursemodule_from_id('pcast', $id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', ['id' => $cm->course], '*', MUST_EXIST);
$episode = $DB->get_record('pcast_episodes', ['id' => $episode], '*', MUST_EXIST);
$pcast = $DB->get_record('pcast', ['id' => $cm->instance], '*', MUST_EXIST);
} else {
throw new moodle_exception('invalidcmorid', 'pcast');
}
require_login($course->id, false, $cm);
$PAGE->set_url($url);
$context = context_module::instance($cm->id);
$PAGE->set_context($context);
$manageentries = has_capability('mod/pcast:manage', $context);
if (($episode->userid != $USER->id) && !$manageentries) { // Guest id is never matched, no need for special check here.
throw new moodle_exception('nopermissiontodelepisode', 'pcast');
}
$ineditperiod = ((time() - $episode->timecreated < $CFG->maxeditingtime));
if (!$ineditperiod && !$manageentries) {
throw new moodle_exception('errdeltimeexpired', 'pcast');
}
// If data is submitted, then process and store.
if ($confirm && confirm_sesskey()) {
// The operation was confirmed.
$origionalepisode = fullclone($episode);
$fs = get_file_storage();
$fs->delete_area_files($context->id, 'pcast_episode', $episode->id);
$DB->delete_records("comments", ['itemid' => $episode->id, 'commentarea' => 'pcast_episode', 'contextid' => $context->id]);
$DB->delete_records("pcast_episodes", ["id" => $episode->id]);
// Delete pcast episode ratings.
require_once($CFG->dirroot . '/rating/lib.php');
$delopt = new stdClass();
$delopt->contextid = $context->id;
$delopt->itemid = $episode->id;
$delopt->component = 'mod_pcast';
$delopt->ratingarea = 'episode';
$rm = new rating_manager();
$rm->delete_ratings($delopt);
// Delete cached RSS feeds.
if (!empty($CFG->enablerssfeeds)) {
require_once($CFG->dirroot . '/mod/pcast/rsslib.php');
pcast_rss_delete_file($pcast);
}
// Remove tags.
core_tag_tag::remove_all_item_tags('mod_pcast', 'pcast_episodes', $origionalepisode->id);
$event = \mod_pcast\event\episode_deleted::create(
[
'context' => $context,
'objectid' => $origionalepisode->id,
'other' => [
'mode' => $prevmode,
'hook' => $hook,
'name' => $origionalepisode->name,
],
]
);
$event->add_record_snapshot('pcast_episodes', $origionalepisode);
$event->trigger();
// Update completion state.
$completion = new completion_info($course);
if ($completion->is_enabled($cm) == COMPLETION_TRACKING_AUTOMATIC && $pcast->completionepisodes) {
$completion->update_state($cm, COMPLETION_COMPLETE, $episode->userid);
}
redirect("view.php?id=$cm->id&mode=$prevmode&hook=$hook");
} else {
// The operation has not been confirmed yet so ask the user to do so.
$PAGE->navbar->add(get_string('delete'));
$PAGE->set_title($pcast->name);
$PAGE->set_heading($course->fullname);
echo $OUTPUT->header();
$areyousure = html_writer::start_tag('div', ['class' => 'pcast-bold']);
$areyousure .= format_string($episode->name);
$areyousure .= html_writer::end_tag('div');
$areyousure .= html_writer::start_tag('div');
$areyousure .= get_string("areyousuredelete", "pcast");
$areyousure .= html_writer::end_tag('div');
$linkyes = 'deleteepisode.php';
$linkno = 'view.php';
$optionsyes = ['id' => $cm->id,
'episode' => $episode->id,
'confirm' => 1,
'sesskey' => sesskey(),
'prevmode' => $prevmode,
'hook' => $hook,
];
$optionsno = ['id' => $cm->id, 'mode' => $prevmode, 'hook' => $hook];
echo $OUTPUT->confirm($areyousure, new moodle_url($linkyes, $optionsyes), new moodle_url($linkno, $optionsno));
echo $OUTPUT->footer();
}