-
Notifications
You must be signed in to change notification settings - Fork 0
/
overrides.php
92 lines (73 loc) · 3.18 KB
/
overrides.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/>.
/**
* @package block_pu
* @copyright 2021 onwards LSU Online & Continuing Education
* @copyright 2021 onwards Tim Hunt, Robert Russo
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
// Grab these for later.
global $CFG, $USER;
// Inlcude the requisite helpers functionality.
require_once('../../config.php');
require_once($CFG->dirroot . '/blocks/pu/overrides_form.php');
require_once($CFG->dirroot . '/blocks/pu/classes/helpers.php');
// Make sure the user is logged in.
require_login();
// Set the context.
$context = \context_system::instance();
$usercontext = \context_user::instance($USER->id);
$returnurl = new moodle_url('/');
// Set up the page.
$PAGE->set_url('/blocks/pu/overrides.php');
$PAGE->set_context($context);
$PAGE->set_pagetype('block-pu');
$PAGE->set_pagelayout('standard');
$PAGE->set_title(get_string('pluginname', 'block_pu') . ': ' . get_string('manage_overrides', 'block_pu'));
$PAGE->navbar->add(get_string('manage_overrides', 'block_pu'));
$PAGE->set_heading(get_string('pluginname', 'block_pu') . ': ' . get_string('manage_overrides', 'block_pu'));
$PAGE->requires->css(new moodle_url('/blocks/pu/styles.css'));
// Check to see if ths user in question can modify pu override settings.
if (!has_capability('block/pu:admin', $context)) {
redirect($returnurl, get_string('no_override_permissions', 'block_pu'), null, \core\output\notification::NOTIFY_ERROR);
}
// Build the guild course list.
$guildcourses = block_pu_helpers::pu_guildcourses();
// Build the list of overrides.
$overrides = block_pu_helpers::pu_overrides($guildcourses);
// Build the form.
$form = new pu_overrides_form(null, $guildcourses, $PAGE);
// Set default data (if any).
$form->set_data($overrides);
// Form processing and displaying.
if ($form->is_cancelled()) {
// Handle form cancel operation, if cancel button is present on form.
redirect($returnurl, get_string('nothingtodo', 'block_pu'), null, \core\output\notification::NOTIFY_WARNING);
} else if ($fromform = $form->get_data()) {
//In this case you process validated data. $mform->get_data() returns data posted in form.
$orcomplete = block_pu_helpers::pu_writeoverrides($fromform, $userid = $USER->id);
if ($orcomplete) {
redirect($returnurl, get_string('override_complete', 'block_pu'), 10, \core\output\notification::NOTIFY_SUCCESS);
} else {
$form->display();
}
} else {
// Output the page header.
echo $OUTPUT->header();
// Display the form.
$form->display();
}
echo $OUTPUT->footer();