ILIAS  release_8 Revision v8.24
DynamicInputDataIterator.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
22
23use Iterator;
24
28class DynamicInputDataIterator implements Iterator
29{
30 protected string $parent_input_name;
31 protected array $post_data;
32 protected int $index = 0;
33
35 {
36 $this->post_data = $data->getOr($parent_input_name, []);
37 $this->parent_input_name = $parent_input_name;
38 }
39
40 public function current(): ?InputData
41 {
42 if ($this->valid()) {
43 $entry = [];
44 // for each input of the dynamic input template, the input data must
45 // be mapped to the rendered name, similar to one delivered by
46 // DynamicInputsNameSource for further processing.
47 foreach ($this->post_data as $input_name => $data) {
48 $dynamic_input_name = "$this->parent_input_name[$input_name][]";
49 $entry[$dynamic_input_name] = $data[$this->index];
50 }
51
52 return new ArrayInputData($entry);
53 }
54
55 return null;
56 }
57
58 public function next(): void
59 {
60 $this->index++;
61 }
62
63 public function key(): ?int
64 {
65 if ($this->valid()) {
66 return $this->index;
67 }
68
69 return null;
70 }
71
72 public function valid(): bool
73 {
74 if (empty($this->post_data)) {
75 return false;
76 }
77
78 foreach ($this->post_data as $input_data) {
79 if (!isset($input_data[$this->index])) {
80 return false;
81 }
82 }
83
84 return true;
85 }
86
87 public function rewind(): void
88 {
89 $this->index = 0;
90 }
91}
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...