ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
DynamicInputDataIterator.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use Iterator;
25
29class DynamicInputDataIterator implements Iterator
30{
31 protected string $parent_input_name;
32 protected array $post_data;
33 protected int $index = 0;
34
36 {
37 $this->post_data = $data->getOr($parent_input_name, []);
38 $this->parent_input_name = $parent_input_name;
39 }
40
41 public function current(): ?InputData
42 {
43 if ($this->valid()) {
44 $entry = [];
45 // for each input of the dynamic input template, the input data must
46 // be mapped to the rendered name, similar to one delivered by
47 // DynamicInputsNameSource for further processing.
48 foreach ($this->post_data as $input_name => $data) {
49 $dynamic_input_name = "$this->parent_input_name[$input_name][]";
50 $entry[$dynamic_input_name] = $data[$this->index];
51 }
52
53 return new ArrayInputData($entry);
54 }
55
56 return null;
57 }
58
59 public function next(): void
60 {
61 $this->index++;
62 }
63
64 public function key(): ?int
65 {
66 if ($this->valid()) {
67 return $this->index;
68 }
69
70 return null;
71 }
72
73 public function valid(): bool
74 {
75 if (empty($this->post_data)) {
76 return false;
77 }
78
79 foreach ($this->post_data as $input_data) {
80 if (!isset($input_data[$this->index])) {
81 return false;
82 }
83 }
84
85 return true;
86 }
87
88 public function rewind(): void
89 {
90 $this->index = 0;
91 }
92}
Describes how Input-Elements want to interact with posted data.
Definition: InputData.php:30
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...