ILIAS  trunk Revision v11.0_alpha-1843-g9e1fad99175
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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  $page = new ilDclDetailedViewDefinitionGUI($tableview_id);
69  $has_view = $page->getPageObject()->isActive();
70  }
71 
72  $components = [];
73 
74  if (in_array($med->getSuffix(), ['jpg', 'jpeg', 'png', 'gif'])) {
75  // Image
76  $dir = ilObjMediaObject::_getDirectory($mob->getId());
77 
78  $image = $this->factory->image()->responsive(ilWACSignedPath::signFile($dir . "/" . $med->getLocation()), "");
79 
80  if ($is_linked_field && $has_view && $link) {
81  $this->ctrl->setParameterByClass(
82  'ilDclDetailedViewGUI',
83  'record_id',
84  $this->getRecordField()->getRecord()->getId()
85  );
86  $image = $image->withAction($this->ctrl->getLinkTargetByClass("ilDclDetailedViewGUI", 'renderRecord'));
87  }
88  $components[] = $image;
89  } else {
90  $location = ilObjMediaObject::_getURL($mob->getId()) . "/" . $med->getLocation();
91  if ($med->getSuffix() == 'mp3') {
92  $components[] = $this->factory->player()->audio($location);
93  } else {
94  $components[] = $this->factory->player()->video($location);
95  }
96 
97  if ($is_linked_field && $has_view) {
98  $this->ctrl->setParameterByClass(
99  'ilDclDetailedViewGUI',
100  'record_id',
101  $this->getRecordField()->getRecord()->getId()
102  );
103  $components[] = $this->factory->link()->standard(
104  $this->lng->txt('details'),
105  $this->ctrl->getLinkTargetByClass(
106  "ilDclDetailedViewGUI",
107  'renderRecord'
108  )
109  );
110  }
111  }
112 
113  $width = "200px";
114  $height = "auto";
115  if ($field->getProperty(ilDclBaseFieldModel::PROP_WIDTH) > 0) {
116  $width = $field->getProperty(ilDclBaseFieldModel::PROP_WIDTH) . "px";
117  }
118  if ($field->getProperty(ilDclBaseFieldModel::PROP_HEIGHT) > 0) {
119  $height = $field->getProperty(ilDclBaseFieldModel::PROP_HEIGHT) . "px";
120  }
121  $content = $this->renderer->render($components);
122  return "<div style='width:$width; height:$height;'>$content</div>";
123  }
124 
125  public function parseFormInput($value)
126  {
127  if (is_array($value)) {
128  return $value;
129  }
130 
131  if ($value === null || !ilObject2::_exists((int) $value) || ilObject2::_lookupType((int) $value) != 'mob') {
132  return '';
133  }
134 
135  return $value;
136  }
137 }
$location
Definition: buildRTE.php:22
factory()
renderer()
ilDclDetailedViewDefinitionGUI: ilPageEditorGUI, ilEditClipboardGUI, ilMediaPoolTargetSelector ilDcl...
$components
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
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)