ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
RevisionListingUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
30
35{
36 protected array $components = [];
38 private \ilLanguage $language;
39
40 public function __construct(
41 private ViewDefinition $view_definition,
42 protected StorableResource $resource,
43 ) {
44 global $DIC;
45 $this->language = $DIC->language();
46 $this->language->loadLanguageModule('irss');
47 $this->ui_factory = $DIC->ui()->factory();
48 match ($view_definition->getMode()) {
52 default => $this->initTable(),
53 };
54 }
55
56 private function initItems(): void
57 {
58 $this->components = array_map(function (Revision $revision): Item {
59 $revision_to_component = new RevisionToComponent(
60 $revision
61 );
62 $item = $revision_to_component->getAsItem(false);
63 return $item->withLeadText($this->language->txt('revision') . ' ' . $revision->getVersionNumber());
64 }, array_reverse($this->resource->getAllRevisionsIncludingDraft()));
65 }
66
67 private function initDeck(): void
68 {
69 $this->components[] = $this->ui_factory->deck(
70 array_map(
71 function (Revision $revision): Card {
72 $revision_to_component = new RevisionToComponent(
73 $revision
74 );
75 $card = $revision_to_component->getAsCard();
76 return $card->withTitle($this->prependRevisionNumberToTitle($revision, $card->getTitle()));
77 },
78 array_reverse($this->resource->getAllRevisionsIncludingDraft())
79 )
80 )->withSmallCardsSize();
81 }
82
83 private function initTable(): void
84 {
85 // Table
86 $this->components[] = $this->ui_factory->table()->presentation(
87 '',
88 [],
89 $this->getRowMapping()
90 )->withData(
91 array_reverse($this->resource->getAllRevisionsIncludingDraft())
92 );
93 }
94
95 public function getRowMapping(): \Closure
96 {
97 return function (
98 PresentationRow $row,
99 Revision $revision
100 ): PresentationRow {
101 $revision_to_component = new RevisionToComponent(
102 $revision
103 );
104 $row = $revision_to_component->getAsRowMapping()($row, $revision->getIdentification());
106 $title = $row->getHeadline();
107 return $row->withHeadline(
108 $this->prependRevisionNumberToTitle($revision, $title)
109 );
110 };
111 }
112
113
114 public function getComponents(): array
115 {
116 return $this->components;
117 }
118
119 public function prependRevisionNumberToTitle(Revision $revision, ?string $title): string
120 {
121 return $this->language->txt('revision') . ' ' . $revision->getVersionNumber() . ': ' . $title;
122 }
123}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
__construct(private ViewDefinition $view_definition, protected StorableResource $resource,)
Common interface to all items.
Definition: Item.php:32
This describes a Row used in Presentation Table.
withHeadline(string $headline)
Get a row like this with the given headline.
This is how the factory for UI elements looks.
Definition: Factory.php:38
Class ilChatroomConfigFileHandler \ILIAS\Chatroom\classes.
global $DIC
Definition: shib_login.php:26