aboutsummaryrefslogtreecommitdiff
path: root/engine/classes
diff options
context:
space:
mode:
authorcash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>2011-02-13 18:48:40 +0000
committercash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>2011-02-13 18:48:40 +0000
commitcaf76cbe72ca6749962a1feddfd70bdd29483c36 (patch)
treec25cc57270602691f3cb756f98e6a17001779d89 /engine/classes
parentac39d8a06f422887cf256d77a096c03783dd349e (diff)
downloadelgg-caf76cbe72ca6749962a1feddfd70bdd29483c36.tar.gz
elgg-caf76cbe72ca6749962a1feddfd70bdd29483c36.tar.bz2
admin menu uses weights for ordering
git-svn-id: http://code.elgg.org/elgg/trunk@8201 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/classes')
-rw-r--r--engine/classes/ElggMenuBuilder.php19
-rw-r--r--engine/classes/ElggMenuItem.php25
2 files changed, 43 insertions, 1 deletions
diff --git a/engine/classes/ElggMenuBuilder.php b/engine/classes/ElggMenuBuilder.php
index f51ec8c62..33abc0c6b 100644
--- a/engine/classes/ElggMenuBuilder.php
+++ b/engine/classes/ElggMenuBuilder.php
@@ -179,9 +179,12 @@ class ElggMenuBuilder {
case 'title':
$sort_callback = array('ElggMenuBuilder', 'compareByTitle');
break;
- case 'name';
+ case 'name':
$sort_callback = array('ElggMenuBuilder', 'compareByName');
break;
+ case 'weight':
+ $sort_callback = array('ElggMenuBuilder', 'compareByWeight');
+ break;
case 'order':
// use registration order
return;
@@ -244,4 +247,18 @@ class ElggMenuBuilder {
return strcmp($a, $b);
}
+
+ /**
+ * Compare two menu items by their weight
+ *
+ * @param ElggMenuItem $a
+ * @param ElggMenuItem $b
+ * @return bool
+ */
+ public static function compareByWeight($a, $b) {
+ $a = $a->getWeight();
+ $b = $b->getWeight();
+
+ return $a > $b;
+ }
}
diff --git a/engine/classes/ElggMenuItem.php b/engine/classes/ElggMenuItem.php
index a190a89ef..108cb56f2 100644
--- a/engine/classes/ElggMenuItem.php
+++ b/engine/classes/ElggMenuItem.php
@@ -39,6 +39,11 @@ class ElggMenuItem {
protected $tooltip = '';
/**
+ * @var int Menu weight - smaller weights float to the top
+ */
+ protected $weight = 100;
+
+ /**
* @var bool Is this the currently selected menu item
*/
protected $selected = false;
@@ -227,6 +232,26 @@ class ElggMenuItem {
}
/**
+ * Set the weight of the menu item
+ *
+ * @param int $weight The lower weight items float to the top of the menu
+ *
+ * @return void
+ */
+ public function setWeight($weight) {
+ $this->weight = $weight;
+ }
+
+ /**
+ * Get the weight of the menu item
+ *
+ * @return int
+ */
+ public function getWeight() {
+ return $this->weight;
+ }
+
+ /**
* Set the section identifier
*
* @param string $section The identifier of the section