public function handleSearch($query, $limit) { $results = array(); foreach (array('name', 'title', 'notation', 'text') as $column) { $qb = $routes = $this->routeRepository->createQueryBuilder('r')->andWhere('r.published = :true')->setParameter('true', TRUE)->andWhere('r.released < :now')->setParameter('now', new \DateTime())->setParameter('query', "%{$query}%")->setMaxResults($limit); if ($this->websiteManager->defaultLanguage !== $this->presenter->lang) { $qb->leftJoin('r.translations', 'a')->andWhere('a.language = :langId')->andWhere('(a.' . $column . ' LIKE :query)')->setParameter('langId', $this->presenter->language->id); } else { $qb->andWhere('r.' . $column . ' LIKE :query'); } foreach ($qb->getQuery()->getResult() as $route) { $text = strip_tags(html_entity_decode($route->{$column})); if (($len = strlen($text)) > 40) { $pos = stripos($text, $query); $start = $pos - 20; if ($start > 0) { $text = '...' . substr($text, $start); } if ($start + 40 < $len) { $text = substr($text, 0, 40) . '...'; } } $results[$route->id] = array('url' => $this->presenter->link('Route', array('route' => $route)), 'name' => mb_convert_encoding($this->highlightText($route->name, $query), 'UTF-8', 'UTF-8'), 'value' => mb_convert_encoding($route->name, 'UTF-8', 'UTF-8'), 'description' => mb_convert_encoding($this->highlightText($text, $query), 'UTF-8', 'UTF-8'), 'photo' => $route->photo ? $this->template->basePath . \CmsModule\Content\Macros\MediaMacro::proccessImage($route->photo->getFileUrl(true), array('size' => 'x48')) : NULL); } } $this->presenter->sendResponse(new JsonResponse(array_merge($results))); }
public function createComponentFileBrowser() { $control = $this->fileBrowserControlFactory->invoke(); $control->setBrowserMode((bool) $this->browserMode); if ($this->type) { if ($this->type == 'page') { $control->setRoot($this->pageRepository->find($this->page)->dir); } elseif ($this->type == 'route') { $control->setRoot($this->routeRepository->find($this->route)->dir); } } return $control; }
protected function createComponentTable() { $admin = new AdminGrid($this->routeRepository); // columns $table = $admin->getTable(); $table->setModel(new Doctrine($this->routeRepository->createQueryBuilder('a')->andWhere('a.page = :page')->setParameter('page', $this->extendedPage->page->id))); $table->setTranslator($this->presenter->context->translator->translator); $table->addColumnText('title', 'Title')->setSortable()->getCellPrototype()->width = '100%'; $table->getColumn('title')->setFilterText()->setSuggestion(); $table->addColumnText('url', 'Url')->setSortable()->getCellPrototype()->width = '100%'; $table->getColumn('url')->setFilterText()->setSuggestion(); // actions $table->addAction('edit', 'Edit')->getElementPrototype()->class[] = 'ajax'; $form = $admin->createForm($this->routeFormFactory, 'Route', NULL, \CmsModule\Components\Table\Form::TYPE_LARGE); $admin->connectFormWithAction($form, $table->getAction('edit')); return $admin; }
/** * @return RouteEntity * @throws \Nette\Application\BadRequestException */ public function getRoute() { if (!$this->_route) { if (($this->_route = $this->routeRepository->find($this->routeId)) === NULL) { throw new BadRequestException(); } } return $this->_route; }
public function getRoutes() { if ($this->page) { return $this->routeRepository->findBy(array('page' => $this->page)); } $lang = $this->getLanguage(); $ids = array(); $pages = $this->pageRepository->createQueryBuilder('a')->where('(a.language IS NULL OR a.language = :lang)')->setParameter('lang', $lang->id)->getQuery()->getResult(); foreach ($pages as $page) { if ($this->countRoutesByPage($page) <= $this->itemsLimit) { $ids[] = $page->id; } } return $this->routeRepository->createQueryBuilder('a')->andWhere('a.page IN (:ids)')->setParameter('ids', $ids)->andWhere('a.published = :true')->setParameter('true', TRUE)->getQuery()->getResult(); }