Esempio n. 1
0
 /**
  * @param int $articleId
  * @return void Odstraneni clanku
  */
 public function handleDeleteArticle($articleId)
 {
     $this->myArticle = $this->articleRepository->getById($articleId);
     if (!$this->myArticle) {
         $this->flashMessage($this->translator->translate('system.invalidId'));
         return;
     }
     $this->imageStorage->deleteArticleImage($this->myArticle);
     $result = $this->articleRepository->deleteArticle($this->myArticle);
     if ($result) {
         $this->flashMessage($this->translator->translate('system.requestS'), self::MESSAGE_SUCCESS);
     } else {
         $this->flashMessage($this->translator->translate('system.requestN'), self::MESSAGE_DANGER);
     }
     $this->redirect('this');
 }
Esempio n. 2
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;
 }