/** * @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); } }
/** * @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); } } }