Skip to content

Commit

Permalink
Rocket menu rights update
Browse files Browse the repository at this point in the history
  • Loading branch information
ianrothmann1 committed Nov 9, 2017
1 parent 887520d commit 1b0acf0
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 40 deletions.
114 changes: 75 additions & 39 deletions src/Menu/RocketMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
namespace IanRothmann\RocketLaravelAppFramework;


use App\User;
use Illuminate\Support\Facades\Auth;

class RocketMenu
{

Expand All @@ -29,34 +32,54 @@ private function makeId($id){
return $this->menuName.'_'.$id;
}

public function route($label,$routeName,$params=[],$icon=null){
$this->items[$this->makeId($this->idcnt)]=RocketMenu::item($label)
->route($routeName,$params)
->icon($icon)
->id($this->idcnt);
$this->idcnt++;
return $this;
private function hasRight($rightOrClosure){
if($rightOrClosure===null)
return true;
elseif(is_callable($rightOrClosure))
return $rightOrClosure();
elseif(Auth::user()){
return Auth::user()->hasRight($rightOrClosure);
}else{
return false;
}

}

public function route($label,$routeName,$params=[],$icon=null,$rightOrClosure=null){
if($this->hasRight($rightOrClosure)){
$this->items[$this->makeId($this->idcnt)]=RocketMenu::item($label)
->route($routeName,$params)
->icon($icon)
->id($this->idcnt)
->right($rightOrClosure);
$this->idcnt++;
}
return $this;
}

public function link($label,$link,$icon=null){
$this->items[$this->makeId($this->idcnt)]=RocketMenu::item($label)
->link($link)
->icon($icon)
->id($this->idcnt);
$this->idcnt++;

public function link($label,$link,$icon=null,$rightOrClosure=null){
if($this->hasRight($rightOrClosure)){
$this->items[$this->makeId($this->idcnt)]=RocketMenu::item($label)
->link($link)
->icon($icon)
->id($this->idcnt)
->right($rightOrClosure);
$this->idcnt++;
}
return $this;
}


public function custom(RocketMenuItem $rocketMenuItem){
if($rocketMenuItem->getItemId()===null)
$rocketMenuItem->id($this->idcnt);
if($this->hasRight($rocketMenuItem->getItemRight())){
if($rocketMenuItem->getItemId()===null)
$rocketMenuItem->id($this->idcnt);

$this->items[$this->makeId($rocketMenuItem->getItemId())]=$rocketMenuItem;
$this->items[$this->makeId($rocketMenuItem->getItemId())]=$rocketMenuItem;

$this->idcnt++;
$this->idcnt++;
}

return $this;
}
Expand All @@ -75,39 +98,50 @@ public function group($label,$icon=null){
return $this->items[$oldid];
}

public function pushRoute($label,$routeName,$params=[],$icon=null){
$temp=[];
$temp[$this->makeId($this->idcnt)]=RocketMenu::item($label)
->route($routeName,$params)
->icon($icon)
->id($this->idcnt);
$this->idcnt++;
$this->items=$temp+$this->items;
public function pushRoute($label,$routeName,$params=[],$icon=null,$rightOrClosure=null){
if($this->hasRight($rightOrClosure)){
$temp=[];
$temp[$this->makeId($this->idcnt)]=RocketMenu::item($label)
->route($routeName,$params)
->icon($icon)
->id($this->idcnt)
->right($rightOrClosure);
$this->idcnt++;
$this->items=$temp+$this->items;
}

return $this;
}


public function pushLink($label,$link,$icon=null){
$temp=[];
$temp[$this->makeId($this->idcnt)]=RocketMenu::item($label)
->link($link)
->icon($icon)
->id($this->idcnt);
$this->idcnt++;
$this->items=$temp+$this->items;
public function pushLink($label,$link,$icon=null,$rightOrClosure=null){
if($this->hasRight($rightOrClosure)){
$temp=[];
$temp[$this->makeId($this->idcnt)]=RocketMenu::item($label)
->link($link)
->icon($icon)
->id($this->idcnt)
->right($rightOrClosure);
$this->idcnt++;
$this->items=$temp+$this->items;
}

return $this;
}


public function pushCustom(RocketMenuItem $rocketMenuItem){
if($rocketMenuItem->getItemId()===null)
$rocketMenuItem->id($this->idcnt);
if($this->hasRight($rocketMenuItem->getItemRight())){
if($rocketMenuItem->getItemId()===null)
$rocketMenuItem->id($this->idcnt);

$temp=[];
$temp[$this->makeId($rocketMenuItem->getItemId())]=$rocketMenuItem;
$temp=[];
$temp[$this->makeId($rocketMenuItem->getItemId())]=$rocketMenuItem;

$this->idcnt++;
$this->items=$temp+$this->items;
}

$this->idcnt++;
$this->items=$temp+$this->items;
return $this;
}

Expand Down Expand Up @@ -135,4 +169,6 @@ public static function item($label){
return new RocketMenuItem($label);
}

//public function prepare

}
17 changes: 16 additions & 1 deletion src/Menu/RocketMenuItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@

class RocketMenuItem
{
public $itemLabel, $itemHint, $itemLink, $itemIcon, $itemId, $itemTarget;
public $itemLabel, $itemHint, $itemLink, $itemIcon, $itemId, $itemTarget, $itemRight;
public $subMenu;


public function __construct($label){
$this->label($label);
$this->subMenu=new RocketMenu($this->itemId);
Expand Down Expand Up @@ -49,6 +50,11 @@ public function icon($value){
return $this;
}

public function right($rightOrClosure){
$this->itemRight=$rightOrClosure;
return $this;
}

public function id($value){
$this->itemId=$value;
return $this;
Expand Down Expand Up @@ -102,6 +108,15 @@ public function subMenu()
return $this->subMenu;
}

/**
* @return mixed
*/
public function getItemRight()
{
return $this->itemRight;
}





Expand Down
3 changes: 3 additions & 0 deletions src/RocketLaravelAppFramework.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public function menu($id){
}

public function getMenus(){
foreach($this->menus as &$menu){
//$menu->c
}
return $this->menus;
}

Expand Down

0 comments on commit 1b0acf0

Please sign in to comment.