This repository has been archived by the owner on Nov 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrenderer.php
478 lines (407 loc) · 16.9 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
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
<?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/>.
/**
* Render class responsible for html parts
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
* @package mod_openwebinar
* @copyright 2015 MoodleFreak.com
* @author Luuk Verhoeven
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/mod/openwebinar/lib/uaparser/vendor/autoload.php');
require_once($CFG->dirroot . '/mod/openwebinar/classes/questiontypes/choice.php');
/**
* The renderer for the openwebinar module.
*/
class mod_openwebinar_renderer extends plugin_renderer_base {
/**
* Number of rows will be shown foreach page
*
* @const int DEFAULT_TABLE_ROW_COUNT
*/
const DEFAULT_TABLE_ROW_COUNT = 20;
/**
* Show the page with all the component
*
* @param int $id
*
* @param $openwebinar
*
* @return string
* @throws coding_exception
*/
public function view_page_live_openwebinar($id = 0, $openwebinar) {
$obj = new stdClass();
$obj->timeopen = date(get_string('dateformat', 'openwebinar'), $openwebinar->timeopen);
$message = html_writer::tag('p', get_string('text:live_openwebinar', 'openwebinar', $obj),
array('class' => 'openwebinar-message'));
$url = new moodle_url('/mod/openwebinar/view_openwebinar.php', array('id' => $id));
// Button.
$output = html_writer::link($url, get_string('btn:enter_live_openwebinar', 'openwebinar'), array(
'class' => 'btn btn-primary',
'target' => '_blank'
));
// Output.
return $this->output->container($message . $output . '<hr/>', 'generalbox attwidth openwebinar-center');
}
/**
* Show help info for broadcaster
*
* @param int $id
* @param \stdClass $openwebinar
*
* @return string
*/
public function view_page_broadcaster_help($id = 0, stdClass $openwebinar) {
$url = new moodle_url('/mod/openwebinar/view_openwebinar.php', array('id' => $id));
$enterroom = html_writer::link($url, get_string('btn:broadcast_enter', 'openwebinar'), array(
'class' => 'btn btn-primary',
'target' => '_blank'
));
$url = new moodle_url('/mod/openwebinar/offline_questions.php', array('id' => $id));
$offlinequestions = html_writer::link($url, get_string('btn:offline_questions', 'openwebinar'), array(
'class' => 'btn',
'target' => '_blank'
));
return $this->output->container(html_writer::tag('p',
get_string('text:broadcaster_help', 'openwebinar', $openwebinar) . '<hr/>' . $enterroom . $offlinequestions,
array('class' => 'openwebinar-message')), 'generalbox attwidth openwebinar-center');
}
/**
* Show a page when the broadcast will be starting
*
* @param $openwebinar
*
* @return string
*/
public function view_page_not_started_openwebinar($openwebinar) {
global $PAGE;
$html = '';
// Language strings.
$PAGE->requires->strings_for_js(array(
'js:countdown_line1',
'js:countdown_line2',
'js:countdown_line3',
), 'openwebinar');
$PAGE->requires->js('/mod/openwebinar/javascript/countdown.js');
// Get cm.
$cm = get_coursemodule_from_instance('openwebinar', $openwebinar->id, $openwebinar->course, false, MUST_EXIST);
// Load js for countdown.
$opts = array();
$opts['timeopen'] = $openwebinar->timeopen;
$opts['cmid'] = $cm->id;
$opts['from'] = time();
$PAGE->requires->yui_module('moodle-mod_openwebinar-base', 'M.mod_openwebinar.base.init', array($opts));
// Add id for the countdown.
$html .= html_writer::tag('h3', get_string('starts_at', 'openwebinar'), array(
'class' => 'openwebinar-center'
));
$html .= html_writer::tag('h3', '', array(
'id' => 'pageTimer',
'class' => 'openwebinar-center'
));
// Show a count down.
// Reload page when it starts.
return $html . '<hr/>';
}
/**
* User has access to the history
*
* @param int $id
* @param $openwebinar
*
* @return string
* @throws coding_exception
*/
public function view_page_history_openwebinar($id = 0, $openwebinar) {
$obj = new stdClass();
$obj->timeopen = date(get_string('dateformat', 'openwebinar'), $openwebinar->timeopen);
$content = html_writer::tag('p', get_string('text:history', 'openwebinar', $obj), array('class' => 'openwebinar-message'));
// Add link to the room.
$url = new moodle_url('/mod/openwebinar/view_openwebinar.php', array('id' => $id));
$content .= html_writer::link($url, get_string('btn:enter_offline_openwebinar', 'openwebinar'), array(
'class' => 'btn btn-primary',
'target' => '_blank'
));
return $this->output->container($content, 'generalbox attwidth openwebinar-center');
}
/**
* Openwebinar has ended and user doesn't have access to history
*
* @param $openwebinar
*
* @return string
*/
public function view_page_ended_message($openwebinar) {
$html = '';
return $html;
}
/**
* get overview of all user activities in given openwebinar
*
* @param $openwebinar
*
* @return string
*/
public function view_user_activity_all(\stdClass $openwebinar) {
global $OUTPUT, $PAGE, $CFG;
require_once($CFG->libdir . '/tablelib.php');
$table = new \mod_openwebinar\table\useractivity('outstation-list-table', $openwebinar);
echo $OUTPUT->heading(get_string('text:useractivity', 'openwebinar'));
echo '<hr/>';
$table->set_attribute('cellspacing', '0');
$table->set_attribute('class', 'admintable generaltable');
$table->initialbars(true); // Always initial bars.
$table->define_columns(array(
'picture',
'firstname',
'lastname',
'email',
'present',
'action'
));
$table->define_headers(array(
get_string('heading:picture', 'openwebinar'),
get_string('heading:firstname', 'openwebinar'),
get_string('heading:lastname', 'openwebinar'),
get_string('heading:email', 'openwebinar'),
get_string('heading:present', 'openwebinar'),
get_string('heading:action', 'openwebinar'),
));
$table->no_sorting('action');
$table->sortable(true, 'name', SORT_DESC);
$table->define_baseurl(new moodle_url($PAGE->url, $PAGE->url->params()));
$table->collapsible(false);
$table->out(self::DEFAULT_TABLE_ROW_COUNT, true);
}
/**
* @param stdClass $openwebinar
*
* @throws coding_exception
* @throws moodle_exception
*/
public function view_mail_users(\stdClass $openwebinar) {
global $OUTPUT, $PAGE, $CFG;
require_once($CFG->libdir . '/tablelib.php');
$table = new \mod_openwebinar\table\usermail('outstation-list-table', $openwebinar);
$table->set_attribute('cellspacing', '0');
$table->set_attribute('class', 'admintable generaltable');
$table->initialbars(true); // Always initial bars.
$table->define_columns(array(
'picture',
'firstname',
'lastname',
'email',
'action'
));
$table->define_headers(array(
get_string('heading:picture', 'openwebinar'),
get_string('heading:firstname', 'openwebinar'),
get_string('heading:lastname', 'openwebinar'),
get_string('heading:email', 'openwebinar'),
get_string('heading:action', 'openwebinar'),
));
$table->no_sorting('action');
$table->sortable(true, 'name', SORT_DESC);
$table->define_baseurl(new moodle_url($PAGE->url, $PAGE->url->params()));
$table->collapsible(false);
$table->out(1000, true);
}
/**
* get overview of all question templates
*
* @param $openwebinar
*
* @return string
*/
public function question_table(\stdClass $openwebinar) {
global $OUTPUT, $PAGE, $CFG;
require_once($CFG->libdir . '/tablelib.php');
$table = new \mod_openwebinar\table\questions('outstation-list-table', $openwebinar);
echo $OUTPUT->heading(get_string('text:question_table', 'openwebinar'));
echo '<hr/>';
$table->set_attribute('cellspacing', '0');
$table->set_attribute('class', 'admintable generaltable');
$table->initialbars(true); // Always initial bars.
$table->define_columns(array(
'question_name',
'question_comment',
'question_type',
'action'
));
$table->define_headers(array(
get_string('heading:question_name', 'openwebinar'),
get_string('heading:question_comment', 'openwebinar'),
get_string('heading:question_type', 'openwebinar'),
get_string('heading:action', 'openwebinar'),
));
$table->no_sorting('action');
$table->sortable(true, 'question_name', SORT_DESC);
$table->define_baseurl(new moodle_url($PAGE->url, $PAGE->url->params()));
$table->collapsible(false);
$table->out(self::DEFAULT_TABLE_ROW_COUNT, true);
}
/**
* Load online time of the user
*
* @param bool|\stdClass $openwebinar
* @param int $userid
*
* @throws coding_exception
*/
public function view_user_chattime($openwebinar = false, $userid = 0) {
global $OUTPUT, $DB, $PAGE;
$backurl = new \moodle_url('/mod/openwebinar/user_activity.php', $PAGE->url->params());
$btn = new single_button($backurl, get_string('btn:back', 'openwebinar'));
$btn->class = 'openwebinar_back';
echo $this->render($btn);
echo '<hr>';
$user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
$user->fullname = fullname($user);
echo $OUTPUT->heading(get_string('heading:chattime', 'openwebinar', $user));
echo $OUTPUT->box_start('generalbox');
$status = $DB->get_record('openwebinar_userstatus', array(
'openwebinar_id' => $openwebinar->id,
'userid' => $user->id
));
if ($status) {
// User info.
// Parse user agent for more readable format.
$parser = Parser::create();
$browser = $parser->parse($status->useragent);
$table = new html_table();
$table->size = array('120px', '');
$table->head = array(get_string('heading:name', 'openwebinar'), get_string('heading:value', 'openwebinar'));
$table->data = array();
$table->data[] = array(
get_string('browser', 'openwebinar'),
$browser->toString(),
);
$table->data[] = array(
get_string('ip_address', 'openwebinar'),
$status->ip_address,
);
$table->data[] = array('<b>' . get_string('time', 'openwebinar') . '</b>', '');
$table->data[] = array(get_string('starttime', 'openwebinar'), date('d-m-Y H:i:s', $status->starttime));
$table->data[] = array(
get_string('online_time', 'openwebinar'),
($status->timer_seconds == 0) ? '-' : gmdate("H:i:s", $status->timer_seconds)
);
echo html_writer::table($table);
// Add time table.
}
echo $OUTPUT->box_end();
}
/**
* Load chat log of a user
*
* @param bool|stdClass $openwebinar
* @param int $userid
*
* @throws coding_exception
*/
public function view_user_chatlog($openwebinar = false, $userid = 0) {
global $OUTPUT, $DB, $PAGE;
$backurl = new \moodle_url('/mod/openwebinar/user_activity.php', $PAGE->url->params());
$btn = new single_button($backurl, get_string('btn:back', 'openwebinar'));
$btn->class = 'openwebinar_back';
echo $this->render($btn);
echo '<hr>';
$user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
$user->fullname = fullname($user);
echo $OUTPUT->heading(get_string('heading:chatlog', 'openwebinar', $user));
echo $OUTPUT->box_start('generalbox');
$table = new html_table();
$table->size = array('120px', '');
$table->head = array(get_string('heading:time', 'openwebinar'), get_string('heading:message', 'openwebinar'));
$table->data = array();
$qr = $DB->get_recordset('openwebinar_messages', array(
'userid' => $userid,
'openwebinar_id' => $openwebinar->id
), 'id ASC');
foreach ($qr as $record) {
$table->data[] = array(
date('d-m-Y H:i:s', $record->timestamp),
$this->convertmessagetoreadable($record->message, $openwebinar)
);
}
$qr->close();
echo html_writer::table($table);
echo $OUTPUT->box_end();
}
/**
* Internal parsing message text for log overview
*
* @param string $message
* @param stdClass $openwebinar
*
* @return string
*/
public function convertmessagetoreadable($message = '', stdClass $openwebinar) {
global $DB;
if (strpos($message, '[') === 0) {
$re = "/\\[([\\w\\-_]+)([^\\]]*)?\\](?:(.+?)?\\[\\/\\1\\])?/";
preg_match_all($re, $message, $matches);
// Convert shortcode.
if (!empty($matches[1][0])) {
$args = !empty($matches[2][0]) ? json_decode($matches[2][0]) : false;
switch ($matches[1][0]) {
case 'answer' :
$answer = $DB->get_field('openwebinar_question_answer', 'answer_data',
['id' => $args->answerid]);
$questionrecord = $DB->get_record('openwebinar_question', ['id' => $args->questionid]);
if ($answer) {
$message = '';
$answer = unserialize($answer);
$question = unserialize($questionrecord->question_data);
$message .= \html_writer::tag('h4', $question->question, []);
$message .= \html_writer::tag('p', $question->summary, []);
if (is_array($answer->answer)) {
$question = new \mod_openwebinar\questiontypes\choice($questionrecord);
$options = $question->get_question_answer_options();
foreach ($answer->answer as $k => $v) {
$message .= \html_writer::tag('b', $options[$k], []) . '<br>';
}
} else {
$message .= \html_writer::tag('b', $answer->answer, []);
}
}
break;
case 'file' :
$message = '';
$message .= \html_writer::tag('h4', $args->filename, []);
$message .= html_writer::link(new moodle_url('/mod/openwebinar/download.php', [
'extra3' => $args->id,
'extra2' => $openwebinar->id,
'extra1' => $openwebinar->course,
'sesskey' => sesskey(),
]), '<img src="'
. $args->thumbnail . '" />');
break;
case 'question' :
$message = '[question]';
break;
default:
$message = '[shortcode unable_to_convert]';
}
}
}
// TODO: convert emoticons in chatlog.
return $message;
}
}