/** * 1. Krok pri pridavani noveho komentare * @return Form Sepsani a nahled, ulozeni do session */ public function createComponentForm() { $form = new Form(); $form->setRenderer(new \Nextras\Forms\Rendering\Bs3FormRenderer()); $form->setTranslator($this->translator); $form->addText('name', 'system.commentName')->setRequired($form->getTranslator()->translate('system.requiredItem', ['label' => '%label'])); $form->addTextArea('content', 'system.commentContent')->setRequired($form->getTranslator()->translate('system.requiredItem', ['label' => '%label']))->setAttribute('rows', 6); $form->addHidden('articleId', $this->article->getId()); $form->addSubmit('preview', 'system.commentPreview'); //prejit ke druhemu kroku, coz je ulozeni $form->onSuccess[] = [$this, 'formPreview']; return $form; }
public function updateArticle(Article $a) { if ($a === NULL) { throw new Exceptions\NullPointerException("Argument Article was null"); } try { $this->entityManager->beginTransaction(); $db = $this->articleDao->find($a->getId()); if ($db !== null) { $this->articlePictureHandle($a, $db); $db->fromArray($a->toArray()); $this->sportGroupsTypeHandle($db); $db->setUpdated(new DateTime()); $this->editorTypeHandle($db); $this->authorTypeHandle($db); $db->setAlias(Strings::webalize($a->getTitle())); $this->entityManager->merge($db); $this->entityManager->flush(); $this->invalidateEntityCache($db); $this->entityManager->commit(); } } catch (DBALException $ex) { $this->entityManager->rollback(); $this->logWarning($ex->getMessage()); throw new Exceptions\DuplicateEntryException($ex->getMessage(), $ex->getCode(), $ex->getPrevious()); } catch (\Exception $ex) { $this->entityManager->rollback(); $this->logError($ex->getMessage()); throw new Exceptions\DataErrorException($ex->getMessage(), $ex->getCode(), $ex->getPrevious()); } $this->onUpdate($a); return $a; }
/** * @param \App\Model\Entities\Article $article * @return array Vychozi hodnoty pro formular */ protected function getDefaults($article) { $result = []; $result['id'] = $article->getId(); $result['title'] = $article->getTitle(); $result['description'] = $article->getDescription(); $result['published'] = $article->isPublished(); $publishDate = $article->getPublishDate(); if ($publishDate) { $result['publishDate'] = $publishDate->format('d. m. Y, H:i'); } $result['content'] = $article->getContent(); foreach ($article->getTags() as $tag) { $result['tags'][] = $tag->getId(); } return $result; }