Skip to content

Commit

Permalink
Add LinkList Column
Browse files Browse the repository at this point in the history
  • Loading branch information
tfamula committed Oct 26, 2023
1 parent e49f115 commit ae5923b
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 4 deletions.
13 changes: 12 additions & 1 deletion src/UI/Component/Table/Column/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
25 changes: 25 additions & 0 deletions src/UI/Component/Table/Column/LinkList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
*********************************************************************/

declare(strict_types=1);

namespace ILIAS\UI\Component\Table\Column;

interface LinkList extends Column
{
}
5 changes: 5 additions & 0 deletions src/UI/Implementation/Component/Table/Column/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,9 @@ public function link(string $title): I\Link
{
return new Link($title);
}

public function linkList(string $title): I\LinkList
{
return new LinkList($title);
}
}
37 changes: 37 additions & 0 deletions src/UI/Implementation/Component/Table/Column/LinkList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
*********************************************************************/

declare(strict_types=1);

namespace ILIAS\UI\Implementation\Component\Table\Column;

use ILIAS\UI\Component\Table\Column as C;
use ILIAS\UI\Component\Link\Standard;
use ILIAS\UI\Component\Listing\Listing;
use ILIAS\UI\Component\Component;

class LinkList extends Column implements C\LinkList
{
public function format($value): string|Component
{
$this->checkArgInstanceOf('value', $value, Listing::class);
$check = $value->getItems();
$this->checkArgListElements("list items", $check, Standard::class);
return $value;
}
}
3 changes: 2 additions & 1 deletion src/UI/examples/Table/Column/Link/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
62 changes: 62 additions & 0 deletions src/UI/examples/Table/Column/LinkList/base.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

declare(strict_types=1);

namespace ILIAS\UI\examples\Table\Column\LinkList;

use ILIAS\UI\Component\Table as I;
use ILIAS\Data\Range;
use ILIAS\Data\Order;

function base(): string
{
global $DIC;
$f = $DIC->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);
}
6 changes: 4 additions & 2 deletions tests/UI/Component/Table/Column/ColumnFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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("")]
];
}

Expand Down
9 changes: 9 additions & 0 deletions tests/UI/Component/Table/Column/ColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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));
}
}

0 comments on commit ae5923b

Please sign in to comment.