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;
32use ilLMObject;
34use Generator;
35
37{
38 protected ilLanguage $lng;
39 protected DataFactory $data_factory;
41
42 public static function type(): string
43 {
44 return 'lm';
45 }
46
47 public function init(Container $dic): void
48 {
49 $this->lng = $dic->language();
50 $this->data_factory = new DataFactory();
51 $this->ctrl = $dic->ctrl();
52 }
53
54 public function getSubitemProperties(
55 PropertiesFactory $factory,
56 int $parent_ref_id,
57 ID ...$subitem_ids
58 ): Generator {
59 $obj_id = ilObject::_lookupObjId($parent_ref_id);
60 foreach ($subitem_ids as $subitem_id) {
61 switch ($subitem_id->type()) {
62 case 'pg':
63 yield $this->getPropertiesForLMObject(
64 $factory,
65 $parent_ref_id,
66 $subitem_id,
67 $this->lng->txt('obj_pg')
68 );
69 break;
70
71 case 'st':
72 yield $this->getPropertiesForLMObject(
73 $factory,
74 $parent_ref_id,
75 $subitem_id,
76 $this->lng->txt('obj_st')
77 );
78 break;
79
80 case 'file':
81 if (!ilObject::_exists((int) $subitem_id->id())) {
82 break;
83 }
84 yield $this->getPropertiesForFile($factory, $parent_ref_id, $subitem_id);
85 }
86 }
87 }
88
89 protected function getPropertiesForLMObject(
90 PropertiesFactory $factory,
91 int $parent_ref_id,
92 ID $subitem_id,
93 string $presentable_type
94 ): Properties {
95 $this->ctrl->setParameterByClass(ilLMPresentationGUI::class, 'ref_id', $parent_ref_id);
96 $this->ctrl->setParameterByClass(ilLMPresentationGUI::class, 'obj_id', $subitem_id->id());
97 $link = rtrim(ILIAS_HTTP_PATH, '/') . '/' .
98 $this->ctrl->getLinkTargetByClass(ilLMPresentationGUI::class, '');
99 $this->ctrl->clearParameterByClass(ilLMPresentationGUI::class, 'obj_id');
100 $this->ctrl->clearParameterByClass(ilLMPresentationGUI::class, 'ref_id');
101 return $factory->get(
102 $subitem_id,
103 ilLMObject::_lookupTitle((int) $subitem_id->id()),
104 $this->data_factory->uri($link),
105 false,
106 $presentable_type
107 );
108 }
109
110 protected function getPropertiesForFile(
111 PropertiesFactory $factory,
112 int $parent_ref_id,
113 ID $subitem_id
114 ): Properties {
115 $this->ctrl->setParameterByClass(ilLMPresentationGUI::class, 'ref_id', $parent_ref_id);
116 $this->ctrl->setParameterByClass(ilLMPresentationGUI::class, 'file_id', 'il__file_' . $subitem_id->id());
117 $link = rtrim(ILIAS_HTTP_PATH, '/') . '/' .
118 $this->ctrl->getLinkTargetByClass(ilLMPresentationGUI::class, 'downloadFile');
119 $this->ctrl->clearParameterByClass(ilLMPresentationGUI::class, 'file_id');
120 $this->ctrl->clearParameterByClass(ilLMPresentationGUI::class, 'ref_id');
121 return $factory->get(
122 $subitem_id,
123 ilObject::_lookupTitle((int) $subitem_id->id()),
124 $this->data_factory->uri($link),
125 false,
126 $this->lng->txt('obj_file')
127 );
128 }
129}
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
getPropertiesForLMObject(PropertiesFactory $factory, int $parent_ref_id, ID $subitem_id, string $presentable_type)
getPropertiesForFile(PropertiesFactory $factory, int $parent_ref_id, ID $subitem_id)
getSubitemProperties(PropertiesFactory $factory, int $parent_ref_id, ID ... $subitem_ids)
Order of the output should respect the order of the subitem_ids.
Class ilLMObject.
static _lookupTitle(int $a_obj_id)
Class ilLMPresentationGUI GUI class for learning module presentation.
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)
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