From ae5923bd8c2af99f8b11290b4c628d71d209e4cb Mon Sep 17 00:00:00 2001 From: Thomas Famula Date: Thu, 26 Oct 2023 17:24:54 +0200 Subject: [PATCH] Add LinkList Column --- src/UI/Component/Table/Column/Factory.php | 13 +++- src/UI/Component/Table/Column/LinkList.php | 25 ++++++++ .../Component/Table/Column/Factory.php | 5 ++ .../Component/Table/Column/LinkList.php | 37 +++++++++++ src/UI/examples/Table/Column/Link/base.php | 3 +- .../examples/Table/Column/LinkList/base.php | 62 +++++++++++++++++++ .../Table/Column/ColumnFactoryTest.php | 6 +- .../UI/Component/Table/Column/ColumnTest.php | 9 +++ 8 files changed, 156 insertions(+), 4 deletions(-) create mode 100644 src/UI/Component/Table/Column/LinkList.php create mode 100644 src/UI/Implementation/Component/Table/Column/LinkList.php create mode 100644 src/UI/examples/Table/Column/LinkList/base.php diff --git a/src/UI/Component/Table/Column/Factory.php b/src/UI/Component/Table/Column/Factory.php index abfb51eeaa69..4195334b357a 100644 --- a/src/UI/Component/Table/Column/Factory.php +++ b/src/UI/Component/Table/Column/Factory.php @@ -114,10 +114,21 @@ public function timeSpan(string $title, \ILIAS\Data\DateFormat\DateFormat $forma * --- * description: * purpose: > - * The Link Column features a Link. + * The Link Column features a Standard Link. * * --- * @return \ILIAS\UI\Component\Table\Column\Link */ public function link(string $title): Link; + + /** + * --- + * description: + * purpose: > + * The Link Column features a Listing of Standard Links. + * + * --- + * @return \ILIAS\UI\Component\Table\Column\LinkList + */ + public function linkList(string $title): LinkList; } diff --git a/src/UI/Component/Table/Column/LinkList.php b/src/UI/Component/Table/Column/LinkList.php new file mode 100644 index 000000000000..7a6df52e15b6 --- /dev/null +++ b/src/UI/Component/Table/Column/LinkList.php @@ -0,0 +1,25 @@ +checkArgInstanceOf('value', $value, Listing::class); + $check = $value->getItems(); + $this->checkArgListElements("list items", $check, Standard::class); + return $value; + } +} diff --git a/src/UI/examples/Table/Column/Link/base.php b/src/UI/examples/Table/Column/Link/base.php index 75526703e224..b086ac45a944 100644 --- a/src/UI/examples/Table/Column/Link/base.php +++ b/src/UI/examples/Table/Column/Link/base.php @@ -55,6 +55,7 @@ public function getTotalRowCount( } }; - $table = $f->table()->data('Link Columns', $columns, $data_retrieval); + $table = $f->table()->data('Link Columns', $columns, $data_retrieval) + ->withRequest($DIC->http()->request()); return $r->render($table); } diff --git a/src/UI/examples/Table/Column/LinkList/base.php b/src/UI/examples/Table/Column/LinkList/base.php new file mode 100644 index 000000000000..cb561916bd4c --- /dev/null +++ b/src/UI/examples/Table/Column/LinkList/base.php @@ -0,0 +1,62 @@ +ui()->factory(); + $r = $DIC->ui()->renderer(); + + $columns = [ + 'l1' => $f->table()->column()->linkList("a link list column") + ]; + + $some_link = $f->link()->standard('ILIAS Homepage', 'http://www.ilias.de'); + $some_linklist = $f->listing()->unordered([$some_link, $some_link, $some_link]); + + $dummy_records = [ + ['l1' => $some_linklist], + ['l1' => $some_linklist] + ]; + + $data_retrieval = new class ($dummy_records) implements I\DataRetrieval { + protected array $records; + + public function __construct(array $dummy_records) + { + $this->records = $dummy_records; + } + + public function getRows( + I\DataRowBuilder $row_builder, + array $visible_column_ids, + Range $range, + Order $order, + ?array $filter_data, + ?array $additional_parameters + ): \Generator { + foreach ($this->records as $idx => $record) { + $row_id = ''; + yield $row_builder->buildDataRow($row_id, $record); + } + } + + public function getTotalRowCount( + ?array $filter_data, + ?array $additional_parameters + ): ?int { + return null; + } + }; + + $table = $f->table()->data('Link List Columns', $columns, $data_retrieval) + ->withRequest($DIC->http()->request()); + return $r->render($table); +} diff --git a/tests/UI/Component/Table/Column/ColumnFactoryTest.php b/tests/UI/Component/Table/Column/ColumnFactoryTest.php index 105a70f290c2..aa53eb994ea3 100644 --- a/tests/UI/Component/Table/Column/ColumnFactoryTest.php +++ b/tests/UI/Component/Table/Column/ColumnFactoryTest.php @@ -34,7 +34,8 @@ class ColumnFactoryTest extends AbstractFactoryTest "status" => ["context" => false, "rules" => false], "statusIcon" => ["context" => false, "rules" => false], "timeSpan" => ["context" => false, "rules" => false], - "link" => ["context" => false, "rules" => false] + "link" => ["context" => false, "rules" => false], + "linkList" => ["context" => false, "rules" => false] ]; public $factory_title = 'ILIAS\\UI\\Component\\Table\\Column\\Factory'; @@ -61,7 +62,8 @@ public function getColumnTypeProvider(): array [Column\Status::class, $f->status("")], [Column\StatusIcon::class, $f->statusIcon("")], [Column\EMail::class, $f->eMail("")], - [Column\Link::class, $f->link("")] + [Column\Link::class, $f->link("")], + [Column\LinkList::class, $f->linkList("")] ]; } diff --git a/tests/UI/Component/Table/Column/ColumnTest.php b/tests/UI/Component/Table/Column/ColumnTest.php index 5f3d93c26d28..a28fd6bb0527 100644 --- a/tests/UI/Component/Table/Column/ColumnTest.php +++ b/tests/UI/Component/Table/Column/ColumnTest.php @@ -24,6 +24,7 @@ use ILIAS\UI\Implementation\Component\Table\Column; use ILIAS\UI\Implementation\Component\Link; +use ILIAS\UI\Implementation\Component\Listing; /** * Basic Tests for Table-Columns. @@ -110,4 +111,12 @@ public function testDataTableColumnLinkFormatAcceptsOnlyLinks(): void $link = 'some string'; $this->assertEquals($link, $col->format($link)); } + + public function testDataTableColumnLinkListFormat(): void + { + $col = new Column\LinkList('col'); + $link = new Link\Standard('label', '#'); + $linklist = new Listing\Unordered([$link,$link,$link]); + $this->assertEquals($linklist, $col->format($linklist)); + } }