-
Notifications
You must be signed in to change notification settings - Fork 18
/
status_view.php
executable file
·250 lines (228 loc) · 10.7 KB
/
status_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
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
<?php
// This file is part of mod_organizer for Moodle - http://moodle.org/
//
// It 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.
//
// It 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/>.
/**
* status_view.php
*
* @package mod_organizer
* @author Andreas Hruska ([email protected])
* @author Katarzyna Potocka ([email protected])
* @author Thomas Niedermaier ([email protected])
* @author Andreas Windbichler
* @author Ivan Šakić
* @copyright 2014 Academic Moodle Cooperation {@link http://www.academic-moodle-cooperation.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
function organizer_generate_registration_table_content($columns, $params) {
global $DB;
list($cm, $course, $organizer, $context) = get_course_module_data();
$groupmode = is_group_mode();
if ($groupmode) {
$entries = organizer_get_status_table_entries_group($params);
} else {
$entries = organizer_get_status_table_entries($params);
}
$rows = array();
foreach ($entries as $entry) {
$row = new html_table_row();
foreach ($columns as $column) {
switch ($column) {
case 'participants':
if ($groupmode) {
$members = $DB->get_fieldset_select('groups_members', 'userid', "groupid = {$entry->id}");
$list = "<em>$entry->name</em><br/ >";
$list .= organizer_get_teacherapplicant_output(
$entry->teacherapplicantid, $entry->teacherapplicanttimemodified);
foreach ($members as $member) {
$identity = organizer_get_user_identity($member);
$identity = $identity ? " (" . $identity . ") " : "";
$list .= organizer_get_name_link($member) . $identity
. (isset($entry->comments) ? get_img('i/feedback', '', $entry->comments) : '');
if ($member == $entry->applicantid) {
$list .= ' '
. organizer_get_icon('applicant', 'applicant') . '<br/>';
} else {
$list .= ' ' . organizer_get_icon('transparent', '') . '<br/>';
}
}
$row->cells[] = new html_table_cell($list);
} else {
$row->cells[] = new html_table_cell(get_name_link($entry->id) . " ({$entry->idnumber})" .
organizer_get_teacherapplicant_output($entry->teacherapplicantid,
$entry->teacherapplicanttimemodified));
}
break;
case 'registered':
$row->cells[] = new html_table_cell(get_status_icon_new($entry->status));
break;
case 'datetime':
$row->cells[] = new html_table_cell(date_time($entry));
break;
case 'appdetails':
if ($groupmode) {
$row->cells[] = new html_table_cell('PLACEHOLDER');
} else {
$row->cells[] = new html_table_cell(app_details($params, $entry));
}
break;
case 'location':
$row->cells[] = new html_table_cell(location_link($entry));
break;
case 'teacher':
$row->cells[] = new html_table_cell(teacher_data($params, $entry));
break;
case 'actions':
$row->cells[] = new html_table_cell(teacher_action_new($params, $entry));
break;
}
}
$rows[] = $row;
}
return $rows;
}
function organizer_get_status_table_entries_group($params) {
global $DB;
list($cm, $course, $organizer, $context) = get_course_module_data();
$query = "SELECT g.id FROM {groups} g
INNER JOIN {groupings_groups} gg ON g.id = gg.groupid
WHERE gg.groupingid = :groupingid";
$par = array('groupingid' => $cm->groupingid);
$groupids = $DB->get_fieldset_sql($query, $par);
if (empty($groupids)) {
$groupids = array(0);
}
list($insql, $inparams) = $DB->get_in_or_equal($groupids, SQL_PARAMS_NAMED);
if ($params['sort'] == 'name') {
if ($params['dir'] == 'DESC') {
$orderby = "ORDER BY g.name DESC, status ASC";
} else {
$orderby = "ORDER BY g.name ASC, status ASC";
}
} else if ($params['sort'] == 'status') {
if ($params['dir'] == 'DESC') {
$orderby = "ORDER BY status DESC, g.name ASC";
} else {
$orderby = "ORDER BY status ASC, g.name ASC";
}
} else {
$orderby = "ORDER BY g.name ASC, status ASC";
}
$par = array();
$par['now1'] = time();
$par['now2'] = time();
$par['organizerid'] = $organizer->id;
$par = array_merge($par, $inparams);
$query = "SELECT DISTINCT
g.id, g.name,
CASE
WHEN a2.id IS NOT NULL AND a2.attended = 1 THEN 0
WHEN a2.id IS NOT NULL AND a2.attended IS NULL AND a2.starttime <= :now1 THEN 1
WHEN a2.id IS NOT NULL AND a2.attended IS NULL AND a2.starttime > :now2 THEN 2
WHEN a2.id IS NOT NULL AND a2.attended = 0 THEN 3
WHEN a2.id IS NULL THEN 4
ELSE -1
END AS status, a2.starttime, a2.duration, a2.location, a2.teacherid, a2.applicantid,
a2.comments, a2.teachervisible, a2.slotid, a2.teacherapplicantid, a2.teacherapplicanttimemodified
FROM {groups} g
LEFT JOIN
(SELECT
a.id, a.groupid, s.id as slotid, s.starttime, s.location, s.teacherid, s.teachervisible,
s.duration, a.applicantid, a.comments, a.teacherapplicantid, a.teacherapplicanttimemodified,
(SELECT MAX(attended) FROM mdl_organizer_slot_appointments a3 WHERE a3.groupid = a.groupid) AS attended
FROM {organizer_slot_appointments} a
INNER JOIN {organizer_slots} s ON a.slotid = s.id
WHERE s.organizerid = :organizerid ORDER BY s.starttime DESC) a2 ON g.id = a2.groupid
WHERE g.id $insql
GROUP BY g.id, g.name, status, a2.starttime, a2.duration, a2.location, a2.teacherid,
a2.applicantid, a2.comments, a2.teachervisible, a2.slotid,
a2.teacherapplicantid, a2.teacherapplicanttimemodified
$orderby";
return $DB->get_records_sql($query, $par);
}
function organizer_get_status_table_entries($params) {
global $DB;
list($cm, $course, $organizer, $context) = get_course_module_data();
if ($cm->groupingid == 0) {
$students = get_enrolled_users($context, 'mod/organizer:register');
$studentids = array();
foreach ($students as $student) {
$studentids[] = $student->id;
}
} else {
$query = "SELECT u.id FROM {user} u
INNER JOIN {groups_members} gm ON u.id = gm.userid
INNER JOIN {groups} g ON gm.groupid = g.id
INNER JOIN {groupings_groups} gg ON g.id = gg.groupid
WHERE gg.groupingid = :grouping";
$par = array('grouping' => $cm->groupingid);
$studentids = $DB->get_fieldset_sql($query, $par);
}
if (empty($studentids)) {
$studentids = array(0);
}
list($insql, $inparams) = $DB->get_in_or_equal($studentids, SQL_PARAMS_NAMED);
if ($params['sort'] == 'name') {
if ($params['dir'] == 'DESC') {
$orderby = "ORDER BY u.lastname DESC, u.firstname DESC, u.idnumber ASC, status ASC";
} else {
$orderby = "ORDER BY u.lastname ASC, u.firstname ASC, u.idnumber ASC, status ASC";
}
} else if ($params['sort'] == 'status') {
if ($params['dir'] == 'DESC') {
$orderby = "ORDER BY status DESC, u.lastname ASC, u.firstname ASC, u.idnumber ASC";
} else {
$orderby = "ORDER BY status ASC, u.lastname ASC, u.firstname ASC, u.idnumber ASC";
}
} else if ($params['sort'] == 'id') {
if ($params['dir'] == 'DESC') {
$orderby = "ORDER BY u.idnumber DESC, u.lastname ASC, u.firstname ASC, status ASC";
} else {
$orderby = "ORDER BY u.idnumber ASC, u.lastname ASC, u.firstname ASC, status ASC";
}
} else {
$orderby = "ORDER BY u.lastname ASC, u.firstname ASC, u.idnumber ASC, status ASC";
}
$par = array();
$par['now1'] = time();
$par['now2'] = time();
$par['organizerid'] = $organizer->id;
$par = array_merge($par, $inparams);
$query = "SELECT DISTINCT
u.id, u.firstname, u.lastname, u.idnumber,
CASE
WHEN a2.id IS NOT NULL AND a2.attended = 1 THEN 0
WHEN a2.id IS NOT NULL AND a2.attended IS NULL AND a2.starttime <= :now1 THEN 1
WHEN a2.id IS NOT NULL AND a2.attended IS NULL AND a2.starttime > :now2 THEN 2
WHEN a2.id IS NOT NULL AND a2.attended = 0 THEN 3
WHEN a2.id IS NULL THEN 4
ELSE -1
END AS status,
a2.starttime, a2.duration, a2.attended, a2.location, a2.grade, a2.comments,
a2.feedback, a2.teacherid, a2.userid, a2.teachervisible, a2.slotid,
a2.teacherapplicantid, a2.teacherapplicanttimemodified
FROM {user} u
LEFT JOIN
(SELECT a.id, a.attended, a.grade, a.feedback, a.userid, s.starttime, s.location,
s.teacherid, s.comments, s.duration, s.teachervisible, s.id as slotid, a.teacherapplicantid, a.teacherapplicanttimemodified
FROM {organizer_slot_appointments} a INNER JOIN {organizer_slots} s ON a.slotid = s.id
WHERE s.organizerid = :organizerid ORDER BY s.starttime DESC) a2 ON u.id = a2.userid
WHERE u.id $insql
GROUP BY u.id, u.firstname, u.lastname, u.idnumber, status, a2.starttime, a2.duration, a2.attended,
a2.location, a2.grade, a2.comments, a2.feedback, a2.teacherid, a2.userid, a2.teachervisible, a2.slotid,
a2.teacherapplicantid, a2.teacherapplicanttimemodified
$orderby";
return $DB->get_records_sql($query, $par);
}