Beispiel #1
0
 /**
  * @todo Vylepsit to inkrementovani
  * Detail clanku
  * @param string $id Identifikator clanku: article_id-webalize_title
  */
 public function actionPost($id)
 {
     list($parseId, $parseWebTitle) = Model\Entities\Article::parseWebId($id);
     $this->article = $this->articleRepository->getById($parseId);
     if (!is_object($this->article)) {
         //nepodarilo se ziskat clanek
         $this->flashMessage($this->translator->translate('system.articleNF'), self::MESSAGE_DANGER);
         $this->redirect('default');
     }
     if (!$this->user->isLoggedIn() && !$this->article->isPublished()) {
         //nezobrazovat nezverejnene clanky neprihlasenym uzivatelum
         $this->flashMessage($this->translator->translate('system.requestNA'), self::MESSAGE_DANGER);
         $this->redirect('default');
     }
     //inkrementovat citac pristupu a ulozeni zmeny
     $this->article->setCounter();
     $this->entityManager->flush();
 }
Beispiel #2
0
 /**
  * @param int $articleId
  */
 public function actionEdit($articleId)
 {
     $this->myArticle = $this->articleRepository->getById($articleId);
     if (!$this->myArticle) {
         $this->flashMessage($this->translator->translate('system.invalidId'), self::MESSAGE_DANGER);
         $this->redirect('default');
     }
     $this->template->title = $this->translator->translate('system.editPost');
 }
Beispiel #3
0
 /**
  * @param Form $form
  * @return void Zpracovani formulare - pridani noveho komentare
  */
 public function formSucceeded(Form $form)
 {
     //nacteni a smazani session
     $values = \Nette\Utils\ArrayHash::from($this->commentSession->content);
     $this->commentSession->remove();
     //ulozit novy prispevek ke clanku
     $this->article = $this->articleRepository->getById($values->articleId);
     if (isset($this->myUser)) {
         $values->user = $this->myUser;
         $values->name = NULL;
     } else {
         $values->user = NULL;
     }
     //vytvoreni komentu, prirazeni ke clanku a ulozeni
     $newComment = new \App\Model\Entities\Comment($this->article, $values->user, $values->name, $values->content);
     $this->articleRepository->getEntityManager()->persist($newComment);
     $this->article->addComment($newComment);
     $this->articleRepository->getEntityManager()->flush();
     $this->redirect('this');
 }
Beispiel #4
0
 /**
  * @param Nette\Utils\ArrayHash $values Hodnoty z formulare
  * @return boolean Editace provedena uspesne?
  */
 protected function editArticle($values)
 {
     $result = TRUE;
     try {
         /** @var \App\Model\Entities\Article $editArticle */
         $editArticle = $this->repository->getById($values->id);
         if (!$editArticle) {
             return FALSE;
         }
         // nastaveni atributu
         $editArticle->setPublished($values->published);
         $editArticle->setTitle($values->title);
         $editArticle->setUpdateDate();
         $editArticle->setPublishDate($values->publishDate);
         $editArticle->setDescription($values->description);
         $editArticle->setContent($values->content);
         $tags = [];
         foreach ($values->tags as $tagId) {
             $tag = $this->em->getReference(\App\Model\Entities\Tag::class, $tagId);
             $tags[$tagId] = $tag;
         }
         $editArticle->setTags($tags);
         if ($values->image->isImage()) {
             $this->imageStorage->setArticleImage($editArticle, $values->image->toImage(), $values->imageSource);
         } elseif (!empty($values->imageSource)) {
             $editImage = $editArticle->getImage();
             if ($editImage !== NULL) {
                 $editImage->source = $values->imageSource;
             }
         }
         //ulozeni zmeny
         $this->em->flush();
     } catch (\Exception $e) {
         \Tracy\Debugger::log($e, \Tracy\Debugger::INFO);
         $result = FALSE;
     }
     return $result;
 }