ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
EntriesTable.php
Go to the documentation of this file.
1 <?php
2 
20 
26 use ILIAS\Data\URI;
36 
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';
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  ) {
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->allForParent($this->group->getId()) as $entry) {
70  if ($entry->isCore()) {
71  $title = $this->collector->getSingleItemFromRaw(
72  $this->identification->fromSerializedIdentification($entry->getId()),
73  )->getTitle();
74  } else {
75  $title = $this->translations_repository->get($entry)->getDefault()?->getTranslation(
76  ) ?? $entry->getTitle();
77  }
78 
79  $row = $row_builder->buildOrderingRow(
80  $this->hash($entry->getId()),
81  [
82  self::COLUMN_TITLE => $title,
83  self::COLUMN_ACTIVE => $entry->isActive() ? $ok : $nok,
84  ]
85  );
86 
87  if ($entry->isCore()) {
88  $row = $row->withDisabledAction('delete')
89  ->withDisabledAction('edit')
90  ->withDisabledAction('translate')
91  ->withDisabledAction('move');
92  }
93 
94  yield $row;
95  }
96  }
97 
98  public function get(
99  URI $here_uri,
100  URI $translations_uri
101  ): Ordering {
102  $uri_builder = $this->initURIBuilder($here_uri);
103 
104  return $this->ui_factory
105  ->table()
106  ->ordering(
107  $this,
108  $here_uri,
109  $this->group->getTitle(),
110  [
111  self::COLUMN_TITLE => $this->ui_factory->table()->column()->text(
112  $this->translator->translate('title', 'entry')
113  ),
114  self::COLUMN_ACTIVE => $this->ui_factory->table()->column()->statusIcon(
115  $this->translator->translate('active', 'entry')
116  )
117  ],
118  )
119  ->withRequest($this->request)
120  ->withActions(
121  [
122  'edit' => $this->ui_factory->table()->action()->single(
123  $this->translator->translate('edit', 'entry'),
124  $uri_builder->withURI($here_uri->withParameter('cmd', 'edit')),
125  $this->id_token
126  )->withAsync(true),
127 
128  'toggle_activation' => $this->ui_factory->table()->action()->standard(
129  $this->translator->translate('toggle_activation', 'entry'),
130  $uri_builder->withURI($here_uri->withParameter('cmd', 'toggleActivation')),
131  $this->id_token
132  )->withAsync(false),
133 
134  'delete' => $this->ui_factory->table()->action()->standard(
135  $this->translator->translate('delete', 'entry'),
136  $uri_builder->withURI($here_uri->withParameter('cmd', 'confirmDelete')),
137  $this->id_token
138  )->withAsync(true),
139 
140  'move' => $this->ui_factory->table()->action()->standard(
141  $this->translator->translate('move', 'entry'),
142  $uri_builder->withURI($here_uri->withParameter('cmd', 'selectMove')),
143  $this->id_token
144  )->withAsync(true),
145 
146  'translate' => $this->ui_factory->table()->action()->single(
147  $this->translator->translate('translate', 'group'),
148  $uri_builder->withURI(
149  $translations_uri->withParameter('async', 'true')->withParameter(
150  'cmd',
152  )
153  ),
154  $this->id_token
155  )->withAsync(true),
156  ]
157  );
158  }
159 
160  protected function initURIBuilder(URI $target): URLBuilder
161  {
162  $url_builder = new URLBuilder(
163  $target
164  );
165 
166  // these are the query parameters this instance is controlling
167  $query_params_namespace = ['gsfo'];
168  [$url_builder, $this->id_token] = $url_builder->acquireParameters(
169  $query_params_namespace,
170  'entry_id'
171  );
172  return $url_builder;
173  }
174 
175  public function getToken(URI $target): ?URLBuilderToken
176  {
177  $this->initURIBuilder($target);
178 
179  return $this->id_token;
180  }
181 
182 }
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...
__construct(private readonly Group $group, private readonly EntriesRepository $repository, private readonly TranslationsRepository $translations_repository, private readonly Translator $translator)
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
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...
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