ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
5 require_once "./Services/Object/classes/class.ilObject.php";
6 
14 class ilObjMediaCast extends ilObject
15 {
19  protected $user;
20 
21  public static $purposes = array("Standard", "VideoAlternative", "VideoPortable", "AudioPortable");
22  protected $online = false;
23  protected $publicfiles = false;
24  protected $downloadable = true;
25  protected $order;
26  protected $view_mode = "";
27 
28  const ORDER_TITLE = 1;
31  const ORDER_MANUAL = 4;
32 
33  const VIEW_LIST = "";
34  const VIEW_GALLERY = "gallery";
35 
41  protected $defaultAccess = 0;
42 
43  // mapping for copy process
44  protected $mob_mapping = [];
45 
52  public function __construct($a_id = 0, $a_call_by_reference = true)
53  {
54  global $DIC;
55 
56  $this->db = $DIC->database();
57  $this->user = $DIC->user();
58  $this->type = "mcst";
59  parent::__construct($a_id, $a_call_by_reference);
60  $mcst_set = new ilSetting("mcst");
61  $this->setDefaultAccess($mcst_set->get("defaultaccess") == "users" ? 0 : 1);
62  $this->setOrder(self::ORDER_CREATION_DATE_DESC);
63  }
64 
70  public function setOnline($a_online)
71  {
72  $this->online = $a_online;
73  }
74 
80  public function getOnline()
81  {
82  return $this->online;
83  }
84 
90  public function setPublicFiles($a_publicfiles)
91  {
92  $this->publicfiles = $a_publicfiles;
93  }
94 
100  public function getPublicFiles()
101  {
102  return $this->publicfiles;
103  }
104 
110  public function setViewMode($a_val)
111  {
112  $this->view_mode = $a_val;
113  }
114 
120  public function getViewMode()
121  {
122  return $this->view_mode;
123  }
129  public function setItemsArray($a_itemsarray)
130  {
131  $this->itemsarray = $a_itemsarray;
132  }
133 
139  public function getItemsArray()
140  {
141  return $this->itemsarray;
142  }
143 
150  public function getSortedItemsArray()
151  {
152  $med_items = $this->getItemsArray();
153 
154  // sort by order setting
155  switch ($this->getOrder()) {
157  $med_items = ilUtil::sortArray($med_items, "title", "asc", false, true);
158  break;
159 
161  $med_items = ilUtil::sortArray($med_items, "creation_date", "asc", false, true);
162  break;
163 
165  $med_items = ilUtil::sortArray($med_items, "creation_date", "desc", false, true);
166  break;
167 
169  $order = array_flip($this->readOrder());
170  $pos = sizeof($order);
171  foreach (array_keys($med_items) as $idx) {
172  if (array_key_exists($idx, $order)) {
173  $med_items[$idx]["order"] = ($order[$idx]+1)*10;
174  }
175  // item has no order yet
176  else {
177  $med_items[$idx]["order"] = (++$pos)*10;
178  }
179  }
180 
181  $med_items = ilUtil::sortArray($med_items, "order", "asc", true, true);
182  break;
183  }
184 
185  return $med_items;
186  }
187 
188 
194  public function setDownloadable($a_downloadable)
195  {
196  $this->downloadable = $a_downloadable;
197  }
203  public function getDownloadable()
204  {
205  return $this->downloadable;
206  }
207 
213  public function getDefaultAccess()
214  {
215  return $this->defaultAccess;
216  }
217 
223  public function setDefaultAccess($value)
224  {
225  $this->defaultAccess = (int) $value == 0 ? 0 : 1;
226  }
227 
233  public function setOrder($a_value)
234  {
235  $this->order = $a_value;
236  }
242  public function getOrder()
243  {
244  return $this->order;
245  }
246 
253  public function getDiskUsage()
254  {
255  require_once("./Modules/MediaCast/classes/class.ilObjMediaCastAccess.php");
256  return ilObjMediaCastAccess::_lookupDiskUsage($this->id);
257  }
258 
262  public function create()
263  {
264  $ilDB = $this->db;
265 
266  parent::create();
267 
268  $query = "INSERT INTO il_media_cast_data (" .
269  " id" .
270  ", is_online" .
271  ", public_files" .
272  ", downloadable" .
273  ", def_access" .
274  ", sortmode" .
275  ", viewmode" .
276  " ) VALUES (" .
277  $ilDB->quote($this->getId(), "integer")
278  . "," . $ilDB->quote((int) $this->getOnline(), "integer")
279  . "," . $ilDB->quote((int) $this->getPublicFiles(), "integer")
280  . "," . $ilDB->quote((int) $this->getDownloadable(), "integer")
281  . "," . $ilDB->quote((int) $this->getDefaultAccess(), "integer")
282  . "," . $ilDB->quote((int) $this->getOrder(), "integer")
283  . "," . $ilDB->quote((int) $this->getViewMode(), "text")
284  . ")";
285  $ilDB->manipulate($query);
286  }
287 
294  public function update()
295  {
296  $ilDB = $this->db;
297 
298  if (!parent::update()) {
299  return false;
300  }
301 
302  // update media cast data
303  $query = "UPDATE il_media_cast_data SET " .
304  " is_online = " . $ilDB->quote((int) $this->getOnline(), "integer") .
305  ", public_files = " . $ilDB->quote((int) $this->getPublicFiles(), "integer") .
306  ", downloadable = " . $ilDB->quote((int) $this->getDownloadable(), "integer") .
307  ", def_access = " . $ilDB->quote((int) $this->getDefaultAccess(), "integer") .
308  ", sortmode = " . $ilDB->quote((int) $this->getOrder(), "integer") .
309  ", viewmode = " . $ilDB->quote($this->getViewMode(), "text") .
310  " WHERE id = " . $ilDB->quote((int) $this->getId(), "integer");
311 
312  $ilDB->manipulate($query);
313 
314  return true;
315  }
316 
320  public function read()
321  {
322  $ilDB = $this->db;
323 
324  parent::read();
325  $this->readItems();
326 
327  $query = "SELECT * FROM il_media_cast_data WHERE id = " .
328  $ilDB->quote($this->getId(), "integer");
329  $set = $ilDB->query($query);
330  $rec = $ilDB->fetchAssoc($set);
331 
332  $this->setOnline($rec["is_online"]);
333  $this->setPublicFiles($rec["public_files"]);
334  $this->setDownloadable($rec["downloadable"]);
335  $this->setDefaultAccess($rec["def_access"]);
336  $this->setOrder($rec["sortmode"]);
337  $this->setViewMode($rec["viewmode"]);
338  }
339 
340 
347  public function delete()
348  {
349  $ilDB = $this->db;
350 
351  // always call parent delete function first!!
352  if (!parent::delete()) {
353  return false;
354  }
355 
356  // delete all items
357  $med_items = $this->getItemsArray();
358  foreach ($med_items as $item) {
359  include_once("./Services/News/classes/class.ilNewsItem.php");
360  $news_item = new ilNewsItem($item["id"]);
361  $news_item->delete();
362  }
363 
364  $this->deleteOrder();
365 
366  // delete record of table il_media_cast_data
367  $query = "DELETE FROM il_media_cast_data" .
368  " WHERE id = " . $ilDB->quote($this->getId(), "integer");
369  $ilDB->manipulate($query);
370 
371  return true;
372  }
373 
377  public function readItems($a_oldest_first = false)
378  {
379  //
380  include_once("./Services/News/classes/class.ilNewsItem.php");
381  $it = new ilNewsItem();
382  $it->setContextObjId($this->getId());
383  $it->setContextObjType($this->getType());
384  $this->itemsarray = $it->queryNewsForContext(false, 0, "", false, $a_oldest_first);
385 
386  return $this->itemsarray;
387  }
388 
389  public function deleteOrder()
390  {
391  $ilDB = $this->db;
392 
393  if (!$this->getId()) {
394  return;
395  }
396 
397  $sql = "DELETE FROM il_media_cast_data_ord" .
398  " WHERE obj_id = " . $ilDB->quote($this->getId(), "integer");
399  $ilDB->manipulate($sql);
400  }
401 
402  public function readOrder()
403  {
404  $ilDB = $this->db;
405 
406  if (!$this->getId()) {
407  return;
408  }
409 
410  $all = array();
411  $sql = "SELECT item_id FROM il_media_cast_data_ord" .
412  " WHERE obj_id = " . $ilDB->quote($this->getId(), "integer") .
413  " ORDER BY pos";
414  $res = $ilDB->query($sql);
415  while ($row = $ilDB->fetchAssoc($res)) {
416  $all[] = $row["item_id"];
417  }
418  return $all;
419  }
420 
421  public function saveOrder(array $a_items)
422  {
423  $ilDB = $this->db;
424 
425  if (!$this->getId()) {
426  return;
427  }
428 
429  $this->deleteOrder();
430 
431  $pos = 0;
432  foreach ($a_items as $item_id) {
433  $pos++;
434 
435  $sql = "INSERT INTO il_media_cast_data_ord (obj_id,item_id,pos)" .
436  " VALUES (" . $ilDB->quote($this->getId(), "integer") . "," .
437  $ilDB->quote($item_id, "integer") . "," .
438  $ilDB->quote($pos, "integer") . ")";
439  $ilDB->manipulate($sql);
440  }
441  }
442 
449  public function cloneObject($a_target_id, $a_copy_id = 0, $a_omit_tree = false)
450  {
451  $new_obj = parent::cloneObject($a_target_id, $a_copy_id, $a_omit_tree);
452 
453  //copy online status if object is not the root copy object
454  $cp_options = ilCopyWizardOptions::_getInstance($a_copy_id);
455 
456  if (!$cp_options->isRootNode($this->getRefId())) {
457  $new_obj->setOnline($this->getOnline());
458  }
459 
460  //$new_obj->setTitle($this->getTitle());
461  $new_obj->setPublicFiles($this->getPublicFiles());
462  $new_obj->setDownloadable($this->getDownloadable());
463  $new_obj->setDefaultAccess($this->getDefaultAccess());
464  $new_obj->setOrder($this->getOrder());
465  $new_obj->setViewMode($this->getViewMode());
466  $new_obj->update();
467 
468  include_once("./Services/Block/classes/class.ilBlockSetting.php");
469  $pf = ilBlockSetting::_lookup("news", "public_feed", 0, $this->getId());
470  $keeprss = (int) ilBlockSetting::_lookup("news", "keep_rss_min", 0, $this->getId());
471  ilBlockSetting::_write("news", "public_feed", $pf, 0, $new_obj->getId());
472  ilBlockSetting::_write("news", "keep_rss_min", $keeprss, 0, $new_obj->getId());
473 
474  // copy items
475  $this->copyItems($new_obj);
476 
477  // copy order!?
478 
479  // clone LP settings
480  include_once('./Services/Tracking/classes/class.ilLPObjSettings.php');
481  $obj_settings = new ilLPObjSettings($this->getId());
482  $obj_settings->cloneSettings($new_obj->getId());
483  unset($obj_settings);
484 
487  $olp = ilObjectLP::getInstance($this->getId());
488  $collection = $olp->getCollectionInstance();
489  if ($collection) {
490  $collection->cloneCollection($new_obj->getRefId(), $cp_options->getCopyId(), $this->mob_mapping);
491  }
492 
493  return $new_obj;
494  }
495 
502  public function copyItems($a_new_obj)
503  {
505 
506  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
507  foreach ($this->readItems(true) as $item) {
508  // copy media object
509  $mob_id = $item["mob_id"];
510  $mob = new ilObjMediaObject($mob_id);
511  $new_mob = $mob->duplicate();
512 
513  // copy news item
514  // create new media cast item
515  include_once("./Services/News/classes/class.ilNewsItem.php");
516  $mc_item = new ilNewsItem();
517  $mc_item->setMobId($new_mob->getId());
518  $mc_item->setContentType(NEWS_AUDIO);
519  $mc_item->setContextObjId($a_new_obj->getId());
520  $mc_item->setContextObjType($a_new_obj->getType());
521  $mc_item->setUserId($ilUser->getId());
522  $mc_item->setPlaytime($item["playtime"]);
523  $mc_item->setTitle($item["title"]);
524  $mc_item->setContent($item["content"]);
525  $mc_item->setVisibility($item["visibility"]);
526  $mc_item->create();
527  $this->mob_mapping[$mob_id] = $new_mob->getId();
528  }
529  }
530 
531  public function handleLPUpdate($a_user_id, $a_mob_id)
532  {
533  // using read events to persist mob status
534  require_once 'Services/Tracking/classes/class.ilChangeEvent.php';
536  "mob",
537  $this->getRefId(),
538  $a_mob_id,
539  $a_user_id
540  );
541 
542  // trigger LP update
543  require_once 'Services/Tracking/classes/class.ilLPStatusWrapper.php';
544  ilLPStatusWrapper::_updateStatus($this->getId(), $a_user_id);
545  }
546 }
static sortArray( $array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
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.
saveOrder(array $a_items)
getDefaultAccess()
return default access for news items
static _write($a_type, $a_setting, $a_value, $a_user=0, $a_block_id=0)
Write setting to database.
global $DIC
Definition: saml.php:7
static _updateStatus($a_obj_id, $a_usr_id, $a_obj=null, $a_percentage=false, $a_force_raise=false)
Update status.
getOnline()
Get Online.
handleLPUpdate($a_user_id, $a_mob_id)
user()
Definition: user.php:4
setOrder($a_value)
Set order.
read()
Read media cast.
static _getInstance($a_copy_id)
Get instance of copy wizard options.
Class ilObjMediaCast.
foreach($_POST as $key=> $value) $res
getId()
get object id public
getViewMode()
Get view mode.
setDownloadable($a_downloadable)
Set Downloadable.
static _lookup($a_type, $a_setting, $a_user=0, $a_block_id=0)
Lookup setting from database.
$ilUser
Definition: imgupload.php:18
create()
Create mew media cast.
Class ilObjMediaObject.
$query
getType()
get object type public
static _lookupDiskUsage($a_id)
Returns the number of bytes used on the harddisk by the file object with the specified object id...
setItemsArray($a_itemsarray)
Set ItemsArray.
setOnline($a_online)
Set Online.
getDownloadable()
Get Downloadable.
Create styles array
The data for the language used.
getItemsArray()
Get ItemsArray.
update()
update object data
update($pash, $contents, Config $config)
setViewMode($a_val)
Set view mode.
__construct($a_id=0, $a_call_by_reference=true)
Constructor public.
getPublicFiles()
Get PublicFiles.
setDefaultAccess($value)
set default access: 0 logged in users, 1 for public access
global $ilDB
getRefId()
get reference id public
readItems($a_oldest_first=false)
Get all items of media cast.
const NEWS_AUDIO
copyItems($a_new_obj)
Copy items.
static getInstance($a_obj_id)
getSortedItemsArray()
Get sorted items array.
setPublicFiles($a_publicfiles)
Set PublicFiles.
getDiskUsage()
Gets the disk usage of the object in bytes.