forked from catalyst/moodle-mod_facetoface
-
Notifications
You must be signed in to change notification settings - Fork 0
/
renderer.php
186 lines (164 loc) · 8.56 KB
/
renderer.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
<?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/>.
/**
* Copyright (C) 2007-2011 Catalyst IT (http://www.catalyst.net.nz)
* Copyright (C) 2011-2013 Totara LMS (http://www.totaralms.com)
* Copyright (C) 2014 onwards Catalyst IT (http://www.catalyst-eu.net)
*
* @package mod
* @subpackage facetoface
* @copyright 2014 onwards Catalyst IT <http://www.catalyst-eu.net>
* @author Stacey Walker <[email protected]>
* @author Alastair Munro <[email protected]>
* @author Aaron Barnes <[email protected]>
* @author Francois Marier <[email protected]>
*/
defined('MOODLE_INTERNAL') || die();
class mod_facetoface_renderer extends plugin_renderer_base {
/**
* Builds session list table given an array of sessions
*/
public function print_session_list_table($customfields, $sessions, $viewattendees, $editsessions) {
$output = '';
$tableheader = array();
foreach ($customfields as $field) {
if (!empty($field->showinsummary)) {
$tableheader[] = format_string($field->name);
}
}
$tableheader[] = get_string('date', 'facetoface');
$tableheader[] = get_string('time', 'facetoface');
if ($viewattendees) {
$tableheader[] = get_string('capacity', 'facetoface');
} else {
$tableheader[] = get_string('seatsavailable', 'facetoface');
}
$tableheader[] = get_string('status', 'facetoface');
$tableheader[] = get_string('options', 'facetoface');
$timenow = time();
$table = new html_table();
$table->summary = get_string('previoussessionslist', 'facetoface');
$table->head = $tableheader;
$table->data = array();
foreach ($sessions as $session) {
$isbookedsession = false;
$bookedsession = $session->bookedsession;
$sessionstarted = false;
$sessionfull = false;
$sessionrow = array();
// Custom fields.
$customdata = $session->customfielddata;
foreach ($customfields as $field) {
if (empty($field->showinsummary)) {
continue;
}
if (empty($customdata[$field->id])) {
$sessionrow[] = ' ';
} else {
if (CUSTOMFIELD_TYPE_MULTISELECT == $field->type) {
$sessionrow[] = str_replace(CUSTOMFIELD_DELIMITER, html_writer::empty_tag('br'), format_string($customdata[$field->id]->data));
} else {
$sessionrow[] = format_string($customdata[$field->id]->data);
}
}
}
// Dates/times.
$allsessiondates = '';
$allsessiontimes = '';
if ($session->datetimeknown) {
foreach ($session->sessiondates as $date) {
if (!empty($allsessiondates)) {
$allsessiondates .= html_writer::empty_tag('br');
}
$allsessiondates .= userdate($date->timestart, get_string('strftimedate'));
if (!empty($allsessiontimes)) {
$allsessiontimes .= html_writer::empty_tag('br');
}
$allsessiontimes .= userdate($date->timestart, get_string('strftimetime')).
' - '.userdate($date->timefinish, get_string('strftimetime'));
}
} else {
$allsessiondates = get_string('wait-listed', 'facetoface');
$allsessiontimes = get_string('wait-listed', 'facetoface');
$sessionwaitlisted = true;
}
$sessionrow[] = $allsessiondates;
$sessionrow[] = $allsessiontimes;
// Capacity.
$signupcount = facetoface_get_num_attendees($session->id, MDL_F2F_STATUS_APPROVED);
$stats = $session->capacity - $signupcount;
if ($viewattendees) {
$stats = $signupcount . ' / ' . $session->capacity;
} else {
$stats = max(0, $stats);
}
$sessionrow[] = $stats;
// Status.
$status = get_string('bookingopen', 'facetoface');
if ($session->datetimeknown && facetoface_has_session_started($session, $timenow) && facetoface_is_session_in_progress($session, $timenow)) {
$status = get_string('sessioninprogress', 'facetoface');
$sessionstarted = true;
} else if ($session->datetimeknown && facetoface_has_session_started($session, $timenow)) {
$status = get_string('sessionover', 'facetoface');
$sessionstarted = true;
} else if ($bookedsession && $session->id == $bookedsession->sessionid) {
$signupstatus = facetoface_get_status($bookedsession->statuscode);
$status = get_string('status_' . $signupstatus, 'facetoface');
$isbookedsession = true;
} else if ($signupcount >= $session->capacity) {
$status = get_string('bookingfull', 'facetoface');
$sessionfull = true;
}
$sessionrow[] = $status;
// Options.
$options = '';
if ($editsessions) {
$options .= $this->output->action_icon(new moodle_url('sessions.php', array('s' => $session->id)), new pix_icon('t/edit', get_string('edit', 'facetoface')), null, array('title' => get_string('editsession', 'facetoface'))) . ' ';
$options .= $this->output->action_icon(new moodle_url('sessions.php', array('s' => $session->id, 'c' => 1)), new pix_icon('t/copy', get_string('copy', 'facetoface')), null, array('title' => get_string('copysession', 'facetoface'))) . ' ';
$options .= $this->output->action_icon(new moodle_url('sessions.php', array('s' => $session->id, 'd' => 1)), new pix_icon('t/delete', get_string('delete', 'facetoface')), null, array('title' => get_string('deletesession', 'facetoface'))) . ' ';
$options .= html_writer::empty_tag('br');
}
if ($viewattendees) {
$options .= html_writer::link('attendees.php?s='.$session->id.'&backtoallsessions='.$session->facetoface, get_string('attendees', 'facetoface'), array('title' => get_string('seeattendees', 'facetoface'))) . html_writer::empty_tag('br');
}
if ($isbookedsession) {
$options .= html_writer::link('signup.php?s='.$session->id.'&backtoallsessions='.$session->facetoface, get_string('moreinfo', 'facetoface'), array('title' => get_string('moreinfo', 'facetoface'))) . html_writer::empty_tag('br');
if ($session->allowcancellations) {
$options .= html_writer::link('cancelsignup.php?s=' . $session->id . '&backtoallsessions=' . $session->facetoface, get_string('cancelbooking', 'facetoface'), array('title' => get_string('cancelbooking', 'facetoface')));
}
} else if (!$sessionstarted and !$bookedsession) {
$options .= html_writer::link('signup.php?s='.$session->id.'&backtoallsessions='.$session->facetoface, get_string('signup', 'facetoface'));
}
if (empty($options)) {
$options = get_string('none', 'facetoface');
}
$sessionrow[] = $options;
$row = new html_table_row($sessionrow);
// Set the CSS class for the row.
if ($sessionstarted) {
$row->attributes = array('class' => 'dimmed_text');
} else if ($isbookedsession) {
$row->attributes = array('class' => 'highlight');
} else if ($sessionfull) {
$row->attributes = array('class' => 'dimmed_text');
}
// Add row to table.
$table->data[] = $row;
}
$output .= html_writer::table($table);
return $output;
}
}