ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ProfileTable.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Skill\Table;
22
23use ILIAS\Data;
24use ILIAS\UI;
25use Psr\Http\Message\ServerRequestInterface;
30
35{
36 protected \ilCtrl $ctrl;
37 protected \ilLanguage $lng;
38 protected UI\Factory $ui_fac;
39 protected UI\Renderer $ui_ren;
40 protected ServerRequestInterface $request;
42 protected Data\Factory $df;
46 protected string $requested_table_profile_action = "";
47
51 protected array $requested_table_profile_ids = [];
52 protected int $skill_tree_id = 0;
53
54 public function __construct(int $ref_id, int $skill_tree_id)
55 {
56 global $DIC;
57
58 $this->ctrl = $DIC->ctrl();
59 $this->lng = $DIC->language();
60 $this->ui_fac = $DIC->ui()->factory();
61 $this->ui_ren = $DIC->ui()->renderer();
62 $this->request = $DIC->http()->request();
63 $this->query = $DIC->http()->wrapper()->query();
64 $this->df = new Data\Factory();
65 $this->tree_access_manager = $DIC->skills()->internal()->manager()->getTreeAccessManager($ref_id);
66 $this->profile_manager = $DIC->skills()->internal()->manager()->getProfileManager();
67 $this->admin_gui_request = $DIC->skills()->internal()->gui()->admin_request();
68 $this->requested_table_profile_action = $this->admin_gui_request->getTableProfileAction();
69 $this->requested_table_profile_ids = $this->admin_gui_request->getTableProfileIds();
70 $this->skill_tree_id = $skill_tree_id;
71 }
72
73 public function getComponent(): UI\Component\Table\Data
74 {
75 $columns = $this->getColumns();
76 $actions = $this->getActions();
77 $data_retrieval = $this->getDataRetrieval();
78
79 if ($this->requested_table_profile_action === "deleteProfiles") {
80 $items = [];
81 foreach ($this->requested_table_profile_ids as $id) {
82 if ($id === "ALL_OBJECTS") {
83 $profiles = $this->skill_tree_id
84 ? $this->profile_manager->getProfilesForSkillTree($this->skill_tree_id)
85 : $this->profile_manager->getProfilesForAllSkillTrees();
86 foreach ($profiles as $profile) {
87 $items[] = $this->ui_fac->modal()->interruptiveItem()->standard(
88 (string) $profile->getId(),
89 $profile->getTitle()
90 );
91 }
92 } else {
93 $items[] = $this->ui_fac->modal()->interruptiveItem()->standard(
94 $id,
95 $this->profile_manager->lookupTitle((int) $id)
96 );
97 }
98 }
99 echo($this->ui_ren->renderAsync([
100 $this->ui_fac->modal()->interruptive(
101 "",
102 empty($items) ? $this->lng->txt("no_checkbox") : $this->lng->txt("skmg_delete_profiles"),
103 $this->ctrl->getFormActionByClass("ilskillprofilegui", "deleteProfiles")
104 )
105 ->withAffectedItems($items)
106 ->withActionButtonLabel(empty($items) ? $this->lng->txt("ok") : $this->lng->txt("delete"))
107 ]));
108 exit();
109 }
110
111 $table = $this->ui_fac->table()
112 ->data($data_retrieval, $this->lng->txt("skmg_skill_profiles"), $columns)
113 ->withId(
114 "pt_" . $this->skill_tree_id
115 )
116 ->withActions($actions)
117 ->withRequest($this->request);
118
119 return $table;
120 }
121
122 protected function getColumns(): array
123 {
124 $columns = [
125 "title" => $this->ui_fac->table()->column()->link($this->lng->txt("title"))
126 ->withIsSortable(true),
127 "context" => $this->ui_fac->table()->column()->text($this->lng->txt("context"))
128 ->withIsSortable(false),
129 "users" => $this->ui_fac->table()->column()->text($this->lng->txt("users"))
130 ->withIsSortable(false),
131 "roles" => $this->ui_fac->table()->column()->text($this->lng->txt("roles"))
132 ->withIsSortable(false),
133 ];
134
135 return $columns;
136 }
137
138 protected function getActions(): array
139 {
140 $query_params_namespace = ["skl_profile_table"];
141
142 $url_builder_delete = new UI\URLBuilder($this->df->uri($this->request->getUri()->__toString()));
143 list($url_builder_delete, $action_parameter_token_delete, $row_id_token_delete) =
144 $url_builder_delete->acquireParameters(
145 $query_params_namespace,
146 "action",
147 "profile_ids"
148 );
149
150 $uri_export = $this->df->uri(
151 ILIAS_HTTP_PATH . "/" . $this->ctrl->getLinkTargetByClass("ilskillprofilegui", "exportProfiles")
152 );
153 $url_builder_export = new UI\URLBuilder($uri_export);
154 list($url_builder_export, $action_parameter_token_export, $row_id_token_export) =
155 $url_builder_export->acquireParameters(
156 $query_params_namespace,
157 "action",
158 "profile_ids"
159 );
160
161 $actions = [];
162 if ($this->tree_access_manager->hasManageProfilesPermission()) {
163 $actions["delete"] = $this->ui_fac->table()->action()->multi(
164 $this->lng->txt("delete"),
165 $url_builder_delete->withParameter($action_parameter_token_delete, "deleteProfiles"),
166 $row_id_token_delete
167 )
168 ->withAsync();
169 $actions["export"] = $this->ui_fac->table()->action()->multi(
170 $this->lng->txt("export"),
171 $url_builder_export->withParameter($action_parameter_token_export, "exportProfiles"),
172 $row_id_token_export
173 );
174 }
175
176 return $actions;
177 }
178
179 protected function getDataRetrieval(): UI\Component\Table\DataRetrieval
180 {
181 $data_retrieval = new class (
187 ) implements UI\Component\Table\DataRetrieval {
188 use TableRecords;
189
190 public function __construct(
191 protected \ilLanguage $lng,
192 protected int $skill_tree_id,
193 protected Profile\SkillProfileManager $skill_profile_manager,
194 protected UI\Factory $ui_fac,
195 protected \ilCtrl $ctrl
196 ) {
197 }
198
199 public function getRows(
200 UI\Component\Table\DataRowBuilder $row_builder,
201 array $visible_column_ids,
203 Data\Order $order,
204 mixed $additional_viewcontrol_data,
205 mixed $filter_data,
206 mixed $additional_parameters
207 ): \Generator {
208 [$column_name, $direction] = $order->join([], fn($ret, $key, $value) => [$key, $value]);
209 $comparator = function (array $f1, array $f2) { return strcmp($f1['title']->getLabel(), $f2['title']->getLabel()); };
210 $rows = $this->getRecords($range, $order);
211 uasort($rows, $comparator);
212 if ($direction === "DESC") {
213 $rows = array_reverse($rows, true);
214 }
215 $rows = array_slice($rows, $range->getStart(), $range->getLength(), true);
216 foreach ($rows as $idx => $record) {
217 $row_id = (string) $record["profile_id"];
218
219 yield $row_builder->buildDataRow($row_id, $record);
220 }
221 }
222
223 public function getTotalRowCount(
224 mixed $additional_viewcontrol_data,
225 mixed $filter_data,
226 mixed $additional_parameters
227 ): ?int {
228 return count($this->getRecords());
229 }
230
231 protected function getRecords(?Data\Range $range = null, ?Data\Order $order = null): array
232 {
233 if ($this->skill_tree_id) {
234 $profiles = $this->skill_profile_manager->getProfilesForSkillTree($this->skill_tree_id);
235 } else {
236 $profiles = $this->skill_profile_manager->getProfilesForAllSkillTrees();
237 }
238
239 $records = [];
240 $i = 0;
241 foreach ($profiles as $profile) {
242 $records[$i]["profile_id"] = $profile->getId();
243 $this->ctrl->setParameterByClass("ilskillprofilegui", "sprof_id", $profile->getId());
244 $records[$i]["title"] = $this->ui_fac->link()->standard(
245 $profile->getTitle(),
246 $this->ctrl->getLinkTargetByClass("ilskillprofilegui", "showLevels")
247 );
248 $this->ctrl->clearParameterByClass("ilskillprofilegui", "sprof_id");
249 $profile_ref_id = $this->skill_profile_manager->lookupRefId($profile->getId());
250 $profile_obj_id = \ilContainerReference::_lookupObjectId($profile_ref_id);
251 $profile_obj_title = \ilObject::_lookupTitle($profile_obj_id);
252 if ($profile_ref_id > 0) {
253 $records[$i]["context"] = $this->lng->txt("skmg_context_local") . " (" . $profile_obj_title . ")";
254 } else {
255 $records[$i]["context"] = $this->lng->txt("skmg_context_global");
256 }
257 $records[$i]["users"] = $this->skill_profile_manager->countUsers($profile->getId());
258 $records[$i]["roles"] = $this->skill_profile_manager->countRoles($profile->getId());
259 $i++;
260 }
261
262 if ($order) {
263 $records = $this->orderRecords($records, $order);
264 }
265
266 if ($range) {
267 $records = $this->limitRecords($records, $range);
268 }
269
270 return $records;
271 }
272 };
273
274 return $data_retrieval;
275 }
276}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
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
Request wrapper for guis in skill administration.
ArrayBasedRequestWrapper $query
__construct(int $ref_id, int $skill_tree_id)
Profile SkillProfileManager $profile_manager
ServerRequestInterface $request
Access SkillTreeAccess $tree_access_manager
Service SkillAdminGUIRequest $admin_gui_request
Definition: UI.php:24
Class ilCtrl provides processing control methods.
language handling
static _lookupObjectId(int $ref_id)
static _lookupTitle(int $obj_id)
exit
$ref_id
Definition: ltiauth.php:66
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