Example #1
0
 /**
  * comments
  */
 public function isAllowed($module, $controller = null, $action = null)
 {
     $acl = new Digitalus_Acl();
     $mdlUser = new model_User();
     $user = $mdlUser->getCurrentUser();
     //go from more specific to less specific
     $moduleLevel = $module;
     $controllerLevel = $moduleLevel . '_' . $controller;
     $actionLevel = $controllerLevel . '_' . $action;
     if (null != $action && $acl->has($actionLevel)) {
         $resource = $actionLevel;
     } else {
         if (null != $controller && $acl->has($controllerLevel)) {
             $resource = $controllerLevel;
         } else {
             $resource = $moduleLevel;
         }
     }
     if ($acl->has($resource)) {
         if ($acl->isAllowed($user->role, $resource)) {
             return true;
         }
     }
     return false;
 }
Example #2
0
 public function renderAclList($zfModule = 'admin', $usersPermissions = array(), $id = 'aclList')
 {
     $this->permissions = $usersPermissions;
     $acl = new Digitalus_Acl();
     $resources = $acl->getResourceList();
     $xhtml = '<ul id="' . $id . '">';
     foreach ($resources as $module => $resources) {
         if (strtolower($module) == strtolower($zfModule) || 'module' == strtolower($zfModule) && substr($module, 0, 4) == 'mod_') {
             if (!is_array($resources)) {
                 $key = $module;
                 $xhtml .= '<li class="module">' . $this->view->formCheckbox("acl_resources[{$key}]", $this->hasPermision($key, $usersPermissions)) . $module;
             } else {
                 $xhtml .= '<li class="module">' . $module;
                 $xhtml .= '<ul>';
                 foreach ($resources as $controller => $actions) {
                     if (!is_array($actions)) {
                         $key = $module . '_' . $controller;
                         $xhtml .= '<li class="controller">' . $this->view->formCheckbox("acl_resources[{$key}]", $this->hasPermision($key, $usersPermissions)) . $controller;
                     } else {
                         $xhtml .= '<li class="controller">' . $controller;
                         $xhtml .= '<ul>';
                         foreach ($actions as $action) {
                             $key = $module . '_' . $controller . '_' . $action;
                             $xhtml .= '<li class="action">' . $this->view->formCheckbox("acl_resources[{$key}]", $this->hasPermision($key, $usersPermissions)) . $action . '</li>';
                         }
                         $xhtml .= '</ul>';
                     }
                     $xhtml .= '</li>';
                     //end of controller
                 }
                 $xhtml .= '</ul>';
             }
             $xhtml .= '</li>';
             //end of module
         }
     }
     $xhtml .= '</ul>';
     return $xhtml;
 }
Example #3
0
 public function RenderAclList($usersPermissions = array(), $id = 'aclList')
 {
     $this->permissions = $usersPermissions;
     $acl = new Digitalus_Acl();
     $resources = $acl->getResourceList();
     $xhtml = "<ul id='{$id}'>";
     foreach ($resources as $module => $resources) {
         if (!is_array($resources)) {
             $key = $module;
             $xhtml .= '<li class="module">' . $this->view->formCheckbox("acl_resources[{$key}]", $this->hasPermision($key, $usersPermissions)) . $module;
         } else {
             $xhtml .= '<li class="module"><a class="trigger" href="#">' . $module . "</a>";
             $xhtml .= '<ul class="toggle_container">';
             foreach ($resources as $controller => $actions) {
                 if (!is_array($actions)) {
                     $key = $module . '_' . $controller;
                     $xhtml .= '<li class="controller">' . $this->view->formCheckbox("acl_resources[{$key}]", $this->hasPermision($key, $usersPermissions)) . $controller;
                 } else {
                     $xhtml .= '<li class="controller">' . $controller;
                     $xhtml .= '<ul>';
                     foreach ($actions as $action) {
                         $key = $module . '_' . $controller . '_' . $action;
                         $xhtml .= "<li class='action'>" . $this->view->formCheckbox("acl_resources[{$key}]", $this->hasPermision($key, $usersPermissions)) . $action . '</li>';
                     }
                     $xhtml .= '</ul>';
                 }
                 $xhtml .= '</li>';
                 //end of controller
             }
             $xhtml .= '</ul>';
         }
         $xhtml .= '</li>';
         //end of module
     }
     $xhtml .= '</ul>';
     return $xhtml;
 }