ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilIdentifiedMultiValuesJsPositionIndexRemover.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once 'Services/Form/interfaces/interface.ilFormValuesManipulator.php';
5 
13 {
14  const IDENTIFIER_INDICATOR_PREFIX = 'IDENTIFIER~';
15 
16  public function manipulateFormInputValues($inputValues)
17  {
18  return $this->brandIdentifiersWithIndicator($inputValues);
19  }
20 
21  protected function brandIdentifiersWithIndicator($origValues)
22  {
23  $brandedValues = array();
24 
25  foreach($origValues as $identifier => $val)
26  {
27  $brandedValues[$this->getIndicatorBrandedIdentifier($identifier)] = $val;
28  }
29 
30  return $brandedValues;
31  }
32 
33  protected function getIndicatorBrandedIdentifier($identifier)
34  {
35  return self::IDENTIFIER_INDICATOR_PREFIX . $identifier;
36  }
37 
38  public function manipulateFormSubmitValues($submitValues)
39  {
41  return $this->removePositionIndexLevels($submitValues);
42  }
43 
44  protected function cleanSubmitCommandFromPossibleIdentifierIndicators($cmdArrayLevel)
45  {
46  if( is_array($cmdArrayLevel) )
47  {
48  $currentKey = key($cmdArrayLevel);
49  $nextLevel = current($cmdArrayLevel);
50 
51  $nextLevel = $this->cleanSubmitCommandFromPossibleIdentifierIndicators($nextLevel);
52 
53  unset($cmdArrayLevel[$currentKey]);
54 
55  if( $this->isValueIdentifier($currentKey) )
56  {
57  $currentKey = $this->removeIdentifierIndicator($currentKey);
58  }
59 
60  $cmdArrayLevel[$currentKey] = $nextLevel;
61  }
62 
63  return $cmdArrayLevel;
64  }
65 
66  protected function removePositionIndexLevels($values)
67  {
68  foreach($values as $key => $val)
69  {
70  unset($values[$key]);
71 
72  if( $this->isValueIdentifier($key) )
73  {
74  $key = $this->removeIdentifierIndicator($key);
75 
76  if( $this->isPositionIndexLevel($val) )
77  {
78  $val = $this->fetchPositionIndexedValue($val);
79  }
80  }
81  elseif( is_array($val) )
82  {
83  $val = $this->removePositionIndexLevels($val);
84  }
85 
86  $values[$key] = $val;
87  }
88 
89  return $values;
90  }
91 
92  protected function isPositionIndexLevel($val)
93  {
94  if( !is_array($val) )
95  {
96  return false;
97  }
98 
99  if( count($val) != 1 )
100  {
101  return false;
102  }
103 
104  return true;
105  }
106 
107  protected function isValueIdentifier($key)
108  {
109  $indicatorPrefixLength = self::IDENTIFIER_INDICATOR_PREFIX;
110 
111  if( strlen($key) <= strlen($indicatorPrefixLength) )
112  {
113  return false;
114  }
115 
116  if( substr($key, 0, strlen($indicatorPrefixLength)) != $indicatorPrefixLength )
117  {
118  return false;
119  }
120 
121  return true;
122  }
123 
124  protected function removeIdentifierIndicator($key)
125  {
126  return str_replace(self::IDENTIFIER_INDICATOR_PREFIX, '', $key);
127  }
128 
129  protected function fetchPositionIndexedValue($value)
130  {
131  return current($value);
132  }
133 }
Create styles array
The data for the language used.
$_POST["username"]