forked from richardjonesnz/moodle-mod_simplelesson
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautosequence.php
More file actions
executable file
·55 lines (45 loc) · 2.14 KB
/
Copy pathautosequence.php
File metadata and controls
executable file
·55 lines (45 loc) · 2.14 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
<?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/>.
/**
* Puts page sequence numbers in logical order according to placement on page management screen.
*
* @package mod_simplelesson
* @copyright 2018 Richard Jones https://richardnz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use mod_simplelesson\local\lesson;
use core\output\notification;
require_once('../../config.php');
defined('MOODLE_INTERNAL') || die();
global $DB;
$courseid = required_param('courseid', PARAM_INT);
$simplelessonid = required_param('simplelessonid', PARAM_INT);
$PAGE->set_url('/mod/simplelesson/autosequence.php', ['courseid' => $courseid, 'simplelessonid' => $simplelessonid]);
require_course_login($courseid);
$lesson = new lesson($simplelessonid);
$pagecount = $lesson->count_pages();
if ($pagecount > 0) {
for ($p = 1; $p <= $pagecount; $p++) {
$thispage = $lesson->get_page_record($p);
$prevpageid = $lesson->get_page_id_from_sequence($p - 1);
$nextpageid = ($p < $pagecount) ? $lesson->get_page_id_from_sequence($p + 1) : 0;
$DB->set_field('simplelesson_pages', 'prevpageid', $prevpageid, ['id' => $thispage->id]);
$DB->set_field('simplelesson_pages', 'nextpageid', $nextpageid, ['id' => $thispage->id]);
}
}
// Go back to page where request came from.
redirect(new moodle_url('/mod/simplelesson/edit_lesson.php', ['courseid' => $courseid, 'simplelessonid' => $simplelessonid]),
get_string('sequence_updated', 'mod_simplelesson'), 1, notification::NOTIFY_SUCCESS);