ILIAS  trunk Revision v11.0_alpha-1843-g9e1fad99175
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
GroupForm.php
Go to the documentation of this file.
1 <?php
2 
20 
25 
26 class GroupForm
27 {
28  private readonly Factory $ui_factory;
29  private readonly \ILIAS\Refinery\Factory $refinery;
30 
31  public function __construct(
32  private readonly GroupsRepository $repository,
33  private readonly Translator $translator,
34  private ?Group $group = null,
35  ) {
36  global $DIC;
37  $this->ui_factory = $DIC->ui()->factory();
38  $this->refinery = $DIC->refinery();
39  $this->group ??= $this->repository->blank();
40  }
41 
42  protected function getInputs(): array
43  {
44  $ff = $this->ui_factory->input()->field();
45 
46  $inputs = [
47  'title' => $ff
48  ->text($this->translator->translate('title', 'group'))
49  ->withValue($this->group->getTitle())
51  $this->refinery->custom()->transformation(function (string $value): string {
52  $this->group = $this->group->withTitle($value);
53  return $value;
54  })
55  )
56  ->withRequired(true)
57  ->withMaxLength(255),
58  'active' => $ff
59  ->checkbox($this->translator->translate('active', 'group'))
60  ->withValue($this->group->isActive())
62  $this->refinery->custom()->transformation(function (bool $value): bool {
63  $this->group = $this->group->withActive($value);
64  return $value;
65  })
66  )
67  ,
68  ];
69 
70  return [
71  $ff->section($inputs, $this->translator->translate($this->group->getId() === '' ? 'add' : 'edit', 'group'))
72  ];
73  }
74 
75  public function get(string $target): Standard
76  {
77  return $this->ui_factory
78  ->input()
79  ->container()
80  ->form()
81  ->standard($target, $this->getInputs())
83  $this->refinery->custom()->transformation(fn(array $value): ?Group => $this->group)
84  );
85  }
86 
87  public function store(RequestInterface $request, string $target): bool
88  {
89  $form = $this->get($target)->withRequest($request);
90  $data = $form->getData();
91  if ($data !== null) {
92  $this->repository->store($this->group);
93  return true;
94  }
95  return false;
96  }
97 
98 }
store(RequestInterface $request, string $target)
Definition: GroupForm.php:87
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Group.php:19
withAdditionalTransformation(Transformation $trafo)
Apply a transformation to the data of the form.
repository()
description: > Example for rendering a repository card
Definition: repository.php:33
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
readonly ILIAS Refinery Factory $refinery
Definition: GroupForm.php:29
This is how the factory for UI elements looks.
Definition: Factory.php:37
global $DIC
Definition: shib_login.php:22
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:61
This describes a standard form.
Definition: Standard.php:28
__construct(private readonly GroupsRepository $repository, private readonly Translator $translator, private ?Group $group=null,)
Definition: GroupForm.php:31