ILIAS  trunk Revision v11.0_alpha-1715-g7fc467680fb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilDclIliasReferenceRecordRepresentation.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 {
23  public function getHTML(bool $link = true, array $options = []): string
24  {
25  $title = $this->getRecordField()->getValueForRepresentation();
26  if (!$title) {
27  return '';
28  }
29  $field = $this->getRecordField()->getField();
30 
32  $html = $this->getLinkHTML($title, true);
33  } else {
34  if ($field->getProperty(ilDclBaseFieldModel::PROP_ILIAS_REFERENCE_LINK)) {
35  $html = $this->getLinkHTML($title);
36  } else {
37  $html = $title;
38  }
39  }
40 
41  return $html;
42  }
43 
44  public function getSingleHTML(?array $options = null, bool $link = true): string
45  {
46  $value = $this->getRecordField()->getValue();
47  if (!$value) {
48  return '';
49  }
50  $id = ilObject::_lookupObjId($value);
51  $value = ilObject::_lookupTitle($id);
53  return $this->getLinkHTML($value);
54  }
55 
56  return $value;
57  }
58 
59  public function getLinkHTML(string $title, bool $show_action_menu = false): string
60  {
61  $link = ilLink::_getStaticLink($this->getRecordField()->getValue());
62  if ($show_action_menu) {
63  $field = $this->getRecordField()->getField();
64  $dropdown_items = [];
65  if ($field->getProperty(ilDclBaseFieldModel::PROP_ILIAS_REFERENCE_LINK)) {
66  $dropdown_items[] = $this->factory->link()->standard(
67  $this->lng->txt('view'),
68  $link
69  );
70  }
71  $dropdown_items[] = $this->factory->link()->standard(
72  $this->lng->txt('link'),
73  $this->getActionLink('link')
74  );
75  $dropdown_items[] = $this->factory->link()->standard(
76  $this->lng->txt('copy'),
77  $this->getActionLink('copy')
78  );
79  $dropdown = $this->factory->dropdown()->standard($dropdown_items)->withLabel($title);
80  return $this->renderer->render($dropdown);
81  } else {
82  return $this->renderer->render($this->factory->link()->standard($title, $link));
83  }
84  }
85 
89  protected function getActionLink(string $mode): string
90  {
91  switch ($mode) {
92  case 'copy':
93  $this->ctrl->setParameterByClass(ilObjectCopyGUI::class, 'item_ref_id', $this->getRecordField()->getValue());
94  $this->ctrl->setParameterByClass(ilObjRootFolderGUI::class, 'item_ref_id', $this->getRecordField()->getValue());
95  $this->ctrl->setParameterByClass(ilObjectCopyGUI::class, 'source_id', $this->getRecordField()->getValue());
96 
97  return $this->ctrl->getLinkTargetByClass(ilObjectCopyGUI::class, 'initTargetSelection');
98  case 'link':
99  return $this->ctrl->getLinkTargetByClass([ilRepositoryGUI::class, ilObjRootFolderGUI::class], 'link');
100  default:
101  return '';
102  }
103  }
104 }
getValue()
Get the value that is displayed in the input client side.
Definition: Group.php:49
factory()
renderer()
static _lookupObjId(int $ref_id)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static _lookupTitle(int $obj_id)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23