33 public function getMenu($sort_by =
'text') {
43 $this->
sort($sort_by);
63 if (!isset($this->
menu)) {
64 $this->
menu = array();
69 $selected_menu = array();
70 foreach ($this->
menu as $menu_item) {
71 if (!is_object($menu_item)) {
72 elgg_log(
"A non-object was passed to ElggMenuBuilder",
"ERROR");
75 if ($menu_item->inContext()) {
76 $selected_menu[] = $menu_item;
80 $this->
menu = $selected_menu;
89 $sectioned_menu = array();
90 foreach ($this->
menu as $menu_item) {
91 if (!isset($sectioned_menu[$menu_item->getSection()])) {
92 $sectioned_menu[$menu_item->getSection()] = array();
94 $sectioned_menu[$menu_item->getSection()][] = $menu_item;
96 $this->
menu = $sectioned_menu;
106 $menu_tree = array();
108 foreach ($this->
menu as
$key => $section) {
112 foreach ($section as $menu_item) {
114 $parent_name = $menu_item->getParentName();
116 $parents[$menu_item->getName()] = $menu_item;
124 $current_gen = $parents;
126 while (count(
$children) && $iteration < 20) {
127 foreach (
$children as $index => $menu_item) {
128 $parent_name = $menu_item->getParentName();
129 if (array_key_exists($parent_name, $current_gen)) {
130 $next_gen[$menu_item->getName()] = $menu_item;
131 if (!in_array($menu_item, $current_gen[$parent_name]->getData(
'children'))) {
132 $current_gen[$parent_name]->addChild($menu_item);
133 $menu_item->setParent($current_gen[$parent_name]);
138 $current_gen = $next_gen;
143 $parents = array_values($parents);
145 $menu_tree[
$key] = $parents;
148 $this->
menu = $menu_tree;
159 foreach ($this->
menu as $menu_item) {
160 if ($menu_item->getSelected()) {
166 foreach ($this->
menu as $menu_item) {
167 if ($menu_item->getHref()) {
169 $menu_item->setSelected(
true);
184 protected function sort($sort_by) {
191 $sort_callback = array(
'ElggMenuBuilder',
'compareByText');
194 $sort_callback = array(
'ElggMenuBuilder',
'compareByName');
197 $sort_callback = array(
'ElggMenuBuilder',
'compareByPriority');
204 if (is_callable($sort_by)) {
205 $sort_callback = $sort_by;
213 foreach ($this->
menu as $index => $section) {
214 foreach ($section as
$key => $node) {
215 $section[
$key]->setData(
'original_order',
$key);
217 usort($section, $sort_callback);
218 $this->
menu[$index] = $section;
221 foreach ($section as $root) {
223 array_push($stack, $root);
224 while (!empty($stack)) {
225 $node = array_pop($stack);
227 $node->sortChildren($sort_callback);
250 return $a->getData(
'original_order') - $b->getData(
'original_order');
268 return $a->getData(
'original_order') - $b->getData(
'original_order');
282 $aw = $a->getPriority();
283 $bw = $b->getPriority();
286 return $a->getData(
'original_order') - $b->getData(
'original_order');
300 elgg_deprecated_notice(
"ElggMenuBuilder::compareByWeight() deprecated by ElggMenuBuilder::compareByPriority", 1.9);
301 $aw = $a->getPriority();
302 $bw = $b->getPriority();
305 return $a->getData(
'original_order') - $b->getData(
'original_order');
elgg_http_url_is_identical($url1, $url2, $ignore_params=array('offset', 'limit'))
Test if two URLs are functionally identical.
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Sends a notice about deprecated use of a function, view, etc.
elgg_log($message, $level= 'NOTICE')
Display or log a message.