ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ViewControl.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
37 use ILIAS\UI\Component as C;
38 
40 
41 abstract class ViewControl extends Container implements I\ViewControl
42 {
44 
46  protected ?ServerRequestInterface $request = null;
48 
52  public function __construct(
53  SignalGeneratorInterface $signal_generator,
55  C\Input\ViewControl\Factory $view_control_factory,
56  array $controls
57  ) {
58  parent::__construct($name_source);
59  $this->setInputGroup($view_control_factory->group($controls)->withDedicatedName('view_control'));
60  $this->submit_signal = $signal_generator->create();
61  $this->stored_input = new Input\ArrayInputData([]);
62  }
63 
64  public function getSubmissionSignal(): Signal
65  {
66  return $this->submit_signal;
67  }
68 
72  public function withRequest(ServerRequestInterface $request): Container
73  {
74  $clone = parent::withRequest($request);
75  $clone->request = $request;
76  return $clone;
77  }
78 
79  public function getRequest(): ?ServerRequestInterface
80  {
81  return $this->request;
82  }
83 
84  public function withStoredInput(Input\ArrayInputData $input): self
85  {
86  $clone = clone $this;
87  $clone->stored_input = $input;
88  return $clone;
89  }
90 
94  protected function extractRequestData(ServerRequestInterface $request): InputData
95  {
96  $internal_input_data = new Input\ArrayInputData($this->getComponentInternalValues());
97 
98  return new StackedInputData(
99  new QueryParamsFromServerRequest($request),
100  $this->stored_input,
101  $internal_input_data,
102  );
103  }
104 
108  public function getComponentInternalValues(
109  C\Input\Group $component = null,
110  array $input_values = []
111  ): array {
112  if(is_null($component)) {
113  $component = $this->getInputGroup();
114  }
115  foreach ($component->getInputs() as $input) {
116  if ($input instanceof C\Input\Group) {
117  $input_values = $this->getComponentInternalValues($input, $input_values);
118  }
119  if ($input instanceof HasInputGroup) {
120  $input_values = $this->getComponentInternalValues($input->getInputGroup(), $input_values);
121  }
122  if($name = $input->getName()) {
123  $input_values[$input->getName()] = $input->getValue();
124  }
125  }
126 
127  return $input_values;
128  }
129 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This implements commonalities between all forms.
Definition: Container.php:33
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
trait JavaScriptBindable
Trait for components implementing JavaScriptBindable providing standard implementation.
Describes how Input-Elements want to interact with posted data.
Definition: InputData.php:29
setInputGroup(C\Input\Group $input_group)
This setter should be used in the constructor only, to initialize the group input property...
Definition: Container.php:132
Implements interaction of input element with get data from psr-7 server request.
__construct(VocabulariesInterface $vocabularies)
getComponentInternalValues(C\Input\Group $component=null, array $input_values=[])
Implements interaction of input element with get data from psr-7 server request.
__construct(SignalGeneratorInterface $signal_generator, Input\NameSource $name_source, C\Input\ViewControl\Factory $view_control_factory, array $controls)
Definition: ViewControl.php:52
create(string $class='')
Create a signal, each created signal MUST have a unique ID.
This describes commonalities between all inputs.
Definition: Input.php:46
Describes a source for input names.
Definition: NameSource.php:26
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...