ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ILIAS\LegalDocuments\Administration Class Reference
+ Collaboration diagram for ILIAS\LegalDocuments\Administration:

Public Member Functions

 __construct (private readonly Config $config, private readonly Container $container, private readonly UI $ui, ?Closure $confirmation=null)
 
 deleteDocumentsConfirmation (string $form_link, string $submit_command, string $cancel_command, array $documents)
 
 deleteDocuments (array $documents)
 
 withDocumentAndCriterion (Closure $proc)
 
 retrieveDocuments ()
 
 retrieveIds ()
 
 idOrHash (object $gui, Closure $then)
 
 targetWithDoc (object $gui, $document, string $cmd, string $method='getLinkTarget')
 
 targetWithDocAndCriterion (object $gui, $document, $criterion, string $cmd, string $method='getLinkTarget')
 
 willLinkWith ($gui, array $parameters=[])
 
 withFormData ($form, Closure $then)
 
 find (Closure $predicate, array $array)
 A More...
 
 currentDocument ()
 
 criterionForm (string $url, Document $document, $criterion=null)
 
 requireDocumentHash ()
 
 tabs (array $tabs, array $run_after=[])
 
 uploadContent ()
 
 setContent ($component)
 
 addDocumentButton (string $add_document_link)
 
 setVariable (string $variable, $component)
 
 render ($component)
 
 resetBox (DateTimeImmutable $reset_date, array $buttons=[])
 
 resetButton (string $confirm_reset_link)
 
 documentForm (Closure $link, string $title, Closure $document_content, bool $may_be_new)
 
 saveDocumentOrder (array $documents, array $order_by_document)
 
 withDocumentsAndOrder (Closure $proc)
 
 exitWithJsonResponse ($value)
 
 requireEditable ()
 
 externalSettingsMessage (bool $enabled)
 
 isInvalidHTML (string $string)
 
 isValidHTML (string $string)
 
 canReadUserAdministration ()
 

Private Member Functions

 addTab (string $id, string $text, string $link, bool $can_access=true)
 

Private Attributes

readonly Closure $confirmation
 

Detailed Description

Definition at line 48 of file Administration.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\LegalDocuments\Administration::__construct ( private readonly Config  $config,
private readonly Container  $container,
private readonly UI  $ui,
?Closure  $confirmation = null 
)
Parameters
null|Closure()Confirmation $confirmation

Definition at line 56 of file Administration.php.

References ILIAS\UI\examples\MessageBox\Confirmation\confirmation().

61  {
62  $this->confirmation = $confirmation ?? fn() => new Confirmation($this->container->language());
63  }
+ Here is the call graph for this function:

Member Function Documentation

◆ addDocumentButton()

ILIAS\LegalDocuments\Administration::addDocumentButton ( string  $add_document_link)

Definition at line 296 of file Administration.php.

References ILIAS\Repository\ui().

296  : Component
297  {
298  return $this->ui->create()->button()->primary(
299  $this->ui->txt('add_document_btn_label'),
300  $add_document_link
301  );
302  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the call graph for this function:

◆ addTab()

ILIAS\LegalDocuments\Administration::addTab ( string  $id,
string  $text,
string  $link,
bool  $can_access = true 
)
private

Definition at line 461 of file Administration.php.

Referenced by ILIAS\LegalDocuments\Administration\tabs().

461  : void
462  {
463  if ($can_access) {
464  $this->container->tabs()->addTab($id, $text, $link);
465  }
466  }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the caller graph for this function:

◆ canReadUserAdministration()

ILIAS\LegalDocuments\Administration::canReadUserAdministration ( )

Definition at line 456 of file Administration.php.

References USER_FOLDER_ID.

456  : bool
457  {
458  return $this->container->rbac()->system()->checkAccess('read', USER_FOLDER_ID);
459  }
const USER_FOLDER_ID
Definition: constants.php:33

◆ criterionForm()

ILIAS\LegalDocuments\Administration::criterionForm ( string  $url,
Document  $document,
  $criterion = null 
)

Definition at line 234 of file Administration.php.

References ILIAS\LegalDocuments\Value\Document\content(), ILIAS\Repository\ui(), and ILIAS\UI\Implementation\Component\Input\withValue().

235  {
236  $groups = $this->config->legalDocuments()->document()->conditionGroups($criterion);
237  $group = $this->ui->create()->input()->field()->switchableGroup($groups->choices(), $this->ui->txt('form_criterion'));
238  $value = $criterion ? $criterion->type() : $groups->defaultSelection();
239  if ($value) {
240  $group = $group->withValue($value);
241  }
242 
243  $title = $this->ui->create()->input()->field()->text($this->ui->txt('form_document'))->withValue($document->content()->title())->withDisabled(true);
244 
245  $section = $this->ui->create()->input()->field()->section([
246  $title,
247  'content' => $group,
248  ], $this->ui->txt($criterion ? 'form_edit_criterion_head' : 'form_attach_criterion_head'));
249 
250  return $this->ui->create()->input()->container()->form()->standard($url, [$section]);
251  }
$url
Definition: ltiregstart.php:35
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:58
+ Here is the call graph for this function:

◆ currentDocument()

ILIAS\LegalDocuments\Administration::currentDocument ( )
Returns
Result<Document>

Definition at line 227 of file Administration.php.

References ILIAS\Data\Result\then().

Referenced by ILIAS\LegalDocuments\Administration\idOrHash(), and ILIAS\LegalDocuments\Administration\withDocumentAndCriterion().

227  : Result
228  {
229  $repo = $this->config->legalDocuments()->document()->repository();
230  $doc_id = $this->container->http()->request()->getQueryParams()['doc_id'] ?? null;
231  return $this->container->refinery()->kindlyTo()->int()->applyTo(new Ok($doc_id))->then($repo->find(...));
232  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deleteDocuments()

ILIAS\LegalDocuments\Administration::deleteDocuments ( array  $documents)
Parameters
list<Document>$documents

Definition at line 84 of file Administration.php.

84  : void
85  {
86  array_map(
87  $this->config->legalDocuments()->document()->repository()->deleteDocument(...),
88  $documents
89  );
90  }

◆ deleteDocumentsConfirmation()

ILIAS\LegalDocuments\Administration::deleteDocumentsConfirmation ( string  $form_link,
string  $submit_command,
string  $cancel_command,
array  $documents 
)
Parameters
list<Document>$documents

Definition at line 68 of file Administration.php.

References ILIAS\UI\examples\MessageBox\Confirmation\confirmation(), and ILIAS\Repository\ui().

68  : string
69  {
70  $items = array_column(array_map(fn($x) => [$x->id(), $x->content()->title()], $documents), 1, 0);
71 
72  return (($this->confirmation)())->render(
73  $form_link,
74  $submit_command,
75  $cancel_command,
76  $this->ui->txt('sure_delete_documents_p'),
77  $items
78  );
79  }
+ Here is the call graph for this function:

◆ documentForm()

ILIAS\LegalDocuments\Administration::documentForm ( Closure  $link,
string  $title,
Closure  $document_content,
bool  $may_be_new 
)
Parameters
Closure(string)string $link
Closure()Result<DocumentContent> $document_content

Definition at line 347 of file Administration.php.

References ILIAS\Repository\ui().

347  : Component
348  {
349  $edit_link = $link('editDocument');
350  $content_title = $may_be_new ? 'form_document' : 'form_document_new';
351 
352  $section = $this->ui->create()->input()->field()->section([
353  'title' => $this->ui->create()->input()->field()->text($this->ui->txt('title'))->withRequired(true)->withValue($title),
354  'content' => $this->ui->create()->input()->field()->file(new UploadHandler($link, $document_content, $this->ui->txt(...)), $this->ui->txt($content_title))->withAcceptedMimeTypes([
355  'text/html',
356  'text/plain',
357  ])->withRequired($may_be_new),
358  ], $this->ui->txt($may_be_new ? 'form_new_doc_head' : 'form_edit_doc_head'));
359 
360  return $this->ui->create()->input()->container()->form()->standard($edit_link, [$section]);
361  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the call graph for this function:

◆ exitWithJsonResponse()

ILIAS\LegalDocuments\Administration::exitWithJsonResponse (   $value)

Definition at line 415 of file Administration.php.

References ILIAS\Filesystem\Stream\Streams\ofString().

415  : void
416  {
417  // ... The content type cannot be set to application/json, because the src/UI/templates/js/Input/Field/file.js:392
418  // does not expect that the content type is correct and parses it again ...
419  $this->container->http()->saveResponse($this->container->http()->response()/* ->withHeader('Content-Type', 'application/json') */->withBody(
420  Streams::ofString(json_encode($value))
421  ));
422 
423  $this->container->http()->sendResponse();
424  $this->container->http()->close();
425  }
static ofString(string $string)
Creates a new stream with an initial value.
Definition: Streams.php:41
+ Here is the call graph for this function:

◆ externalSettingsMessage()

ILIAS\LegalDocuments\Administration::externalSettingsMessage ( bool  $enabled)

Definition at line 434 of file Administration.php.

References ILIAS\Repository\ui(), USER_FOLDER_ID, and ILIAS\LegalDocuments\Administration\willLinkWith().

434  : Component
435  {
436  return $this->ui->create()->messageBox()->info(
437  $this->ui->txt('withdrawal_usr_deletion') . ': ' . $this->ui->txt($enabled ? 'enabled' : 'disabled')
438  )->withLinks([
439  $this->ui->create()->link()->standard(
440  $this->ui->txt('adm_external_setting_edit'),
441  $this->willLinkWith(ilObjUserFolderGUI::class, ['ref_id' => USER_FOLDER_ID])('generalSettings')
442  )
443  ]);
444  }
bool $enabled
Whether the system instance is enabled to accept connection requests.
Definition: System.php:123
const USER_FOLDER_ID
Definition: constants.php:33
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
willLinkWith($gui, array $parameters=[])
+ Here is the call graph for this function:

◆ find()

ILIAS\LegalDocuments\Administration::find ( Closure  $predicate,
array  $array 
)

A

Parameters
Closure(A)bool $predicate
list<A>$array
Returns
A|null

Definition at line 213 of file Administration.php.

Referenced by ILIAS\LegalDocuments\Administration\withDocumentAndCriterion().

214  {
215  foreach ($array as $value) {
216  if ($predicate($value)) {
217  return $value;
218  }
219  }
220 
221  return null;
222  }
+ Here is the caller graph for this function:

◆ idOrHash()

ILIAS\LegalDocuments\Administration::idOrHash ( object  $gui,
Closure  $then 
)
Parameters
Closure(Closure(string)string, DocumentId, bool): void $then

Definition at line 138 of file Administration.php.

References ILIAS\LegalDocuments\Administration\currentDocument(), ILIAS\LegalDocuments\Administration\requireDocumentHash(), and ILIAS\LegalDocuments\Administration\willLinkWith().

138  : void
139  {
140  $with_doc_id = fn($document) => $then($this->willLinkWith($gui, ['doc_id' => $document->id()]), $document->content()->title(), new NumberId($document), false);
141  $with_hash = fn(string $hash) => $then($this->willLinkWith($gui, ['hash' => $hash]), '', new HashId($hash), true);
142  $try_hash = fn() => new Ok($with_hash($this->requireDocumentHash()));
143 
144  $this->currentDocument()
145  ->map($with_doc_id)
146  ->except($try_hash)
147  ->value();
148 
149  }
willLinkWith($gui, array $parameters=[])
+ Here is the call graph for this function:

◆ isInvalidHTML()

ILIAS\LegalDocuments\Administration::isInvalidHTML ( string  $string)

Definition at line 446 of file Administration.php.

References ILIAS\LegalDocuments\Administration\isValidHTML().

446  : bool
447  {
448  return !$this->isValidHTML($string);
449  }
+ Here is the call graph for this function:

◆ isValidHTML()

ILIAS\LegalDocuments\Administration::isValidHTML ( string  $string)

Definition at line 451 of file Administration.php.

Referenced by ILIAS\LegalDocuments\Administration\isInvalidHTML().

451  : bool
452  {
453  return (new ValidHTML())->isTrue($string);
454  }
+ Here is the caller graph for this function:

◆ render()

ILIAS\LegalDocuments\Administration::render (   $component)
Parameters
list<Component>|Component|string$component

Definition at line 315 of file Administration.php.

Referenced by ILIAS\LegalDocuments\Administration\setContent(), and ILIAS\LegalDocuments\Administration\setVariable().

315  : string
316  {
317  if (is_string($component)) {
318  return $component;
319  }
320  return $this->container->ui()->renderer()->render($component);
321  }
+ Here is the caller graph for this function:

◆ requireDocumentHash()

ILIAS\LegalDocuments\Administration::requireDocumentHash ( )

Definition at line 253 of file Administration.php.

Referenced by ILIAS\LegalDocuments\Administration\idOrHash().

253  : string
254  {
255  return $this->container->http()->wrapper()->query()->retrieve('hash', $this->container->refinery()->to()->string());
256  }
+ Here is the caller graph for this function:

◆ requireEditable()

ILIAS\LegalDocuments\Administration::requireEditable ( )

Definition at line 427 of file Administration.php.

427  : void
428  {
429  if (!$this->config->editable()) {
430  $this->container['ilErr']->raiseError($this->container->language()->txt('permission_denied'), $this->container['ilErr']->WARNING);
431  }
432  }

◆ resetBox()

ILIAS\LegalDocuments\Administration::resetBox ( DateTimeImmutable  $reset_date,
array  $buttons = [] 
)
Parameters
list<Button>$buttons

Definition at line 326 of file Administration.php.

References ilDatePresentation\formatDate(), IL_CAL_UNIX, and ILIAS\Repository\ui().

326  : Component
327  {
328  $reset_date = new ilDateTime($reset_date->getTimeStamp(), IL_CAL_UNIX);
329  return $this->ui->create()
330  ->messageBox()
331  ->info(sprintf($this->ui->txt('last_reset_date'), ilDatePresentation::formatDate($reset_date)))
332  ->withButtons($buttons);
333  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
const IL_CAL_UNIX
+ Here is the call graph for this function:

◆ resetButton()

ILIAS\LegalDocuments\Administration::resetButton ( string  $confirm_reset_link)

Definition at line 335 of file Administration.php.

References ILIAS\Repository\ui().

335  : Component
336  {
337  return $this->ui->create()->button()->standard(
338  $this->ui->txt('reset_for_all_users'),
339  $confirm_reset_link
340  );
341  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the call graph for this function:

◆ retrieveDocuments()

ILIAS\LegalDocuments\Administration::retrieveDocuments ( )

Definition at line 115 of file Administration.php.

References ILIAS\LegalDocuments\Administration\retrieveIds().

115  : array
116  {
117  $ids = $this->retrieveIds();
118  $documents = $this->config->legalDocuments()->document()->repository()->select($ids);
119  if (count($documents) !== count($ids)) {
120  throw new InvalidArgumentException('List contains invalid documents.');
121  }
122 
123  return $documents;
124  }
+ Here is the call graph for this function:

◆ retrieveIds()

ILIAS\LegalDocuments\Administration::retrieveIds ( )

Definition at line 126 of file Administration.php.

References $r.

Referenced by ILIAS\LegalDocuments\Administration\retrieveDocuments().

126  : array
127  {
128  $r = $this->container->refinery();
129  return $this->container->http()->wrapper()->post()->retrieve('ids', $this->container->refinery()->byTrying([
130  $r->in()->series([$r->null(), $r->always([])]),
131  $r->to()->listOf($r->kindlyTo()->int())
132  ]));
133  }
$r
+ Here is the caller graph for this function:

◆ saveDocumentOrder()

ILIAS\LegalDocuments\Administration::saveDocumentOrder ( array  $documents,
array  $order_by_document 
)
Parameters
list<Document>$documents
array<int,int>$order_by_document

Definition at line 367 of file Administration.php.

367  : void
368  {
369  $update = $this->config->legalDocuments()->document()->repository()->updateDocumentOrder(...);
370 
371  usort($documents, fn($document, $other) => $order_by_document[$document->id()] - $order_by_document[$other->id()]);
372 
373  array_map(
374  fn($document, int $order) => $update(new NumberId($document), $order),
375  $documents,
376  range(10, 10 * count($documents), 10)
377  );
378  }

◆ setContent()

ILIAS\LegalDocuments\Administration::setContent (   $component)
Parameters
list<Component>|Component$component

Definition at line 291 of file Administration.php.

References ILIAS\LegalDocuments\Administration\render(), and ILIAS\Repository\ui().

291  : void
292  {
293  $this->ui->mainTemplate()->setContent($this->render($component));
294  }
+ Here is the call graph for this function:

◆ setVariable()

ILIAS\LegalDocuments\Administration::setVariable ( string  $variable,
  $component 
)
Parameters
list<Component>|Component$component

Definition at line 307 of file Administration.php.

References ILIAS\LegalDocuments\Administration\render(), and ILIAS\Repository\ui().

307  : void
308  {
309  $this->ui->mainTemplate()->setVariable($variable, $this->render($component));
310  }
+ Here is the call graph for this function:

◆ tabs()

ILIAS\LegalDocuments\Administration::tabs ( array  $tabs,
array  $run_after = [] 
)
Parameters
list<array{0string, 1: string, 2: string}> $tabs
array<string,Closure()void> $run_after

Definition at line 262 of file Administration.php.

References ILIAS\LegalDocuments\Administration\addTab().

262  : void
263  {
264  foreach ($tabs as $tab) {
265  $this->addTab(...$tab);
266  if (isset($run_after[$tab[0]])) {
267  $run_after[$tab[0]]();
268  }
269  }
270  }
addTab(string $id, string $text, string $link, bool $can_access=true)
+ Here is the call graph for this function:

◆ targetWithDoc()

ILIAS\LegalDocuments\Administration::targetWithDoc ( object  $gui,
  $document,
string  $cmd,
string  $method = 'getLinkTarget' 
)

Definition at line 151 of file Administration.php.

References ILIAS\LegalDocuments\Administration\willLinkWith().

151  : string
152  {
153  $link = $this->willLinkWith($gui, ['doc_id' => (string) $document->id()]);
154  return $link($cmd, $method);
155  }
willLinkWith($gui, array $parameters=[])
+ Here is the call graph for this function:

◆ targetWithDocAndCriterion()

ILIAS\LegalDocuments\Administration::targetWithDocAndCriterion ( object  $gui,
  $document,
  $criterion,
string  $cmd,
string  $method = 'getLinkTarget' 
)

Definition at line 157 of file Administration.php.

References ILIAS\LegalDocuments\Administration\willLinkWith().

158  {
159  $link = $this->willLinkWith($gui, [
160  'doc_id' => (string) $document->id(),
161  'criterion_id' => (string) $criterion->id(),
162  ]);
163 
164  return $link($cmd, $method);
165  }
willLinkWith($gui, array $parameters=[])
+ Here is the call graph for this function:

◆ uploadContent()

ILIAS\LegalDocuments\Administration::uploadContent ( )

Definition at line 272 of file Administration.php.

272  : string
273  {
274  $value = null;
275  $upload = $this->container->upload();
276  $upload->register(new PreProcessor(function (string $content) use (&$value): void {
277  $value = $content;
278  }));
279  $upload->process();
280  $result_array = $upload->getResults();
281  if (count($result_array) !== 1 || !current($result_array)->isOk()) {
282  throw new Exception('Unexpected upload result.');
283  }
284 
285  return $value;
286  }

◆ willLinkWith()

ILIAS\LegalDocuments\Administration::willLinkWith (   $gui,
array  $parameters = [] 
)
Parameters
array<string,string>$parameters

Definition at line 170 of file Administration.php.

References ILIAS\LTI\ToolProvider\$key.

Referenced by ILIAS\LegalDocuments\Administration\externalSettingsMessage(), ILIAS\LegalDocuments\Administration\idOrHash(), ILIAS\LegalDocuments\Administration\targetWithDoc(), and ILIAS\LegalDocuments\Administration\targetWithDocAndCriterion().

170  : Closure
171  {
172  $class = is_string($gui) ? $gui : get_class($gui);
173  return function (string $cmd, ?string $method = null) use ($gui, $class, $parameters): string {
174  $method ??= $class === $gui ? 'getLinkTargetByClass' : 'getLinkTarget';
175  $array = $this->container->ctrl()->getParameterArrayByClass($class);
176  foreach ($parameters as $key => $value) {
177  $this->container->ctrl()->setParameterByClass($class, $key, $value);
178  }
179  $link = $this->container->ctrl()->$method($gui, $cmd);
180  foreach ($parameters as $key => $_) {
181  $this->container->ctrl()->setParameterByClass($class, $key, $array[$key] ?? '');
182  }
183 
184  return $link;
185  };
186  }
string $key
Consumer key/client ID value.
Definition: System.php:193
+ Here is the caller graph for this function:

◆ withDocumentAndCriterion()

ILIAS\LegalDocuments\Administration::withDocumentAndCriterion ( Closure  $proc)
Parameters
Closure(Document,Criterion)void $proc

Definition at line 95 of file Administration.php.

References ILIAS\LegalDocuments\Administration\currentDocument(), ILIAS\LegalDocuments\Administration\find(), and ILIAS\Repository\int().

95  : void
96  {
97  $document = $this->currentDocument()->value();
98  $criterion_id = ($this->container->http()->request()->getQueryParams()['criterion_id'] ?? null);
99  if (null === $criterion_id) {
100  throw new InvalidArgumentException('Missing query parameter criterion_id.');
101  }
102  $criterion_id = (int) $criterion_id;
103 
104  $criterion = $this->find(
105  fn($criterion) => $criterion->id() === $criterion_id,
106  $document->criteria()
107  );
108  if (!$criterion) {
109  throw new InvalidArgumentException('Invalid criterion_id given.');
110  }
111 
112  $proc($document, $criterion);
113  }
find(Closure $predicate, array $array)
A
+ Here is the call graph for this function:

◆ withDocumentsAndOrder()

ILIAS\LegalDocuments\Administration::withDocumentsAndOrder ( Closure  $proc)
Parameters
Closure(list<Document>,array<int,int>)$proc

Definition at line 383 of file Administration.php.

384  {
385  // kindlyTo->int() does not accept numbers of the form "01".
386  $to_int = $this->container->refinery()->byTrying([
387  $this->container->refinery()->kindlyTo()->int(),
388  $this->container->refinery()->in()->series([
389  $this->container->refinery()->to()->string(),
390  $this->container->refinery()->custom()->transformation(fn($s) => ltrim($s, '0') ?: '0'),
391  $this->container->refinery()->kindlyTo()->int(),
392  ]),
393  ]);
394 
395  $order = $this->container->http()->request()->getParsedBody()['order'] ?? null;
396  if (!is_array($order)) {
397  throw new InvalidArgumentException('Invalid order given. List of numbers expected.');
398  }
399 
400  $order = array_map($to_int, $order);
401  $document_ids = array_map($to_int, array_keys($order));
402  $order = array_combine($document_ids, array_values($order));
403 
404  $documents = $this->config->legalDocuments()->document()->repository()->all();
405 
406  foreach ($documents as $document) {
407  if (!isset($order[$document->id()])) {
408  $order[$document->id()] = $document->meta()->sorting();
409  }
410  }
411 
412  return $proc($documents, $order);
413  }

◆ withFormData()

ILIAS\LegalDocuments\Administration::withFormData (   $form,
Closure  $then 
)
Parameters
Closure(array)void $then

Definition at line 191 of file Administration.php.

References $data.

192  {
193  $request = $this->container->http()->request();
194  if ($request->getMethod() !== 'POST') {
195  return $form;
196  }
197  $form = $form->withRequest($request);
198  $data = $form->getData();
199 
200  if ($data !== null) {
201  $then($data);
202  }
203 
204  return $form;
205  }

Field Documentation

◆ $confirmation

readonly Closure ILIAS\LegalDocuments\Administration::$confirmation
private

Definition at line 51 of file Administration.php.


The documentation for this class was generated from the following file: