/**
  * @param Form $form
  * @throws ForbiddenRequestException
  */
 public function articleFormSucceeded(Form $form)
 {
     $v = $form->getValues();
     if (!$this->user->isAllowed('Article', 'add') || !$this->user->isAllowed('Article', 'edit')) {
         throw new ForbiddenRequestException();
     }
     $tags = [];
     if ($v->tags !== '') {
         $articleTags = explode(',', $v->tags);
         $tags = $this->articleManager->createTagsAndReturnIds($articleTags);
     }
     // type
     if ($v->type != 'default') {
         $type = $this->articleManager->addTag($v->type, 'type');
     } else {
         $type = NULL;
     }
     if (empty($this->article)) {
         $article = $this->articleManager->addArticle($v->title, $v->content, $v->language, $tags, $type, $this->getUser()->getId());
         $this->flashMessage('Article was added');
         $this->redirect('edit', $article->id);
     } else {
         $this->articleManager->editArticle($this->article->id, $v->title, $v->content, $v->language, $tags, $type, $this->getUser()->getId());
         $this->flashMessage('Article was updated');
         $this->redirect('edit', $this->article->id);
     }
 }
Exemplo n.º 2
0
 /**
  * @param Form $form
  * @throws ForbiddenRequestException
  */
 public function articleFormSucceeded(Form $form)
 {
     $v = $form->getValues();
     if (!$this->user->isAllowed('Article', 'add') || !$this->user->isAllowed('Article', 'edit')) {
         throw new ForbiddenRequestException();
     }
     $tags = [];
     if ($v->tags !== '') {
         $articleTags = explode(',', $v->tags);
         $tags = $this->articleManager->createTagsAndReturnIds($articleTags);
     }
     // type
     if ($v->type != 'default') {
         $type = $this->articleManager->addTag($v->type, 'type');
     } else {
         $type = NULL;
     }
     if ($v->draft) {
         $draft = TRUE;
     } else {
         $draft = FALSE;
     }
     if (empty($this->article)) {
         $article = $this->articleManager->addArticle($v->title, $v->content, $draft, $v->language, $tags, $type, $this->getUser()->getId());
         $this->versionManager->addVersionToArticle($v->version, $article->id);
         $this->flashMessage('Article was added');
         $this->redirect('Detail:default', $article->id, $article->slug);
     } else {
         // file upload
         if ($v->file->isOk()) {
             /** @var \Nette\Http\FileUpload $file */
             $file = $v->file;
             // TODO : refactor
             $this->imageStorage->setNamespace("knowledgebase");
             $filename = uniqid() . '.' . (pathinfo($file->name, PATHINFO_EXTENSION) ?: 'png');
             $image = $this->imageStorage->save($file->getContents(), $filename);
             $returnPath = pathinfo($image->file, PATHINFO_BASENAME);
             $note = '';
             if ($v->fileNote) {
                 $note = $v->fileNote;
             }
             $status = $this->articleManager->assignImageToArticle($this->article->id, $returnPath, "knowledgebase", $note);
             if ($status) {
                 $this->flashMessage('Image was uploaded');
             }
         }
         $this->article = $this->articleManager->editArticle($this->article->id, $v->title, $v->content, $draft, $v->language, $tags, $type, $this->getUser()->getId());
         // .. Update version
         $this->versionManager->updateVersion($v->version, $this->article->id);
         $this->flashMessage('Article was updated');
         if (isset($form['sendAndView']) && $form['sendAndView']->isSubmittedBy()) {
             $this->redirect('Detail:default', $this->article->id, $this->article->slug);
         } else {
             $this->redirect('Edit:edit', $this->article->id);
         }
     }
 }
Exemplo n.º 3
0
 public function addSucceeded(Form $form)
 {
     $valuesForm = $form->getValues(true);
     $valuesHttp = $form->getHttpData();
     if (!$valuesForm['photo']->isImage() && $valuesForm['photo']->isOK()) {
         $form->addError('Toto není obrázek');
         return;
     }
     $valuesForm['underSubSection'] = (int) $valuesHttp['underSubSection'];
     $valuesForm['underSerial'] = (int) $valuesHttp['underSerial'];
     $values = Nette\Utils\ArrayHash::from($valuesForm);
     $id = $this->articleManager->addArticle($this->user->getId(), $values);
     $this->flashMessage('Článek úspěšně přidán');
     $this->redirect('Article:UpdateArticle', $id);
 }