ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.AssignedObjectsTable.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use ILIAS\Data;
24use ILIAS\UI;
25use Psr\Http\Message\ServerRequestInterface;
26
31{
32 protected \ilLanguage $lng;
33 protected \ilTree $tree;
34 protected UI\Factory $ui_fac;
35 protected UI\Renderer $ui_ren;
36 protected ServerRequestInterface $request;
37 protected object $parent_obj;
38 protected array $objects = [];
39 protected int $skill_id = 0;
40 protected int $tref_id = 0;
41 protected int $profile_id = 0;
42
43 public function __construct(
44 object $parent_obj,
45 array $objects,
46 int $skill_id = 0,
47 int $tref_id = 0,
48 int $profile_id = 0
49 ) {
50 global $DIC;
51
52 $this->lng = $DIC->language();
53 $this->tree = $DIC->repositoryTree();
54 $this->ui_fac = $DIC->ui()->factory();
55 $this->ui_ren = $DIC->ui()->renderer();
56 $this->request = $DIC->http()->request();
57
58 $this->parent_obj = $parent_obj;
59 $this->objects = $objects;
60 $this->skill_id = $skill_id;
61 $this->tref_id = $tref_id;
62 $this->profile_id = $profile_id;
63 }
64
65 public function getComponent(): UI\Component\Table\Data
66 {
67 $columns = $this->getColumns();
68 $data_retrieval = $this->getDataRetrieval();
69
70 $table = $this->ui_fac->table()
71 ->data($data_retrieval, $this->lng->txt("skmg_assigned_objects"), $columns)
72 ->withId(
73 self::class . "_" .
74 $this->parent_obj::class . "_" .
75 $this->skill_id . "_" .
76 $this->tref_id . "_" .
77 $this->profile_id
78 )
79 ->withRequest($this->request);
80
81 return $table;
82 }
83
84 protected function getColumns(): array
85 {
86 $columns = [
87 "type" => $this->ui_fac->table()->column()->statusIcon($this->lng->txt("type"))
88 ->withIsSortable(false),
89 "title" => $this->ui_fac->table()->column()->text($this->lng->txt("title")),
90 "path" => $this->ui_fac->table()->column()->text($this->lng->txt("path"))
91 ->withIsSortable(false)
92 ];
93
94 return $columns;
95 }
96
97 protected function getDataRetrieval(): UI\Component\Table\DataRetrieval
98 {
99 $data_retrieval = new class (
105 ) implements UI\Component\Table\DataRetrieval {
106 use TableRecords;
107
108 public function __construct(
109 protected \ilLanguage $lng,
110 protected UI\Factory $ui_fac,
111 protected UI\Renderer $ui_ren,
112 protected \ilTree $tree,
113 protected array $objects
114 ) {
115 }
116
117 public function getRows(
118 UI\Component\Table\DataRowBuilder $row_builder,
119 array $visible_column_ids,
121 Data\Order $order,
122 ?array $filter_data,
123 ?array $additional_parameters
124 ): \Generator {
125 $records = $this->getRecords($range, $order);
126 foreach ($records as $idx => $record) {
127 $row_id = (string) $record["obj_id"];
128
129 yield $row_builder->buildDataRow($row_id, $record);
130 }
131 }
132
133 public function getTotalRowCount(
134 ?array $filter_data,
135 ?array $additional_parameters
136 ): ?int {
137 return count($this->getRecords());
138 }
139
140 protected function getRecords(?Data\Range $range = null, ?Data\Order $order = null): array
141 {
142 $records = [];
143 $i = 0;
144 foreach ($this->objects as $obj_id) {
145 $obj_ref_id = \ilObject::_getAllReferences($obj_id);
146 $obj_ref_id = end($obj_ref_id);
147
148 if (!$obj_ref_id) {
149 continue;
150 }
151
152 $records[$i]["obj_id"] = $obj_id;
153 $records[$i]["title"] = \ilObject::_lookupTitle($obj_id);
154
155 $obj_type = \ilObject::_lookupType($obj_id);
156 $icon = $this->ui_fac->symbol()->icon()->standard(
157 $obj_type,
158 $this->lng->txt("icon") . " " . $this->lng->txt($obj_type),
159 "medium"
160 );
161 $records[$i]["type"] = $icon;
162
163 $obj_ref_id_parent = $this->tree->getParentId($obj_ref_id);
164 $path = new \ilPathGUI();
165 $records[$i]["path"] = $path->getPath($this->tree->getParentId($obj_ref_id_parent), $obj_ref_id);
166
167 $i++;
168 }
169
170 if ($order) {
171 $records = $this->orderRecords($records, $order);
172 }
173
174 if ($range) {
175 $records = $this->limitRecords($records, $range);
176 }
177
178 return $records;
179 }
180 };
181
182 return $data_retrieval;
183 }
184}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Both the subject and the direction need to be specified when expressing an order.
Definition: Order.php:29
A simple class to express a naive range of whole positive numbers.
Definition: Range.php:29
__construct(object $parent_obj, array $objects, int $skill_id=0, int $tref_id=0, int $profile_id=0)
Definition: UI.php:24
language handling
static _lookupType(int $id, bool $reference=false)
static _getAllReferences(int $id)
get all reference ids for object ID
static _lookupTitle(int $obj_id)
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
An entity that renders components to a string output.
Definition: Renderer.php:31
$path
Definition: ltiservices.php:30
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: shib_login.php:26