Exemplo n.º 1
0
 /**
  * @param $name
  * @return Grid
  * @throws \Grido\Exception
  */
 protected function createComponentGrid($name)
 {
     $grid = new Grid($this, $name);
     $grid->translator->lang = 'cs';
     $fluent = $this->commentsRepository->getAll();
     $grid->model = $fluent;
     $grid->addColumnText('author', 'Autor')->setSortable()->setFilterText();
     $grid->addColumnDate('date', 'Datum')->setSortable()->setFilterText();
     $grid->addColumnText('allowed', 'Schváleno')->setCustomRender(function ($item) {
         if ($item['allowed'] === 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("allowed!", $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("allowed!", $item['id']))->setHtml($i);
         }
         return $el;
     })->cellPrototype->class[] = 'center';
     $grid->addColumnText('text', 'Text')->setCustomRender(function ($item) {
         $el = Html::el('span')->setText(Strings::substring($item['text'], 0, 80));
         return $el;
     });
     $grid->getColumn('text')->headerPrototype->style['width'] = '90%';
     $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'])->href($this->presenter->link("delete!", $item['id']))->setHtml($i);
         return $el;
     });
     $grid->setDefaultSort(['date' => 'DESC']);
     $grid->setDefaultPerPage(50);
     $grid->filterRenderType = $this->filterRenderType;
     $grid->setExport();
     return $grid;
 }
Exemplo n.º 2
0
 /**
  * @param UI\Form $form
  */
 public function processForm(UI\Form $form)
 {
     $values = $form->getValues();
     $comment = new CommentsEntity();
     $comment->pageId($this->pageId);
     $comment->articleId($this->articleId);
     $comment->author($values->name);
     $comment->text($values->text);
     $comment->date(new DateTime());
     $comment->allowed(0);
     $this->commentsRepository->save($comment);
     $this->flashMessage("Děkujeme za názor. Váš komentář byl odeslán a po schválení bude zobrazen", 'success');
     if (!$this->presenter->isAjax()) {
         $this->redirect('this');
     }
     $this->redrawControl();
 }