コード例 #1
0
ファイル: CommentsPresenter.php プロジェクト: svatekr/rsrs
 /**
  * @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);
     }
 }
コード例 #2
0
ファイル: MenuControl.php プロジェクト: svatekr/rsrs
 public function render()
 {
     $template = $this->getTemplate();
     if (file_exists(__DIR__ . '/' . $this->menuType . '.latte')) {
         $template->setFile(__DIR__ . '/' . $this->menuType . '.latte');
     } else {
         $template->setFile(__DIR__ . '/topMenu.latte');
     }
     $pagesInMenu = $this->pagesRepository->getPagesInMenu($this->menuType);
     $template->menuItems = $this->convertAdjacencyListToTree(1, $pagesInMenu, 'id', 'parent', 'children');
     $template->render();
 }
コード例 #3
0
ファイル: PageRoute.php プロジェクト: svatekr/rsrs
 /**
  * @return Nette\Application\IRouter
  * @param IRequest $httpRequest
  */
 public function match(IRequest $httpRequest)
 {
     $appRequest = parent::match($httpRequest);
     if (!isset($appRequest->parameters['id'])) {
         return NULL;
     }
     $id = $appRequest->parameters['id'];
     if (!is_numeric($id)) {
         $page = NULL;
         try {
             $page = $this->pagesRepository->getOneWhere(['url' => $id]);
         } catch (BadRequestException $exc) {
             return NULL;
         }
         $appRequest->parameters['id'] = $page->id();
     }
     return $appRequest;
 }
コード例 #4
0
ファイル: BlogControl.php プロジェクト: svatekr/rsrs
 /**
  * @param null $params
  */
 public function render($params = NULL)
 {
     $blogPages = $this->pagesRepository->getFrontAll()->orderBy(['upDate' => 'DESC']);
     $pagesPerPage = $this->settings['pagesPerPage'];
     $template = 'BlogControl';
     if (is_array($params) && count($params)) {
         $template = $params[1];
         if (isset($params[2])) {
             $pagesPerPage = $params[2];
         }
     }
     $blogPages->limit($pagesPerPage);
     $this->getTemplate()->blogPages = $blogPages->fetchAll();
     $dir = dirname($this->getReflection()->getFileName());
     $pagesControlTemplate = $dir . '/../../../themes/' . $this->settings['theme'] . '/Homepage/' . $template . '.latte';
     if (file_exists($pagesControlTemplate)) {
         $this->getTemplate()->setFile($pagesControlTemplate);
     } else {
         $this->getTemplate()->setFile(__DIR__ . '/' . $template . '.latte');
     }
     $this->getTemplate()->render();
 }
コード例 #5
0
ファイル: AddPageFormFactory.php プロジェクト: svatekr/rsrs
 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->pagesRepository->getAllWhere(['url' => $url]))) {
         $this->getUrl($values, ++$iterator);
     } else {
         $this->page->url($url);
         $this->pagesRepository->save($this->page);
     }
 }
コード例 #6
0
ファイル: PagesPresenter.php プロジェクト: svatekr/rsrs
 /**
  * @param $name
  * @return Grid
  */
 protected function createComponentGrid($name)
 {
     $grid = new Grid($this, $name);
     $grid->translator->lang = 'cs';
     $fluent = $this->pagesRepository->getAll();
     $pages = [];
     foreach ($fluent as $pageRow) {
         $pages[$pageRow->id] = $pageRow;
     }
     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'] = '80%';
     $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->addColumnText('inMenu', 'Top menu')->setCustomRender(function ($item) {
         $menuItems = (array) json_decode($item->inMenu);
         if (!in_array('topMenu', $menuItems)) {
             $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("inTopMenu!", $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("inTopMenu!", $item->id))->setHtml($i);
         }
         return $el;
     })->cellPrototype->class[] = 'center';
     $grid->addActionHref('edit', '')->setIcon('pencil');
     $grid->addActionEvent('delete', '')->setCustomRender(function ($item) {
         if ($item->parent === 0 || $item->rgt - $item->lft > 1) {
             $i = Html::el('i', ['class' => 'fa']);
             $el = Html::el('span', ['class' => 'btn btn-xs btn-mini'])->setHtml($i);
         } else {
             $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->addActionEvent('moveup', '')->setCustomRender(function ($item) use($pages) {
         $first = $item->parent == 0 || $item->lft - 1 == $pages[$item->parent]['lft'];
         if ($first) {
             $i = Html::el('i', ['class' => 'fa']);
             $el = Html::el('span', ['class' => 'btn btn-xs btn-mini'])->setHtml($i);
         } else {
             $i = Html::el('i', ['class' => 'fa fa-arrow-up']);
             $el = Html::el('a', ['class' => 'btn btn-default btn-xs btn-mini ajax'])->href($this->presenter->link("move!", $item->id, self::UP))->setHtml($i);
         }
         return $el;
     });
     $grid->addActionEvent('movedn', '')->setCustomRender(function ($item) use($pages) {
         $last = $item->parent == 0 || $item->rgt + 1 == $pages[$item->parent]['rgt'];
         if ($last) {
             $i = Html::el('i', ['class' => 'fa']);
             $el = Html::el('span', ['class' => 'btn btn-xs btn-mini'])->setHtml($i);
         } else {
             $i = Html::el('i', ['class' => 'fa fa-arrow-down']);
             $el = Html::el('a', ['class' => 'btn btn-default btn-xs btn-mini ajax'])->href($this->presenter->link("move!", $item->id, self::DN))->setHtml($i);
         }
         return $el;
     });
     $grid->addActionHref('add', '')->setIcon('plus');
     $grid->setDefaultSort(['lft' => 'ASC']);
     $grid->setRememberState(TRUE);
     $grid->setPrimaryKey('id');
     $grid->setDefaultPerPage(50);
     $grid->setRowCallback(function ($item, $tr) {
         $tr->class[] = "level_{$item->level}";
         return $tr;
     });
     $grid->filterRenderType = $this->filterRenderType;
     $grid->setExport();
     return $grid;
 }
コード例 #7
0
ファイル: RouterFactory.php プロジェクト: svatekr/rsrs
 /**
  * @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;
 }