-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclass.ilInteractiveVideoOpenCastGUI.php
More file actions
328 lines (286 loc) · 11.2 KB
/
class.ilInteractiveVideoOpenCastGUI.php
File metadata and controls
328 lines (286 loc) · 11.2 KB
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
<?php
require_once 'Customizing/global/plugins/Services/Repository/RepositoryObject/InteractiveVideo/VideoSources/interface.ilInteractiveVideoSourceGUI.php';
require_once 'Customizing/global/plugins/Services/Repository/RepositoryObject/InteractiveVideo/VideoSources/plugin/InteractiveVideoOpenCast/class.ilInteractiveVideoOpenCast.php';
require_once 'Customizing/global/plugins/Services/COPage/PageComponent/OpencastPageComponent/vendor/autoload.php';
require_once 'Customizing/global/plugins/Services/Repository/RepositoryObject/OpenCast/vendor/autoload.php';
use ILIAS\DI\Container;
/**
* Class ilInteractiveVideoOpenCastGUI
*/
class ilInteractiveVideoOpenCastGUI implements ilInteractiveVideoSourceGUI
{
const PLUGIN_CLASS_NAME = ilOpencastPageComponentPlugin::class;
const CMD_CANCEL = "cancel";
const CMD_CREATE = "create";
const CMD_EDIT = "edit";
const CMD_INSERT = "insert";
const CMD_UPDATE = "update";
const CMD_APPLY_FILTER = "applyFilter";
const CMD_RESET_FILTER = "resetFilter";
const CUSTOM_CMD = 'ocpc_cmd';
const POST_SIZE = 'size';
const CMD_SAVE = 'save';
const CMD_INDEX = 'index';
const OPC_DUMMY_ID = 'opc_dummy';
/**
* @var Container
*/
protected $dic;
/**
* @var ilCtrl
*/
protected $ilCtrlFake;
/**
* @var string
*/
protected $command_url;
/**
* @var string
*/
protected $ajax_url;
/**
* @param ilRadioOption $option
* @param $obj_id
* @return ilRadioOption
*/
public function getForm($option, $obj_id) : ilRadioOption
{
global $tpl, $DIC;
$this->dic = $DIC;
$ctrl = $DIC->ctrl();
$this->createCtrlFake($this->dic);
$object = new ilInteractiveVideoOpenCast();
$object->doReadVideoSource($obj_id);
$DIC->language()->toJSMap([
'select_video' => ilInteractiveVideoPlugin::getInstance()->txt('opc_select_video'),
'title' => ilInteractiveVideoPlugin::getInstance()->txt('opc_title'),
'opc_insert' => ilInteractiveVideoPlugin::getInstance()->txt('opc_insert')
], $DIC->ui()->mainTemplate());
if(array_key_exists('cmd', $_GET) && $_GET['cmd'] === 'create'){
$info_test = new ilNonEditableValueGUI('', 'oc_info_text');
$info_test->setValue(ilInteractiveVideoPlugin::getInstance()->txt('please_create_object_first'));
$option->addSubItem($info_test);
$opc_inject_text = new ilHiddenInputGUI('opc_id');
$opc_inject_text->setValue(self::OPC_DUMMY_ID);
$option->addSubItem($opc_inject_text);
} else {
$tpl->addJavaScript('Customizing/global/plugins/Services/Repository/RepositoryObject/InteractiveVideo/VideoSources/plugin/InteractiveVideoOpenCast/js/opcMediaPortalAjaxQuery.js');
$opc_id = new ilHiddenInputGUI( 'opc_id');
$option->addSubItem($opc_id);
$info_test = new ilNonEditableValueGUI('', 'opc_id_text');
$info_test->setValue('');
$option->addSubItem($info_test);
$opc_url = new ilHiddenInputGUI('opc_url');
$option->addSubItem($opc_url);
}
$tpl_modal = new ilTemplate('Customizing/global/plugins/Services/Repository/RepositoryObject/InteractiveVideo/VideoSources/plugin/InteractiveVideoOpenCast/tpl/tpl.modal.html', false, false);
$modal = ilModalGUI::getInstance();
$modal->setId("OpencastSelectionModal");
$modal->setType(ilModalGUI::TYPE_LARGE);
$tpl_modal->setVariable('MODAL', $modal->getHTML());
$tpl_modal->setVariable('AJAX_URL', $this->ajax_url);
$this->dic->ui()->mainTemplate()->setVariable('WEBDAV_MODAL', $tpl_modal->get());
$action_text = ilInteractiveVideoPlugin::getInstance()->txt('opc_select_video');
$opc_inject_text = new ilHiddenInputGUI('opc_inject_text');
$opc_inject_text->setValue($action_text);
$option->addSubItem($opc_inject_text);
$this->restoreIlCtrl($ctrl);
if($object->getOpcId() === self::OPC_DUMMY_ID){
$this->dic->ui()->mainTemplate()->addOnLoadCode('il.opcMediaPortalAjaxQuery.openSelectionModal(true);');
}
return $option;
}
public function getAjaxOpenCastTable(){
global $DIC;
$tpl_json = ilInteractiveVideoPlugin::getInstance()->getTemplate('default/tpl.show_question.html', false, false);
$tpl_json->setVariable('JSON', $this->getTable($DIC)->getHTML());
$tpl_json->show("DEFAULT", false, true );
exit();
}
/**
* @param ilPropertyFormGUI $form
* @return bool
*/
public function checkForm($form) :bool
{
$opc_url = ilUtil::stripSlashes($_POST['opc_url']);
if($opc_url != '' )
{
return true;
}
return false;
}
/**
* @param ilTemplate $tpl
* @return ilTemplate
*/
public function addPlayerElements($tpl)
{
$tpl->addJavaScript('Customizing/global/plugins/Services/Repository/RepositoryObject/InteractiveVideo/VideoSources/plugin/InteractiveVideoOpenCast/js/jquery.InteractiveVideoOpenCastPlayer.js');
ilPlayerUtil::initMediaElementJs($tpl, false);
return $tpl;
}
/**
* @param $player_id
* @param ilObjInteractiveVideo $obj
* @return ilTemplate
*/
public function getPlayer($player_id, $obj)
{
$player = new ilTemplate('Customizing/global/plugins/Services/Repository/RepositoryObject/InteractiveVideo/VideoSources/plugin/InteractiveVideoOpenCast/tpl/tpl.video.html', false, false);
$instance = new ilInteractiveVideoOpenCast();
$instance->doReadVideoSource($obj->getId());
if($instance->getOpcId() !== self::OPC_DUMMY_ID) {
$player->setVariable('PLAYER_ID', $player_id);
$url = xoctSecureLink::signPlayer($this->getVideoUrl($instance->getOpcId()));
# $signed_url = xoctConf::getConfig(xoctConf::F_SIGN_DOWNLOAD_LINKS) ? xoctSecureLink::signDownload($url) : $url;
$player->setVariable('OPC_URL', $url);
}
return $player;
}
/**
* @param array $a_values
* @param ilObjInteractiveVideo $obj
*/
public function getEditFormCustomValues(array &$a_values, $obj)
{
$instance = new ilInteractiveVideoOpenCast();
$instance->doReadVideoSource($obj->getId());
$a_values[ilInteractiveVideoOpenCast::FORM_ID_FIELD] = '';
if($instance->getOpcId() !== self::OPC_DUMMY_ID){
$a_values[ilInteractiveVideoOpenCast::FORM_ID_FIELD] = $instance->getOpcId();
}
$a_values[ilInteractiveVideoOpenCast::FORM_URL_FIELD] = $instance->getOpcUrl();
}
/**
* @param $form
*/
public function getConfigForm($form)
{
$event_id = $_GET[VideoSearchTableGUI::GET_PARAM_EVENT_ID];
}
/**
* @return boolean
*/
public function hasOwnConfigForm() : bool
{
return false;
}
/**
* @param ILIAS\DI\Container $dic
* @return VideoSearchTableGUI
* @throws \srag\DIC\OpencastPageComponent\Exception\DICException
*/
protected function getTable(ILIAS\DI\Container $dic) : VideoSearchTableGUI{
$this->createCtrlFake($dic);
$table = new VideoSearchTableGUI($this->ilCtrlFake, self::CMD_INDEX, $dic, $this->command_url);
$table->setLimit(999999);
$table->initializeData();
return $table;
}
/**
* @throws \srag\DIC\OpencastPageComponent\Exception\DICException
*/
public function applyFilter() {
global $DIC;
$table = $this->getTable($DIC);
$table->resetOffset();
$table->writeFilterToSession();
$this->dic->ctrl()->redirect(new ilObjInteractiveVideoGUI(), 'editProperties');
}
/**
*
*/
public function resetFilter() {
global $DIC;
$table = $this->getTable($DIC);
$table->resetOffset();
$table->resetFilter();
$this->dic->ctrl()->redirect(new ilObjInteractiveVideoGUI(), 'editProperties');
}
/**
* @param string $event_id
* @return string
* @throws ilException
* @throws xoctException
*/
protected function getVideoUrl(string $event_id) : string {
$event = xoctInternalAPI::getInstance()->events()->read($event_id);
$download_dtos = $event->publications()->getDownloadDtos(); // sortiert nach Auflösung (descending)
if (empty($download_dtos)) {
throw new ilException('Video with id ' . $event_id . ' has no valid download url');
}
return array_shift($download_dtos)->getUrl(); // höchste Auflösung, URL unter Umständen signiert (nur temporär gültig)
}
/**
* @return ilCtrl
*/
private function getIlCtrlTabFake() : ilCtrl
{
$oldIlCtrl = $this->dic->ctrl();
unset($this->dic['ilCtrl']);
$ilCtrlFake = new class($oldIlCtrl) extends ilCtrl {
/** @var array[] */
protected $linkTargets = [];
private $oldIlCtrl;
/**
* constructor.
* @param ilCtrl $oldIlCtrl
*/
public function __construct(ilCtrl $oldIlCtrl)
{
$this->oldIlCtrl = $oldIlCtrl;
}
/**
* @inheritDoc
*/
public function getLinkTargetByClass(
$a_class,
$a_cmd = "",
$a_anchor = "",
$a_asynch = false,
$xml_style = true
) {
$this->oldIlCtrl->setParameter(new ilObjInteractiveVideoGUI(), 'xvid_plugin_ctrl', ilInteractiveVideoOpenCastGUI::class);
$this->oldIlCtrl->setParameter(new ilObjInteractiveVideoGUI(), 'xvid_source_id', 'opc');
$this->oldIlCtrl->setParameter(new ilObjInteractiveVideoGUI(), 'xvid_custom_js', 'il.opcMediaPortalAjaxQuery.openSelectionModal(false)');
return $this->oldIlCtrl->getLinkTargetByClass([ilRepositoryGUI::class, ilObjPluginDispatchGUI::class, ilObjInteractiveVideoGUI::class], $a_cmd,$a_anchor, $a_asynch, $xml_style );
}
/**
* @return array
*/
public function getLinkTargets() : array
{
return $this->linkTargets;
}
};
$GLOBALS['ilCtrl'] = $ilCtrlFake;
$this->dic['ilCtrl'] = static function (Container $e) use ($ilCtrlFake) : ilCtrl {
return $ilCtrlFake;
};
return $ilCtrlFake;
}
/**
* @param ilCtrl $ctrl
*/
private function restoreIlCtrl(ilCtrl $ctrl) : void
{
unset($this->dic['ilCtrl']);
$GLOBALS['ilCtrl'] = $ctrl;
$this->dic['ilCtrl'] = static function (Container $e) : ilCtrl {
return $GLOBALS['ilCtrl'];
};
}
/**
* @param $dic
*/
public function createCtrlFake($dic): void
{
$dic->ctrl()->clearParameterByClass(self::class, self::CUSTOM_CMD);
$this->command_url = $dic->ctrl()->getLinkTargetByClass(['ilRepositoryGUI', 'ilObjInteractiveVideoGUI'], 'ilInteractiveVideoOpenCastGUI::create');
$dic->ctrl()->setParameter($this, self::CUSTOM_CMD, self::CMD_APPLY_FILTER);
$this->dic = $dic;
$this->ilCtrlFake = $this->getIlCtrlTabFake($this->dic);
$this->ajax_url = $this->ilCtrlFake->getLinkTargetByClass(['ilRepositoryGUI', 'ilObjInteractiveVideoGUI'], 'getAjaxOpenCastTable','', true, false);
}
}