ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
ILIAS\Badge\ilBadgeTableGUI Class Reference
+ Inheritance diagram for ILIAS\Badge\ilBadgeTableGUI:
+ Collaboration diagram for ILIAS\Badge\ilBadgeTableGUI:

Public Member Functions

 __construct (int $parent_obj_id, string $parent_obj_type, protected bool $has_write=false)
 
 getRows (DataRowBuilder $row_builder, array $visible_column_ids, Range $range, Order $order, ?array $filter_data, ?array $additional_parameters)
 
 getTotalRowCount (?array $filter_data, ?array $additional_parameters)
 Mainly for the purpose of pagination-support, it is important to know about the total number of records available. More...
 
 renderTable (string $url)
 
- Public Member Functions inherited from ILIAS\UI\Component\Table\DataRetrieval
 getRows (DataRowBuilder $row_builder, array $visible_column_ids, Range $range, Order $order, ?array $filter_data, ?array $additional_parameters)
 This is called by the table to retrieve rows; map data-records to rows using the $row_builder e.g. More...
 

Private Member Functions

 getRecords ()
 
 enrichRecord (ModalBuilder $modal_builder, array $record)
 
 getColumns ()
 
 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 int $parent_id
 
readonly string $parent_type
 
readonly ilLanguage $lng
 
readonly ilGlobalTemplateInterface $tpl
 
readonly ILIAS ResourceStorage Services $irss
 
readonly ilBadgeImage $badge_image_service
 
array $cached_records = null
 

Detailed Description

Definition at line 41 of file class.ilBadgeTableGUI.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Badge\ilBadgeTableGUI::__construct ( int  $parent_obj_id,
string  $parent_obj_type,
protected bool  $has_write = false 
)

Definition at line 68 of file class.ilBadgeTableGUI.php.

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

69  {
70  global $DIC;
71 
72  $this->lng = $DIC->language();
73  $this->tpl = $DIC->ui()->mainTemplate();
74  $this->factory = $DIC->ui()->factory();
75  $this->renderer = $DIC->ui()->renderer();
76  $this->refinery = $DIC->refinery();
77  $this->request = $DIC->http()->request();
78  $this->http = $DIC->http();
79  $this->irss = $DIC->resourceStorage();
80 
81  $this->parent_id = $parent_obj_id;
82  $this->parent_type = $parent_obj_type;
83  $this->badge_image_service = new ilBadgeImage(
84  $this->irss,
85  $DIC->upload(),
86  $DIC->ui()->mainTemplate()
87  );
88  }
static http()
Fetches the global http state from ILIAS.
global $DIC
Definition: shib_login.php:25
+ Here is the call graph for this function:

Member Function Documentation

◆ enrichRecord()

ILIAS\Badge\ilBadgeTableGUI::enrichRecord ( ModalBuilder  $modal_builder,
array  $record 
)
private
Parameters
array{id: int, badge: ilBadge, active: bool, type: string, manual: bool, title_sortable: string } $record
Returns
array{ id: int, badge: ilBadge, active: bool, type: string, manual: bool, title_sortable: string, title: string, image: string }

Definition at line 145 of file class.ilBadgeTableGUI.php.

References ILIAS\Badge\ModalBuilder\constructModal(), ILIAS\Badge\ilBadgeImage\IMAGE_SIZE_XL, ILIAS\Badge\ModalBuilder\renderModal(), and ILIAS\Badge\ModalBuilder\renderShyButton().

Referenced by ILIAS\Badge\ilBadgeTableGUI\getRows().

145  : array
146  {
147  $badge = $record['badge'];
148 
149  $images = [
150  'rendered' => null,
151  'large' => null,
152  ];
153 
154  $image_src = $this->badge_image_service->getImageFromBadge($badge);
155  if ($image_src !== '') {
156  $images['rendered'] = $this->renderer->render(
157  $this->factory->image()->responsive(
158  $image_src,
159  $badge->getTitle()
160  )
161  );
162 
163  $image_src_large = $this->badge_image_service->getImageFromBadge(
164  $badge,
166  );
167  if ($image_src_large !== '') {
168  $images['large'] = $this->factory->image()->responsive(
169  $image_src_large,
170  $badge->getTitle()
171  );
172  }
173  }
174 
175  $modal = $modal_builder->constructModal(
176  $images['large'],
177  $badge->getTitle(),
178  [
179  'description' => $badge->getDescription(),
180  'badge_criteria' => $badge->getCriteria(),
181  ]
182  );
183 
184  $record['image'] = $images['rendered']
185  ? $modal_builder->renderShyButton($images['rendered'], $modal) . ' '
186  : '';
187  $record['title'] = implode('', [
188  $modal_builder->renderShyButton($badge->getTitle(), $modal),
189  $modal_builder->renderModal($modal)
190  ]);
191 
192  return $record;
193  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getActions()

ILIAS\Badge\ilBadgeTableGUI::getActions ( URLBuilder  $url_builder,
URLBuilderToken  $action_parameter_token,
URLBuilderToken  $row_id_token 
)
private
Returns
array<string, >

Definition at line 292 of file class.ilBadgeTableGUI.php.

References ILIAS\Repository\lng().

Referenced by ILIAS\Badge\ilBadgeTableGUI\renderTable().

296  : array {
297  return $this->has_write ? [
298  'badge_table_activate' =>
299  $this->factory->table()->action()->multi(
300  $this->lng->txt('activate'),
301  $url_builder->withParameter($action_parameter_token, 'badge_table_activate'),
302  $row_id_token
303  ),
304  'badge_table_deactivate' =>
305  $this->factory->table()->action()->multi(
306  $this->lng->txt('deactivate'),
307  $url_builder->withParameter($action_parameter_token, 'badge_table_deactivate'),
308  $row_id_token
309  ),
310  'badge_table_edit' => $this->factory->table()->action()->single(
311  $this->lng->txt('edit'),
312  $url_builder->withParameter($action_parameter_token, 'badge_table_edit'),
313  $row_id_token
314  ),
315  'badge_table_delete' =>
316  $this->factory->table()->action()->standard(
317  $this->lng->txt('delete'),
318  $url_builder->withParameter($action_parameter_token, 'badge_table_delete'),
319  $row_id_token
320  ),
321  'award_revoke_badge' =>
322  $this->factory->table()->action()->single(
323  $this->lng->txt('badge_award_revoke'),
324  $url_builder->withParameter($action_parameter_token, 'award_revoke_badge'),
325  $row_id_token
326  )
327  ] : [];
328  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getColumns()

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

Definition at line 272 of file class.ilBadgeTableGUI.php.

References ILIAS\Repository\lng().

Referenced by ILIAS\Badge\ilBadgeTableGUI\renderTable().

272  : array
273  {
274  return [
275  'image' => $this->factory->table()->column()->text($this->lng->txt('image'))->withIsSortable(false),
276  'title' => $this->factory->table()->column()->text($this->lng->txt('title')),
277  'type' => $this->factory->table()->column()->text($this->lng->txt('type')),
278  'active' => $this->factory->table()->column()->boolean(
279  $this->lng->txt('active'),
280  $this->lng->txt('yes'),
281  $this->lng->txt('no')
282  )->withOrderingLabels(
283  $this->lng->txt('badge_sort_active_badges_first'),
284  $this->lng->txt('badge_sort_active_badges_last')
285  )
286  ];
287  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getRecords()

ILIAS\Badge\ilBadgeTableGUI::getRecords ( )
private
Returns
list<array{ id: int, badge: ilBadge, active: bool, type: string, manual: bool, title_sortable: string }>

Definition at line 100 of file class.ilBadgeTableGUI.php.

References ILIAS\Badge\ilBadgeTableGUI\$cached_records, ilBadge\getExtendedTypeCaption(), and ilBadge\getInstancesByParentId().

Referenced by ILIAS\Badge\ilBadgeTableGUI\getRows(), and ILIAS\Badge\ilBadgeTableGUI\getTotalRowCount().

100  : array
101  {
102  if ($this->cached_records !== null) {
103  return $this->cached_records;
104  }
105 
106  $rows = [];
107  foreach (ilBadge::getInstancesByParentId($this->parent_id) as $badge) {
108  $rows[] = [
109  'id' => $badge->getId(),
110  'badge' => $badge,
111  'active' => $badge->isActive(),
112  'type' => $this->parent_type !== 'bdga'
113  ? ilBadge::getExtendedTypeCaption($badge->getTypeInstance())
114  : $badge->getTypeInstance()->getCaption(),
115  'manual' => !$badge->getTypeInstance() instanceof ilBadgeAuto,
116  'title_sortable' => $badge->getTitle()
117  ];
118  }
119 
120  $this->cached_records = $rows;
121 
122  return $rows;
123  }
static getExtendedTypeCaption(ilBadgeType $a_type)
static getInstancesByParentId(int $a_parent_id, array $a_filter=null)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getRows()

ILIAS\Badge\ilBadgeTableGUI::getRows ( DataRowBuilder  $row_builder,
array  $visible_column_ids,
Range  $range,
Order  $order,
?array  $filter_data,
?array  $additional_parameters 
)

Definition at line 196 of file class.ilBadgeTableGUI.php.

References ILIAS\Data\Order\DESC, ILIAS\Badge\ilBadgeTableGUI\enrichRecord(), and ILIAS\Badge\ilBadgeTableGUI\getRecords().

203  : Generator {
204  $records = $this->getRecords();
205 
206  if ($order) {
207  [$order_field, $order_direction] = $order->join(
208  [],
209  fn($ret, $key, $value) => [$key, $value]
210  );
211 
212  usort($records, static function (array $left, array $right) use ($order_field): int {
213  if (\in_array($order_field, ['title', 'type'], true)) {
214  if ($order_field === 'title') {
215  $order_field .= '_sortable';
216  }
217 
218  return \ilStr::strCmp(
219  $left[$order_field],
220  $right[$order_field]
221  );
222  }
223 
224  if ($order_field === 'active') {
225  return $right[$order_field] <=> $left[$order_field];
226  }
227 
228  return $left[$order_field] <=> $right[$order_field];
229  });
230 
231  if ($order_direction === Order::DESC) {
232  $records = array_reverse($records);
233  }
234  }
235 
236  if ($range) {
237  $records = \array_slice($records, $range->getStart(), $range->getLength());
238  }
239 
240  $identifications = [];
241  foreach ($records as $record) {
242  if ($record['badge']->getImageRid() !== null && $record['badge']->getImageRid() !== '') {
243  $identifications[] = $record['badge']->getImageRid();
244  }
245  }
246 
247  $this->irss->preload($identifications);
248 
249  $modal_container = new ModalBuilder();
250  foreach ($records as $record) {
251  $record = $this->enrichRecord($modal_container, $record);
252 
253  yield $row_builder
254  ->buildDataRow((string) $record['id'], $record)
255  ->withDisabledAction(
256  'award_revoke_badge',
257  !$record['manual'] || !$record['active']
258  );
259  }
260  }
enrichRecord(ModalBuilder $modal_builder, array $record)
const DESC
Definition: Order.php:15
+ Here is the call graph for this function:

◆ getTotalRowCount()

ILIAS\Badge\ilBadgeTableGUI::getTotalRowCount ( ?array  $filter_data,
?array  $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 262 of file class.ilBadgeTableGUI.php.

References ILIAS\Badge\ilBadgeTableGUI\getRecords().

265  : ?int {
266  return \count($this->getRecords());
267  }
+ Here is the call graph for this function:

◆ renderTable()

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

Definition at line 330 of file class.ilBadgeTableGUI.php.

References $id, $out, ILIAS\Data\Order\ASC, ILIAS\Badge\ilBadgeTableGUI\getActions(), ILIAS\Badge\ilBadgeTableGUI\getColumns(), ILIAS\FileDelivery\http(), ILIAS\Repository\lng(), ILIAS\Filesystem\Stream\Streams\ofString(), and ILIAS\Repository\refinery().

330  : void
331  {
332  $df = new \ILIAS\Data\Factory();
333 
334  $table_uri = $df->uri($url);
335  $url_builder = new URLBuilder($table_uri);
336  $query_params_namespace = ['tid'];
337 
338  [$url_builder, $action_parameter_token, $row_id_token] = $url_builder->acquireParameters(
339  $query_params_namespace,
340  'table_action',
341  'id',
342  );
343 
344  $table = $this->factory
345  ->table()
346  ->data($this->lng->txt('obj_bdga'), $this->getColumns(), $this)
347  ->withId(self::class . '_' . $this->parent_id)
348  ->withOrder(new Order('title', Order::ASC))
349  ->withActions($this->getActions($url_builder, $action_parameter_token, $row_id_token))
350  ->withRequest($this->request);
351  $out = [$table];
352 
353  $query = $this->http->wrapper()->query();
354 
355  if ($query->has($action_parameter_token->getName())) {
356  $action = $query->retrieve($action_parameter_token->getName(), $this->refinery->to()->string());
357  $ids = $query->retrieve($row_id_token->getName(), $this->refinery->custom()->transformation(fn($v) => $v));
358 
359  if ($action === 'delete') {
360  $items = [];
361  foreach ($ids as $id) {
362  $items[] = $this->factory->modal()->interruptiveItem()->keyValue(
363  $id,
364  $row_id_token->getName(),
365  $id
366  );
367  }
368 
369  $this->http->saveResponse(
370  $this->http
371  ->response()
372  ->withBody(
373  Streams::ofString($this->renderer->renderAsync([
374  $this->factory->modal()->interruptive(
375  $this->lng->txt('badge_deletion'),
376  $this->lng->txt('badge_deletion_confirmation'),
377  '#'
378  )->withAffectedItems($items)
379  ]))
380  )
381  );
382  $this->http->sendResponse();
383  $this->http->close();
384  }
385  }
386 
387  $this->tpl->setContent($this->renderer->render($out));
388  }
getActions(URLBuilder $url_builder, URLBuilderToken $action_parameter_token, URLBuilderToken $row_id_token,)
$url
Definition: shib_logout.php:63
static http()
Fetches the global http state from ILIAS.
$out
Definition: buildRTE.php:24
static ofString(string $string)
Creates a new stream with an initial value.
Definition: Streams.php:41
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:24
+ Here is the call graph for this function:

Field Documentation

◆ $badge_image_service

readonly ilBadgeImage ILIAS\Badge\ilBadgeTableGUI::$badge_image_service
private

Definition at line 53 of file class.ilBadgeTableGUI.php.

◆ $cached_records

array ILIAS\Badge\ilBadgeTableGUI::$cached_records = null
private
Returns
null|list<array{ id: int, badge: ilBadge, active: bool, type: string, manual: bool, image: string, title: string, title_sortable: string }>

Definition at line 66 of file class.ilBadgeTableGUI.php.

Referenced by ILIAS\Badge\ilBadgeTableGUI\getRecords().

◆ $factory

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

Definition at line 43 of file class.ilBadgeTableGUI.php.

◆ $http

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

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

◆ $irss

readonly ILIAS ResourceStorage Services ILIAS\Badge\ilBadgeTableGUI::$irss
private

Definition at line 52 of file class.ilBadgeTableGUI.php.

◆ $lng

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

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

◆ $parent_id

readonly int ILIAS\Badge\ilBadgeTableGUI::$parent_id
private

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

◆ $parent_type

readonly string ILIAS\Badge\ilBadgeTableGUI::$parent_type
private

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

◆ $refinery

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

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

◆ $renderer

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

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

◆ $request

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

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

◆ $tpl

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

Definition at line 51 of file class.ilBadgeTableGUI.php.


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