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