ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
GroupsTable.php
Go to the documentation of this file.
1 <?php
2 
20 
26 use ILIAS\Data\URI;
35 
36 class GroupsTable implements OrderingBinding
37 {
38  use Hasher;
39  use UIHelper;
40 
41  public const COLUMN_ACTIVE = 'active';
42  public const COLUMN_TITLE = 'title';
43  public const CLUMNS_ITEMS = 'items';
46  private ?URLBuilderToken $id_token = null;
47  private ?URLBuilder $url_builder = null;
50 
51  public function __construct(
52  private readonly GroupsRepository $repository,
53  private readonly TranslationsRepository $translations_repository,
54  private readonly Translator $translator,
55  private bool $write_access = false
56  ) {
57  global $DIC;
58  $this->ui_factory = $DIC->ui()->factory();
59  $this->request = $DIC->http()->request();
60  $this->collector = $DIC->globalScreen()->collector()->footer();
61  $this->identification = $DIC->globalScreen()->identification();
62  }
63 
64  public function getRows(OrderingRowBuilder $row_builder, array $visible_column_ids): \Generator
65  {
66  $ok = $this->ok($this->ui_factory);
67  $nok = $this->nok($this->ui_factory);
68 
69  foreach ($this->repository->all() as $group) {
70  if ($group->isCore()) {
71  $title = $this->collector->getSingleItemFromRaw(
72  $this->identification->fromSerializedIdentification($group->getId()),
73  )->getTitle();
74  } else {
75  $title = $this->translations_repository->get($group)->getDefault()?->getTranslation(
76  ) ?? $group->getTitle();
77  }
78  $row = $row_builder->buildOrderingRow(
79  $this->hash($group->getId()),
80  [
81  self::COLUMN_TITLE => $this->ui_factory->link()->standard(
82  $title,
83  $this->url_builder
84  ->withParameter($this->id_token, $this->hash($group->getId()))
85  ->buildURI()
86  ->withParameter('cmd', 'editEntries')
87  ),
88  self::COLUMN_ACTIVE => $group->isActive() ? $ok : $nok,
89  self::CLUMNS_ITEMS => $group->getItems(),
90  ]
91  );
92 
93  if (!$this->write_access || $group->isCore()) {
94  $row = $row->withDisabledAction('delete')
95  ->withDisabledAction('translate')
96  ->withDisabledAction('move');
97  }
98  if (!$this->write_access) {
99  $row = $row->withDisabledAction('edit')
100  ->withDisabledAction('toggle_activation');
101  }
102 
103  yield $row;
104  }
105  }
106 
107  public function get(
108  URI $here_uri,
109  URI $translations_uri
110  ): Ordering {
111  $uri_builder = $this->initURIBuilder($here_uri);
112 
113  return $this->ui_factory
114  ->table()
115  ->ordering(
116  $this->translator->translate('groups'),
117  [
118  self::COLUMN_TITLE => $this->ui_factory->table()->column()->link(
119  $this->translator->translate('title', 'group')
120  ),
121  self::COLUMN_ACTIVE => $this->ui_factory->table()->column()->statusIcon(
122  $this->translator->translate('active', 'group')
123  ),
124  self::CLUMNS_ITEMS => $this->ui_factory->table()->column()->text(
125  $this->translator->translate('items', 'group')
126  ),
127  ],
128  $this,
129  $here_uri
130  )
131  ->withRequest($this->request)
132  ->withActions(
133  [
134  'edit_entries' => $this->ui_factory->table()->action()->single(
135  $this->translator->translate('edit_entries', 'group'),
136  $uri_builder->withURI($here_uri->withParameter('cmd', 'editEntries')),
137  $this->id_token
138  )->withAsync(false),
139 
140  'edit' => $this->ui_factory->table()->action()->single(
141  $this->translator->translate('edit', 'group'),
142  $uri_builder->withURI($here_uri->withParameter('cmd', 'edit')),
143  $this->id_token
144  )->withAsync(true),
145 
146  'toggle_activation' => $this->ui_factory->table()->action()->standard(
147  $this->translator->translate('toggle_activation', 'group'),
148  $uri_builder->withURI($here_uri->withParameter('cmd', 'toggleActivation')),
149  $this->id_token
150  )->withAsync(false),
151 
152  'delete' => $this->ui_factory->table()->action()->standard(
153  $this->translator->translate('delete', 'group'),
154  $uri_builder->withURI($here_uri->withParameter('cmd', 'confirmDelete')),
155  $this->id_token
156  )->withAsync(true),
157 
158  'translate' => $this->ui_factory->table()->action()->single(
159  $this->translator->translate('translate', 'group'),
160  $uri_builder->withURI(
161  $translations_uri->withParameter('async', 'true')->withParameter(
162  'cmd',
164  )
165  ),
166  $this->id_token
167  )->withAsync(true),
168  ]
169  );
170  }
171 
172  protected function initURIBuilder(URI $target): URLBuilder
173  {
174  $this->url_builder = new URLBuilder(
175  $target
176  );
177 
178  // these are the query parameters this instance is controlling
179  $query_params_namespace = ['gsfo'];
180  [$this->url_builder, $this->id_token] = $this->url_builder->acquireParameters(
181  $query_params_namespace,
182  'group_id'
183  );
184  return $this->url_builder;
185  }
186 
187  public function getToken(URI $target): ?URLBuilderToken
188  {
189  $this->initURIBuilder($target);
190 
191  return $this->id_token;
192  }
193 
194 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Group.php:19
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
global $DIC
Definition: shib_login.php:25
__construct(private readonly GroupsRepository $repository, private readonly TranslationsRepository $translations_repository, private readonly Translator $translator, private bool $write_access=false)
Definition: GroupsTable.php:51
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
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...
Definition: GroupsTable.php:64