00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Varien_Data_Form_Element_Collection implements ArrayAccess, IteratorAggregate
00035 {
00036
00037
00038
00039
00040
00041
00042 private $_elements;
00043
00044
00045
00046
00047
00048
00049 private $_container;
00050
00051
00052
00053
00054
00055
00056 public function __construct($container)
00057 {
00058 $this->_elements = array();
00059 $this->_container = $container;
00060 }
00061
00062
00063
00064
00065
00066
00067 public function getIterator()
00068 {
00069 return new ArrayIterator($this->_elements);
00070 }
00071
00072
00073
00074
00075
00076
00077
00078 public function offsetSet($key, $value)
00079 {
00080 $this->_elements[$key] = $value;
00081 }
00082
00083
00084
00085
00086
00087
00088 public function offsetGet($key)
00089 {
00090 return $this->_elements[$key];
00091 }
00092
00093
00094
00095
00096
00097
00098 public function offsetUnset($key)
00099 {
00100 unset($this->_elements[$key]);
00101 }
00102
00103
00104
00105
00106
00107
00108
00109 public function offsetExists($key)
00110 {
00111 return isset($this->_elements[$key]);
00112 }
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122 public function add(Varien_Data_Form_Element_Abstract $element, $after=false)
00123 {
00124
00125 if ($this->_container->getForm() instanceof Varien_Data_Form) {
00126 $element->setContainer($this->_container);
00127 $element->setForm($this->_container->getForm());
00128 }
00129
00130 if ($after === false) {
00131 $this->_elements[] = $element;
00132 }
00133 elseif ($after === '^') {
00134 array_unshift($this->_elements, $element);
00135 }
00136 elseif (is_string($after)) {
00137 $newOrderElements = array();
00138 foreach ($this->_elements as $index => $currElement) {
00139 if ($currElement->getId() == $after) {
00140 $newOrderElements[] = $currElement;
00141 $newOrderElements[] = $element;
00142 $this->_elements = array_merge($newOrderElements, array_slice($this->_elements, $index+1));
00143 return $element;
00144 }
00145 $newOrderElements[] = $currElement;
00146 }
00147 $this->_elements[] = $element;
00148 }
00149
00150 return $element;
00151 }
00152
00153
00154
00155
00156
00157
00158
00159 public function usort($callback)
00160 {
00161 usort($this->_elements, $callback);
00162 return $this;
00163 }
00164
00165
00166
00167
00168
00169
00170
00171 public function remove($elementId)
00172 {
00173 foreach ($this->_elements as $index => $element) {
00174 if ($elementId == $element->getId()) {
00175 unset($this->_elements[$index]);
00176 }
00177 }
00178 return $this;
00179 }
00180
00181
00182
00183
00184
00185
00186 public function count()
00187 {
00188 return count($this->_elements);
00189 }
00190
00191
00192
00193
00194
00195
00196
00197 public function searchById($elementId)
00198 {
00199 foreach ($this->_elements as $element) {
00200 if ($element->getId() == $elementId) {
00201 return $element;
00202 }
00203 }
00204 return null;
00205 }
00206
00207 }