/** * @param $id */ public function actionView($id) { $this->article = $this->articlesRepository->get($id); $this->getTemplate()->article = $this->article; $this->getTemplate()->title = $this->article->title() > '' ? $this->article->title() : $this->article->name(); $this->getTemplate()->description = $this->article->description() > '' ? $this->article->description() : $this->article->text(); $this->getTemplate()->keywords = $this->article->keywords() > '' ? $this->article->keywords() : ''; }
/** * @param int $id */ public function renderEdit($id = 0) { /** @var Form $form */ $form = $this['editForm']; if (!$form->isSubmitted()) { /** @var CommentsEntity $item */ $item = $this->commentsRepository->get($id); $row = $this->commentsRepository->itemToArray($item); if (!$row) { throw new PDOException('Záznam nenalezen'); } if (is_null($item->pageId())) { $row['pageName'] = ''; } else { /** @var PagesEntity $page */ $page = $this->pagesRepository->get($item->pageId()); $row['pageName'] = $page->name(); } if (is_null($item->articleId())) { $row['articleName'] = ''; } else { /** @var ArticlesEntity $aricle */ $aricle = $this->articlesRepository->get($item->articleId()); $row['articleName'] = $aricle->name(); } $form->setDefaults($row); } }
/** * @param IRequest $httpRequest * @return \Nette\Application\Request|NULL */ public function match(IRequest $httpRequest) { $appRequest = parent::match($httpRequest); if (!isset($appRequest->parameters['id'])) { return NULL; } $id = $appRequest->parameters['id']; if (!is_numeric($id)) { $article = NULL; try { $article = $this->articlesRepository->getOneWhere(['url' => $id]); } catch (BadRequestException $exc) { return NULL; } $appRequest->parameters['id'] = $article->id(); } return $appRequest; }
private function getUrl($values, $iterator = 1) { if ($values->url == "/") { return $values->url; } if ($values->url == "") { $url = Strings::webalize($values->name) . ($iterator != 1 ? "-" . $iterator : ''); } else { $url = $values->url . ($iterator != 1 ? "-" . $iterator : ''); } if (count($this->articlesRepository->getAllWhere(['url' => $url])) > 1) { $this->getUrl($values, ++$iterator); } else { $this->article->url($url); $this->articlesRepository->save($this->article); } }
/** * @param $name * @return Grid */ protected function createComponentGrid($name) { $grid = new Grid($this, $name); $grid->translator->lang = 'cs'; $fluent = $this->articlesRepository->getAll(); $articles = []; foreach ($fluent as $articleRow) { $articles[$articleRow->id] = $articleRow; } if (isset($grid->model)) { $grid->model = $fluent; } $grid->addColumnNumber('id', 'ID'); $header = $grid->getColumn('id')->headerPrototype; $header->style['width'] = '0.5%'; $grid->addColumnText('name', 'Název')->setFilterText()->setSuggestion(); $grid->getColumn('name')->headerPrototype->style['width'] = '40%'; $grid->addColumnText('active', 'Aktivní')->setCustomRender(function ($item) { if ($item->active == 0) { $i = Html::el('i', ['class' => 'glyphicon glyphicon-thumbs-down']); $el = Html::el('a', ['class' => 'btn btn-danger btn-xs btn-mini ajax'])->href($this->presenter->link("active!", $item->id))->setHtml($i); } else { $i = Html::el('i', ['class' => 'glyphicon glyphicon-thumbs-up']); $el = Html::el('a', ['class' => 'btn btn-success btn-xs btn-mini ajax'])->href($this->presenter->link("active!", $item->id))->setHtml($i); } return $el; })->cellPrototype->class[] = 'center'; $grid->addActionHref('edit', '')->setIcon('pencil'); $grid->addActionEvent('delete', '')->setCustomRender(function ($item) { $i = Html::el('i', ['class' => 'fa fa-trash']); $el = Html::el('a', ['class' => 'btn btn-default btn-xs btn-mini ajax', 'data-grido-confirm' => "Opravdu chcete tuto položku odstranit?"])->href($this->presenter->link("delete!", $item->id))->setHtml($i); return $el; }); $grid->setDefaultSort(['date' => 'DESC']); $grid->setRememberState(true); $grid->setPrimaryKey('id'); $grid->setDefaultPerPage(50); $grid->filterRenderType = $this->filterRenderType; $grid->setExport(); return $grid; }
/** * @return Nette\Application\IRouter */ public function createRouter() { $router = new RouteList(); $router[] = $adminRouter = new RouteList('Admin'); $adminRouter[] = new Route('[<locale=cs cs|en>/]admin/<presenter>/<action>', 'Pages:default'); $router[] = $frontRouter = new RouteList('Front'); $frontRouter[] = new Route("rss.xml", 'Homepage:rss'); $frontRouter[] = new Route("sitemap.xml", 'Homepage:sitemap'); $frontRouter[] = new Route('[<locale=cs cs|en>/]blog', 'Articles:default'); $frontRouter[] = new PageRoute('[<locale=cs cs|en>/][stranky/]<id>', array('id' => array(Route::FILTER_IN => function ($id) { if (is_numeric($id)) { return $id; } else { $page = $this->pagesRepository->getOneWhere(['url' => $id]); if ($page === NULL) { return NULL; } return $page->id(); } }, Route::FILTER_OUT => function ($id) { if (!is_numeric($id)) { return $id; } else { $page = $this->pagesRepository->get($id); return $page->url(); } }), 'presenter' => 'Pages', 'action' => 'view')); $frontRouter[] = new ArticleRoute('[<locale=cs cs|en>/]blog/<id>', array('id' => array(Route::FILTER_IN => function ($id) { if (is_numeric($id)) { return $id; } else { $article = $this->articlesRepository->getOneWhere(['url' => $id]); if ($article === NULL) { return NULL; } return $article->id(); } }, Route::FILTER_OUT => function ($id) { if (!is_numeric($id)) { return $id; } else { $article = $this->articlesRepository->get($id); return $article->url(); } }), 'presenter' => [Route::VALUE => 'Articles', Route::FILTER_TABLE => ['blog' => 'Articles']], 'action' => 'view')); $frontRouter[] = new NewsRoute('[<locale=cs cs|en>/][novinky/]<id>', array('id' => array(Route::FILTER_IN => function ($id) { if (is_numeric($id)) { return $id; } else { $page = $this->newsRepository->getOneWhere(['url' => $id]); if ($page === NULL) { return NULL; } return $page->id(); } }, Route::FILTER_OUT => function ($id) { if (!is_numeric($id)) { return $id; } else { $page = $this->newsRepository->get($id); return $page->url(); } }), 'presenter' => 'News', 'action' => 'view')); $frontRouter[] = new Route('[<locale=cs cs|en>/]<presenter>/<action>[/<id>]', 'Homepage:default'); $frontRouter[] = new Route('[<locale=cs cs|en>/]index.php', 'Homepage:default', Route::ONE_WAY); return $router; }