-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathview.php
79 lines (66 loc) · 3.31 KB
/
view.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
<?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/>.
/**
* Post signup page to notify user of courses enrolled via enrolment keys.
*
* @package auth_enrolkey
* @copyright 2016 Nicholas Hoobin ([email protected])
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once('../../config.php');
require_login();
$availableenrolids = required_param('ids', PARAM_TEXT);
$availableenrolids = explode(',', $availableenrolids);
$PAGE->set_url(new moodle_url('/auth/enrolkey/view.php'));
$PAGE->set_course($SITE);
$PAGE->set_title(get_string('pluginname', 'auth_enrolkey'));
$PAGE->set_heading(get_string('signup_view', 'auth_enrolkey'));
echo $OUTPUT->header();
if (!empty($availableenrolids)) {
foreach ($availableenrolids as $enrolid) {
$plugin = $DB->get_record('enrol', ['enrol' => 'self', 'id' => $enrolid]);
$course = $DB->get_record('course', ['id' => $plugin->courseid]);
$coursecontext = context_course::instance($plugin->courseid);
$rolenames = role_get_names($coursecontext, ROLENAME_ALIAS, true);
$data = new stdClass();
$data->course = $course->fullname;
$data->enrolinstance = $plugin->name;
$data->role = $rolenames[$plugin->roleid];
$data->startdate = date('Y-m-d H:i', $plugin->enrolstartdate);
$data->enddate = date('Y-m-d H:i', $plugin->enrolenddate);
$data->href = (new moodle_url('/course/view.php', ['id' => $plugin->courseid]))->out();
if ($plugin->enrolstartdate > 0 && $plugin->enrolenddate > 0) {
// The course had both a start and end date.
$successoutput = get_string('signup_view_message_basic_dates', 'auth_enrolkey', $data);
} else if ($plugin->enrolstartdate > 0 && $plugin->enrolenddate == 0) {
// The course only has a start date set.
$successoutput = get_string('signup_view_message_basic_dates_startonly', 'auth_enrolkey', $data);
} else if ($plugin->enrolstartdate == 0 && $plugin->enrolenddate > 0) {
// The course only has a start date set.
$successoutput = get_string('signup_view_message_basic_dates_endonly', 'auth_enrolkey', $data);
} else {
// The course has no date restrictions.
$successoutput = get_string('signup_view_message_basic', 'auth_enrolkey', $data);
}
echo $OUTPUT->notification($successoutput, 'notifysuccess');
}
} else {
$data = new stdClass();
$data->href = (new moodle_url('/'))->out();
$failure = get_string('signup_failure', 'auth_enrolkey', $data);
echo $OUTPUT->notification($failure, 'notifyfailure');
}
echo $OUTPUT->footer();