public function getTargetFormat() { return $this->view->getTargetFormat(); }
public function prepareView(\Nethgui\View\ViewInterface $view) { if ($view->getTargetFormat() === $view::TARGET_JSON) { if ($this->getRequest()->isEmpty()) { return; } $view['tags'] = $this->searchTags($view, $this->parameters['search']); return; } parent::prepareView($view); $view->setTemplate(array($this, 'renderModuleMenu')); $categories = array(); $translator = $view->getTranslator(); if (defined('NETHGUI_MENU_CATEGORIES')) { $categoryOrder = array_flip(array_map('trim', explode(',', NETHGUI_MENU_CATEGORIES))); } else { $categoryOrder = array(); } foreach ($this->moduleSet as $moduleIdentifier => $moduleInstance) { if (!$moduleInstance instanceof \Nethgui\Module\ModuleInterface) { continue; } $attributes = $moduleInstance->getAttributesProvider(); $category = $attributes->getCategory(); $title = $translator->translate($moduleInstance, $attributes->getTitle()); $tags = $translator->translate($moduleInstance, $attributes->getTags()); $description = $translator->translate($moduleInstance, $attributes->getDescription()); $href = $view->spawnView($moduleInstance)->getModuleUrl(); $position = $attributes->getMenuPosition(); // skip elements without any category if (is_null($category)) { continue; } // initialize category: if (!isset($categories[$category])) { $categories[$category] = array('key' => $category, 'title' => $translator->translate($moduleInstance, $category), 'items' => array()); } // add item to category if (!isset($categories[$category]['items'][$moduleIdentifier])) { $categories[$category]['items'][$moduleIdentifier] = array('identifier' => $moduleIdentifier, 'title' => $title, 'description' => $description, 'href' => $href, 'tags' => $tags, 'position' => $position); } } foreach ($categories as &$category) { usort($category['items'], array($this, 'sortItems')); } usort($categories, function ($c, $d) use($categoryOrder) { if (isset($categoryOrder[$c['key']], $categoryOrder[$d['key']])) { return $categoryOrder[$c['key']] - $categoryOrder[$d['key']]; } return strcmp($c['title'], $d['title']); }); $view['categories'] = $categories; }
/** * Save a request/response round, putting the next view data in the response * * @param \Nethgui\View\ViewInterface $view */ private function prepareNextViewOptimized(\Nethgui\View\ViewInterface $view) { $np = $this->currentAction->nextPath(); if ($np === FALSE) { return; } $nextModule = $this->getAction(\Nethgui\array_head(explode('/', $np))); $location = $view->getModuleUrl($np); if ($nextModule instanceof \Nethgui\View\ViewableInterface) { // spawn and prepare the next view data: $nextView = $view->spawnView($nextModule, TRUE); $nextModule->prepareView($nextView); if ($view->getTargetFormat() === $view::TARGET_JSON) { $nextView->getCommandList()->prefetched(); // placeholder. $nextView->getCommandList()->show(); // Display the prefetched view $this->getPlatform()->setDetachedProcessCondition('success', array('location' => array('url' => $location . '?taskStatus=success&taskId={taskId}'), 'freeze' => TRUE))->setDetachedProcessCondition('failure', array('location' => array('url' => $location . '?taskStatus=failure&taskId={taskId}'), 'freeze' => TRUE)); } else { // show is implemented as HTTP redirection. Avoid self-loops: if ($nextModule !== $this->currentAction) { $view->getCommandList()->sendQuery($location); } } } else { // next path does not corresponds to a child action: start // a new query request to get the next view data: $view->getCommandList()->sendQuery($location); } }