aboutsummaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
authorcash <cash.costello@gmail.com>2011-12-31 17:22:55 -0500
committercash <cash.costello@gmail.com>2011-12-31 17:23:25 -0500
commitdfcd3dafeeb61fe61fec96f4a0a6c09ed92deda7 (patch)
treea0ad4a6e878b24c2dc83afefb5c369ae9220af37 /engine
parentdb073ebcb0d52f263eac5a39560b113a4aec7a1d (diff)
downloadelgg-dfcd3dafeeb61fe61fec96f4a0a6c09ed92deda7.tar.gz
elgg-dfcd3dafeeb61fe61fec96f4a0a6c09ed92deda7.tar.bz2
Fixes #4255 new widget ordering code
Diffstat (limited to 'engine')
-rw-r--r--engine/classes/ElggWidget.php25
1 files changed, 19 insertions, 6 deletions
diff --git a/engine/classes/ElggWidget.php b/engine/classes/ElggWidget.php
index 7a5a37ac8..70eaf8a73 100644
--- a/engine/classes/ElggWidget.php
+++ b/engine/classes/ElggWidget.php
@@ -133,17 +133,30 @@ class ElggWidget extends ElggObject {
if ($rank == 0) {
// top of the column
$this->order = $widgets[0]->order - 10;
- } elseif ($rank == count($widgets)) {
+ } elseif ($rank == (count($widgets)-1)) {
// bottom of the column
$this->order = end($widgets)->order + 10;
} else {
- // reorder widgets that are below
- $this->order = $widgets[$rank]->order;
- for ($index = $rank; $index < count($widgets); $index++) {
- if ($widgets[$index]->guid != $this->guid) {
- $widgets[$index]->order += 10;
+ // reorder widgets
+
+ // remove the widget that's being moved from the array
+ foreach ($widgets as $index => $widget) {
+ if ($widget->guid == $this->guid) {
+ unset($widgets[$index]);
}
}
+
+ // split the array in two and recombine with the moved array in middle
+ $before = array_slice($widgets, 0, $rank);
+ array_push($before, $this);
+ $after = array_slice($widgets, $rank);
+ $widgets = array_merge($before, $after);
+ ksort($widgets);
+ $order = 0;
+ foreach ($widgets as $widget) {
+ $widget->order = $order;
+ $order += 10;
+ }
}
$this->column = $column;
}