]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Fixes #3035 - menu items appearing in reverse registration order
authorSrokap <srokap@gmail.com>
Tue, 3 Jul 2012 13:22:10 +0000 (15:22 +0200)
committerSrokap <srokap@gmail.com>
Tue, 25 Sep 2012 16:11:10 +0000 (18:11 +0200)
engine/classes/ElggMenuBuilder.php
engine/classes/ElggMenuItem.php

index de0017599199567ae131eca2ec347db6b9fb97e2..df0f9147fb73f6e604231816f984bc05d9680786 100644 (file)
@@ -204,6 +204,9 @@ class ElggMenuBuilder {
 
                // sort each section
                foreach ($this->menu as $index => $section) {
+                       foreach ($section as $key => $node) {
+                               $section[$key]->original_order = $key;
+                       }
                        usort($section, $sort_callback);
                        $this->menu[$index] = $section;
 
@@ -232,10 +235,14 @@ class ElggMenuBuilder {
         * @return bool
         */
        public static function compareByText($a, $b) {
-               $a = $a->getText();
-               $b = $b->getText();
+               $at = $a->getText();
+               $bt = $b->getText();
 
-               return strnatcmp($a, $b);
+               $result = strnatcmp($at, $bt);
+               if ($result === 0) {
+                       return $a->original_order - $b->original_order;
+               }
+               return $result;
        }
 
        /**
@@ -246,10 +253,14 @@ class ElggMenuBuilder {
         * @return bool
         */
        public static function compareByName($a, $b) {
-               $a = $a->getName();
-               $b = $b->getName();
+               $an = $a->getName();
+               $bn = $b->getName();
 
-               return strcmp($a, $b);
+               $result = strcmp($an, $bn);
+               if ($result === 0) {
+                       return $a->original_order - $b->original_order;
+               }
+               return $result;
        }
 
        /**
@@ -260,9 +271,12 @@ class ElggMenuBuilder {
         * @return bool
         */
        public static function compareByWeight($a, $b) {
-               $a = $a->getWeight();
-               $b = $b->getWeight();
+               $aw = $a->getWeight();
+               $bw = $b->getWeight();
 
-               return $a > $b;
+               if ($aw == $bw) {
+                       return $a->original_order - $b->original_order;
+               }
+               return $aw - $bw;
        }
 }
index 4bc9144d451c15e1924e610a1cf322b6438e58a7..fe25f3ddde5c4161fab90e4920a097ca66699d30 100644 (file)
@@ -542,6 +542,9 @@ class ElggMenuItem {
         * @return void
         */
        public function sortChildren($sortFunction) {
+               foreach ($this->data['children'] as $key => $node) {
+                       $this->data['children'][$key]->original_order = $key;
+               }
                usort($this->data['children'], $sortFunction);
        }