/**
  * Dispatches or redirects the node action to the right node action controller
  * @param string $action
  * @param int $id id of the node
  * @return null
  */
 public function indexAction($action = null, $id = null)
 {
     if (!$id && !$action) {
         $this->response->setRedirect($this->getJoppaBaseUrl());
         return;
     }
     if (!$this->site) {
         $this->response->setRedirect($this->getJoppaBaseUrl());
         return;
     }
     if (!$id && is_numeric($action)) {
         $lastAction = $this->getSession()->get(self::SESSION_LAST_ACTION, 'content');
         $this->response->setRedirect($this->getJoppaBaseUrl() . '/node/' . $lastAction . '/' . $action);
         return;
     }
     if (!$this->node || $this->node->id != $id) {
         $this->node = $this->models[NodeModel::NAME]->getNode($id, 0);
         if ($this->node) {
             $parameters = func_get_args();
             $url = $this->request->getBasePath() . Request::QUERY_SEPARATOR . implode(Request::QUERY_SEPARATOR, $parameters);
             $this->response->setRedirect($url);
         } else {
             $this->response->setRedirect($this->getJoppaBaseUrl());
         }
         return;
     }
     $nodeActionManager = NodeActionManager::getInstance();
     if ($nodeActionManager->hasAction($action)) {
         // chain to the node action
         $this->getSession()->set(self::SESSION_LAST_ACTION, $action);
         $nodeAction = $nodeActionManager->getAction($action);
         $parameters = func_get_args();
         $action = array_shift($parameters);
         $id = array_shift($parameters);
         $basePath = $this->request->getBasePath();
         $basePath .= Request::QUERY_SEPARATOR . $action . Request::QUERY_SEPARATOR . $id;
         return $this->forward(get_class($nodeAction), null, $parameters, $basePath);
     }
     // chain to the node type's backend controller
     $nodeTypeFacade = NodeTypeFacade::getInstance();
     if (!$nodeTypeFacade->hasNodeType($this->node->type)) {
         return $this->setError404();
     }
     $nodeTypeController = $nodeTypeFacade->getBackendController($this->node->type);
     if (!$nodeTypeController) {
         return $this->setError404();
     }
     $nodeId = $this->node->id;
     $nodeData = $nodeTypeFacade->getNodeData($this->node->type, $nodeId, 0);
     if ($nodeData) {
         $nodeId = $nodeData->id;
     }
     $parameters = func_get_args();
     $action = array_shift($parameters);
     array_shift($parameters);
     array_unshift($parameters, $action, $nodeId);
     $basePath = $this->getJoppaBaseUrl() . Request::QUERY_SEPARATOR . $this->node->type;
     return $this->forward($nodeTypeController, null, $parameters, $basePath);
 }
Beispiel #2
0
 /**
  * Get the html of the node tree
  * @param array $nodeTree array with Node objects
  * @param int $defaultNodeId id of the node of the default page
  * @param joppa\model\Node $selectedNode the current node in the ui
  * @param boolean $addUnlocalizedClass Set to true to add the unlocalized class to nodes which are not localized in the current locale
  * @return string html representation of the nodes
  */
 private function getNodeTreeHtml(array $nodeTree, $defaultNodeId, $addUnlocalizedClass, Node $selectedNode = null)
 {
     $this->actions = NodeActionManager::getInstance()->getActions();
     $html = '<ul id="nodeTree">';
     foreach ($nodeTree as $node) {
         $html .= $this->getNodeHtml($node, $defaultNodeId, $addUnlocalizedClass, $selectedNode);
     }
     $html .= '</ul>';
     return $html;
 }