ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
GroupsTable.php
Go to the documentation of this file.
1 <?php
2 
20 
26 use ILIAS\Data\URI;
35 
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';
50 
51  public function __construct(
52  private readonly GroupsRepository $repository,
53  private readonly TranslationsRepository $translations_repository,
54  private readonly Translator $translator
55  ) {
56  global $DIC;
57  $this->ui_factory = $DIC->ui()->factory();
58  $this->request = $DIC->http()->request();
59  $this->collector = $DIC->globalScreen()->collector()->footer();
60  $this->identification = $DIC->globalScreen()->identification();
61  }
62 
63  public function getRows(OrderingRowBuilder $row_builder, array $visible_column_ids): \Generator
64  {
65  $ok = $this->ok($this->ui_factory);
66  $nok = $this->nok($this->ui_factory);
67 
68  foreach ($this->repository->all() as $group) {
69  if ($group->isCore()) {
70  $title = $this->collector->getSingleItemFromRaw(
71  $this->identification->fromSerializedIdentification($group->getId()),
72  )->getTitle();
73  } else {
74  $title = $this->translations_repository->get($group)->getDefault()?->getTranslation(
75  ) ?? $group->getTitle();
76  }
77  $row = $row_builder->buildOrderingRow(
78  $this->hash($group->getId()),
79  [
80  self::COLUMN_TITLE => $this->ui_factory->link()->standard(
81  $title,
82  $this->url_builder
83  ->withParameter($this->id_token, $this->hash($group->getId()))
84  ->buildURI()
85  ->withParameter('cmd', 'editEntries')
86  ),
87  self::COLUMN_ACTIVE => $group->isActive() ? $ok : $nok,
88  self::CLUMNS_ITEMS => $group->getItems(),
89  ]
90  );
91 
92  if ($group->isCore()) {
93  $row = $row->withDisabledAction('delete')
94  ->withDisabledAction('translate')
95  ->withDisabledAction('move');
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,
112  $here_uri,
113  $this->translator->translate('groups'),
114  [
115  self::COLUMN_TITLE => $this->ui_factory->table()->column()->link(
116  $this->translator->translate('title', 'group')
117  ),
118  self::COLUMN_ACTIVE => $this->ui_factory->table()->column()->statusIcon(
119  $this->translator->translate('active', 'group')
120  ),
121  self::CLUMNS_ITEMS => $this->ui_factory->table()->column()->text(
122  $this->translator->translate('items', 'group')
123  ),
124  ],
125  )
126  ->withRequest($this->request)
127  ->withActions(
128  [
129  'edit_entries' => $this->ui_factory->table()->action()->single(
130  $this->translator->translate('edit_entries', 'group'),
131  $uri_builder->withURI($here_uri->withParameter('cmd', 'editEntries')),
132  $this->id_token
133  )->withAsync(false),
134 
135  'edit' => $this->ui_factory->table()->action()->single(
136  $this->translator->translate('edit', 'group'),
137  $uri_builder->withURI($here_uri->withParameter('cmd', 'edit')),
138  $this->id_token
139  )->withAsync(true),
140 
141  'toggle_activation' => $this->ui_factory->table()->action()->standard(
142  $this->translator->translate('toggle_activation', 'group'),
143  $uri_builder->withURI($here_uri->withParameter('cmd', 'toggleActivation')),
144  $this->id_token
145  )->withAsync(false),
146 
147  'delete' => $this->ui_factory->table()->action()->standard(
148  $this->translator->translate('delete', 'group'),
149  $uri_builder->withURI($here_uri->withParameter('cmd', 'confirmDelete')),
150  $this->id_token
151  )->withAsync(true),
152 
153  'translate' => $this->ui_factory->table()->action()->single(
154  $this->translator->translate('translate', 'group'),
155  $uri_builder->withURI(
156  $translations_uri->withParameter('async', 'true')->withParameter(
157  'cmd',
159  )
160  ),
161  $this->id_token
162  )->withAsync(true),
163  ]
164  );
165  }
166 
167  protected function initURIBuilder(URI $target): URLBuilder
168  {
169  $this->url_builder = new URLBuilder(
170  $target
171  );
172 
173  // these are the query parameters this instance is controlling
174  $query_params_namespace = ['gsfo'];
175  [$this->url_builder, $this->id_token] = $this->url_builder->acquireParameters(
176  $query_params_namespace,
177  'group_id'
178  );
179  return $this->url_builder;
180  }
181 
182  public function getToken(URI $target): ?URLBuilderToken
183  {
184  $this->initURIBuilder($target);
185 
186  return $this->id_token;
187  }
188 
189 }
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:33
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
This describes a Table to specify the order of its data (rows).
Definition: Ordering.php:28
__construct(private readonly GroupsRepository $repository, private readonly TranslationsRepository $translations_repository, private readonly Translator $translator)
Definition: GroupsTable.php:51
This is how the factory for UI elements looks.
Definition: Factory.php:37
global $DIC
Definition: shib_login.php:26
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:40
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:63