-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathclarity.php
145 lines (119 loc) · 5.01 KB
/
clarity.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
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
<?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/>.
/**
* Let's clarify the setup and layout of the site - intakes, users & courses.
*
* @package enrol_selma
* @copyright 2020 LearningWorks <selma@learningworks.ac.nz>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(dirname(__FILE__, 3) . '/config.php');
defined('MOODLE_INTERNAL') || die();
require_login();
// Only allow admins to this page.
if (!is_siteadmin()) {
redirect($CFG->wwwroot);
}
global $OUTPUT, $SITE, $PAGE, $DB;
// Retrieve/clean params.
$scope = optional_param('scope', 'overview', PARAM_TEXT);
$params['scope'] = $scope;
// We only accept 'student', 'teacher' or 'course'.
if ($scope === 'overview' || $scope === 'student' || $scope === 'course' || $scope === 'teacher') {
// If not at the overview page, we need to know which intake's students/teachers/course to display.
if ($scope !== 'overview') {
$intake = required_param('intake', PARAM_TEXT);
$params['intake'] = $intake;
}
} else {
throw new moodle_exception('unexpectedvalue', 'enrol_selma', null, 'scope');
}
// Setup url & params.
$context = context_system::instance();
$url = new moodle_url($CFG->wwwroot . '/enrol/selma/clarity.php', $params);
// Set PAGE variables.
$PAGE->set_context($context);
$PAGE->set_url($url);
// Only print headers if not asked to download data.
// Print the page header.
$heading = get_string('clarity' . $scope, 'enrol_selma');
$PAGE->set_title($heading);
$PAGE->set_heading($heading);
$PAGE->requires->jquery();
$PAGE->requires->js_call_amd('enrol_selma/jssearch', 'init');
// Breadcrumbs.
$PAGE->navbar->add(get_string('enrol', 'enrol'));
$PAGE->navbar->add(get_string('pluginname', 'enrol_selma'));
$PAGE->navbar->add(get_string('clarityoverview', 'enrol_selma'), new moodle_url($CFG->wwwroot . '/enrol/selma/clarity.php'));
if ($scope !== 'overview') {
$PAGE->navbar->add($heading);
}
$PAGE->set_pagelayout('standard');
$PAGE->add_body_class($scope);
// Get the renderer for this page.
$renderer = $PAGE->get_renderer('enrol_selma');
// Process params & generate HTML.
$html = get_string('nothingtosee', 'enrol_selma');
if ($scope === 'overview') {
// Get overview of intake.
$intakes = $DB->get_records('enrol_selma_intake');
if (!empty($intakes)) {
foreach ($intakes as $intake) {
$students = $DB->count_records('enrol_selma_student_intake', array('intakeid' => $intake->id));
$teachers = $DB->count_records('enrol_selma_teacher_intake', array('intakeid' => $intake->id));
$courses = $DB->count_records('enrol_selma_course_intake', array('intakeid' => $intake->id));
$intake->numstudents = $students;
$intake->numteachers = $teachers;
$intake->numcourses = $courses;
}
$html = $renderer->overview($intakes);
}
} elseif ($scope === 'student') {
// Get students of given intake.
$students = $DB->get_records('enrol_selma_student_intake', array('intakeid' => $params['intake']));
if (!empty($students)) {
$userids = array_column($students, 'userid');
// Get actual Moodle users.
list($insql, $inparams) = $DB->get_in_or_equal($userids);
$users = $DB->get_records_select('user', "id $insql", $inparams);
$html = $renderer->student($users);
}
} elseif ($scope === 'teacher') {
// Get teacher of given intake.
$teachers = $DB->get_records('enrol_selma_teacher_intake', array('intakeid' => $params['intake']));
if (!empty($teachers)) {
$userids = array_column($teachers, 'userid');
// Get actual Moodle users.
list($insql, $inparams) = $DB->get_in_or_equal($userids);
$users = $DB->get_records_select('user', "id $insql", $inparams);
$html = $renderer->teacher($users);
}
} elseif ($scope === 'course') {
// Get courses of given intake.
$courseintakes = $DB->get_records('enrol_selma_course_intake', array('intakeid' => $params['intake']));
if (!empty($courseintakes)) {
$courseids = array_column($courseintakes, 'courseid');
list($insql, $inparams) = $DB->get_in_or_equal($courseids);
$courses = $DB->get_records_select('course', "id $insql", $inparams);
$html = $renderer->course($courses);
}
}
// Render the page.
echo $OUTPUT->header();
echo $OUTPUT->heading($heading);
// Output page's main HTML.
echo $html;
echo $OUTPUT->footer();