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; }
protected function getRouteParams(ListControllerOptions $options, $action = 'index', $id = 0, $alias = '', $privilege = '') { $res = array('controller' => $options->getControllerClass(), $options->getAliasParamName() => $alias, 'xelax_admin_privilege' => $privilege); if (!empty($id)) { $res[$options->getIdParamName()] = $id; } if (!empty($action)) { $res['action'] = $action; } return $res; }