ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
class.ilMultipleImagesAdditionalIndexLevelRemover.php
Go to the documentation of this file.
1<?php
2
20
25{
27 'name', 'tmp_name', 'type', 'error', 'size'
28 ];
29
30 protected $postVar;
31
32 public function getPostVar()
33 {
34 return $this->postVar;
35 }
36
37 public function setPostVar($postVar): void
38 {
39 $this->postVar = $postVar;
40 }
41
42 protected function getFilesSubmissionProperties(): array
43 {
45 }
46 public function manipulateFormInputValues(array $inputValues): array
47 {
48 return $inputValues;
49 }
50
51 #[AllowSuperglobalWrite('normalises the shape of $_FILES[postVar], because the inherited getInput() reads it back from there.', 12)]
52 public function manipulateFormSubmitValues(array $submitValues): array
53 {
54 $submitValues = $this->removeAdditionalSubFieldsLevelFromSubmitValues($submitValues);
55
56 if ($_FILES) {
58 $_FILES[$this->getPostVar()]
59 );
60 }
61
62 return $submitValues;
63 }
64 protected function isSubFieldAvailable($values, $subFieldName): bool
65 {
66 if (!is_array($values)) {
67 return false;
68 }
69
70 if (!isset($values[$subFieldName])) {
71 return false;
72 }
73
74 if (!is_array($values[$subFieldName])) {
75 return false;
76 }
77
78 return true;
79 }
80
81 protected function isIteratorSubfieldAvailable($values): bool
82 {
84 }
85
86 protected function isUploadSubfieldAvailable($values): bool
87 {
89 }
90
91 protected function removeAdditionalSubFieldsLevelFromSubmitValues($values): array
92 {
93 if (!$this->isIteratorSubfieldAvailable($values)) {
94 return $values;
95 }
96
97 $storedImages = $values[ilMultipleImagesInputGUI::STORED_IMAGE_SUBFIELD_NAME] ?? [];
98 $actualValues = [];
99
100 foreach ($values[ilMultipleImagesInputGUI::ITERATOR_SUBFIELD_NAME] as $index => $value) {
101 if (!isset($storedImages[$index])) {
102 $actualValues[$index] = '';
103 continue;
104 }
105
106 $actualValues[$index] = $storedImages[$index];
107 }
108
109 return $actualValues;
110 }
111
113 {
114 if (!$this->isUploadSubfieldAvailable($uploadProperty)) {
115 return $uploadProperty;
116 }
117
118 foreach ($uploadProperty as $subField => $submittedFile) {
119 if (!is_array($submittedFile)) {
120 unset($uploadProperty[$subField]);
121 continue;
122 }
123 foreach ($submittedFile as $identifier => $uploadValue) {
124 $uploadProperty[$identifier] = $uploadValue;
125 }
126
127 unset($uploadProperty[$subField]);
128 }
129
130 return $uploadProperty;
131 }
132
133 protected function removeAdditionalSubFieldsLevelFromFilesSubmit($filesSubmit)
134 {
135 foreach ($this->getFilesSubmissionProperties() as $uploadProperty) {
136 if (!isset($filesSubmit[$uploadProperty])) {
137 continue;
138 }
139
140 $filesSubmit[$uploadProperty] = $this->removeAdditionalSubFieldsLevelFromFilesSubmitProperty(
141 $filesSubmit[$uploadProperty]
142 );
143 }
144
145 return $filesSubmit;
146 }
147}