ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilDclMobRecordRepresentation.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 {
26  public function getHTML(bool $link = true, array $options = []): string
27  {
28  $value = $this->getRecordField()->getValue();
29 
30  if (is_null($value)) {
31  return "";
32  }
33 
34  // the file is only temporary uploaded. Still need to be confirmed before stored
35  $has_ilfilehash = $this->http->wrapper()->post()->has('ilfilehash');
36  if (is_array($value) && $has_ilfilehash) {
37  $ilfilehash = $this->http->wrapper()->post()->retrieve('ilfilehash', $this->refinery->kindlyTo()->string());
38 
39  $this->ctrl->setParameterByClass(ilDclRecordListGUI::class, "ilfilehash", $ilfilehash);
40  $this->ctrl->setParameterByClass(
41  ilDclRecordListGUI::class,
42  "field_id",
43  $this->getRecordField()->getField()->getId()
44  );
45 
46  return '<a href="' . $this->ctrl->getLinkTargetByClass(
47  ilDclRecordListGUI::class,
48  "sendFile"
49  ) . '">' . $value['name'] . '</a>';
50  }
51 
52  $mob = new ilObjMediaObject($value);
53  $med = $mob->getMediaItem('Standard');
54 
55  if (!$med || $med->getLocation() === "") {
56  return "";
57  }
58 
59  $field = $this->getRecordField()->getField();
60 
61  $is_linked_field = $field->getProperty(ilDclBaseFieldModel::PROP_LINK_DETAIL_PAGE_MOB);
62  $has_view = false;
63  if ($this->http->wrapper()->query()->has("tableview_id")) {
64  $tableview_id = $this->http->wrapper()->query()->retrieve(
65  'tableview_id',
66  $this->refinery->kindlyTo()->int()
67  );
68  $has_view = ilDclDetailedViewDefinition::isActive($tableview_id);
69  }
70 
71  $components = [];
72 
73  if (in_array($med->getSuffix(), ['jpg', 'jpeg', 'png', 'gif'])) {
74  // Image
75  $dir = ilObjMediaObject::_getDirectory($mob->getId());
76 
77  $image = $this->factory->image()->responsive(ilWACSignedPath::signFile($dir . "/" . $med->getLocation()), "");
78 
79  if ($is_linked_field && $has_view && $link) {
80  $this->ctrl->setParameterByClass(
81  'ilDclDetailedViewGUI',
82  'record_id',
83  $this->getRecordField()->getRecord()->getId()
84  );
85  $image = $image->withAction($this->ctrl->getLinkTargetByClass("ilDclDetailedViewGUI", 'renderRecord'));
86  }
87  $components[] = $image;
88  } else {
89  $location = ilObjMediaObject::_getURL($mob->getId()) . "/" . $med->getLocation();
90  if ($med->getSuffix() == 'mp3') {
91  $components[] = $this->factory->player()->audio($location);
92  } else {
93  $components[] = $this->factory->player()->video($location);
94  }
95 
96  if ($is_linked_field && $has_view) {
97  $this->ctrl->setParameterByClass(
98  'ilDclDetailedViewGUI',
99  'record_id',
100  $this->getRecordField()->getRecord()->getId()
101  );
102  $components[] = $this->factory->link()->standard(
103  $this->lng->txt('details'),
104  $this->ctrl->getLinkTargetByClass(
105  "ilDclDetailedViewGUI",
106  'renderRecord'
107  )
108  );
109  }
110  }
111 
112  $width = "200px";
113  $height = "auto";
114  if ($field->getProperty(ilDclBaseFieldModel::PROP_WIDTH) > 0) {
115  $width = $field->getProperty(ilDclBaseFieldModel::PROP_WIDTH) . "px";
116  }
117  if ($field->getProperty(ilDclBaseFieldModel::PROP_HEIGHT) > 0) {
118  $height = $field->getProperty(ilDclBaseFieldModel::PROP_HEIGHT) . "px";
119  }
120  $content = $this->renderer->render($components);
121  return "<div style='width:$width; height:$height;'>$content</div>";
122  }
123 
124  public function parseFormInput($value)
125  {
126  if (is_array($value)) {
127  return $value;
128  }
129 
130  if ($value === null || !ilObject2::_exists((int) $value) || ilObject2::_lookupType((int) $value) != 'mob') {
131  return '';
132  }
133 
134  return $value;
135  }
136 }
$location
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: buildRTE.php:22
$components
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
static _getDirectory(int $a_mob_id)
Get absolute directory.
static http()
Fetches the global http state from ILIAS.
getHTML(bool $link=true, array $options=[])
Outputs html of a certain field.
static signFile(string $path_to_file)
static _getURL(int $a_mob_id)
get directory for files of media object
static _lookupType(int $id, bool $reference=false)