ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilObjMediaCast.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2011 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5require_once "./Services/Object/classes/class.ilObject.php";
6
15{
19 protected $user;
20
21 //public static $purposes = array("Standard", "VideoAlternative", "VideoPortable", "AudioPortable");
22 public static $purposes = array("Standard");
23 protected $online = false;
24 protected $publicfiles = false;
25 protected $downloadable = true;
26 protected $order;
27 protected $view_mode = "";
28
29 const ORDER_TITLE = 1;
32 const ORDER_MANUAL = 4;
33
34 const VIEW_LIST = "";
35 const VIEW_GALLERY = "gallery";
36
42 protected $defaultAccess = 0;
43
44 // mapping for copy process
45 protected $mob_mapping = [];
46
53 public function __construct($a_id = 0, $a_call_by_reference = true)
54 {
55 global $DIC;
56
57 $this->db = $DIC->database();
58 $this->user = $DIC->user();
59 $this->type = "mcst";
60 parent::__construct($a_id, $a_call_by_reference);
61 $mcst_set = new ilSetting("mcst");
62 $this->setDefaultAccess($mcst_set->get("defaultaccess") == "users" ? 0 : 1);
63 $this->setOrder(self::ORDER_CREATION_DATE_DESC);
64 }
65
71 public function setOnline($a_online)
72 {
73 $this->online = $a_online;
74 }
75
81 public function getOnline()
82 {
83 return $this->online;
84 }
85
91 public function setPublicFiles($a_publicfiles)
92 {
93 $this->publicfiles = $a_publicfiles;
94 }
95
101 public function getPublicFiles()
102 {
103 return $this->publicfiles;
104 }
105
111 public function setViewMode($a_val)
112 {
113 $this->view_mode = $a_val;
114 }
115
121 public function getViewMode()
122 {
123 return $this->view_mode;
124 }
130 public function setItemsArray($a_itemsarray)
131 {
132 $this->itemsarray = $a_itemsarray;
133 }
134
140 public function getItemsArray()
141 {
142 return $this->itemsarray;
143 }
144
151 public function getSortedItemsArray()
152 {
153 $med_items = $this->getItemsArray();
154
155 // sort by order setting
156 switch ($this->getOrder()) {
158 $med_items = ilUtil::sortArray($med_items, "title", "asc", false, true);
159 break;
160
162 $med_items = ilUtil::sortArray($med_items, "creation_date", "asc", false, true);
163 break;
164
166 $med_items = ilUtil::sortArray($med_items, "creation_date", "desc", false, true);
167 break;
168
170 $order = array_flip($this->readOrder());
171 $pos = sizeof($order);
172 foreach (array_keys($med_items) as $idx) {
173 if (array_key_exists($idx, $order)) {
174 $med_items[$idx]["order"] = ($order[$idx] + 1) * 10;
175 }
176 // item has no order yet
177 else {
178 $med_items[$idx]["order"] = (++$pos) * 10;
179 }
180 }
181
182 $med_items = ilUtil::sortArray($med_items, "order", "asc", true, true);
183 break;
184 }
185
186 return $med_items;
187 }
188
189
195 public function setDownloadable($a_downloadable)
196 {
197 $this->downloadable = $a_downloadable;
198 }
204 public function getDownloadable()
205 {
206 return $this->downloadable;
207 }
208
214 public function getDefaultAccess()
215 {
217 }
218
224 public function setDefaultAccess($value)
225 {
226 $this->defaultAccess = (int) $value == 0 ? 0 : 1;
227 }
228
234 public function setOrder($a_value)
235 {
236 $this->order = $a_value;
237 }
243 public function getOrder()
244 {
245 return $this->order;
246 }
247
254 public function getDiskUsage()
255 {
256 require_once("./Modules/MediaCast/classes/class.ilObjMediaCastAccess.php");
258 }
259
263 public function create()
264 {
266
267 parent::create();
268
269 $query = "INSERT INTO il_media_cast_data (" .
270 " id" .
271 ", is_online" .
272 ", public_files" .
273 ", downloadable" .
274 ", def_access" .
275 ", sortmode" .
276 ", viewmode" .
277 " ) VALUES (" .
278 $ilDB->quote($this->getId(), "integer")
279 . "," . $ilDB->quote((int) $this->getOnline(), "integer")
280 . "," . $ilDB->quote((int) $this->getPublicFiles(), "integer")
281 . "," . $ilDB->quote((int) $this->getDownloadable(), "integer")
282 . "," . $ilDB->quote((int) $this->getDefaultAccess(), "integer")
283 . "," . $ilDB->quote((int) $this->getOrder(), "integer")
284 . "," . $ilDB->quote((int) $this->getViewMode(), "text")
285 . ")";
286 $ilDB->manipulate($query);
287 }
288
295 public function update()
296 {
298
299 if (!parent::update()) {
300 return false;
301 }
302
303 // update media cast data
304 $query = "UPDATE il_media_cast_data SET " .
305 " is_online = " . $ilDB->quote((int) $this->getOnline(), "integer") .
306 ", public_files = " . $ilDB->quote((int) $this->getPublicFiles(), "integer") .
307 ", downloadable = " . $ilDB->quote((int) $this->getDownloadable(), "integer") .
308 ", def_access = " . $ilDB->quote((int) $this->getDefaultAccess(), "integer") .
309 ", sortmode = " . $ilDB->quote((int) $this->getOrder(), "integer") .
310 ", viewmode = " . $ilDB->quote($this->getViewMode(), "text") .
311 " WHERE id = " . $ilDB->quote((int) $this->getId(), "integer");
312
313 $ilDB->manipulate($query);
314
315 return true;
316 }
317
321 public function read()
322 {
324
325 parent::read();
326 $this->readItems();
327
328 $query = "SELECT * FROM il_media_cast_data WHERE id = " .
329 $ilDB->quote($this->getId(), "integer");
330 $set = $ilDB->query($query);
331 $rec = $ilDB->fetchAssoc($set);
332
333 $this->setOnline($rec["is_online"]);
334 $this->setPublicFiles($rec["public_files"]);
335 $this->setDownloadable($rec["downloadable"]);
336 $this->setDefaultAccess($rec["def_access"]);
337 $this->setOrder($rec["sortmode"]);
338 $this->setViewMode($rec["viewmode"]);
339 }
340
341
348 public function delete()
349 {
351
352 // always call parent delete function first!!
353 if (!parent::delete()) {
354 return false;
355 }
356
357 // delete all items
358 $med_items = $this->getItemsArray();
359 foreach ($med_items as $item) {
360 include_once("./Services/News/classes/class.ilNewsItem.php");
361 $news_item = new ilNewsItem($item["id"]);
362 $news_item->delete();
363 }
364
365 $this->deleteOrder();
366
367 // delete record of table il_media_cast_data
368 $query = "DELETE FROM il_media_cast_data" .
369 " WHERE id = " . $ilDB->quote($this->getId(), "integer");
370 $ilDB->manipulate($query);
371
372 return true;
373 }
374
378 public function readItems($a_oldest_first = false)
379 {
380 //
381 include_once("./Services/News/classes/class.ilNewsItem.php");
382 $it = new ilNewsItem();
383 $it->setContextObjId($this->getId());
384 $it->setContextObjType($this->getType());
385 $this->itemsarray = $it->queryNewsForContext(false, 0, "", false, $a_oldest_first);
386
387 return $this->itemsarray;
388 }
389
390 public function deleteOrder()
391 {
393
394 if (!$this->getId()) {
395 return;
396 }
397
398 $sql = "DELETE FROM il_media_cast_data_ord" .
399 " WHERE obj_id = " . $ilDB->quote($this->getId(), "integer");
400 $ilDB->manipulate($sql);
401 }
402
403 public function readOrder()
404 {
406
407 if (!$this->getId()) {
408 return;
409 }
410
411 $all = array();
412 $sql = "SELECT item_id FROM il_media_cast_data_ord" .
413 " WHERE obj_id = " . $ilDB->quote($this->getId(), "integer") .
414 " ORDER BY pos";
415 $res = $ilDB->query($sql);
416 while ($row = $ilDB->fetchAssoc($res)) {
417 $all[] = $row["item_id"];
418 }
419 return $all;
420 }
421
422 public function saveOrder(array $a_items)
423 {
425
426 if (!$this->getId()) {
427 return;
428 }
429
430 $this->deleteOrder();
431
432 $pos = 0;
433 foreach ($a_items as $item_id) {
434 $pos++;
435
436 $sql = "INSERT INTO il_media_cast_data_ord (obj_id,item_id,pos)" .
437 " VALUES (" . $ilDB->quote($this->getId(), "integer") . "," .
438 $ilDB->quote($item_id, "integer") . "," .
439 $ilDB->quote($pos, "integer") . ")";
440 $ilDB->manipulate($sql);
441 }
442 }
443
447 protected function copyOrder($newObj, $mapping)
448 {
449 $items = [];
450 foreach ($this->readOrder() as $i) {
451 $items[] = $mapping[$i];
452 }
453 $newObj->saveOrder($items);
454 }
455
462 public function cloneObject($a_target_id, $a_copy_id = 0, $a_omit_tree = false)
463 {
464 $new_obj = parent::cloneObject($a_target_id, $a_copy_id, $a_omit_tree);
465
466 //copy online status if object is not the root copy object
467 $cp_options = ilCopyWizardOptions::_getInstance($a_copy_id);
468
469 if (!$cp_options->isRootNode($this->getRefId())) {
470 $new_obj->setOnline($this->getOnline());
471 }
472
473 //$new_obj->setTitle($this->getTitle());
474 $new_obj->setPublicFiles($this->getPublicFiles());
475 $new_obj->setDownloadable($this->getDownloadable());
476 $new_obj->setDefaultAccess($this->getDefaultAccess());
477 $new_obj->setOrder($this->getOrder());
478 $new_obj->setViewMode($this->getViewMode());
479 $new_obj->update();
480
481 include_once("./Services/Block/classes/class.ilBlockSetting.php");
482 $pf = ilBlockSetting::_lookup("news", "public_feed", 0, $this->getId());
483 $keeprss = (int) ilBlockSetting::_lookup("news", "keep_rss_min", 0, $this->getId());
484 ilBlockSetting::_write("news", "public_feed", $pf, 0, $new_obj->getId());
485 ilBlockSetting::_write("news", "keep_rss_min", $keeprss, 0, $new_obj->getId());
486
487 // copy items
488 $mapping = $this->copyItems($new_obj);
489 $this->copyOrder($new_obj, $mapping);
490
491
492 // clone LP settings
493 include_once('./Services/Tracking/classes/class.ilLPObjSettings.php');
494 $obj_settings = new ilLPObjSettings($this->getId());
495 $obj_settings->cloneSettings($new_obj->getId());
496 unset($obj_settings);
497
500 $olp = ilObjectLP::getInstance($this->getId());
501 $collection = $olp->getCollectionInstance();
502 if ($collection) {
503 $collection->cloneCollection($new_obj->getRefId(), $cp_options->getCopyId(), $this->mob_mapping);
504 }
505
506 return $new_obj;
507 }
508
515 public function copyItems($a_new_obj)
516 {
518
519 $item_mapping = [];
520 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
521 foreach ($this->readItems(true) as $item) {
522 // copy media object
523 $mob_id = $item["mob_id"];
524 $mob = new ilObjMediaObject($mob_id);
525 $new_mob = $mob->duplicate();
526
527 // copy news item
528 // create new media cast item
529 include_once("./Services/News/classes/class.ilNewsItem.php");
530 $mc_item = new ilNewsItem();
531 $mc_item->setMobId($new_mob->getId());
532 $mc_item->setContentType(NEWS_AUDIO);
533 $mc_item->setContextObjId($a_new_obj->getId());
534 $mc_item->setContextObjType($a_new_obj->getType());
535 $mc_item->setUserId($ilUser->getId());
536 $mc_item->setPlaytime($item["playtime"]);
537 $mc_item->setTitle($item["title"]);
538 $mc_item->setContent($item["content"]);
539 $mc_item->setVisibility($item["visibility"]);
540 $mc_item->create();
541 $this->mob_mapping[$mob_id] = $new_mob->getId();
542 $item_mapping[$item["id"]] = $mc_item->getId();
543 }
544 return $item_mapping;
545 }
546
547 public function handleLPUpdate($a_user_id, $a_mob_id)
548 {
549 // using read events to persist mob status
550 require_once 'Services/Tracking/classes/class.ilChangeEvent.php';
552 "mob",
553 $this->getRefId(),
554 $a_mob_id,
555 $a_user_id
556 );
557
558 // trigger LP update
559 require_once 'Services/Tracking/classes/class.ilLPStatusWrapper.php';
560 ilLPStatusWrapper::_updateStatus($this->getId(), $a_user_id);
561 }
562
569 public function addMobToCast($mob_id, $user_id, $long_desc = "")
570 {
571 $mob = new ilObjMediaObject($mob_id);
572 $news_set = new ilSetting("news");
573 $enable_internal_rss = $news_set->get("enable_rss_for_internal");
574
575 // create new media cast item
576 $mc_item = new ilNewsItem();
577 $mc_item->setMobId($mob->getId());
578 $mc_item->setContentType(NEWS_AUDIO);
579 $mc_item->setContextObjId($this->getId());
580 $mc_item->setContextObjType($this->getType());
581 $mc_item->setUserId($user_id);
582 $med_item = $mob->getMediaItem("Standard");
583 $mc_item->setPlaytime($this->getPlaytimeForSeconds($med_item->getDuration()));
584 $mc_item->setTitle($mob->getTitle());
585 $mc_item->setContent($mob->getLongDescription());
586 if ($long_desc != "") {
587 $mc_item->setContent($long_desc);
588 }
589 $mc_item->setLimitation(false);
590 // @todo handle visibility
591 $mc_item->create();
592
593 $lp = ilObjectLP::getInstance($this->getId());
594
595 // see ilLPListOfSettingsGUI assign
596 $collection = $lp->getCollectionInstance();
597 if ($collection && $collection->hasSelectableItems()) {
598 /* not yet...
599 $collection->activateEntries([$mob_id]);
600 $lp->resetCaches();
601 ilLPStatusWrapper::_refreshStatus($this->getId());
602 */
603 }
604 return $mc_item->getId();
605 }
606
612 protected function getPlaytimeForSeconds(int $seconds)
613 {
614 $hours = floor($seconds / 3600);
615 $minutes = floor(($seconds % 3600) / 60);
616 $seconds = $seconds % 60;
617 $duration = str_pad($hours, 2, "0", STR_PAD_LEFT) . ":" .
618 str_pad($minutes, 2, "0", STR_PAD_LEFT) . ":" .
619 str_pad($seconds, 2, "0", STR_PAD_LEFT);
620 return $duration;
621 }
622}
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
const NEWS_AUDIO
static _write($a_type, $a_setting, $a_value, $a_user=0, $a_block_id=0)
Write setting to database.
static _lookup($a_type, $a_setting, $a_user=0, $a_block_id=0)
Lookup setting from database.
static _recordReadEvent( $a_type, $a_ref_id, $obj_id, $usr_id, $isCatchupWriteEvents=true, $a_ext_rc=false, $a_ext_time=false)
Records a read event and catches up with write events.
static _getInstance($a_copy_id)
Get instance of copy wizard options.
static _updateStatus($a_obj_id, $a_usr_id, $a_obj=null, $a_percentage=false, $a_force_raise=false)
Update status.
static _lookupDiskUsage($a_id)
Returns the number of bytes used on the harddisk by the file object with the specified object id.
Class ilObjMediaCast.
setDownloadable($a_downloadable)
Set Downloadable.
getPublicFiles()
Get PublicFiles.
getOnline()
Get Online.
saveOrder(array $a_items)
setOnline($a_online)
Set Online.
update()
update object data
read()
Read media cast.
setDefaultAccess($value)
set default access: 0 logged in users, 1 for public access
getDefaultAccess()
return default access for news items
setOrder($a_value)
Set order.
setItemsArray($a_itemsarray)
Set ItemsArray.
getItemsArray()
Get ItemsArray.
copyItems($a_new_obj)
Copy items.
getSortedItemsArray()
Get sorted items array.
getDownloadable()
Get Downloadable.
handleLPUpdate($a_user_id, $a_mob_id)
__construct($a_id=0, $a_call_by_reference=true)
Constructor @access public.
setViewMode($a_val)
Set view mode.
readItems($a_oldest_first=false)
Get all items of media cast.
getPlaytimeForSeconds(int $seconds)
Get playtime for seconds.
getViewMode()
Get view mode.
addMobToCast($mob_id, $user_id, $long_desc="")
Add mob to cast.
setPublicFiles($a_publicfiles)
Set PublicFiles.
create()
Create mew media cast.
getDiskUsage()
Gets the disk usage of the object in bytes.
copyOrder($newObj, $mapping)
Copy order.
Class ilObjMediaObject.
static getInstance($a_obj_id)
Class ilObject Basic functions for all objects.
getType()
get object type @access public
getRefId()
get reference id @access public
getId()
get object id @access public
ILIAS Setting Class.
static sortArray( $array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
global $DIC
Definition: goto.php:24
$ilUser
Definition: imgupload.php:18
$i
Definition: metadata.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$query
foreach($_POST as $key=> $value) $res
global $ilDB