Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 115 additions & 0 deletions components/ILIAS/Membership/classes/Export/Table/DataRetrieval.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?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\Membership\Export\Table;

use ILIAS\UI\Component\Table\DataRetrieval as DataRetrievalInterface;
use ILIAS\UI\Component\Table\DataRowBuilder;
use ILIAS\Data\Range;
use ILIAS\Data\Order;
use Generator;
use ilFileSystemAbstractionStorage;
use ilLanguage;
use ilUtil;
use DateTimeImmutable;

class DataRetrieval implements DataRetrievalInterface
{
protected ilFileSystemAbstractionStorage $fss_export;
protected ilLanguage $lng;

protected ?array $raw_data = null;

public function __construct(
ilFileSystemAbstractionStorage $fss_export,
ilLanguage $lng
) {
$this->fss_export = $fss_export;
$this->lng = $lng;
}

public function getRows(
DataRowBuilder $row_builder,
array $visible_column_ids,
Range $range,
Order $order,
mixed $additional_viewcontrol_data,
mixed $filter_data,
mixed $additional_parameters
): Generator {
$data = $this->getRawData();

$order_field = array_keys($order->get())[0] ?? TableBuilder::COL_DATE;
$order_direction = $order->get()[$order_field] ?? Order::DESC;

uasort($data, function ($a, $b) use ($order_field) {
if ($order_field === TableBuilder::COL_SIZE || $order_field === TableBuilder::COL_DATE) {
return $a[$order_field] <=> $b[$order_field];
}
return strnatcasecmp((string) $a[$order_field], (string) $b[$order_field]);
});

if ($order_direction === Order::DESC) {
$data = array_reverse($data, true);
}

$data = array_slice($data, $range->getStart(), $range->getLength() ?? 50, true);

foreach ($data as $id => $row) {
$row_copy = $row;
$row_copy[TableBuilder::COL_SIZE] = ilUtil::formatSize((int) $row[TableBuilder::COL_SIZE]);
$row_copy[TableBuilder::COL_DATE] = new DateTimeImmutable('@' . $row[TableBuilder::COL_DATE]);

yield $row_builder->buildDataRow((string) $id, $row_copy);
}
}

public function getTotalRowCount(
mixed $additional_viewcontrol_data,
mixed $filter_data,
mixed $additional_parameters
): ?int {
return count($this->getRawData());
}

public function getAllIDs(): array
{
return array_keys($this->getRawData());
}

protected function getRawData(): array
{
if ($this->raw_data !== null) {
return $this->raw_data;
}
$data = [];
foreach ($this->fss_export->getMemberExportFiles() as $exp_file) {
$id = md5($exp_file['name']);
$data[$id] = [
TableBuilder::COL_ID => $id,
TableBuilder::COL_NAME => $exp_file['name'],
TableBuilder::COL_TYPE => strtoupper((string) $exp_file["type"]),
TableBuilder::COL_DATE => $exp_file['timest'],
TableBuilder::COL_SIZE => $exp_file['size']
];
}
return $this->raw_data = $data;
}
}
96 changes: 96 additions & 0 deletions components/ILIAS/Membership/classes/Export/Table/TableBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?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\Membership\Export\Table;

use ILIAS\UI\Factory as UIFactory;
use ILIAS\UI\Component\Table\Data as DataTable;
use ilLanguage;
use ILIAS\HTTP\Services as HTTP;
use ILIAS\UI\URLBuilder;
use ILIAS\UI\URLBuilderToken;
use ilObjUser;
use ILIAS\Data\Factory as DataFactory;
use ilCalendarSettings;

class TableBuilder
{
public const string COL_ID = 'id';
public const string COL_NAME = 'name';
public const string COL_TYPE = 'type';
public const string COL_SIZE = 'size';
public const string COL_DATE = 'date';

public const string ACTION_DOWNLOAD = 'downloadExportFile';
public const string ACTION_DELETE = 'confirmDeleteExportFile';

public function __construct(
protected DataRetrieval $data_retrieval,
protected ilLanguage $lng,
protected UIFactory $ui_factory,
protected HTTP $http,
protected ilObjUser $user,
protected DataFactory $data_factory
) {
}

public function get(
URLBuilder $url_builder,
URLBuilderToken $id_token,
URLBuilderToken $action_token
): DataTable {
$date_format = $this->user->getDateFormat();
if ($this->user->getTimeFormat() == ilCalendarSettings::TIME_FORMAT_24) {
$date_format = $this->data_factory->dateFormat()->withTime24($date_format);
} else {
$date_format = $this->data_factory->dateFormat()->withTime12($date_format);
}

$columns = [];
$columns[self::COL_TYPE] = $this->ui_factory->table()->column()->text(
$this->lng->txt('type')
)->withIsSortable(true);
$columns[self::COL_SIZE] = $this->ui_factory->table()->column()->text(
$this->lng->txt('ps_size')
)->withIsSortable(true);
$columns[self::COL_DATE] = $this->ui_factory->table()->column()->date(
$this->lng->txt('date'),
$date_format
)->withIsSortable(true);

$actions = [];
$actions[self::ACTION_DOWNLOAD] = $this->ui_factory->table()->action()->single(
$this->lng->txt('download'),
$url_builder->withParameter($action_token, self::ACTION_DOWNLOAD),
$id_token
);
$actions[self::ACTION_DELETE] = $this->ui_factory->table()->action()->standard(
$this->lng->txt('delete'),
$url_builder->withParameter($action_token, self::ACTION_DELETE),
$id_token
);

return $this->ui_factory->table()->data(
$this->data_retrieval,
$this->lng->txt('ps_export_files'),
$columns
)->withActions($actions)->withRequest($this->http->request());
}
}

This file was deleted.

Loading
Loading