ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
GroupsTable.php
Go to the documentation of this file.
1 <?php
2 
20 
24 use ILIAS\Data\URI;
33 
35 {
36  use Hasher;
37  use UIHelper;
38 
39  public const COLUMN_ACTIVE = 'active';
40  public const COLUMN_TITLE = 'title';
41  public const CLUMNS_ITEMS = 'items';
46 
47  public function __construct(
48  private readonly GroupsRepository $repository,
49  private readonly TranslationsRepository $translations_repository,
50  private readonly Translator $translator
51  ) {
52  global $DIC;
53  $this->ui_factory = $DIC->ui()->factory();
54  $this->request = $DIC->http()->request();
55  }
56 
57  public function getRows(OrderingRowBuilder $row_builder, array $visible_column_ids): \Generator
58  {
59  $ok = $this->ok($this->ui_factory);
60  $nok = $this->nok($this->ui_factory);
61 
62  foreach ($this->repository->all() as $group) {
63  $title = $this->translations_repository->get($group)->getDefault()?->getTranslation() ?? $group->getTitle();
64  $row = $row_builder->buildOrderingRow(
65  $this->hash($group->getId()),
66  [
67  self::COLUMN_TITLE => $this->ui_factory->link()->standard(
68  $title,
69  $this->url_builder
70  ->withParameter($this->id_token, $this->hash($group->getId()))
71  ->buildURI()
72  ->withParameter('cmd', 'editEntries')
73  ),
74  self::COLUMN_ACTIVE => $group->isActive() ? $ok : $nok,
75  self::CLUMNS_ITEMS => $group->getItems(),
76  ]
77  );
78 
79  if ($group->isCore()) {
80  $row = $row->withDisabledAction('delete')
81  ->withDisabledAction('translate')
82  ->withDisabledAction('move');
83  }
84 
85  yield $row;
86  }
87  }
88 
89  public function get(
90  URI $here_uri,
91  URI $translations_uri
92  ): Ordering {
93  $uri_builder = $this->initURIBuilder($here_uri);
94 
95  $async_translation = false;
96 
97  return $this->ui_factory
98  ->table()
99  ->ordering(
100  $this,
101  $here_uri,
102  $this->translator->translate('groups'),
103  [
104  self::COLUMN_TITLE => $this->ui_factory->table()->column()->link(
105  $this->translator->translate('title', 'group')
106  ),
107  self::COLUMN_ACTIVE => $this->ui_factory->table()->column()->statusIcon(
108  $this->translator->translate('active', 'group')
109  ),
110  self::CLUMNS_ITEMS => $this->ui_factory->table()->column()->text(
111  $this->translator->translate('items', 'group')
112  ),
113  ],
114  )
115  ->withRequest($this->request)
116  ->withActions(
117  [
118  'edit_entries' => $this->ui_factory->table()->action()->single(
119  $this->translator->translate('edit_entries', 'group'),
120  $uri_builder->withURI($here_uri->withParameter('cmd', 'editEntries')),
121  $this->id_token
122  )->withAsync(false),
123 
124  'edit' => $this->ui_factory->table()->action()->single(
125  $this->translator->translate('edit', 'group'),
126  $uri_builder->withURI($here_uri->withParameter('cmd', 'edit')),
127  $this->id_token
128  )->withAsync(true),
129 
130  'toggle_activation' => $this->ui_factory->table()->action()->standard(
131  $this->translator->translate('toggle_activation', 'group'),
132  $uri_builder->withURI($here_uri->withParameter('cmd', 'toggleActivation')),
133  $this->id_token
134  )->withAsync(false),
135 
136  'delete' => $this->ui_factory->table()->action()->standard(
137  $this->translator->translate('delete', 'group'),
138  $uri_builder->withURI($here_uri->withParameter('cmd', 'confirmDelete')),
139  $this->id_token
140  )->withAsync(true),
141 
142  'translate' => $this->ui_factory->table()->action()->single(
143  $this->translator->translate('translate', 'group'),
144  $uri_builder->withURI(
145  $translations_uri->withParameter('async', 'true')->withParameter(
146  'cmd',
148  )
149  ),
150  $this->id_token
151  )->withAsync(true),
152  ]
153  );
154  }
155 
156  protected function initURIBuilder(URI $target): URLBuilder
157  {
158  $this->url_builder = new URLBuilder(
159  $target
160  );
161 
162  // these are the query parameters this instance is controlling
163  $query_params_namespace = ['gsfo'];
164  [$this->url_builder, $this->id_token] = $this->url_builder->acquireParameters(
165  $query_params_namespace,
166  'group_id'
167  );
168  return $this->url_builder;
169  }
170 
171  public function getToken(URI $target): ?URLBuilderToken
172  {
173  $this->initURIBuilder($target);
174 
175  return $this->id_token;
176  }
177 
178 }
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:47
This is how the factory for UI elements looks.
Definition: Factory.php:37
global $DIC
Definition: shib_login.php:22
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
buildOrderingRow(string $id, array $record)
URLBuilder.
Definition: URLBuilder.php:40
withParameter(string $key, $value)
Get URI with modified parameters.
Definition: URI.php:384
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:57