ILIAS  release_8 Revision v8.24
class.ilDclReferenceRecordRepresentation.php
Go to the documentation of this file.
1<?php
2
20{
21 public function getHTML(bool $link = true, array $options = []): string
22 {
23 $value = $this->getRecordField()->getValue();
25
26 if (!$value || $value == "-") {
27 return "";
28 }
29
30 if (!is_array($value)) {
31 $value = [$value];
32 }
33
34 $items = [];
35
36 foreach ($value as $k => $v) {
37 $ref_record = ilDclCache::getRecordCache($v);
38 if (!$ref_record->getId() || !$ref_record->getTableId() || !$record_field->getField() || !$record_field->getField()->getTableId()) {
39 //the referenced record_field does not seem to exist.
40 unset($value[$k]);
41 $value = array_values($value); // resets the keys
42 $record_field->setValue($value);
44 continue;
45 } else {
46 $field = $this->getRecordField()->getField();
47 if ($field->getProperty(ilDclBaseFieldModel::PROP_REFERENCE_LINK)) {
48 $ref_table = $ref_record->getTable();
49 $ref_id = $this->http->wrapper()->query()->retrieve('ref_id', $this->refinery->kindlyTo()->int());
50 if ($v !== null && $v !== '' && $v !== '-') {
51 $view = $ref_record->getTable()->getFirstTableViewId($ref_id, $this->user->getId(), true);
52 if ($view) {
53 $items[] = $this->getLinkHTML($ref_record, $view);
54 continue;
55 }
56 }
57 }
58 $items[] = $ref_record->getRecordFieldHTML($field->getProperty(ilDclBaseFieldModel::PROP_REFERENCE));
59 }
60 }
61
62 return implode('<br>', $items);
63 }
64
65 protected function getLinkHTML(ilDclBaseRecordModel $record, int $view): string
66 {
67 $this->ctrl->setParameterByClass(ilDclDetailedViewGUI::class, "table_id", $record->getTableId());
68 $this->ctrl->setParameterByClass(ilDclDetailedViewGUI::class, "record_id", $record->getId());
69 $this->ctrl->setParameterByClass(ilDclDetailedViewGUI::class, "tableview_id", $view);
70 $html = $this->factory->link()->standard(
71 $record->getRecordFieldValue($this->getField()->getProperty(ilDclBaseFieldModel::PROP_REFERENCE)),
72 $this->ctrl->getLinkTargetByClass(
73 ilDclDetailedViewGUI::class,
74 "renderRecord"
75 )
76 );
77
78 return $this->renderer->render($html);
79 }
80
85 public function parseFormInput($value)
86 {
87 if (!$value || $value == []) {
88 return null;
89 }
90
91 return $value;
92 }
93}
setValue($value, bool $omit_parsing=false)
Set value for record field.
doUpdate()
Update object in database.
getRecordFieldValue(?int $field_id)
Get Field Value.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getRecordCache(?int $record_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getLinkHTML(ilDclBaseRecordModel $record, int $view)
parseFormInput($value)
function parses stored value to the variable needed to fill into the form for editing.
getHTML(bool $link=true, array $options=[])
Outputs html of a certain field.
$ref_id
Definition: ltiauth.php:67
static http()
Fetches the global http state from ILIAS.