public function search($searchQuery, \lib\Repository $repository = null) { if (!empty($repository)) { $packages = $repository->getPackagesList(); } else { $packages = $this->getPackagesList(); } $items = array(); foreach ($packages as $pkg) { $item = $pkg->toArray(); $item['searchName'] = $pkg['name']; $items[] = $item; } $searcher = new \lib\ArraySearcher($items); return $searcher->search($searchQuery, array('searchName', 'title', 'subtitle', 'description', 'url', 'maintainer')); }
public function executeShowAction(\core\HTTPRequest $request) { $this->page()->addVar('title', 'Afficher une action'); $this->page()->addVar('breadcrumb', array(array())); $moduleName = $request->getData('module'); $actionName = $request->getData('action'); $searchQuery = $request->getExists('q') ? trim($request->getData('q')) : null; $backend = $this->_getBackendMetadata($moduleName); $action = $this->_getAction($moduleName, $actionName); $this->page()->addVar('searchQuery', $searchQuery); if (!empty($backend) && !empty($action)) { $this->page()->addVar('backend', $backend); $this->page()->addVar('action', $action); $this->page()->addVar('title', $action['title']); $this->page()->addVar('breadcrumb', array(array('title' => $backend['title'], 'url' => $this->app->router()->getUrl($this->module(), 'showModule', array('module' => $moduleName))), array('title' => $action['title']))); if (isset($action['list'])) { if (!isset($action['list']['items'])) { return; } $itemsToList = $action['list']['items']; $ctrl = $this->app->buildController($moduleName, $actionName); $methodName = 'list' . ucfirst($itemsToList); if (method_exists($ctrl, $methodName)) { $items = $ctrl->{$methodName}($request); $router = $this->app->router(); $route = $router->getRoute($moduleName, $actionName); foreach ($items as $key => $item) { if (isset($item['vars']) && $route->hasVars()) { if (isset($action['list']['vars'])) { $routeVarsNames = $route->varsNames(); $joinVarsNames = $action['list']['vars']; $itemsVars = $item['vars']; $vars = array(); foreach ($routeVarsNames as $routeVarName) { if (isset($joinVarsNames[$routeVarName])) { $itemVarName = $joinVarsNames[$routeVarName]; $vars[$routeVarName] = $itemsVars[$itemVarName]; } } } else { $vars = $item['vars']; } $route->setVars($vars); } $items[$key]['url'] = $route->buildUrl(); } //Search query if (!empty($searchQuery)) { $searcher = new \lib\ArraySearcher($items); $items = $searcher->search($searchQuery, array('title', 'shortDescription')); } $this->page()->addVar('items', $items); } } } }