From a0211fce1bc4f7cea93c9e5048c3e2e48bea787f Mon Sep 17 00:00:00 2001 From: Guido Vollbach Date: Tue, 9 Jan 2024 09:31:23 +0100 Subject: [PATCH] Starting to convert tables --- .../class.ilBadgePictureDefinition.php | 77 +++++ .../Flavours/class.ilBadgePictureMachine.php | 109 +++++++ Services/Badge/classes/class.ilBadgeImage.php | 7 +- .../classes/class.ilBadgeImageTemplate.php | 7 +- .../class.ilBadgeImageTemplateTable.php | 240 ++++++++++++++++ .../classes/class.ilBadgeManagementGUI.php | 10 +- Services/Badge/classes/class.ilBadgeTable.php | 271 ++++++++++++++++++ .../Badge/classes/class.ilBadgeTableGUI.php | 2 +- .../class.ilObjBadgeAdministrationGUI.php | 75 ++--- 9 files changed, 740 insertions(+), 58 deletions(-) create mode 100644 Services/Badge/classes/Flavours/class.ilBadgePictureDefinition.php create mode 100644 Services/Badge/classes/Flavours/class.ilBadgePictureMachine.php create mode 100644 Services/Badge/classes/class.ilBadgeImageTemplateTable.php create mode 100644 Services/Badge/classes/class.ilBadgeTable.php diff --git a/Services/Badge/classes/Flavours/class.ilBadgePictureDefinition.php b/Services/Badge/classes/Flavours/class.ilBadgePictureDefinition.php new file mode 100644 index 000000000000..9609bf44bd5a --- /dev/null +++ b/Services/Badge/classes/Flavours/class.ilBadgePictureDefinition.php @@ -0,0 +1,77 @@ + 512, + 'small' => 100, + 'xsmall' => 75, + 'xxsmall' => 30 + ]; + + public function __construct( + ) { + } + + public function getId(): string + { + return self::ID; + } + + public function getFlavourMachineId(): string + { + return ilBadgePictureMachine::ID; + } + + public function getInternalName(): string + { + return 'badge_picture'; + } + + public function getVariantName(): ?string + { + return json_encode([ + 'quality' => $this->quality, + 'sizes' => $this->sizes + ]); + } + + public function persist(): bool + { + return true; + } + + public function getSizes(): array + { + return $this->sizes; + } + + public function getQuality(): int + { + return $this->quality; + } +} diff --git a/Services/Badge/classes/Flavours/class.ilBadgePictureMachine.php b/Services/Badge/classes/Flavours/class.ilBadgePictureMachine.php new file mode 100644 index 000000000000..725c5af9eb53 --- /dev/null +++ b/Services/Badge/classes/Flavours/class.ilBadgePictureMachine.php @@ -0,0 +1,109 @@ + + */ +class ilBadgePictureMachine extends AbstractMachine implements FlavourMachine +{ + use GdImageToStreamTrait; + public const ID = "badge_image_resize_machine"; + private const FULL_QUALITY_SIZE_THRESHOLD = 100; + private CropSquare $crop; + private MakeGreyScale $grey; + private ?ilBadgePictureDefinition $definition = null; + private ?FileInformation $information = null; + + public function __construct() + { + $this->crop = new CropSquare(); + } + + + public function getId(): string + { + return self::ID; + } + + public function canHandleDefinition(FlavourDefinition $definition): bool + { + return $definition instanceof ilBadgePictureDefinition; + } + + public function dependsOnEngine(): ?string + { + return GDEngine::class; + } + + public function processStream( + FileInformation $information, + FileStream $stream, + FlavourDefinition $for_definition + ): \Generator { + /** @var ilBadgePictureDefinition $for_definition */ + $this->definition = $for_definition; + $this->information = $information; + + $i = 0; + foreach ($for_definition->getSizes() as $size) { + yield new Result( + $for_definition, + $this->cropImage($stream, $size), + $i, + true + ); + $i++; + } + } + + protected function cropImage( + FileStream $stream, + int $size + ) { + $quality = $size <= self::FULL_QUALITY_SIZE_THRESHOLD + ? 100 // we take 100% jpeg quality for small resultions + : $this->definition->getQuality(); + + + return $this->crop->processStream( + $this->information, + $stream, + new CropToSquare( + false, + $size, + $quality + ) + )->current()->getStream(); + } + +} diff --git a/Services/Badge/classes/class.ilBadgeImage.php b/Services/Badge/classes/class.ilBadgeImage.php index 9da8626b44d1..75aaab983f44 100644 --- a/Services/Badge/classes/class.ilBadgeImage.php +++ b/Services/Badge/classes/class.ilBadgeImage.php @@ -38,7 +38,11 @@ public function getImageFromResourceId(ilBadge $badge, ?string $image_rid) : str if ($image_rid !== null) { $identification = $this->resource_storage->manage()->find($image_rid); if ($identification !== null) { - $image_src = $this->resource_storage->consume()->src($identification)->getSrc(); + $flavour = $this->resource_storage->flavours()->get($identification, new \ilBadgePictureDefinition()); + $urls = $this->resource_storage->consume()->flavourUrls($flavour)->getURLsAsArray(false); + if(is_array($urls) && sizeof($urls) === 4 && isset($urls[1])) { + $image_src = $urls[1]; + } } } else { $image_src = $badge->getImage(); @@ -55,6 +59,7 @@ public function processImageUpload(ilBadge $badge) : void $array_result = array_pop($array_result); $stakeholder = new ilBadgeFileStakeholder(); $identification = $this->resource_storage->manage()->upload($array_result, $stakeholder); + $this->resource_storage->flavours()->ensure($identification, new \ilBadgePictureDefinition()); $badge->setImageRid($identification); $badge->update(); } catch (IllegalStateException $e) { diff --git a/Services/Badge/classes/class.ilBadgeImageTemplate.php b/Services/Badge/classes/class.ilBadgeImageTemplate.php index f22e77f781e5..c3728bc9dd0d 100644 --- a/Services/Badge/classes/class.ilBadgeImageTemplate.php +++ b/Services/Badge/classes/class.ilBadgeImageTemplate.php @@ -182,6 +182,7 @@ public function processImageUpload( $badge) : void if($array_result->getName() !== '') { $stakeholder = new ilBadgeFileStakeholder(); $identification = $this->resource_storage->manage()->upload($array_result, $stakeholder); + $this->resource_storage->flavours()->ensure($identification, new \ilBadgePictureDefinition()); $badge->setImageRid($identification); $badge->update(); } @@ -377,7 +378,11 @@ public function getImageFromResourceId(?string $image_rid, int $badge_id = null) if ($image_rid !== null) { $identification = $this->resource_storage->manage()->find($image_rid); if ($identification !== null) { - $image_src = $this->resource_storage->consume()->src($identification)->getSrc(); + $flavour = $this->resource_storage->flavours()->get($identification, new \ilBadgePictureDefinition()); + $urls = $this->resource_storage->consume()->flavourUrls($flavour)->getURLsAsArray(false); + if(is_array($urls) && sizeof($urls) === 4 && isset($urls[1])) { + $image_src = $urls[1]; + } } } else { if($badge_id !== null) { diff --git a/Services/Badge/classes/class.ilBadgeImageTemplateTable.php b/Services/Badge/classes/class.ilBadgeImageTemplateTable.php new file mode 100644 index 000000000000..f71b91c8ab79 --- /dev/null +++ b/Services/Badge/classes/class.ilBadgeImageTemplateTable.php @@ -0,0 +1,240 @@ +lng = $DIC->language(); + $this->tpl = $DIC->ui()->mainTemplate(); + $this->factory = $DIC->ui()->factory(); + $this->renderer = $DIC->ui()->renderer(); + $this->refinery = $DIC->refinery(); + $this->request = $DIC->http()->request(); + $this->http = $DIC->http(); + } + + /** + * @param Factory $f + * @param Renderer $r + * @return DataRetrieval|__anonymous@1221 + */ + protected function buildDataRetrievalObject(Factory $f, Renderer $r) + { + return new class ($f, $r) implements DataRetrieval { + public function __construct( + protected Factory $ui_factory, + protected Renderer $ui_renderer + ) { + } + + /** + * @param Container $DIC + * @param array $data + * @return array + */ + protected function getBadgeImageTemplates(Container $DIC, array $data) : array + { + foreach (ilBadgeImageTemplate::getInstances() as $template) { + $image_html = ''; + if ($template->getId() !== null) { + $badge_template_image = $template->getImageFromResourceId($template->getImageRid()); + if($badge_template_image !== '') { + $badge_img = $DIC->ui()->factory()->image()->responsive( + $badge_template_image, + $template->getTitle() + ); + $image_html = $DIC->ui()->renderer()->render($badge_img); + } + + $data[] = + ['id' => $template->getId(), + 'title' => $template->getTitle(), + 'image_rid' => $image_html + ]; + } + } + return $data; + } + + public function getRows( + DataRowBuilder $row_builder, + array $visible_column_ids, + Range $range, + Order $order, + ?array $filter_data, + ?array $additional_parameters + ) : Generator { + $records = $this->getRecords($range, $order); + foreach ($records as $idx => $record) { + $row_id = (string) $record['id']; + yield $row_builder->buildDataRow($row_id, $record); + } + } + + public function getTotalRowCount( + ?array $filter_data, + ?array $additional_parameters + ) : ?int { + return count($this->getRecords()); + } + + protected function getRecords(Range $range = null, Order $order = null) : array + { + + global $DIC; + $data = array(); + + $data = $this->getBadgeImageTemplates($DIC, $data); + + if ($order) { + list($order_field, $order_direction) = $order->join([], + fn($ret, $key, $value) => [$key, $value]); + usort($data, fn($a, $b) => $a[$order_field] <=> $b[$order_field]); + if ($order_direction === 'DESC') { + $data = array_reverse($data); + } + } + if ($range) { + $data = array_slice($data, $range->getStart(), $range->getLength()); + } + + return $data; + } + }; + } + + /** + * @param URLBuilder $url_builder + * @param URLBuilderToken $action_parameter_token + * @param URLBuilderToken $row_id_token + * @return array + */ + protected function getActions( + URLBuilder $url_builder, + URLBuilderToken $action_parameter_token, + URLBuilderToken $row_id_token + ) : array { + $f = $this->factory; + return [ + 'edit' => $f->table()->action()->single( //never in multi actions + $this->lng->txt("edit"), + $url_builder->withParameter($action_parameter_token, "editImageTemplate"), + $row_id_token + ), + 'info' => + $f->table()->action()->standard( //in both + $this->lng->txt("info"), + $url_builder->withParameter($action_parameter_token, "info"), + $row_id_token + ) + ->withAsync() + , + 'delete' => + $f->table()->action()->standard( //in both + $this->lng->txt("delete"), + $url_builder->withParameter($action_parameter_token, "delete"), + $row_id_token + ) + ->withAsync() + ]; + } + + public function renderTable() : void + { + $f = $this->factory; + $r = $this->renderer; + $refinery = $this->refinery; + $request = $this->request; + $df = new \ILIAS\Data\Factory(); + + $columns = [ + 'title' => $f->table()->column()->text($this->lng->txt("title")), + 'image_rid' => $f->table()->column()->text($this->lng->txt("image")), + ]; + + $table_uri = $df->uri($request->getUri()->__toString()); + $url_builder = new URLBuilder($table_uri); + $query_params_namespace = ['tid']; + + list($url_builder, $action_parameter_token, $row_id_token) = + $url_builder->acquireParameters( + $query_params_namespace, + "table_action", + "id" + ); + + $actions = $this->getActions($url_builder, $action_parameter_token, $row_id_token); + + $data_retrieval = $this->buildDataRetrievalObject($f, $r); + + $table = $f->table() + ->data('', $columns, $data_retrieval) + ->withActions($actions) + ->withRequest($request); + + $out = [$table]; + + $query = $this->http->wrapper()->query(); + if ($query->has($action_parameter_token->getName())) { + $action = $query->retrieve($action_parameter_token->getName(), $refinery->to()->string()); + $ids = $query->retrieve($row_id_token->getName(), $refinery->custom()->transformation(fn($v) => $v)); + $listing = $f->listing()->characteristicValue()->text([ + 'table_action' => $action, + 'id' => print_r($ids, true), + ]); + + if ($action === 'delete') { + $items = []; + foreach ($ids as $id) { + $items[] = $f->modal()->interruptiveItem()->keyValue($id, $row_id_token->getName(), $id); + } + echo($r->renderAsync([ + $f->modal()->interruptive( + 'Deletion', + 'You are about to delete items!', + '#' + )->withAffectedItems($items) + ->withAdditionalOnLoadCode(static fn($id) : string => "console.log('ASYNC JS');") + ])); + exit(); + } + if ($action === 'info') { + echo( + $r->render($f->messageBox()->info('an info message:
  • ' . implode('
  • ', $ids))) + . '' + ); + + } + + $out[] = $f->divider()->horizontal(); + $out[] = $listing; + } + + $this->tpl->setContent($r->render($out)); + } +} \ No newline at end of file diff --git a/Services/Badge/classes/class.ilBadgeManagementGUI.php b/Services/Badge/classes/class.ilBadgeManagementGUI.php index 88dc0537088d..5b2dbbde41c6 100644 --- a/Services/Badge/classes/class.ilBadgeManagementGUI.php +++ b/Services/Badge/classes/class.ilBadgeManagementGUI.php @@ -20,6 +20,8 @@ use ILIAS\ResourceStorage\Services; use ILIAS\FileUpload\FileUpload; use ILIAS\FileUpload\Exception\IllegalStateException; +use ILIAS\ResourceStorage\Flavour\Definition\FlavourDefinition; +use ILIAS\Badge\ilBadgeTable; /** * Class ilBadgeManagementGUI @@ -45,6 +47,7 @@ class ilBadgeManagementGUI private ?ilBadgeImage $badge_image_service = null; private ?Services $resource_storage = null; private ?FileUpload $upload_service = null; + private ?ilBadgePictureDefinition $flavour_definition = null; public function __construct( private readonly int $parent_ref_id, @@ -82,6 +85,7 @@ public function __construct( $this->session_repo = new ilBadgeManagementSessionRepository(); $this->badge_image_service = new ilBadgeImage($DIC->resourceStorage(), $DIC->upload(), $DIC->ui()->mainTemplate()); + $this->flavour_definition = new ilBadgePictureDefinition(); } public function executeCommand(): void @@ -215,6 +219,8 @@ protected function listBadges(): void $tbl = new ilBadgeTableGUI($this, 'listBadges', $this->parent_obj_id, $this->hasWrite()); $tpl->setContent($tbl->getHTML()); + $table = new ilBadgeTable($this->parent_obj_id, $this->parent_obj_type); + #$table->renderTable(); } protected function applyBadgeFilter(): void @@ -461,7 +467,9 @@ protected function setBadgeFormValues( $a_form->getItemByPostVar('img')->setImage($a_badge->getImagePath()); $image_src = $this->badge_image_service->getImageFromBadge($a_badge); - $a_form->getItemByPostVar('img')->setImage($image_src); + if($image_src !== '') { + $a_form->getItemByPostVar('img')->setImage($image_src); + } $a_form->getItemByPostVar('valid')->setValue($a_badge->getValid()); diff --git a/Services/Badge/classes/class.ilBadgeTable.php b/Services/Badge/classes/class.ilBadgeTable.php new file mode 100644 index 000000000000..d832a4f79465 --- /dev/null +++ b/Services/Badge/classes/class.ilBadgeTable.php @@ -0,0 +1,271 @@ +lng = $DIC->language(); + $this->tpl = $DIC->ui()->mainTemplate(); + $this->factory = $DIC->ui()->factory(); + $this->renderer = $DIC->ui()->renderer(); + $this->refinery = $DIC->refinery(); + $this->request = $DIC->http()->request(); + $this->http = $DIC->http(); + + $this->parent_id = $parent_obj_id; + $this->parent_type = $parent_obj_type; + } + + /** + * @param Factory $f + * @param Renderer $r + * @return DataRetrieval|__anonymous@1221 + */ + protected function buildDataRetrievalObject(Factory $f, Renderer $r, int $p, string $type) + { + return new class ($f, $r, $p, $type) implements DataRetrieval { + protected $parent_obj_id; + protected $parent_obj_type; + public function __construct( + protected Factory $ui_factory, + protected Renderer $ui_renderer, + protected int $parent_id, + protected string $parent_type + ) { + global $DIC; + $this->parent_obj_id = $parent_id; + $this->parent_obj_type = $parent_type; + $this->badge_image_service = new ilBadgeImage($DIC->resourceStorage(), $DIC->upload(), $DIC->ui()->mainTemplate()); + } + + /** + * @param Container $DIC + * @param array $data + * @return array + */ + protected function getBadges(Container $DIC, array $data) : array + { + if (true) { + $data = array(); + + foreach (ilBadge::getInstancesByParentId($this->parent_id, null) as $badge) { + $badge_rid = $badge->getImageRid(); + $image_src = $this->badge_image_service->getImageFromResourceId($badge, $badge_rid); + if($badge_rid != '') { + $badge_template_image = $image_src; + if($badge_template_image !== '') { + $badge_img = $DIC->ui()->factory()->image()->responsive( + $badge_template_image, + $badge->getTitle() + ); + $image_html = $DIC->ui()->renderer()->render($badge_img); + } + } + + $badge_active = $badge->isActive() ? $DIC->language()->txt('yes') : $DIC->language()->txt('no'); + $data[] = array( + "id" => $badge->getId(), + "badge" => $badge, + "title" => $badge->getTitle(), + "active" => $badge_active, + "type" => ($this->parent_type !== "bdga") + ? ilBadge::getExtendedTypeCaption($badge->getTypeInstance()) + : $badge->getTypeInstance()->getCaption(), + "manual" => (!$badge->getTypeInstance() instanceof ilBadgeAuto), + "image_rid" => $image_html, + "renderer" => fn () => $this->tile->asTitle($this->tile->modalContent($badge)), + ); + } + return $data; + } + } + + public function getRows( + DataRowBuilder $row_builder, + array $visible_column_ids, + Range $range, + Order $order, + ?array $filter_data, + ?array $additional_parameters + ) : Generator { + $records = $this->getRecords($range, $order); + foreach ($records as $idx => $record) { + $row_id = (string) $record['id']; + yield $row_builder->buildDataRow($row_id, $record); + } + } + + public function getTotalRowCount( + ?array $filter_data, + ?array $additional_parameters + ) : ?int { + return count($this->getRecords()); + } + + protected function getRecords(Range $range = null, Order $order = null) : array + { + + global $DIC; + $data = array(); + + $data = $this->getBadges($DIC, $data); + + if ($order) { + list($order_field, $order_direction) = $order->join([], + fn($ret, $key, $value) => [$key, $value]); + usort($data, fn($a, $b) => $a[$order_field] <=> $b[$order_field]); + if ($order_direction === 'DESC') { + $data = array_reverse($data); + } + } + if ($range) { + $data = array_slice($data, $range->getStart(), $range->getLength()); + } + + return $data; + } + }; + } + + /** + * @param URLBuilder $url_builder + * @param URLBuilderToken $action_parameter_token + * @param URLBuilderToken $row_id_token + * @return array + */ + protected function getActions( + URLBuilder $url_builder, + URLBuilderToken $action_parameter_token, + URLBuilderToken $row_id_token + ) : array { + $f = $this->factory; + return [ + 'edit' => $f->table()->action()->single( //never in multi actions + $this->lng->txt("edit"), + $url_builder->withParameter($action_parameter_token, "editImageTemplate"), + $row_id_token + ), + 'info' => + $f->table()->action()->standard( //in both + $this->lng->txt("info"), + $url_builder->withParameter($action_parameter_token, "info"), + $row_id_token + ) + ->withAsync() + , + 'delete' => + $f->table()->action()->standard( //in both + $this->lng->txt("delete"), + $url_builder->withParameter($action_parameter_token, "delete"), + $row_id_token + ) + ->withAsync() + ]; + } + + public function renderTable() : void + { + $f = $this->factory; + $r = $this->renderer; + $refinery = $this->refinery; + $request = $this->request; + $df = new \ILIAS\Data\Factory(); + + $columns = [ + 'title' => $f->table()->column()->text($this->lng->txt("title")), + 'image_rid' => $f->table()->column()->text($this->lng->txt("image")), + 'type' => $f->table()->column()->text($this->lng->txt("type")), + 'active' => $f->table()->column()->text($this->lng->txt("active")), + ]; + + $table_uri = $df->uri($request->getUri()->__toString()); + $url_builder = new URLBuilder($table_uri); + $query_params_namespace = ['tid']; + + list($url_builder, $action_parameter_token, $row_id_token) = + $url_builder->acquireParameters( + $query_params_namespace, + "table_action", + "id" + ); + + $actions = $this->getActions($url_builder, $action_parameter_token, $row_id_token); + + $data_retrieval = $this->buildDataRetrievalObject($f, $r, $this->parent_id, $this->parent_type); + + $table = $f->table() + ->data('', $columns, $data_retrieval) + ->withActions($actions) + ->withRequest($request); + + $out = [$table]; + + $query = $this->http->wrapper()->query(); + if ($query->has($action_parameter_token->getName())) { + $action = $query->retrieve($action_parameter_token->getName(), $refinery->to()->string()); + $ids = $query->retrieve($row_id_token->getName(), $refinery->custom()->transformation(fn($v) => $v)); + $listing = $f->listing()->characteristicValue()->text([ + 'table_action' => $action, + 'id' => print_r($ids, true), + ]); + + if ($action === 'delete') { + $items = []; + foreach ($ids as $id) { + $items[] = $f->modal()->interruptiveItem()->keyValue($id, $row_id_token->getName(), $id); + } + echo($r->renderAsync([ + $f->modal()->interruptive( + 'Deletion', + 'You are about to delete items!', + '#' + )->withAffectedItems($items) + ->withAdditionalOnLoadCode(static fn($id) : string => "console.log('ASYNC JS');") + ])); + exit(); + } + if ($action === 'info') { + echo( + $r->render($f->messageBox()->info('an info message:
  • ' . implode('
  • ', $ids))) + . '' + ); + + } + + $out[] = $f->divider()->horizontal(); + $out[] = $listing; + } + + $this->tpl->setContent($r->render($out)); + } +} \ No newline at end of file diff --git a/Services/Badge/classes/class.ilBadgeTableGUI.php b/Services/Badge/classes/class.ilBadgeTableGUI.php index 6ec2a3aeca50..8f109de182a6 100644 --- a/Services/Badge/classes/class.ilBadgeTableGUI.php +++ b/Services/Badge/classes/class.ilBadgeTableGUI.php @@ -145,7 +145,7 @@ protected function fillRow(array $a_set): void } $image_src = $this->badge_image_service->getImageFromResourceId($a_set['badge'], $a_set['image_rid']); - if (null !== $a_set['image_rid']) { + if (null !== $a_set['image_rid'] && $image_src !== '') { global $DIC; $image_responsive = $DIC->ui()->factory()->image()->responsive($image_src, $a_set['title']); $image = $this->ui->renderer()->render($image_responsive); diff --git a/Services/Badge/classes/class.ilObjBadgeAdministrationGUI.php b/Services/Badge/classes/class.ilObjBadgeAdministrationGUI.php index 8a936cdccb43..81082f555260 100644 --- a/Services/Badge/classes/class.ilObjBadgeAdministrationGUI.php +++ b/Services/Badge/classes/class.ilObjBadgeAdministrationGUI.php @@ -18,6 +18,9 @@ use ILIAS\UI\Implementation\Component\Table\PresentationRow; use ILIAS\UI\Factory; +use ILIAS\UI\URLBuilder; +use ILIAS\Data\Order; +use ILIAS\Data\Range; /** * Badge Administration Settings. @@ -83,7 +86,22 @@ public function executeCommand(): void if (!$cmd || $cmd === 'view') { $cmd = "editSettings"; } + global $DIC; + $action_parameter_token = 'tid_id'; + $query = $DIC->http()->wrapper()->query(); + if ($query->has($action_parameter_token)) { + if($query->has($action_parameter_token)) { + $id = $query->retrieve($action_parameter_token, $DIC->refinery()->kindlyTo()->listOf($DIC->refinery()->kindlyTo()->int())); + if(is_array($id)) { + $id = array_pop($id); + } + $DIC->ctrl()->setParameter( $this, "tid", $id); + } + $a_form = $this->editImageTemplate(); + #$DIC->ui()->mainTemplate()->setContent($a_form->getHTML()); + break; + } $this->$cmd(); break; } @@ -288,62 +306,11 @@ protected function listImageTemplates(): void "listImageTemplates", $ilAccess->checkAccess("write", "", $this->object->getRefId()) ); - $this->tpl->setContent($tbl->getHTML()); - $this->testPresentationTable(); + # $this->tpl->setContent($tbl->getHTML()); + $template_table = new \ILIAS\Badge\ilBadgeImageTemplateTable(); + $template_table->renderTable(); } - protected function testPresentationTable() { - global $DIC; - $f = $DIC->ui()->factory(); - $renderer = $DIC->ui()->renderer(); - - //build viewcontrols - $actions = array("All" => "#", "Upcoming events" => "#"); - $aria_label = "filter entries"; - $view_controls = array( - $f->viewControl()->mode($actions, $aria_label)->withActive("All") - ); - - $ptable = $f->table()->presentation( - "", - $view_controls, - function ( - PresentationRow $row, - ilBadgeImageTemplate $record, - Factory $ui, - $environment - ) { - $img = $ui->image()->responsive( - $record->getImageFromResourceId($record->getImageRid()), - "Thumbnail Example" - ); - $html = $environment['renderer']->render($img); - return $row - ->withHeadline($record->getTitle()) - ->withSubheadline($record->getImageRid()) - ->withContent($ui->listing()->descriptive(['gfdhfgh' => 'dasfasdf'])) - ->withFurtherFields([$html]) - ->withAction($ui->button()->standard('edit BROKEN', '#')) - ; - } - )->withEnvironment([ - 'renderer' => $renderer - ]); - - //example data as from an assoc-query, list of arrays - $data = array(); - - foreach (ilBadgeImageTemplate::getInstances() as $template) { - - if($template->getId() !== null) { - $data[] = $template; - } - } - - - //apply data to table and render - $this->tpl->setContent($renderer->render($ptable->withData($data))); - } protected function addImageTemplate( ilPropertyFormGUI $a_form = null