Commit 0b8e3ae7 authored by Nicolas Widart's avatar Nicolas Widart

Add a navigation helper to sort the items

parent 14b9bb66
<?php namespace Modules\Core\Composers;
class SidebarViewComposer
{
public function compose($view)
{
$view->items->sort(function($item1, $item2) {
if (is_object($item1)) {
if ($item1->first()['weight'] > $item2['weight']) {
return 1;
}
if ($item1->first()['weight'] < $item2['weight']) {
return -1;
}
return 0;
}
if (is_object($item2)) {
if ($item1['weight'] > $item2->first()['weight']) {
return 1;
}
if ($item1['weight'] < $item2->first()['weight']) {
return -1;
}
return 0;
}
if ($item1['weight'] > $item2['weight']) {
return 1;
}
if ($item1['weight'] < $item2['weight']) {
return -1;
}
return 0;
});
}
}
\ No newline at end of file
<?php namespace Modules\Core\Navigation;
use Illuminate\Support\Collection;
class NavigationOrdener
{
public static function order(Collection $items)
{
return $items->sort(
function ($item1, $item2) {
$item1 = self::getItem($item1);
$item2 = self::getItem($item2);
if ($item1['weight'] > $item2['weight']) {
return 1;
}
if ($item1['weight'] < $item2['weight']) {
return -1;
}
return 0;
}
);
}
/**
* @param $item
* @return mixed
*/
public static function getItem($item)
{
return isset($item['weight']) ? $item : $item->first();
}
}
\ No newline at end of file
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
<!-- sidebar menu: : style can be found in sidebar.less --> <!-- sidebar menu: : style can be found in sidebar.less -->
<ul class="sidebar-menu"> <ul class="sidebar-menu">
<?php $items = \Modules\Core\Navigation\NavigationOrdener::order($items); ?>
<?php foreach($items as $i => $item): ?> <?php foreach($items as $i => $item): ?>
<?php if (is_object($item)): ?> <?php if (is_object($item)): ?>
<li class="treeview {{ $item[0]['request'] ? 'active' : ''}}"> <li class="treeview {{ $item[0]['request'] ? 'active' : ''}}">
......
<?php <?php
View::creator('core::partials.sidebar-nav', 'Modules\Core\Composers\SidebarViewCreator'); View::creator('core::partials.sidebar-nav', 'Modules\Core\Composers\SidebarViewCreator');
View::composer('core::partials.sidebar-nav', 'Modules\Core\Composers\SidebarViewComposer');
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment