ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
AssignmentHandler.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26use ILIAS\UI\Factory as UIFactory;
27use ILIAS\Data\Factory as DataFactory;
30use ILIAS\UI\Component\Table\Data as DataTable;
33use ilObject;
34use ilLanguage;
36use ilObjUser;
37use ilTree;
38
40{
41 public const string ID = 'ref_id';
42 protected const string ACTION = 'table_action';
43 protected const string NAMESPACE = 'grouping_assign';
44
45 public const string COL_TITLE = 'title';
46 public const string COL_PATH = 'path';
47 public const string COL_ASSIGNED = 'assigned';
48
49 public const string ACTION_TOGGLE_ASSIGNMENT = 'toggle_assignment';
50
55
56 public function __construct(
57 protected string $action,
58 protected int $content_obj_id,
59 protected ilObjCourseGrouping $grouping,
60 protected ilLanguage $lng,
61 protected UIFactory $ui_factory,
62 protected DataFactory $data_factory,
63 protected HTTP $http,
64 protected Refinery $refinery,
65 ilObjUser $user,
66 ilTree $tree
67 ) {
68 $this->data_retrieval = new AssignmentRetrieval(
69 $this->content_obj_id,
70 $this->grouping,
71 $user,
72 $tree,
73 $this->ui_factory,
74 $this->lng,
75 $this->data_factory
76 );
77 }
78
79 public function getTable(): DataTable
80 {
81 return $this->ui_factory->table()->data(
82 $this->data_retrieval,
83 $this->lng->txt('crs_grp_assign_crs') . ' (' . $this->grouping->getTitle() . ')',
84 $this->buildColumns()
85 )->withRequest($this->http->request())
86 ->withActions($this->buildActions());
87 }
88
92 protected function buildColumns(): array
93 {
94 $f = $this->ui_factory->table()->column();
95 $type = ilObject::_lookupType($this->content_obj_id);
96 return [
97 self::COL_TITLE => $f->text($this->lng->txt('title'))->withIsSortable(true),
98 self::COL_PATH => $f->text($this->lng->txt('path'))->withIsSortable(true),
99 self::COL_ASSIGNED => $f->statusIcon($this->lng->txt('assigned'))->withIsSortable(true)
100 ];
101 }
102
106 protected function buildActions(): array
107 {
108 $f = $this->ui_factory->table()->action();
109 return [
110 self::ACTION_TOGGLE_ASSIGNMENT => $f->standard(
111 $this->lng->txt('grouping_change_assignment'),
112 $this->URLBuilder()->withParameter($this->actionToken(), self::ACTION_TOGGLE_ASSIGNMENT),
113 $this->IDToken()
114 )
115 ];
116 }
117
118 protected function URLBuilder(): URLBuilder
119 {
120 if (!isset($this->url_builder)) {
122 }
123 return $this->url_builder;
124 }
125
126 protected function actionToken(): URLBuilderToken
127 {
128 if (!isset($this->action_token)) {
130 }
131 return $this->action_token;
132 }
133
134 protected function IDToken(): URLBuilderToken
135 {
136 if (!isset($this->id_token)) {
138 }
139 return $this->id_token;
140 }
141
142 protected function initURLBuilderAndTokens(): void
143 {
144 $url_builder = new URLBuilder($this->data_factory->uri(
145 rtrim(ILIAS_HTTP_PATH, '/') . '/' . $this->action
146 ));
148 [self::NAMESPACE],
149 self::ACTION,
150 self::ID
151 );
152 $this->url_builder = $url_builder;
153 $this->action_token = $action_token;
154 $this->id_token = $id_token;
155 }
156
157 public function getSelectedTableAction(): string
158 {
159 $action = '';
160 if ($this->http->wrapper()->query()->has($this->actionToken()->getName())) {
161 $action = $this->http->wrapper()->query()->retrieve(
162 $this->actionToken()->getName(),
163 $this->refinery->identity()
164 );
165 }
166 return $action;
167 }
168
172 public function getSelectedRefIDs(): array
173 {
174 $grouping_ids = [];
176
177 $retrieval_trafo = $this->refinery->byTrying([
178 $this->refinery->custom()->transformation(function ($v) use ($data_retrieval) {
179 if ((string) $v[0] === 'ALL_OBJECTS') {
180 $res = [];
181 foreach ($data_retrieval->getAllEligibleRefIDs() as $ref_id) {
182 $res[] = $ref_id->toInt();
183 }
184 return $res;
185 }
186 throw new \Exception('not all selected');
187 }),
188 $this->refinery->kindlyTo()->listOf(
189 $this->refinery->kindlyTo()->int()
190 )
191 ]);
192
193 if ($this->http->wrapper()->query()->has($this->IDToken()->getName())) {
194 $grouping_ids = $this->http->wrapper()->query()->retrieve(
195 $this->IDToken()->getName(),
196 $retrieval_trafo
197 );
198 }
199
200 return $grouping_ids;
201 }
202}
__construct(protected string $action, protected int $content_obj_id, protected ilObjCourseGrouping $grouping, protected ilLanguage $lng, protected UIFactory $ui_factory, protected DataFactory $data_factory, protected HTTP $http, protected Refinery $refinery, ilObjUser $user, ilTree $tree)
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
Class Services.
Definition: Services.php:38
acquireParameters(array $namespace, string ... $names)
Definition: URLBuilder.php:138
language handling
Class ilObj<module_name>
User class.
Class ilObject Basic functions for all objects.
static _lookupType(int $id, bool $reference=false)
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
$http
Definition: deliver.php:30
A Column describes the form of presentation for a certain aspect of data, i.e.
Definition: Column.php:28
This describes a Data Table.
Definition: Data.php:31
$ref_id
Definition: ltiauth.php:66
$res
Definition: ltiservices.php:69
static http()
Fetches the global http state from ILIAS.
global $lng
Definition: privfeed.php:31