ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
RevisionListingUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
31 
36 {
37  protected array $components = [];
38  private \ILIAS\UI\Factory $ui_factory;
39  private \ilLanguage $language;
40 
41  public function __construct(
42  private ViewDefinition $view_definition,
43  protected StorableResource $resource,
44  ) {
45  global $DIC;
46  $this->language = $DIC->language();
47  $this->language->loadLanguageModule('irss');
48  $this->ui_factory = $DIC->ui()->factory();
49  switch ($view_definition->getMode()) {
51  $this->initTable();
52  break;
54  $this->initItems();
55  break;
57  $this->initDeck();
58  break;
59  default:
60  $this->initTable();
61  break;
62  }
63  }
64 
65  private function initItems(): void
66  {
67  $this->components = array_map(function (Revision $revision): \ILIAS\UI\Component\Item\Item {
68  $revision_to_component = new RevisionToComponent(
69  $revision
70  );
71  $item = $revision_to_component->getAsItem(false);
72  return $item->withLeadText($this->language->txt('revision') . ' ' . $revision->getVersionNumber());
73  }, array_reverse($this->resource->getAllRevisionsIncludingDraft()));
74  }
75 
76  private function initDeck(): void
77  {
78  $this->components[] = $this->ui_factory->deck(
79  array_map(
80  function (Revision $revision) {
81  $revision_to_component = new RevisionToComponent(
82  $revision
83  );
84  $card = $revision_to_component->getAsCard();
85  return $card->withTitle($this->prependRevisionNumberToTitle($revision, $card->getTitle()));
86  },
87  array_reverse($this->resource->getAllRevisionsIncludingDraft())
88  )
89  )->withSmallCardsSize();
90  }
91 
92  private function initTable(): void
93  {
94  // Table
95  $this->components[] = $this->ui_factory->table()->presentation(
96  '',
97  [],
98  $this->getRowMapping()
99  )->withData(
100  array_reverse($this->resource->getAllRevisionsIncludingDraft())
101  );
102  }
103 
104  public function getRowMapping(): \Closure
105  {
106  return function (
107  PresentationRow $row,
108  Revision $revision
109  ): PresentationRow {
110  $revision_to_component = new RevisionToComponent(
111  $revision
112  );
113  $row = $revision_to_component->getAsRowMapping()($row, $revision->getIdentification());
115  $title = $row->getHeadline();
116  return $row->withHeadline(
117  $this->prependRevisionNumberToTitle($revision, $title)
118  );
119  };
120  }
121 
122 
123  public function getComponents(): array
124  {
125  return $this->components;
126  }
127 
128  public function prependRevisionNumberToTitle(Revision $revision, ?string $title): string
129  {
130  return $this->language->txt('revision') . ' ' . $revision->getVersionNumber() . ': ' . $title;
131  }
132 }
Class ChatMainBarProvider .
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
withHeadline(string $headline)
Get a row like this with the given headline.
__construct(private ViewDefinition $view_definition, protected StorableResource $resource,)
This describes a Row used in Presentation Table.