ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 self::class . "_" .
115 $this->skill_tree_id
116 )
117 ->withActions($actions)
118 ->withRequest($this->request);
119
120 return $table;
121 }
122
123 protected function getColumns(): array
124 {
125 $columns = [
126 "title" => $this->ui_fac->table()->column()->link($this->lng->txt("title")),
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 ?array $filter_data,
205 ?array $additional_parameters
206 ): \Generator {
207 $records = $this->getRecords($range, $order);
208 foreach ($records as $idx => $record) {
209 $row_id = (string) $record["profile_id"];
210
211 yield $row_builder->buildDataRow($row_id, $record);
212 }
213 }
214
215 public function getTotalRowCount(
216 ?array $filter_data,
217 ?array $additional_parameters
218 ): ?int {
219 return count($this->getRecords());
220 }
221
222 protected function getRecords(?Data\Range $range = null, ?Data\Order $order = null): array
223 {
224 if ($this->skill_tree_id) {
225 $profiles = $this->skill_profile_manager->getProfilesForSkillTree($this->skill_tree_id);
226 } else {
227 $profiles = $this->skill_profile_manager->getProfilesForAllSkillTrees();
228 }
229
230 $records = [];
231 $i = 0;
232 foreach ($profiles as $profile) {
233 $records[$i]["profile_id"] = $profile->getId();
234 $this->ctrl->setParameterByClass("ilskillprofilegui", "sprof_id", $profile->getId());
235 $records[$i]["title"] = $this->ui_fac->link()->standard(
236 $profile->getTitle(),
237 $this->ctrl->getLinkTargetByClass("ilskillprofilegui", "showLevels")
238 );
239 $this->ctrl->clearParameterByClass("ilskillprofilegui", "sprof_id");
240 $profile_ref_id = $this->skill_profile_manager->lookupRefId($profile->getId());
241 $profile_obj_id = \ilContainerReference::_lookupObjectId($profile_ref_id);
242 $profile_obj_title = \ilObject::_lookupTitle($profile_obj_id);
243 if ($profile_ref_id > 0) {
244 $records[$i]["context"] = $this->lng->txt("skmg_context_local") . " (" . $profile_obj_title . ")";
245 } else {
246 $records[$i]["context"] = $this->lng->txt("skmg_context_global");
247 }
248 $records[$i]["users"] = $this->skill_profile_manager->countUsers($profile->getId());
249 $records[$i]["roles"] = $this->skill_profile_manager->countRoles($profile->getId());
250 $i++;
251 }
252
253 if ($order) {
254 $records = $this->orderRecords($records, $order);
255 }
256
257 if ($range) {
258 $records = $this->limitRecords($records, $range);
259 }
260
261 return $records;
262 }
263 };
264
265 return $data_retrieval;
266 }
267}
$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