ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilObjMediaCast.php
Go to the documentation of this file.
1<?php
2
24{
25 public const ORDER_TITLE = 1;
26 public const ORDER_CREATION_DATE_ASC = 2;
27 public const ORDER_CREATION_DATE_DESC = 3;
28 public const ORDER_MANUAL = 4;
29 public const VIEW_LIST = "";
30 public const VIEW_GALLERY = "gallery"; // legacy gallery, @todo remove
31 public const VIEW_IMG_GALLERY = "img_gallery";
32 public const VIEW_PODCAST = "podcast";
33 public const VIEW_VCAST = "video";
34 public const AUTOPLAY_NO = 0;
35 public const AUTOPLAY_ACT = 1;
36 public const AUTOPLAY_INACT = 2;
37 protected bool $comments = false;
38 protected \ILIAS\Notes\Service $notes;
39 protected \ILIAS\MediaCast\InternalDomainService $domain;
40 protected \ILIAS\MediaObjects\Tracking\TrackingManager $mob_tracking;
41
42 protected array $itemsarray;
43 protected ilObjUser $user;
44 public static array $purposes = array("Standard");
45 protected bool $online = false;
46 protected bool $publicfiles = false;
47 protected bool $downloadable = true;
48 protected int $order = 0;
49 protected string $view_mode = self::VIEW_VCAST;
50 protected int $defaultAccess = 0; // 0 = logged in users, 1 = public access
51 protected array $mob_mapping = [];
52 protected int $nr_initial_videos = 5;
53 protected bool $new_items_in_lp = true;
55
56 public function __construct(
57 int $a_id = 0,
58 bool $a_call_by_reference = true
59 ) {
60 global $DIC;
61
62 $this->db = $DIC->database();
63 $this->user = $DIC->user();
64 $this->type = "mcst";
65 $mcst_set = new ilSetting("mcst");
66 $this->setDefaultAccess($mcst_set->get("defaultaccess") == "users" ? 0 : 1);
67 $this->setOrder(self::ORDER_CREATION_DATE_DESC);
68 $this->mob_tracking = $DIC->mediaObjects()->internal()
69 ->domain()
70 ->tracking();
71 $this->notes = $DIC->notes();
72 $this->domain = $DIC->mediaCast()->internal()->domain();
73 parent::__construct($a_id, $a_call_by_reference);
74 }
75
76 public function setOnline(bool $a_online): void
77 {
78 $this->online = $a_online;
79 }
80
81 public function getOnline(): bool
82 {
83 return $this->online;
84 }
85
86 public function setComments(bool $comments): void
87 {
88 $this->comments = $comments;
89 }
90
91 public function getComments(): bool
92 {
93 return $this->comments;
94 }
95
96 public function setPublicFiles(bool $a_publicfiles): void
97 {
98 $this->publicfiles = $a_publicfiles;
99 }
100
101 public function getPublicFiles(): bool
102 {
103 return $this->publicfiles;
104 }
105
106 public function setViewMode(string $a_val): void
107 {
108 $this->view_mode = $a_val;
109 }
110
111 public function getViewMode(): string
112 {
113 return $this->view_mode;
114 }
115
116 public function setItemsArray(array $a_itemsarray): void
117 {
118 $this->itemsarray = $a_itemsarray;
119 }
120
121 public function getItemsArray(): array
122 {
123 return $this->itemsarray;
124 }
125
126 public function setAutoplayMode(int $a_val): void
127 {
128 $this->autoplay_mode = $a_val;
129 }
130
131 public function getAutoplayMode(): int
132 {
134 }
135
136 public function setNumberInitialVideos(int $a_val): void
137 {
138 $this->nr_initial_videos = $a_val;
139 }
140
141 public function getNumberInitialVideos(): int
142 {
144 }
145
149 public function setNewItemsInLearningProgress(bool $a_val): void
150 {
151 $this->new_items_in_lp = $a_val;
152 }
153
154 public function getNewItemsInLearningProgress(): bool
155 {
157 }
158
159 public function getSortedItemsArray(): array
160 {
161 $med_items = $this->getItemsArray();
162 // sort by order setting
163 switch ($this->getOrder()) {
165 $med_items = ilArrayUtil::sortArray($med_items, "title", "asc", false, true);
166 break;
167
169 $med_items = ilArrayUtil::sortArray($med_items, "creation_date", "asc", false, true);
170 break;
171
173 $med_items = ilArrayUtil::sortArray($med_items, "creation_date", "desc", false, true);
174 break;
175
177 $order = array_flip($this->readOrder());
178 $pos = sizeof($order);
179 foreach (array_keys($med_items) as $idx) {
180 if (array_key_exists($idx, $order)) {
181 $med_items[$idx]["order"] = ($order[$idx] + 1) * 10;
182 }
183 // item has no order yet
184 else {
185 $med_items[$idx]["order"] = (++$pos) * 10;
186 }
187 }
188
189 $med_items = ilArrayUtil::sortArray($med_items, "order", "asc", true, true);
190 break;
191 }
192 return $med_items;
193 }
194
195 public function setDownloadable(bool $a_downloadable): void
196 {
197 $this->downloadable = $a_downloadable;
198 }
199
200 public function getDownloadable(): bool
201 {
202 return $this->downloadable;
203 }
204
205 public function getDefaultAccess(): int
206 {
208 }
209
210 public function setDefaultAccess(int $value): void
211 {
212 $this->defaultAccess = ($value === 0) ? 0 : 1;
213 }
214
215 public function setOrder(int $a_value): void
216 {
217 $this->order = $a_value;
218 }
219
220 public function getOrder(): int
221 {
222 return $this->order;
223 }
224
225
226 public function create(): int
227 {
229
230 $id = parent::create();
231
232 $this->createMetaData();
233
234 $query = "INSERT INTO il_media_cast_data (" .
235 " id" .
236 ", is_online" .
237 ", public_files" .
238 ", downloadable" .
239 ", def_access" .
240 ", sortmode" .
241 ", viewmode" .
242 ", autoplaymode" .
243 ", nr_initial_videos" .
244 ", new_items_in_lp" .
245 " ) VALUES (" .
246 $ilDB->quote($this->getId(), "integer")
247 . "," . $ilDB->quote((int) $this->getOnline(), "integer")
248 . "," . $ilDB->quote((int) $this->getPublicFiles(), "integer")
249 . "," . $ilDB->quote((int) $this->getDownloadable(), "integer")
250 . "," . $ilDB->quote((int) $this->getDefaultAccess(), "integer")
251 . "," . $ilDB->quote((int) $this->getOrder(), "integer")
252 . "," . $ilDB->quote($this->getViewMode(), "text")
253 . "," . $ilDB->quote((int) $this->getAutoplayMode(), "integer")
254 . "," . $ilDB->quote((int) $this->getNumberInitialVideos(), "integer")
255 . "," . $ilDB->quote((int) $this->getNewItemsInLearningProgress(), "integer")
256 . ")";
257 $ilDB->manipulate($query);
258 return $id;
259 }
260
261 public function update(): bool
262 {
264
265 if (!parent::update()) {
266 return false;
267 }
268
269 $this->updateMetaData();
270
271 // update media cast data
272 $query = "UPDATE il_media_cast_data SET " .
273 " is_online = " . $ilDB->quote((int) $this->getOnline(), "integer") .
274 ", public_files = " . $ilDB->quote((int) $this->getPublicFiles(), "integer") .
275 ", downloadable = " . $ilDB->quote((int) $this->getDownloadable(), "integer") .
276 ", def_access = " . $ilDB->quote($this->getDefaultAccess(), "integer") .
277 ", sortmode = " . $ilDB->quote($this->getOrder(), "integer") .
278 ", viewmode = " . $ilDB->quote($this->getViewMode(), "text") .
279 ", autoplaymode = " . $ilDB->quote($this->getAutoplayMode(), "integer") .
280 ", nr_initial_videos = " . $ilDB->quote($this->getNumberInitialVideos(), "integer") .
281 ", new_items_in_lp = " . $ilDB->quote($this->getNewItemsInLearningProgress(), "integer") .
282 " WHERE id = " . $ilDB->quote($this->getId(), "integer");
283
284 $ilDB->manipulate($query);
285
286 $this->notes->domain()->activateComments($this->getId(), $this->getComments());
287
288 return true;
289 }
290
291 public function read(): void
292 {
294
295 parent::read();
296 $this->readItems();
297
298 $query = "SELECT * FROM il_media_cast_data WHERE id = " .
299 $ilDB->quote($this->getId(), "integer");
300 $set = $ilDB->query($query);
301 $rec = $ilDB->fetchAssoc($set);
302
303 $this->setOnline((bool) $rec["is_online"]);
304 $this->setPublicFiles((bool) $rec["public_files"]);
305 $this->setDownloadable((bool) $rec["downloadable"]);
306 $this->setDefaultAccess((int) $rec["def_access"]);
307 $this->setOrder((int) $rec["sortmode"]);
308 $this->setViewMode((string) $rec["viewmode"]);
309 $this->setAutoplayMode((int) $rec["autoplaymode"]);
310 $this->setNumberInitialVideos((int) $rec["nr_initial_videos"]);
311 $this->setNewItemsInLearningProgress((bool) $rec["new_items_in_lp"]);
312
313 $this->setComments($this->notes->domain()->commentsActive($this->getId()));
314 }
315
316
317 public function delete(): bool
318 {
320
321 // always call parent delete function first!!
322 if (!parent::delete()) {
323 return false;
324 }
325
326 $this->deleteMetaData();
327
328 // delete all items
329 $med_items = $this->getItemsArray();
330 foreach ($med_items as $item) {
331 $news_item = new ilNewsItem($item["id"]);
332 $news_item->delete();
333 }
334
335 $this->deleteOrder();
336
337 // delete record of table il_media_cast_data
338 $query = "DELETE FROM il_media_cast_data" .
339 " WHERE id = " . $ilDB->quote($this->getId(), "integer");
340 $ilDB->manipulate($query);
341
342 return true;
343 }
344
345 public function readItems(bool $a_oldest_first = false): array
346 {
347 //
348 $it = new ilNewsItem();
349 $it->setContextObjId($this->getId());
350 $it->setContextObjType($this->getType());
351 $this->itemsarray = $it->queryNewsForContext(false, 0, "", false, $a_oldest_first);
352
353 return $this->itemsarray;
354 }
355
356 public function deleteOrder(): void
357 {
359
360 if (!$this->getId()) {
361 return;
362 }
363
364 $sql = "DELETE FROM il_media_cast_data_ord" .
365 " WHERE obj_id = " . $ilDB->quote($this->getId(), "integer");
366 $ilDB->manipulate($sql);
367 }
368
369 public function readOrder(): ?array
370 {
372
373 if (!$this->getId()) {
374 return null;
375 }
376
377 $all = array();
378 $sql = "SELECT item_id FROM il_media_cast_data_ord" .
379 " WHERE obj_id = " . $ilDB->quote($this->getId(), "integer") .
380 " ORDER BY pos";
381 $res = $ilDB->query($sql);
382 while ($row = $ilDB->fetchAssoc($res)) {
383 $all[] = $row["item_id"];
384 }
385 return $all;
386 }
387
388 public function saveOrder(array $a_items): void
389 {
391
392 if (!$this->getId()) {
393 return;
394 }
395 $this->deleteOrder();
396
397 $pos = 0;
398 foreach ($a_items as $item_id) {
399 $pos++;
400
401 $sql = "INSERT INTO il_media_cast_data_ord (obj_id,item_id,pos)" .
402 " VALUES (" . $ilDB->quote($this->getId(), "integer") . "," .
403 $ilDB->quote($item_id, "integer") . "," .
404 $ilDB->quote($pos, "integer") . ")";
405 $ilDB->manipulate($sql);
406 }
407 }
408
409 protected function copyOrder(
410 ilObjMediaCast $newObj,
411 array $mapping
412 ): void {
413 $items = [];
414 foreach ($this->readOrder() as $i) {
415 if (!array_key_exists($i, $mapping)) {
416 continue;
417 }
418 $items[] = $mapping[$i];
419 }
420 $newObj->saveOrder($items);
421 }
422
423 public function cloneObject(int $a_target_id, int $a_copy_id = 0, bool $a_omit_tree = false): ?ilObject
424 {
426 $new_obj = parent::cloneObject($a_target_id, $a_copy_id, $a_omit_tree);
427
428 //copy online status if object is not the root copy object
429 $cp_options = ilCopyWizardOptions::_getInstance($a_copy_id);
430
431 if (!$cp_options->isRootNode($this->getRefId())) {
432 $new_obj->setOnline($this->getOnline());
433 }
434
435 $new_obj->setPublicFiles($this->getPublicFiles());
436 $new_obj->setDownloadable($this->getDownloadable());
437 $new_obj->setDefaultAccess($this->getDefaultAccess());
438 $new_obj->setOrder($this->getOrder());
439 $new_obj->setViewMode($this->getViewMode());
440 $new_obj->setAutoplayMode($this->getAutoplayMode());
441 $new_obj->setNumberInitialVideos($this->getNumberInitialVideos());
442 $new_obj->setNewItemsInLearningProgress($this->getNewItemsInLearningProgress());
443
444 $new_obj->update();
445
446 $pf = ilBlockSetting::_lookup("news", "public_feed", 0, $this->getId());
447 $keeprss = (int) ilBlockSetting::_lookup("news", "keep_rss_min", 0, $this->getId());
448 ilBlockSetting::_write("news", "public_feed", (string) $pf, 0, $new_obj->getId());
449 ilBlockSetting::_write("news", "keep_rss_min", (string) $keeprss, 0, $new_obj->getId());
450
451 // copy items
452 $mapping = $this->copyItems($new_obj);
453
454 $this->copyOrder($new_obj, $mapping);
455
456 // clone LP settings
457 $obj_settings = new ilLPObjSettings($this->getId());
458 $obj_settings->cloneSettings($new_obj->getId());
459 unset($obj_settings);
460
462 $olp = ilObjectLP::getInstance($this->getId());
464 $collection = $olp->getCollectionInstance();
465 if ($collection) {
466 $collection->cloneCollection($new_obj->getRefId(), $cp_options->getCopyId(), $this->mob_mapping);
467 }
468
469 $this->cloneMetaData($new_obj);
470
471 return $new_obj;
472 }
473
474 public function copyItems(ilObjMediaCast $a_new_obj): array
475 {
476 $ilUser = $this->user;
477
478 $item_mapping = [];
479 foreach ($this->readItems(true) as $item) {
480 // copy media object
481 $mob_id = $item["mob_id"];
482 $mob = new ilObjMediaObject($mob_id);
483 $new_mob = $mob->duplicate();
484
485 // copy news item
486 // create new media cast item
487 $mc_item = new ilNewsItem();
488 $mc_item->setMobId($new_mob->getId());
489 $mc_item->setContentType(NEWS_AUDIO);
490 $mc_item->setContextObjId($a_new_obj->getId());
491 $mc_item->setContextObjType($a_new_obj->getType());
492 $mc_item->setUserId($ilUser->getId());
493 $mc_item->setPlaytime($item["playtime"] ?? "");
494 $mc_item->setTitle($item["title"] ?? "");
495 $mc_item->setContent($item["content"] ?? "");
496 $mc_item->setVisibility($item["visibility"] ?? "users");
497 $mc_item->create();
498 $this->mob_mapping[$mob_id] = $new_mob->getId();
499 $item_mapping[$item["id"]] = $mc_item->getId();
500 }
501 return $item_mapping;
502 }
503
504 public function handleLPUpdate(
505 int $a_user_id,
506 int $a_mob_id
507 ): void {
508 $this->mob_tracking->saveCompletion(
509 $a_mob_id,
510 $this->getRefId(),
511 $a_user_id
512 );
513 }
514
518 public function addMobToCast(
519 int $mob_id,
520 int $user_id,
521 string $long_desc = "",
522 bool $extract = false
523 ): int {
524 $mob = new ilObjMediaObject($mob_id);
525 if ($extract) {
526 try {
527 $mob->getExternalMetadata();
528 } catch (Exception $e) {
529 }
530 }
531 $news_set = new ilSetting("news");
532 $enable_internal_rss = $news_set->get("enable_rss_for_internal");
533
534 // create new media cast item
535 $mc_item = new ilNewsItem();
536 $mc_item->setMobId($mob->getId());
537 $mc_item->setContentType(NEWS_AUDIO);
538 $mc_item->setContextObjId($this->getId());
539 $mc_item->setContextObjType($this->getType());
540 $mc_item->setUserId($user_id);
541 $med_item = $mob->getMediaItem("Standard");
542 $mc_item->setPlaytime($this->getPlaytimeForSeconds($med_item->getDuration()));
543 $mc_item->setTitle($mob->getTitle());
544 $mc_item->setContent($mob->getLongDescription());
545 if ($long_desc != "") {
546 $mc_item->setContent($long_desc);
547 }
548 $mc_item->setLimitation(false);
549 $mc_item->setVisibility($this->getDefaultAccess() == 0 ? "users" : "public");
550 $mc_item->create();
551
552 $lp = $this->domain->learningProgress($this);
553 $lp->addItemToLP($mob_id);
554
555 return $mc_item->getId();
556 }
557
561 public function getPlaytimeForSeconds(int $seconds): string
562 {
563 $hours = floor($seconds / 3600);
564 $minutes = floor(($seconds % 3600) / 60);
565 $seconds = $seconds % 60;
566 $duration = str_pad($hours, 2, "0", STR_PAD_LEFT) . ":" .
567 str_pad($minutes, 2, "0", STR_PAD_LEFT) . ":" .
568 str_pad($seconds, 2, "0", STR_PAD_LEFT);
569 return $duration;
570 }
571}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$duration
const NEWS_AUDIO
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)
static _write(string $a_type, string $a_setting, string $a_value, int $a_user=0, int $a_block_id=0)
Write setting to database.
static _lookup(string $a_type, string $a_setting, int $a_user=0, int $a_block_id=0)
Lookup setting from database.
static _getInstance(int $a_copy_id)
A news item can be created by different sources.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(int $a_id=0, bool $a_call_by_reference=true)
copyOrder(ilObjMediaCast $newObj, array $mapping)
setDownloadable(bool $a_downloadable)
setPublicFiles(bool $a_publicfiles)
saveOrder(array $a_items)
setNumberInitialVideos(int $a_val)
setItemsArray(array $a_itemsarray)
setAutoplayMode(int $a_val)
setViewMode(string $a_val)
getPlaytimeForSeconds(int $seconds)
Get playtime for seconds.
setNewItemsInLearningProgress(bool $a_val)
Set new items automatically in lp.
ILIAS MediaObjects Tracking TrackingManager $mob_tracking
ILIAS MediaCast InternalDomainService $domain
setComments(bool $comments)
static array $purposes
ILIAS Notes Service $notes
create()
note: title, description and type should be set when this function is called
readItems(bool $a_oldest_first=false)
copyItems(ilObjMediaCast $a_new_obj)
setOrder(int $a_value)
handleLPUpdate(int $a_user_id, int $a_mob_id)
setDefaultAccess(int $value)
addMobToCast(int $mob_id, int $user_id, string $long_desc="", bool $extract=false)
Add media object to media cast.
setOnline(bool $a_online)
User class.
static getInstance(int $obj_id)
Class ilObject Basic functions for all objects.
ilDBInterface $db
ILIAS Setting Class.
$res
Definition: ltiservices.php:69
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26