Exemplo n.º 1
0
 public function getRulesController($route, $privilegeBase, ListControllerOptions $options)
 {
     $rules = array();
     $childRoutes = array('index', 'list', 'create', 'edit', 'delete');
     foreach ($childRoutes as $childRoute) {
         $getter = 'get' . ucfirst($childRoute) . 'Route';
         if ($childRoute == 'index') {
             $getter = 'getListRoute';
         }
         /* @var $route \XelaxAdmin\Options\ListControllerRoute */
         $routeOptions = $options->{$getter}();
         if (!$routeOptions->getDisabled()) {
             // [ ['group1', 'group2', ...], 'resource name' ]
             $rules[] = [$routeOptions->getAllowedRoles(), 'xelax-route/' . $route, $privilegeBase . "/" . $childRoute];
         }
     }
     // check child options
     if (!empty($options->getChildOptions())) {
         foreach ($options->getChildOptions() as $name => $childOption) {
             $childRules = $this->getRulesController($route, $privilegeBase . "/" . $name, $childOption);
             $rules = array_merge($rules, $childRules['allow']);
         }
     }
     return array('allow' => $rules);
 }
 protected function getListControllerRoute($routeBase, ListControllerOptions $options)
 {
     if (empty($options->getName())) {
         return null;
     }
     if (!$this->routeNeedsAutogenerate($options->getListRoute()) && !$this->routeNeedsAutogenerate($options->getCreateRoute()) && !$this->routeNeedsAutogenerate($options->getDeleteRoute()) && !$this->routeNeedsAutogenerate($options->getEditRoute())) {
         return null;
     }
     $route = $this->getLiteralConfig('/' . $options->getName(), $options->getControllerClass(), 'index');
     $route['child_routes'] = array();
     if (!empty($options->getChildOptions())) {
         $childOptions = $options->getChildOptions();
         foreach ($childOptions as $childName => $childOption) {
             // get child route
             $childRoute = $this->getListControllerRoute($routeBase . '/' . $childName, $childOption);
             // add parent id parameter
             $childRoute['type'] = 'Segment';
             $childRoute['options']['route'] = '/:' . $options->getChildRouteParamName() . $childRoute['options']['route'];
             $childRoute['options']['defaults'][$options->getChildRouteParamName()] = 0;
             $childRoute['options']['constraints'][$options->getChildRouteParamName()] = '[0-9]*';
             // attach route
             $route['child_routes']['_' . $childName] = $childRoute;
         }
     }
     if ($this->routeNeedsAutogenerate($options->getListRoute())) {
         $route['child_routes']['list'] = $this->getSegmentConfig('/list[/:p]', $options->getControllerClass(), 'list', array(), array('p' => '[0-9]*'));
         $options->getListRoute()->setRoute($routeBase . '/' . 'list');
     }
     if ($this->routeNeedsAutogenerate($options->getCreateRoute())) {
         $route['child_routes']['create'] = $this->getLiteralConfig('/create', $options->getControllerClass(), 'create');
         $options->getCreateRoute()->setRoute($routeBase . '/' . 'create');
     }
     if ($this->routeNeedsAutogenerate($options->getEditRoute())) {
         $route['child_routes']['edit'] = $this->getSegmentConfig('/:' . $options->getEditParamName() . '/edit', $options->getControllerClass(), 'edit', array($options->getEditParamName() => 0), array($options->getEditParamName() => '[0-9]+'));
         $options->getEditRoute()->setRoute($routeBase . '/' . 'edit');
     }
     if ($this->routeNeedsAutogenerate($options->getDeleteRoute())) {
         $route['child_routes']['delete'] = $this->getSegmentConfig('/:' . $options->getDeleteParamName() . '/delete', $options->getControllerClass(), 'delete', array($options->getDeleteParamName() => 0), array($options->getDeleteParamName() => '[0-9]+'));
         $options->getDeleteRoute()->setRoute($routeBase . '/' . 'delete');
     }
     // TODO: Custom child-routes
     // TODO: Configure which default routes should be visible
     return $route;
 }
Exemplo n.º 3
0
 protected function make_alias(ListControllerOptions $options, $params)
 {
     if (empty($params[$options->getIdParamName()])) {
         return false;
     }
     $idAlias = $params[$options->getIdParamName()];
     $this->assembledParams[] = $options->getIdParamName();
     if (!empty($params[$options->getAliasParamName()])) {
         $idAlias .= "-" . $params[$options->getAliasParamName()];
         $this->assembledParams[] = $options->getAliasParamName();
     }
     return $idAlias;
 }