Skip to content

Commit

Permalink
review dashboard #4 blockdto
Browse files Browse the repository at this point in the history
  • Loading branch information
fhelfer committed Jun 26, 2023
1 parent 06b61b0 commit 90272d7
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*********************************************************************/

declare(strict_types=1);
class ilBlockDataDTO
class ilBlockDTO
{
private string $type;
private int $ref_id;
Expand Down
32 changes: 16 additions & 16 deletions Services/Dashboard/Block/classes/class.ilDashboardBlockGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ abstract public function addCustomCommandsToActionMenu(ilObjectListGUI $itemList
abstract public function emptyHandling(): string;


protected function getCardForData(ilBlockDataDTO $data): ?RepositoryObject
protected function getCardForData(ilBlockDTO $data): ?RepositoryObject
{
$itemListGui = $this->byType($data->getType());
$card = $itemListGui->getAsCard(
Expand Down Expand Up @@ -107,7 +107,7 @@ protected function getListItemGroups(): array
return $groupedCards;
}

protected function getListItemForDataDTO(ilBlockDataDTO $data): ?Item
protected function getListItemForDataDTO(ilBlockDTO $data): ?Item
{
$itemListGui = $this->byType($data->getType());
$this->addCustomCommandsToActionMenu($itemListGui, $data->getRefId());
Expand Down Expand Up @@ -200,31 +200,31 @@ public function getHTML(): string
}

/**
* @param array<string, ilBlockDataDTO[]> $a_data
* @param array<string, ilBlockDTO[]> $a_data
*/
public function setData(array $a_data): void
{
$this->data = array_filter(array_map(
static fn ($group) => array_filter($group, fn ($item) => $item instanceof ilBlockDataDTO),
static fn ($group) => array_filter($group, fn ($item) => $item instanceof ilBlockDTO),
$a_data
));
}

/**
* @return array<string, ilBlockDataDTO[]>
* @return array<string, ilBlockDTO[]>
*/
public function getData(): array
{
return parent::getData();
}

/**
* @return array<string, ilBlockDataDTO[]>
* @return array<string, ilBlockDTO[]>
*/
public function groupItemsByStartDate(): array
{
$data = $this->getData();
/** @var ilBlockDataDTO[] $items */
/** @var ilBlockDTO[] $items */
$items = array_merge(...array_values($data));

$groups = [
Expand All @@ -247,7 +247,7 @@ public function groupItemsByStartDate(): array
}
}

$orderByDate = static function (ilBlockDataDTO $left, ilBlockDataDTO $right, bool $asc = true) {
$orderByDate = static function (ilBlockDTO $left, ilBlockDTO $right, bool $asc = true) {
if ($left->getStartDate() && $right->getStartDate() && $left->getStartDate()->get(
IL_CAL_UNIX
) < $right->getStartDate()->get(IL_CAL_UNIX)) {
Expand Down Expand Up @@ -277,7 +277,7 @@ public function groupItemsByStartDate(): array
}

/**
* @return array<string, ilBlockDataDTO[]>
* @return array<string, ilBlockDTO[]>
*/
protected function groupItemsByType(): array
{
Expand All @@ -286,7 +286,7 @@ protected function groupItemsByType(): array
);
$grouped_items = [];
$data = $this->getData();
/** @var ilBlockDataDTO[] $data */
/** @var ilBlockDTO[] $data */
$data = array_merge(...array_values($data));
$provider = new ilPDSelectedItemsBlockMembershipsProvider($this->viewSettings->getActor());

Expand Down Expand Up @@ -317,17 +317,17 @@ protected function groupItemsByType(): array
}

/**
* @return array<string, ilBlockDataDTO[]>
* @return array<string, ilBlockDTO[]>
*/
protected function groupItemsByLocation(): array
{
$grouped_items = [];
$data = $this->getData();
/** @var ilBlockDataDTO[] $data */
/** @var ilBlockDTO[] $data */
$data = array_merge(...array_values($data));

$parent_ref_ids = array_values(array_unique(
array_map(fn (ilBlockDataDTO $item): ?int => $this->tree->getParentId($item->getRefId()), $data)
array_map(fn (ilBlockDTO $item): ?int => $this->tree->getParentId($item->getRefId()), $data)
));
$this->object_cache->preloadReferenceCache($parent_ref_ids);

Expand Down Expand Up @@ -464,7 +464,7 @@ protected function returnToContext(): void
}

/**
* @return array<string, ilBlockDataDTO[]>
* @return array<string, ilBlockDTO[]>
*/
public function getItemGroups(): array
{
Expand Down Expand Up @@ -741,13 +741,13 @@ public function byType(string $a_type): ilObjectListGUI
}

/**
* @param ilBlockDataDTO[] $data
* @param ilBlockDTO[] $data
*/
private function sortByTitle(array $data, bool $asc = true): array
{
uasort(
$data,
static fn (ilBlockDataDTO $left, ilBlockDataDTO $right) => $asc ?
static fn (ilBlockDTO $left, ilBlockDTO $right) => $asc ?
strcmp($left->getTitle(), $right->getTitle()) :
strcmp($right->getTitle(), $left->getTitle())
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function initData(): void
continue;
}

$data[] = new ilBlockDataDTO(
$data[] = new ilBlockDTO(
'lso',
$lso_ref_id,
$lso_obj->getId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function initData(): void
$data = array_map(static function (array $item) {
$start = isset($item['start']) && $item['start'] instanceof ilDateTime ? $item['start'] : null;
$end = isset($item['end']) && $item['end'] instanceof ilDateTime ? $item['end'] : null;
return new ilBlockDataDTO(
return new ilBlockDTO(
$item['type'],
(int) $item['ref_id'],
(int) $item['obj_id'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function initData(): void
break;
}
}
return new ilBlockDataDTO(
return new ilBlockDTO(
ilObject::_lookupType($obj_id),
$ref_id,
$obj_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function initData(): void
$data = array_map(static function (array $item) {
$start = isset($item['start']) && $item['start'] instanceof ilDateTime ? $item['start'] : null;
$end = isset($item['end']) && $item['end'] instanceof ilDateTime ? $item['end'] : null;
return new ilBlockDataDTO(
return new ilBlockDTO(
$item['type'],
(int) $item['ref_id'],
(int) $item['obj_id'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ilStudyProgrammeBlockGUI extends ilDashboardBlockGUI
{
protected ?string $visible_on_pd_mode = null;

protected function getListItemForDataDTO(ilBlockDataDTO $data): ?Item
protected function getListItemForDataDTO(ilBlockDTO $data): ?Item
{
$item_gui = $this->byType($data->getType());
$item_gui->initItem(
Expand Down Expand Up @@ -158,7 +158,7 @@ public function initData(): void
$properties[] = [$this->lng->txt('certificate') => $this->renderer->render($cert_link)];
}

$items[] = new ilBlockDataDTO(
$items[] = new ilBlockDTO(
$prg->getType(),
$prg->getRefId(),
$prg->getId(),
Expand Down

0 comments on commit 90272d7

Please sign in to comment.