19declare(strict_types=1);
30use Psr\Http\Message\ServerRequestInterface;
32use Psr\Http\Message\RequestInterface;
48 private readonly ServerRequestInterface|RequestInterface
$request;
54 private readonly \ILIAS\ResourceStorage\Services
$irss;
70 public function __construct(
int $parent_obj_id,
string $parent_obj_type,
protected bool $has_write =
false)
74 $this->
lng = $DIC->language();
75 $this->tpl =
$DIC->ui()->mainTemplate();
76 $this->
factory = $DIC->ui()->factory();
77 $this->
renderer = $DIC->ui()->renderer();
79 $this->request =
$DIC->http()->request();
80 $this->
http = $DIC->http();
81 $this->irss =
$DIC->resourceStorage();
83 $this->parent_id = $parent_obj_id;
84 $this->parent_type = $parent_obj_type;
88 $DIC->ui()->mainTemplate()
104 if ($this->cached_records !==
null) {
111 'id' => $badge->getId(),
113 'active' => $badge->isActive(),
114 'type' => $this->parent_type !==
'bdga'
116 : $badge->getTypeInstance()->getCaption(),
117 'manual' => !$badge->getTypeInstance() instanceof
ilBadgeAuto,
118 'title_sortable' => $badge->getTitle()
122 $this->cached_records = $rows;
149 $badge = $record[
'badge'];
156 $image_src = $this->badge_image_service->getImageFromBadge($badge);
157 if ($image_src !==
'') {
158 $images[
'rendered'] = $this->
renderer->render(
159 $this->
factory->image()->responsive(
165 $image_src_large = $this->badge_image_service->getImageFromBadge(
169 if ($image_src_large !==
'') {
170 $images[
'large'] = $this->
factory->image()->responsive(
181 'description' => $badge->getDescription(),
182 'badge_criteria' => $badge->getCriteria(),
187 $record[
'image'] = $images[
'rendered']
190 $record[
'title'] = implode(
'', [
201 array $visible_column_ids,
204 mixed $additional_viewcontrol_data,
206 mixed $additional_parameters
211 [$order_field, $order_direction] = $order->
join(
213 fn($ret, $key, $value) => [$key, $value]
216 usort($records,
static function (array $left, array $right) use ($order_field):
int {
217 if (\in_array($order_field, [
'title',
'type'],
true)) {
218 if ($order_field ===
'title') {
219 $order_field .=
'_sortable';
222 return \ilStr::strCmp(
228 if ($order_field ===
'active') {
229 return $right[$order_field] <=> $left[$order_field];
232 return $left[$order_field] <=> $right[$order_field];
236 $records = array_reverse($records);
244 $identifications = [];
245 foreach ($records as $record) {
246 if ($record[
'badge']->getImageRid() !==
null && $record[
'badge']->getImageRid() !==
'') {
247 $identifications[] = $record[
'badge']->getImageRid();
251 $this->irss->preload($identifications);
253 $modal_container =
new ModalBuilder();
254 foreach ($records as $record) {
255 $record = $this->
enrichRecord($modal_container, $record);
259 ->withDisabledAction(
260 'award_revoke_badge',
261 !$record[
'manual'] || !$record[
'active']
267 mixed $additional_viewcontrol_data,
269 mixed $additional_parameters
271 return \count($this->getRecords());
280 'image' => $this->
factory->table()->column()->text($this->
lng->txt(
'image'))->withIsSortable(
false),
281 'title' => $this->
factory->table()->column()->text($this->
lng->txt(
'title')),
282 'type' => $this->
factory->table()->column()->text($this->
lng->txt(
'type')),
283 'active' => $this->
factory->table()->column()->boolean(
284 $this->
lng->txt(
'active'),
285 $this->lng->txt(
'yes'),
286 $this->lng->txt(
'no')
287 )->withOrderingLabels(
288 $this->
lng->txt(
'badge_sort_active_badges_first'),
289 $this->lng->txt(
'badge_sort_active_badges_last')
302 return $this->has_write ? [
303 'badge_table_activate' =>
304 $this->
factory->table()->action()->multi(
305 $this->
lng->txt(
'activate'),
306 $url_builder->withParameter($action_parameter_token,
'badge_table_activate'),
309 'badge_table_deactivate' =>
310 $this->
factory->table()->action()->multi(
311 $this->
lng->txt(
'deactivate'),
312 $url_builder->withParameter($action_parameter_token,
'badge_table_deactivate'),
315 'badge_table_edit' => $this->
factory->table()->action()->single(
316 $this->
lng->txt(
'edit'),
317 $url_builder->withParameter($action_parameter_token,
'badge_table_edit'),
320 'badge_table_delete' =>
322 $this->
lng->txt(
'delete'),
323 $url_builder->withParameter($action_parameter_token,
'badge_table_delete'),
326 'award_revoke_badge' =>
327 $this->
factory->table()->action()->single(
328 $this->
lng->txt(
'badge_award_revoke'),
329 $url_builder->withParameter($action_parameter_token,
'award_revoke_badge'),
337 $df = new \ILIAS\Data\Factory();
339 $table_uri = $df->uri(
$url);
341 $query_params_namespace = [
'tid'];
343 [$url_builder, $action_parameter_token, $row_id_token] = $url_builder->acquireParameters(
344 $query_params_namespace,
351 ->data($this, $this->
lng->txt(
'obj_bdga'), $this->getColumns())
352 ->withId(str_replace(
'\\',
'', self::class) .
'_' . $this->parent_id)
353 ->withOrder(
new Order(
'title', Order::ASC))
354 ->withRange(
new Range(0, 100))
355 ->withActions($this->getActions($url_builder, $action_parameter_token, $row_id_token))
356 ->withRequest($this->request);
358 $query = $this->
http->wrapper()->query();
360 if ($query->has($action_parameter_token->getName())) {
361 $action = $query->retrieve($action_parameter_token->getName(), $this->refinery->to()->string());
362 $ids = $query->retrieve($row_id_token->getName(), $this->refinery->custom()->transformation(fn($v) => $v));
364 if ($action ===
'delete') {
366 foreach ($ids as
$id) {
367 $items[] = $this->
factory->modal()->interruptiveItem()->keyValue(
369 $row_id_token->getName(),
374 $this->
http->saveResponse(
378 Streams::ofString($this->
renderer->renderAsync([
379 $this->factory->modal()->interruptive(
380 $this->lng->txt(
'badge_deletion'),
381 $this->lng->txt(
'badge_deletion_confirmation'),
383 )->withAffectedItems($items)
387 $this->
http->sendResponse();
388 $this->
http->close();
393 $this->tpl->setContent($this->
renderer->render(
394 $content_wrapper->wrap(
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
renderShyButton(string $label, Modal $modal)
renderModal(Modal $modal)
constructModal(?Image $badge_image, string $badge_title, array $badge_properties=[], bool $enclose_in_div=false)
This class provides a central helper method to wrap the content of a KS/UI > Table > Data into a spec...
readonly ILIAS Refinery Factory $refinery
readonly ILIAS ResourceStorage Services $irss
readonly Factory $factory
readonly Renderer $renderer
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 recor...
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....
__construct(int $parent_obj_id, string $parent_obj_type, protected bool $has_write=false)
readonly string $parent_type
readonly ServerRequestInterface RequestInterface $request
readonly ilGlobalTemplateInterface $tpl
getActions(URLBuilder $url_builder, URLBuilderToken $action_parameter_token, URLBuilderToken $row_id_token,)
readonly ilBadgeImage $badge_image_service
enrichRecord(ModalBuilder $modal_builder, array $record)
Builds a Color from either hex- or rgb values.
Both the subject and the direction need to be specified when expressing an order.
join($init, callable $fn)
A simple class to express a naive range of whole positive numbers.
Stream factory which enables the user to create streams without the knowledge of the concrete class.
static getExtendedTypeCaption(ilBadgeType $a_type)
static getInstancesByParentId(int $a_parent_id, ?array $a_filter=null)
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
A Column describes the form of presentation for a certain aspect of data, i.e.
buildDataRow(string $id, array $record)
This is how the factory for UI elements looks.
An entity that renders components to a string output.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static http()
Fetches the global http state from ILIAS.