ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilDclFileuploadRecordRepresentation.php
Go to the documentation of this file.
1 <?php
2 
20 {
24  public function getHTML(bool $link = true, array $options = []): string
25  {
26  $value = $this->getRecordField()->getValue();
27 
28  // the file is only temporary uploaded. Still need to be confirmed before stored
29  $has_ilfilehash = $this->http->wrapper()->post()->has('ilfilehash');
30  if (is_array($value) && $has_ilfilehash) {
31  $ilfilehash = $this->http->wrapper()->post()->retrieve('ilfilehash', $this->refinery->kindlyTo()->string());
32  $this->ctrl->setParameterByClass("ildclrecordlistgui", "ilfilehash", $ilfilehash);
33  $this->ctrl->setParameterByClass(
34  "ildclrecordlistgui",
35  "field_id",
36  $this->getRecordField()->getField()->getId()
37  );
38 
39  return '<a href="' . $this->ctrl->getLinkTargetByClass(
40  "ildclrecordlistgui",
41  "sendFile"
42  ) . '">' . $value['name'] . '</a>';
43  } else {
44  if (!ilObject2::_exists((int) $value) || ilObject2::_lookupType((int) $value, false) !== 'file') {
45  return "";
46  }
47  }
48 
49  $file_obj = new ilObjFile($value, false);
50  $this->ctrl->setParameterByClass(
51  "ildclrecordlistgui",
52  "record_id",
53  $this->getRecordField()->getRecord()->getId()
54  );
55  $this->ctrl->setParameterByClass(
56  "ildclrecordlistgui",
57  "field_id",
58  $this->getRecordField()->getField()->getId()
59  );
60 
61  $html = '<a href="' . $this->ctrl->getLinkTargetByClass(
62  "ildclrecordlistgui",
63  "sendFile"
64  ) . '">' . $file_obj->getFileName() . '</a>';
65  if (ilPreview::hasPreview($file_obj->getId())) {
66  ilPreview::createPreview($file_obj); // Create preview if not already existing
67 
68  $ref_id = $this->http->wrapper()->query()->retrieve('ref_id', $this->refinery->kindlyTo()->int());
69 
70  $preview = new ilPreviewGUI(
71  $ref_id,
73  $file_obj->getId(),
75  );
76  $preview_status = ilPreview::lookupRenderStatus($file_obj->getId());
77  $preview_status_class = "";
78  $preview_text_topic = "preview_show";
79  if ($preview_status == ilPreview::RENDER_STATUS_NONE) {
80  $preview_status_class = "ilPreviewStatusNone";
81  $preview_text_topic = "preview_none";
82  }
83  $wrapper_html_id = 'record_field_' . $this->getRecordField()->getId();
84  $script_preview_click = $preview->getJSCall($wrapper_html_id);
85  $preview_title = $this->lng->txt($preview_text_topic);
86  $preview_icon = ilUtil::getImagePath("preview.png");
87  $html = '<div id="' . $wrapper_html_id . '">' . $html;
88  $html .= '<span class="il_ContainerItemPreview ' . $preview_status_class . '"><a href="javascript:void(0);" onclick="'
89  . $script_preview_click . '" title="' . $preview_title . '"><img src="' . $preview_icon
90  . '" height="16" width="16"></a></span></div>';
91  }
92 
93  return $html;
94  }
95 
101  public function parseFormInput($value)
102  {
103  if (is_array($value)) {
104  return $value;
105  }
106 
107  if (!ilObject2::_exists((int) $value) || ilObject2::_lookupType((int) $value) !== 'file') {
108  return "";
109  }
110 
111  $file_obj = new ilObjFile($value, false);
112 
113  //$input = ilObjFile::_lookupAbsolutePath($value);
114  return $file_obj->getFileName();
115  }
116 }
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const RENDER_STATUS_NONE
static createPreview(\ilObject $a_obj, bool $a_force=false)
Creates the preview for the object with the specified id.
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
$ref_id
Definition: ltiauth.php:67
static http()
Fetches the global http state from ILIAS.
$preview
Definition: imgupload.php:81
Class ilObjFile.
static lookupRenderStatus(int $a_obj_id)
Gets the render status for the object with the specified id.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getHTML(bool $link=true, array $options=[])
Outputs html of a certain field.
static hasPreview(int $a_obj_id, string $a_type="")
Determines whether the object with the specified reference id has a preview.
parseFormInput($value)
function parses stored value to the variable needed to fill into the form for editing.
static _lookupType(int $id, bool $reference=false)