Skip to content
This repository was archived by the owner on Jun 10, 2022. It is now read-only.

Commit 8aa0033

Browse files
committed
Add mnethod to get all elements and to move an element
1 parent 8875b1b commit 8aa0033

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/CS/DataGridBundle/Util/ArrayStack.php

+32
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ public function rewind()
176176
*/
177177
public function first()
178178
{
179+
$key = min(array_keys($this->elements));
179180

180181
return $this->offsetGet($key);
181182
}
@@ -191,4 +192,35 @@ public function last()
191192

192193
return $this->offsetGet($key);
193194
}
195+
196+
/**
197+
* Return an array with all the elements
198+
*
199+
* @return array
200+
*/
201+
public function all()
202+
{
203+
return $this->elements;
204+
}
205+
206+
/**
207+
* Moves an element to another position
208+
*
209+
* @param string $label
210+
* @param integer $position
211+
* @return $this
212+
*/
213+
public function move($label, $position)
214+
{
215+
if ($this->count() > 0) {
216+
foreach ($this->all() as $key => $data) {
217+
if (strtolower((string) $data) === strtolower($label)) {
218+
$this->offsetUnset($key);
219+
$this->offsetSet($position, $data);
220+
}
221+
}
222+
}
223+
224+
return $this;
225+
}
194226
}

0 commit comments

Comments
 (0)