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_services()->logger->error(
"A non-object was passed to \ElggMenuBuilder");
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) {
111 $all_menu_items = array();
114 foreach ($section as $menu_item) {
116 $parent_name = $menu_item->getParentName();
117 $menu_item_name = $menu_item->getName();
121 $parents[$menu_item_name] = $menu_item;
126 $all_menu_items[$menu_item_name] = $menu_item;
129 if (empty($all_menu_items)) {
134 if (empty($parents)) {
143 foreach (
$children as $menu_item_name => $menu_item) {
144 $parent_name = $menu_item->getParentName();
146 if (!array_key_exists($parent_name, $all_menu_items)) {
148 $message =
_elgg_services()->translator->translate(
'ElggMenuBuilder:Trees:OrphanedChild', array($menu_item_name, $parent_name));
154 if (!in_array($menu_item, $all_menu_items[$parent_name]->getData(
'children'))) {
155 $all_menu_items[$parent_name]->addChild($menu_item);
156 $menu_item->setParent($all_menu_items[$parent_name]);
159 $message =
_elgg_services()->translator->translate(
'ElggMenuBuilder:Trees:DuplicateChild', array($menu_item_name));
167 $parents = array_values($parents);
169 $menu_tree[
$key] = $parents;
172 $this->
menu = $menu_tree;
183 foreach ($this->
menu as $menu_item) {
184 if ($menu_item->getSelected()) {
190 foreach ($this->
menu as $menu_item) {
191 if ($menu_item->getHref()) {
193 $menu_item->setSelected(
true);
208 protected function sort($sort_by) {
215 $sort_callback = array(
'\ElggMenuBuilder',
'compareByText');
218 $sort_callback = array(
'\ElggMenuBuilder',
'compareByName');
221 $sort_callback = array(
'\ElggMenuBuilder',
'compareByPriority');
228 if (is_callable($sort_by)) {
229 $sort_callback = $sort_by;
237 foreach ($this->
menu as $index => $section) {
238 foreach ($section as
$key => $node) {
239 $section[
$key]->setData(
'original_order',
$key);
241 usort($section, $sort_callback);
242 $this->
menu[$index] = $section;
245 foreach ($section as $root) {
247 array_push($stack, $root);
248 while (!empty($stack)) {
249 $node = array_pop($stack);
251 $node->sortChildren($sort_callback);
270 $at = strip_tags($a->getText());
271 $bt = strip_tags($b->getText());
275 return $a->getData(
'original_order') - $b->getData(
'original_order');
293 return $a->getData(
'original_order') - $b->getData(
'original_order');
307 $aw = $a->getPriority();
308 $bw = $b->getPriority();
311 return $a->getData(
'original_order') - $b->getData(
'original_order');
325 elgg_deprecated_notice(
"\ElggMenuBuilder::compareByWeight() deprecated by \ElggMenuBuilder::compareByPriority", 1.9);
326 $aw = $a->getPriority();
327 $bw = $b->getPriority();
330 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)
Log a notice about deprecated use of a function, view, etc.