コード例 #1
0
ファイル: MenuManager.php プロジェクト: flysap/administrator
 /**
  * @param null $group
  * @param array $attributes
  * @return mixed
  */
 public function render($group = null, array $attributes = array())
 {
     $this->buildMenu();
     if ($attributes) {
         $this->setAttributes($attributes);
     }
     $groups = $this->getGroups();
     if (!is_null($group)) {
         $groups = [$this->getGroup($group)];
     }
     array_walk($groups, function ($group) use(&$result) {
         #@todo ..
         $result = '<ul';
         $result .= $this->renderAttributes(['class']);
         $result .= '>';
         $menus = $group->getElements();
         array_walk($menus, function ($menu) use(&$result) {
             /** Check for permissions . */
             if (isset($menu['permissions'])) {
                 if (!Users\can($menu['permissions'])) {
                     return false;
                 }
             }
             /** Check for roles . */
             if (isset($module['roles'])) {
                 if (!Users\is($menu['roles'])) {
                     return false;
                 }
             }
             /** @var Get the variable from view shared . $label */
             $label = $this->detectVariables($menu['label']);
             $url = isset($menu['route']) ? route($menu['route']) : (isset($menu['href']) ? $menu['href'] : '#');
             $result .= '<li><a href="' . $url . '">' . $label . '</a></li>';
         });
         $result .= '</ul>';
     });
     return $result;
 }
コード例 #2
0
 /**
  * Allow current user to update that relation ?
  *
  * @param array $attributes
  * @param array $defaultAllowedRole
  * @return bool
  */
 protected function isGranted(array $attributes, $defaultAllowedRole = ['admin'])
 {
     /** By default we have to add that only to admins . */
     if (!isset($attributes['permissions']) && !isset($attributes['roles'])) {
         $attributes['roles'] = $defaultAllowedRole;
     }
     if (isset($attributes['permissions'])) {
         if (!Users\can($attributes['permissions'])) {
             return false;
         }
     }
     if (isset($attributes['roles'])) {
         if (!Users\is($attributes['roles'])) {
             return false;
         }
     }
     return true;
 }