/
controller.php
217 lines (186 loc) · 4.92 KB
/
controller.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
<?php
namespace Concrete\Block\Video;
use Concrete\Core\Block\BlockController;
use Concrete\Core\Feature\Features;
use Concrete\Core\Feature\UsesFeatureInterface;
use Concrete\Core\File\File;
class Controller extends BlockController implements UsesFeatureInterface
{
/**
* @var int
*/
protected $btInterfaceWidth = 450;
/**
* @var int
*/
protected $btInterfaceHeight = 440;
/**
* @var string
*/
protected $btTable = 'btVideo';
/**
* @var bool
*/
protected $btCacheBlockOutput = true;
/**
* @var bool
*/
protected $btCacheBlockOutputOnPost = true;
/**
* @var string[]
*/
protected $btExportFileColumns = ['webmfID', 'oggfID', 'posterfID', 'mp4fID'];
/**
* @var string
*/
protected $btWrapperClass = 'ccm-ui';
/**
* @var int|null
*/
protected $mp4fID;
/**
* @var int|null
*/
protected $webmfID;
/**
* @var int|null
*/
protected $oggfID;
/**
* @var int|null
*/
protected $posterfID;
/**
* @var int|null
*/
protected $videoSize;
/**
* @var int|null
*/
protected $width;
/**
* @var string[]
*/
protected $helpers = ['form'];
/**
* {@inheritdoc}
*
* @return string
*/
public function getBlockTypeDescription()
{
return t('Embeds uploaded video into a web page. Supports WebM, Ogg, and Quicktime/MPEG4 formats.');
}
/**
* {@inheritdoc}
*
* @return string
*/
public function getBlockTypeName()
{
return t('Video Player');
}
/**
* Get the file id for the mp4 file.
*
* @return int
*/
public function getMp4FileID(): int
{
return $this->mp4fID ?? 0;
}
/**
* Get the file id for the webm file.
*
* @return int
*/
public function getWebmFileID(): int
{
return $this->webmfID ?? 0;
}
/**
* Get the file id for the webm file.
*
* @return int
*/
public function getOggFileID(): int
{
return $this->oggfID ?? 0;
}
public function getPosterFileID(): int
{
return $this->posterfID ?? 0;
}
public function getMp4FileObject(): ?\Concrete\Core\Entity\File\File
{
return File::getByID($this->getMp4FileID());
}
public function getOggFileObject(): ?\Concrete\Core\Entity\File\File
{
return File::getByID($this->getOggFileID());
}
public function getWebmFileObject(): ?\Concrete\Core\Entity\File\File
{
return File::getByID($this->getWebmFileID());
}
public function getPosterFileObject(): ?\Concrete\Core\Entity\File\File
{
return File::getByID($this->getPosterFileID());
}
/**
* {@inheritdoc}
*
* @return string[]
*/
public function getRequiredFeatures(): array
{
return [
Features::VIDEO,
];
}
/**
* Run when a block is added or edited. Automatically saves block data against the block's database table. If a block needs to do more than this (save to multiple tables, upload files, etc... it should override this.
*
* @param array<string,mixed> $data
*
* @return void
*/
public function save($data)
{
$data += [
'webmfID' => 0,
'oggfID' => 0,
'mp4fID' => 0,
'posterfID' => 0,
'width' => 0,
'videoSize' => 0,
'title' => '',
];
$args = [
'webmfID' => max(0, (int) $data['webmfID']),
'oggfID' => max(0, (int) $data['oggfID']),
'mp4fID' => max(0, (int) $data['mp4fID']),
'posterfID' => max(0, (int) $data['posterfID']),
'videoSize' => max(0, (int) $data['videoSize']),
'title' => $data['title'],
];
$args['width'] = $args['videoSize'] === 0 || $args['videoSize'] == 1 ? 0 : (int) $data['width'];
parent::save($args);
}
/**
* The view function called when ever a block is viewed on a page.
*
* @return void
*/
public function view()
{
$mp4File = $this->getMp4FileObject();
$webmFile = $this->getWebmFileObject();
$posterFile = $this->getPosterFileObject();
$oggFile = $this->getOggFileObject();
$this->set('posterURL', ($posterFile === null || $posterFile->getApprovedVersion() === null) ? '' : $posterFile->getApprovedVersion()->getURL());
$this->set('mp4URL', ($mp4File === null || $mp4File->getApprovedVersion() === null) ? '' : $mp4File->getApprovedVersion()->getURL());
$this->set('webmURL', ($webmFile === null || $webmFile->getApprovedVersion() === null) ? '' : $webmFile->getApprovedVersion()->getURL());
$this->set('oggURL', ($oggFile === null || $oggFile->getApprovedVersion() === null) ? '' : $oggFile->getApprovedVersion()->getURL());
}
}