ILIAS  trunk Revision v12.0_alpha-16-g3e876e53c80
SubitemPropertiesReader.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
25use ILIAS\Data\Factory as DataFactory;
26use ilLanguage;
27use ilObject;
30use ilWikiPage;
31use ilObjWikiGUI;
36use Generator;
37
39{
40 protected ilLanguage $lng;
41 protected DataFactory $data_factory;
43
44 public static function type(): string
45 {
46 return 'wiki';
47 }
48
49 public function init(Container $dic): void
50 {
51 $this->lng = $dic->language();
52 $this->data_factory = new DataFactory();
53 $this->ctrl = $dic->ctrl();
54 }
55
56 public function getSubitemProperties(
57 PropertiesFactory $factory,
58 int $parent_ref_id,
59 ID ...$subitem_ids
60 ): Generator {
61 $obj_id = ilObject::_lookupObjId($parent_ref_id);
62 foreach ($subitem_ids as $subitem_id) {
63 switch ($subitem_id->type()) {
64 case 'file':
65 if (ilObject::_exists((int) $subitem_id->id())) {
66 yield $this->getPropertiesForFile($factory, $parent_ref_id, $subitem_id);
67 }
68 break;
69
70 case 'wpg':
71 $title = (string) ilWikiPage::lookupTitle((int) $subitem_id->id());
72 if ($title !== '') {
73 yield $this->getPropertiesForWikiPage($factory, $parent_ref_id, $subitem_id, $title);
74 }
75 break;
76 }
77 }
78 }
79
80 protected function getPropertiesForWikiPage(
81 PropertiesFactory $factory,
82 int $parent_ref_id,
83 ID $subitem_id,
84 string $title
85 ): Properties {
86 $link = rtrim(ILIAS_HTTP_PATH, '/') . '/' .
87 ilObjWikiGUI::getGotoLink($parent_ref_id, $title) . '&srcstring=1';
88 return $factory->get(
89 $subitem_id,
90 $title,
91 $this->data_factory->uri($link),
92 false,
93 $this->lng->txt('obj_pg')
94 );
95 }
96
97 protected function getPropertiesForFile(
98 PropertiesFactory $factory,
99 int $parent_ref_id,
100 ID $subitem_id
101 ): Properties {
102 $this->ctrl->setParameterByClass(ilWikiPageGUI::class, 'file_id', 'il__file_' . $subitem_id->id());
103 $this->ctrl->setParameterByClass(ilWikiPageGUI::class, 'ref_id', $parent_ref_id);
104 $link = rtrim(ILIAS_HTTP_PATH, '/') . '/' .
105 $this->ctrl->getLinkTargetByClass([ilWikiHandlerGUI::class, ilObjWikiGUI::class, ilWikiPageGUI::class], 'downloadFile');
106 $this->ctrl->clearParameterByClass(ilWikiPageGUI::class, 'file_id');
107 $this->ctrl->clearParameterByClass(ilWikiPageGUI::class, 'ref_id');
108 return $factory->get(
109 $subitem_id,
110 ilObject::_lookupTitle((int) $subitem_id->id()),
111 $this->data_factory->uri($link),
112 false,
113 $this->lng->txt('obj_file')
114 );
115 }
116}
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:36
language()
Get interface to the i18n service.
Definition: Container.php:95
ctrl()
Get the interface to the control structure.
Definition: Container.php:63
Builds data types.
Definition: Factory.php:36
getSubitemProperties(PropertiesFactory $factory, int $parent_ref_id, ID ... $subitem_ids)
Order of the output should respect the order of the subitem_ids.
getPropertiesForFile(PropertiesFactory $factory, int $parent_ref_id, ID $subitem_id)
getPropertiesForWikiPage(PropertiesFactory $factory, int $parent_ref_id, ID $subitem_id, string $title)
static type()
Type of the parent object.
language handling
Class ilObject Basic functions for all objects.
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
static _lookupTitle(int $obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilWikiPage GUI class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static lookupTitle(int $a_page_id, string $lang="-")
get(ID $id, string $title, ?URI $link_to_subitem, bool $open_link_in_new_viewport, string $presentable_subitem_type)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$dic
Definition: ltiresult.php:33