forked from robertmarsal/moodle-block_videoconverter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
renderer.php
166 lines (143 loc) · 6.3 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
<?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/>.
/**
* @author Robert Boloc <[email protected]>
* @copyright 2014 Servei de Recursos Educatius (http://www.sre.urv.cat)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__ . '/lib.php');
class block_video_converter_renderer extends plugin_renderer_base {
public function user_queue(array $queue, $token) {
if (empty($queue)) {
global $OUTPUT;
return $OUTPUT->box(get_string('queueempty', 'block_video_converter')) . '<br>';
}
$table = new html_table();
$table->align = array(
'center', 'center', 'center',
'center', 'center', 'center',
'center', 'center', 'center',
);
$table->width = "100%";
$table->head = array(
get_string('name', 'block_video_converter'),
get_string('size', 'block_video_converter'),
get_string('status', 'block_video_converter'),
get_string('position', 'block_video_converter'),
get_string('timeadded', 'block_video_converter'),
get_string('timeupdated', 'block_video_converter'),
get_string('timefinished', 'block_video_converter'),
get_string('timedownloaded', 'block_video_converter'),
get_string('action', 'block_video_converter'),
);
foreach ($queue as $row) {
// Action.
$downloader = rtrim(get_config('block_video_converter', 'converterurl'), '/') . '/download.php';
$download_url = new moodle_url($downloader, array(
'token' => $token,
'file' => $row->hash,
'queue_item_id' => $row->id,
));
$action_attributes = array(
'class' => 'block_video_converter-cell-action-content block_video_converter-hidden'
);
// Status.
$status_class = 'block_video_converter-cell-status-content ';
switch($row->status) {
case queue::STATUS_CONVERTED :
case queue::STATUS_DOWNLOADED :
// Show the download link
$action_attributes['class'] = 'block_video_converter-cell-action-content';
// Status.
$status_class .= 'block_video_converter-badge-green';
break;
case queue::STATUS_QUEUED :
$status_class .= 'block_video_converter-badge-blue';
break;
case queue::STATUS_CONVERTING :
$status_class .= 'block_video_converter-badge-yellow';
break;
case queue::STATUS_FAILED :
$status_class .= 'block_video_converter-badge-red';
break;
}
$action = html_writer::link(
$download_url->out(false),
get_string('download', 'block_video_converter'),
$action_attributes
);
$status = html_writer::tag(
'span',
get_string('status:' . $row->status, 'block_video_converter'),
array('class' => $status_class)
);
$status_cell = new html_table_cell($status);
$status_cell->attributes = array(
'class' => 'block_video_converter-cell-status',
'data-id' => $row->id,
'data-status' => $row->status,
);
$timeupdated_cell = new html_table_cell(!empty($row->timeupdated) ? userdate($row->timeupdated) : '-');
$timeupdated_cell->attributes = array(
'class' => 'block_video_converter-cell-timeupdated',
);
$timefinished_cell = new html_table_cell(
$row->status === queue::STATUS_QUEUED ||
$row->status === queue::STATUS_CONVERTING ||
$row->status === queue::STATUS_FAILED ? '-' : userdate($row->timefinished));
$timefinished_cell->attributes = array(
'class' => 'block_video_converter-cell-timefinished',
);
$action_cell = new html_table_cell($action);
$action_cell->attributes = array(
'class' => 'block_video_converter-cell-action',
);
$position_cell = new html_table_cell(
$row->status === queue::STATUS_CONVERTING ||
$row->status === queue::STATUS_CONVERTED ||
$row->status === queue::STATUS_FAILED ||
$row->status === queue::STATUS_DOWNLOADED ? '-' : $row->position);
$position_cell->attributes = array(
'class' => 'block_video_converter-cell-position',
);
$html_row = new html_table_row(array(
$row->name,
format_bytes($row->size),
$status_cell,
$position_cell,
userdate($row->timeadded),
$timeupdated_cell,
$timefinished_cell,
$row->status === queue::STATUS_DOWNLOADED ? userdate($row->timedownloaded) : '-',
$action_cell,
));
$html_row->attributes = array(
'class' => 'block_video_converter-row',
);
$table->data[] = $html_row;
}
$refresh_script = "
<script>
window.onload = function(){
setInterval(function(){
M.block_video_converter.refreshStatuses('" . $token . "');
}, 5000);
}
</script>
";
return html_writer::table($table) . $refresh_script;
}
}