forked from ILIAS-eLearning/ILIAS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
250 additions
and
102 deletions.
There are no files selected for viewing
168 changes: 168 additions & 0 deletions
168
components/ILIAS/DataCollection/classes/DataRetrieval/Table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
<?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\DataCollection\DataRetrieval; | ||
|
||
use Generator; | ||
use ilDclFieldListGUI; | ||
use ilDclTable; | ||
use ilDclTableEditGUI; | ||
use ilDclTableListGUI; | ||
use ILIAS\Data\Factory; | ||
use ILIAS\Data\Order; | ||
use ILIAS\Data\Range; | ||
use ILIAS\DI; | ||
use ILIAS\DI\Container; | ||
use ILIAS\UI\Component\Table\Action\Action; | ||
use ILIAS\UI\Component\Table\DataRetrieval; | ||
use ILIAS\UI\Component\Table\DataRowBuilder; | ||
use ILIAS\UI\URLBuilder; | ||
use ILIAS\UI\URLBuilderToken; | ||
use ilObjDataCollection; | ||
use ilObjDataCollectionGUI; | ||
|
||
class Table implements DataRetrieval | ||
{ | ||
private Container $dic; | ||
|
||
public function __construct(protected readonly ilObjDataCollection $object) | ||
{ | ||
global $DIC; | ||
$this->dic = $DIC; | ||
} | ||
|
||
public function getRows( | ||
DataRowBuilder $row_builder, | ||
array $visible_column_ids, | ||
Range $range, | ||
Order $order, | ||
?array $filter_data, | ||
?array $additional_parameters | ||
): Generator { | ||
foreach ($this->object->getTables() as $table) { | ||
$this->dic->ctrl()->setParameterByClass(ilDclFieldListGUI::class, 'table_id', $table->getId()); | ||
$row_builder = $row_builder->withSingleActions($this->getActions($table)); | ||
yield $row_builder->buildDataRow((string) $table->getId(), [ | ||
'title' => $this->dic->ui()->renderer()->render( | ||
$this->dic->ui()->factory()->link()->standard( | ||
$table->getTitle(), | ||
$this->dic->ctrl()->getLinkTargetByClass(ilDclFieldListGUI::class, 'listFields') | ||
) | ||
), | ||
'default' => $table->getOrder() === 10, | ||
'visible' => $table->getIsVisible(), | ||
'comments' => $table->getPublicCommentsEnabled() | ||
]); | ||
} | ||
} | ||
|
||
/** | ||
* @return Action[] | ||
*/ | ||
protected function getActions(ilDclTable $table): array | ||
{ | ||
$this->dic->ctrl()->setParameterByClass(ilObjDataCollectionGUI::class, 'table_id', $table->getId()); | ||
|
||
$actions = []; | ||
[$builder, $token] = $this->buildURL(ilDclTableEditGUI::class, 'edit'); | ||
$actions[] = $this->dic->ui()->factory()->table()->action()->single( | ||
$this->dic->language()->txt('settings'), | ||
$builder, | ||
$token | ||
); | ||
|
||
[$builder, $token] = $this->buildURL(ilDclFieldListGUI::class, 'listFields'); | ||
$actions[] = $this->dic->ui()->factory()->table()->action()->single( | ||
$this->dic->language()->txt('dcl_list_fields'), | ||
$builder, | ||
$token | ||
); | ||
|
||
[$builder, $token] = $this->buildURL(ilDclFieldListGUI::class, 'show'); | ||
$actions[] = $this->dic->ui()->factory()->table()->action()->single( | ||
$this->dic->language()->txt('dcl_tableviews'), | ||
$builder, | ||
$token | ||
); | ||
|
||
[$builder, $token] = $this->buildURL(ilDclFieldListGUI::class, 'confirmDelete'); | ||
$actions[] = $this->dic->ui()->factory()->table()->action()->single( | ||
$this->dic->language()->txt('delete'), | ||
$builder, | ||
$token | ||
); | ||
|
||
if ($table->getIsVisible()) { | ||
[$builder, $token] = $this->buildURL(ilDclTableEditGUI::class, 'disableVisible'); | ||
$actions[] = $this->dic->ui()->factory()->table()->action()->single( | ||
$this->dic->language()->txt('disable_visible'), | ||
$builder, | ||
$token | ||
); | ||
} else { | ||
[$builder, $token] = $this->buildURL(ilDclTableEditGUI::class, 'enableVisible'); | ||
$actions[] = $this->dic->ui()->factory()->table()->action()->single( | ||
$this->dic->language()->txt('enable_visible'), | ||
$builder, | ||
$token | ||
); | ||
} | ||
|
||
if ($table->getPublicCommentsEnabled()) { | ||
[$builder, $token] = $this->buildURL(ilDclTableEditGUI::class, 'disableComments'); | ||
$actions[] = $this->dic->ui()->factory()->table()->action()->single( | ||
$this->dic->language()->txt('disable_comments'), | ||
$builder, | ||
$token | ||
); | ||
} else { | ||
[$builder, $token] = $this->buildURL(ilDclTableEditGUI::class, 'enableComments'); | ||
$actions[] = $this->dic->ui()->factory()->table()->action()->single( | ||
$this->dic->language()->txt('enable_comments'), | ||
$builder, | ||
$token | ||
); | ||
} | ||
|
||
if ($table->getOrder() !== 10) { | ||
[$builder, $token] = $this->buildURL(ilDclTableEditGUI::class, 'setAsDefault'); | ||
$actions[] = $this->dic->ui()->factory()->table()->action()->single( | ||
$this->dic->language()->txt('set_as_default'), | ||
$builder, | ||
$token | ||
); | ||
} | ||
|
||
return $actions; | ||
} | ||
|
||
private function buildURL(string $class, string $cmd): array | ||
{ | ||
global $DIC; | ||
$link = ILIAS_HTTP_PATH . '/' . $DIC->ctrl()->getLinkTargetByClass($class, $cmd); | ||
$url_builder = new URLBuilder((new Factory())->uri($link)); | ||
return $url_builder->acquireParameters(['i'], 'i'); | ||
} | ||
|
||
public function getTotalRowCount(?array $filter_data, ?array $additional_parameters): ?int | ||
{ | ||
return count($this->object->getTables()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.