ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
EntriesTable.php
Go to the documentation of this file.
1 <?php
2 
20 
26 use ILIAS\Data\URI;
36 
37 class EntriesTable implements OrderingBinding
38 {
39  use Hasher;
40  use UIHelper ;
41 
42  public const COLUMN_ACTIVE = 'active';
43  public const COLUMN_TITLE = 'title';
44  public const CLUMNS_ITEMS = 'items';
47  private ?URLBuilderToken $id_token = null;
50 
51  public function __construct(
52  private readonly Group $group,
53  private readonly EntriesRepository $repository,
54  private readonly TranslationsRepository $translations_repository,
55  private readonly Translator $translator,
56  private bool $write_access = false
57  ) {
58  global $DIC;
59  $this->ui_factory = $DIC->ui()->factory();
60  $this->request = $DIC->http()->request();
61  $this->collector = $DIC->globalScreen()->collector()->footer();
62  $this->identification = $DIC->globalScreen()->identification();
63  }
64 
65  public function getRows(OrderingRowBuilder $row_builder, array $visible_column_ids): \Generator
66  {
67  $ok = $this->ok($this->ui_factory);
68  $nok = $this->nok($this->ui_factory);
69 
70  foreach ($this->repository->allForParent($this->group->getId()) as $entry) {
71  if ($entry->isCore()) {
72  $title = $this->collector->getSingleItemFromRaw(
73  $this->identification->fromSerializedIdentification($entry->getId()),
74  )->getTitle();
75  } else {
76  $title = $this->translations_repository->get($entry)->getDefault()?->getTranslation(
77  ) ?? $entry->getTitle();
78  }
79 
80  $row = $row_builder->buildOrderingRow(
81  $this->hash($entry->getId()),
82  [
83  self::COLUMN_TITLE => $title,
84  self::COLUMN_ACTIVE => $entry->isActive() ? $ok : $nok,
85  ]
86  );
87 
88  if (!$this->write_access || $entry->isCore()) {
89  $row = $row->withDisabledAction('delete')
90  ->withDisabledAction('edit')
91  ->withDisabledAction('translate')
92  ->withDisabledAction('move');
93  }
94  if (!$this->write_access) {
95  $row = $row->withDisabledAction('toggle_activation');
96  }
97 
98  yield $row;
99  }
100  }
101 
102  public function get(
103  URI $here_uri,
104  URI $translations_uri
105  ): Ordering {
106  $uri_builder = $this->initURIBuilder($here_uri);
107 
108  return $this->ui_factory
109  ->table()
110  ->ordering(
111  $this->group->getTitle(),
112  [
113  self::COLUMN_TITLE => $this->ui_factory->table()->column()->text(
114  $this->translator->translate('title', 'entry')
115  ),
116  self::COLUMN_ACTIVE => $this->ui_factory->table()->column()->statusIcon(
117  $this->translator->translate('active', 'entry')
118  )
119  ],
120  $this,
121  $here_uri
122  )
123  ->withRequest($this->request)
124  ->withActions(
125  [
126  'edit' => $this->ui_factory->table()->action()->single(
127  $this->translator->translate('edit', 'entry'),
128  $uri_builder->withURI($here_uri->withParameter('cmd', 'edit')),
129  $this->id_token
130  )->withAsync(true),
131 
132  'toggle_activation' => $this->ui_factory->table()->action()->standard(
133  $this->translator->translate('toggle_activation', 'entry'),
134  $uri_builder->withURI($here_uri->withParameter('cmd', 'toggleActivation')),
135  $this->id_token
136  )->withAsync(false),
137 
138  'delete' => $this->ui_factory->table()->action()->standard(
139  $this->translator->translate('delete', 'entry'),
140  $uri_builder->withURI($here_uri->withParameter('cmd', 'confirmDelete')),
141  $this->id_token
142  )->withAsync(true),
143 
144  'move' => $this->ui_factory->table()->action()->standard(
145  $this->translator->translate('move', 'entry'),
146  $uri_builder->withURI($here_uri->withParameter('cmd', 'selectMove')),
147  $this->id_token
148  )->withAsync(true),
149 
150  'translate' => $this->ui_factory->table()->action()->single(
151  $this->translator->translate('translate', 'group'),
152  $uri_builder->withURI(
153  $translations_uri->withParameter('async', 'true')->withParameter(
154  'cmd',
156  )
157  ),
158  $this->id_token
159  )->withAsync(true),
160  ]
161  );
162  }
163 
164  protected function initURIBuilder(URI $target): URLBuilder
165  {
166  $url_builder = new URLBuilder(
167  $target
168  );
169 
170  // these are the query parameters this instance is controlling
171  $query_params_namespace = ['gsfo'];
172  [$url_builder, $this->id_token] = $url_builder->acquireParameters(
173  $query_params_namespace,
174  'entry_id'
175  );
176  return $url_builder;
177  }
178 
179  public function getToken(URI $target): ?URLBuilderToken
180  {
181  $this->initURIBuilder($target);
182 
183  return $this->id_token;
184  }
185 
186 }
getRows(OrderingRowBuilder $row_builder, array $visible_column_ids)
This is called by the (ordering-)table to retrieve rows; map data-records to rows using the $row_buil...
repository()
description: > Example for rendering a repository card
Definition: repository.php:17
This describes a Table to specify the order of its data (rows).
Definition: Ordering.php:28
This is how the factory for UI elements looks.
Definition: Factory.php:37
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(private readonly Group $group, private readonly EntriesRepository $repository, private readonly TranslationsRepository $translations_repository, private readonly Translator $translator, private bool $write_access=false)
global $DIC
Definition: shib_login.php:25
The scope of this class is split ilias-conform URI&#39;s into components.
Definition: URI.php:34
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class IdentificationFactory All elements in the GlobalScreen service must be identifiable for the sup...
buildOrderingRow(string $id, array $record)
URLBuilder.
Definition: URLBuilder.php:39
withParameter(string $key, $value)
Get URI with modified parameters.
Definition: URI.php:388