forked from drachels/moodle-mod_mootyper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherem.php
executable file
·92 lines (81 loc) · 3.32 KB
/
erem.php
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
<?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/>.
/**
* This file is used to remove exercises and lessons.
*
* Called from exercises.php when clicking on Remove all from 'xxxx' or
* one of the remove icon/link for an individual exercise.
*
* @package mod_mootyper
* @copyright 2011 Jaka Luthar ([email protected])
* @copyright 2016 onwards AL Rachels ([email protected]
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
use \mod_mootyper\event\exercise_deleted;
use \mod_mootyper\event\lesson_deleted;
// Changed to this newer format 20190301.
require(__DIR__ . '/../../config.php');
global $DB;
$id = optional_param('id', 0, PARAM_INT); // Course_module ID.
if (! $cm = get_coursemodule_from_id('mootyper', $id)) {
print_error("Course Module ID was incorrect");
}
if (! $course = $DB->get_record("course", array('id' => $cm->course))) {
print_error("Course is misconfigured");
}
require_login($course, true, $cm);
$context = context_module::instance($cm->id);
// If r is set we remove an exercise.
// if l is set we remove a lesson and all its exercises.
$exerciseid = optional_param('r', '', PARAM_TEXT);
$lessonid = optional_param('l', '', PARAM_TEXT);
// Added cmid so can exit back to MooTyper activity we came from.
$cmid = optional_param('cmid', '0', PARAM_INT); // Course Module ID.
if ($exerciseid) {
$lessonpo = optional_param('lesson', '', PARAM_INT);
$DB->delete_records('mootyper_exercises', array('id' => $exerciseid));
// Trigger module exercise_deleted event.
$params = array(
'objectid' => $course->id,
'context' => $context,
'other' => array(
'lesson' => $lessonpo,
'exercise' => $exerciseid
)
);
$event = exercise_deleted::create($params);
$event->trigger();
} else if ($lessonid) {
$DB->delete_records('mootyper_exercises', array('lesson' => $lessonid));
$DB->delete_records('mootyper_lessons', array('id' => $lessonid));
$lessonpo = 0;
// Trigger module lesson_deleted event.
$params = array(
'objectid' => $course->id,
'context' => $context,
'other' => $lessonid
);
$event = lesson_deleted::create($params);
$event->trigger();
}
// 20200224 $cid not needed after changes to id. Delete after more testing. Out of sequence
// lesson delete seems to have made follow on exercise appear as part of wrong lesson!
// Lesson contained three exercises. I deleted number 2, and then number 3 appeared as part
// of another lesson, lesson aaaa(121).
// Later - seems to work okay now.
$cid = optional_param('id', 0, PARAM_INT);
$webdir = $CFG->wwwroot . '/mod/mootyper/exercises.php?id='.$id.'&lesson='.$lessonpo;
header('Location: '.$webdir);