ILIAS  trunk Revision v12.0_alpha-454-g178fcb218fa
ILIAS\Badge\ilBadgeImageTemplateTableGUI Class Reference
+ Inheritance diagram for ILIAS\Badge\ilBadgeImageTemplateTableGUI:
+ Collaboration diagram for ILIAS\Badge\ilBadgeImageTemplateTableGUI:

Public Member Functions

 __construct (protected bool $has_write=false)
 
 getRows (DataRowBuilder $row_builder, array $visible_column_ids, Range $range, Order $order, mixed $additional_viewcontrol_data, mixed $filter_data, mixed $additional_parameters)
 This is called by the table to retrieve rows; map data-records to rows using the $row_builder e.g. More...
 
 getTotalRowCount (mixed $additional_viewcontrol_data, mixed $filter_data, mixed $additional_parameters)
 Mainly for the purpose of pagination-support, it is important to know about the total number of records available. More...
 
 getColumns ()
 
 renderTable (string $url)
 
 getRows (DataRowBuilder $row_builder, array $visible_column_ids, Range $range, Order $order, mixed $additional_viewcontrol_data, mixed $filter_data, mixed $additional_parameters)
 This is called by the table to retrieve rows; map data-records to rows using the $row_builder e.g. More...
 
 getTotalRowCount (mixed $additional_viewcontrol_data, mixed $filter_data, mixed $additional_parameters)
 Mainly for the purpose of pagination-support, it is important to know about the total number of records available. More...
 

Private Member Functions

 getRecords ()
 
 getActions (URLBuilder $url_builder, URLBuilderToken $action_parameter_token, URLBuilderToken $row_id_token)
 

Private Attributes

readonly Factory $factory
 
readonly Renderer $renderer
 
readonly ILIAS Refinery Factory $refinery
 
readonly ServerRequestInterface RequestInterface $request
 
readonly Services $http
 
readonly ilLanguage $lng
 
readonly ilGlobalTemplateInterface $tpl
 
array $cached_records = null
 

Detailed Description

Definition at line 42 of file class.ilBadgeImageTemplateTableGUI.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Badge\ilBadgeImageTemplateTableGUI::__construct ( protected bool  $has_write = false)

Definition at line 54 of file class.ilBadgeImageTemplateTableGUI.php.

55 {
56 global $DIC;
57 $this->lng = $DIC->language();
58 $this->tpl = $DIC->ui()->mainTemplate();
59 $this->factory = $DIC->ui()->factory();
60 $this->renderer = $DIC->ui()->renderer();
61 $this->refinery = $DIC->refinery();
62 $this->request = $DIC->http()->request();
63 $this->http = $DIC->http();
64 }
renderer()
factory()
static http()
Fetches the global http state from ILIAS.
global $DIC
Definition: shib_login.php:26

References $DIC, factory(), ILIAS\FileDelivery\http(), ILIAS\Repository\lng(), ILIAS\Repository\refinery(), and renderer().

+ Here is the call graph for this function:

Member Function Documentation

◆ getActions()

ILIAS\Badge\ilBadgeImageTemplateTableGUI::getActions ( URLBuilder  $url_builder,
URLBuilderToken  $action_parameter_token,
URLBuilderToken  $row_id_token 
)
private
Returns
array<string, \ILIAS\UI\Component\Table\Action\Action>

Definition at line 181 of file class.ilBadgeImageTemplateTableGUI.php.

185 : array {
186 return $this->has_write ? [
187 'badge_image_template_edit' => $this->factory->table()->action()->single(
188 $this->lng->txt('edit'),
189 $url_builder->withParameter($action_parameter_token, 'badge_image_template_editImageTemplate'),
190 $row_id_token
191 ),
192 'badge_image_template_delete' =>
193 $this->factory->table()->action()->standard(
194 $this->lng->txt('delete'),
195 $url_builder->withParameter($action_parameter_token, 'badge_image_template_delete'),
196 $row_id_token
197 )
198 ] : [];
199 }
withParameter(URLBuilderToken $token, string|array $value)
Change an acquired parameter's value if the supplied token is valid.
Definition: URLBuilder.php:166

◆ getColumns()

ILIAS\Badge\ilBadgeImageTemplateTableGUI::getColumns ( )
Returns
array<string, Column>

Definition at line 170 of file class.ilBadgeImageTemplateTableGUI.php.

170 : array
171 {
172 return [
173 'image' => $this->factory->table()->column()->text($this->lng->txt('image'))->withIsSortable(false),
174 'title' => $this->factory->table()->column()->text($this->lng->txt('title'))
175 ];
176 }

References factory(), and ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ getRecords()

ILIAS\Badge\ilBadgeImageTemplateTableGUI::getRecords ( )
private
Returns
list<array{id: int, image: string, title: string, title_sortable: string}>

Definition at line 69 of file class.ilBadgeImageTemplateTableGUI.php.

69 : array
70 {
71 if ($this->cached_records !== null) {
73 }
74
75 $modal_container = new ModalBuilder();
76 $rows = [];
77
78 foreach (ilBadgeImageTemplate::getInstances() as $template) {
79 $image = '';
80 $title = $template->getTitle();
81
82 $image_src = $template->getImageFromResourceId();
83 if ($image_src !== '') {
84 $image_component = $this->factory->image()->responsive(
85 $image_src,
86 $template->getTitle()
87 );
88 $image_html = $this->renderer->render($image_component);
89
90 $large_image_component = $this->factory->image()->responsive(
91 $image_src,
92 $template->getTitle()
93 );
94
95 $modal = $modal_container->constructModal($large_image_component, $template->getTitle(), [], true);
96
97 $image = implode('', [
98 $modal_container->renderShyButton($image_html, $modal),
99 $modal_container->renderModal($modal)
100 ]);
101 $title = $modal_container->renderShyButton($template->getTitle(), $modal);
102 }
103
104 $rows[] = [
105 'id' => $template->getId(),
106 'image' => $image,
107 'title' => $title,
108 'title_sortable' => $template->getTitle()
109 ];
110 }
111
112 $this->cached_records = $rows;
113
114 return $rows;
115 }

References ILIAS\Badge\ilBadgeImageTemplateTableGUI\$cached_records, factory(), ilBadgeImageTemplate\getInstances(), and renderer().

+ Here is the call graph for this function:

◆ getRows()

ILIAS\Badge\ilBadgeImageTemplateTableGUI::getRows ( DataRowBuilder  $row_builder,
array  $visible_column_ids,
Range  $range,
Order  $order,
mixed  $additional_viewcontrol_data,
mixed  $filter_data,
mixed  $additional_parameters 
)

This is called by the table to retrieve rows; map data-records to rows using the $row_builder e.g.

yield $row_builder->buildStandardRow($row_id, $record).

Parameters
string[]$visible_column_ids

Implements ILIAS\UI\Component\Table\DataRetrieval.

Definition at line 117 of file class.ilBadgeImageTemplateTableGUI.php.

125 : Generator {
126 $records = $this->getRecords();
127
128 if ($order) {
129 [$order_field, $order_direction] = $order->join(
130 [],
131 fn($ret, $key, $value) => [$key, $value]
132 );
133
134 usort($records, static function (array $left, array $right) use ($order_field): int {
135 if ($order_field === 'title') {
136 return \ilStr::strCmp(
137 $left[$order_field . '_sortable'],
138 $right[$order_field . '_sortable']
139 );
140 }
141
142 return $left[$order_field] <=> $right[$order_field];
143 });
144
145 if ($order_direction === Order::DESC) {
146 $records = array_reverse($records);
147 }
148 }
149
150 if ($range) {
151 $records = \array_slice($records, $range->getStart(), $range->getLength());
152 }
153
154 foreach ($records as $record) {
155 yield $row_builder->buildDataRow((string) $record['id'], $record);
156 }
157 }
join($init, callable $fn)
Definition: Order.php:75
const DESC
Definition: Order.php:31
buildDataRow(string $id, array $record)

References ILIAS\Data\Order\DESC, and ILIAS\Data\Order\join().

+ Here is the call graph for this function:

◆ getTotalRowCount()

ILIAS\Badge\ilBadgeImageTemplateTableGUI::getTotalRowCount ( mixed  $additional_viewcontrol_data,
mixed  $filter_data,
mixed  $additional_parameters 
)

Mainly for the purpose of pagination-support, it is important to know about the total number of records available.

Given the nature of a DataTable, which is, opposite to a PresentationTable, rather administrative than explorative, this information will increase user experience quite a bit. However, you may return null, if the call is to costly, but expect the View Control to look a little different in this case.

Make sure that potential filters or user restrictions are being applied to the count.

Implements ILIAS\UI\Component\Table\DataRetrieval.

Definition at line 159 of file class.ilBadgeImageTemplateTableGUI.php.

163 : ?int {
164 return \count($this->getRecords());
165 }

◆ renderTable()

ILIAS\Badge\ilBadgeImageTemplateTableGUI::renderTable ( string  $url)

Definition at line 201 of file class.ilBadgeImageTemplateTableGUI.php.

201 : void
202 {
203 $df = new \ILIAS\Data\Factory();
204
205 $table_uri = $df->uri($url);
206 $url_builder = new URLBuilder($table_uri);
207 $query_params_namespace = ['tid'];
208
209 [$url_builder, $action_parameter_token, $row_id_token] = $url_builder->acquireParameters(
210 $query_params_namespace,
211 'table_action',
212 'id',
213 );
214
215 $table = $this->factory
216 ->table()
217 ->data($this, $this->lng->txt('badge_image_templates'), $this->getColumns())
218 ->withId(self::class)
219 ->withOrder(new Order('title', Order::ASC))
220 ->withActions($this->getActions($url_builder, $action_parameter_token, $row_id_token))
221 ->withRequest($this->request);
222
223 $query = $this->http->wrapper()->query();
224 if ($query->has('tid')) {
225 $query_values = $query->retrieve(
226 'tid',
227 $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->string())
228 );
229
230 $items = [];
231 if ($query_values === ['ALL_OBJECTS']) {
232 foreach (ilBadgeImageTemplate::getInstances() as $template) {
233 if ($template->getId() !== null) {
234 $items[] = $this->factory->modal()->interruptiveItem()->keyValue(
235 (string) $template->getId(),
236 (string) $template->getId(),
237 $template->getTitle()
238 );
239 }
240 }
241 } elseif (\is_array($query_values)) {
242 foreach ($query_values as $id) {
243 $badge = new ilBadgeImageTemplate((int) $id);
244 $items[] = $this->factory->modal()->interruptiveItem()->keyValue(
245 (string) $id,
246 (string) $badge->getId(),
247 $badge->getTitle()
248 );
249 }
250 } else {
251 $badge = new ilBadgeImageTemplate($query_values);
252 $items[] = $this->factory->modal()->interruptiveItem()->keyValue(
253 (string) $badge->getId(),
254 (string) $badge->getId(),
255 $badge->getTitle()
256 );
257 }
258 if ($query->has($action_parameter_token->getName())) {
259 $action = $query->retrieve($action_parameter_token->getName(), $this->refinery->kindlyTo()->string());
260 if ($action === 'badge_image_template_delete') {
261 $this->http->saveResponse(
262 $this->http
263 ->response()
264 ->withBody(
265 Streams::ofString($this->renderer->renderAsync([
266 $this->factory->modal()->interruptive(
267 $this->lng->txt('badge_deletion'),
268 $this->lng->txt('badge_deletion_confirmation'),
269 '#'
270 )->withAffectedItems($items)
271 ]))
272 )
273 );
274 $this->http->sendResponse();
275 $this->http->close();
276 }
277 }
278 }
279
280 $content_wrapper = new TableContentWrapper($this->renderer, $this->factory);
281 $this->tpl->setContent($this->renderer->render(
282 $content_wrapper->wrap(
283 $table
284 )
285 ));
286 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
getActions(URLBuilder $url_builder, URLBuilderToken $action_parameter_token, URLBuilderToken $row_id_token)
Both the subject and the direction need to be specified when expressing an order.
Definition: Order.php:29
static ofString(string $string)
Creates a new stream with an initial value.
Definition: Streams.php:41
$url
Definition: shib_logout.php:68

References $id, $url, factory(), ilBadgeImageTemplate\getInstances(), ILIAS\FileDelivery\http(), ILIAS\Repository\lng(), ILIAS\Repository\refinery(), and renderer().

+ Here is the call graph for this function:

Field Documentation

◆ $cached_records

array ILIAS\Badge\ilBadgeImageTemplateTableGUI::$cached_records = null
private

◆ $factory

readonly Factory ILIAS\Badge\ilBadgeImageTemplateTableGUI::$factory
private

Definition at line 44 of file class.ilBadgeImageTemplateTableGUI.php.

◆ $http

readonly Services ILIAS\Badge\ilBadgeImageTemplateTableGUI::$http
private

Definition at line 48 of file class.ilBadgeImageTemplateTableGUI.php.

◆ $lng

readonly ilLanguage ILIAS\Badge\ilBadgeImageTemplateTableGUI::$lng
private

Definition at line 49 of file class.ilBadgeImageTemplateTableGUI.php.

◆ $refinery

readonly ILIAS Refinery Factory ILIAS\Badge\ilBadgeImageTemplateTableGUI::$refinery
private

Definition at line 46 of file class.ilBadgeImageTemplateTableGUI.php.

◆ $renderer

readonly Renderer ILIAS\Badge\ilBadgeImageTemplateTableGUI::$renderer
private

Definition at line 45 of file class.ilBadgeImageTemplateTableGUI.php.

◆ $request

readonly ServerRequestInterface RequestInterface ILIAS\Badge\ilBadgeImageTemplateTableGUI::$request
private

Definition at line 47 of file class.ilBadgeImageTemplateTableGUI.php.

◆ $tpl

readonly ilGlobalTemplateInterface ILIAS\Badge\ilBadgeImageTemplateTableGUI::$tpl
private

Definition at line 50 of file class.ilBadgeImageTemplateTableGUI.php.


The documentation for this class was generated from the following file: