Example #1
0
 public function processForm(Form $form, $values)
 {
     if ($this->page->getAllowedComments() === false and !$this->authorizator->isAllowed($this->user, 'page_comment_form', 'comment_on_closed')) {
         $this->flashMessage('page.comments.form.messages.closedComments', FlashMessage::WARNING);
         $this->redirect('this#comments');
     }
     $values['page'] = $this->page;
     try {
         $comment = $this->commentFacade->save((array) $values);
         $this->flashMessage('page.comments.form.messages.success', FlashMessage::SUCCESS);
         $this->redirect('this#comment-' . $comment->getId());
     } catch (ActionFailedException $e) {
         $form->addError($this->translator->translate('page.comments.form.messages.error'));
     }
 }
Example #2
0
 /**
  * @param array $values
  * @param Page|null $page
  * @return Page
  * @throws PagePublicationTimeException
  * @throws PagePublicationTimeMissingException
  * @throws UrlAlreadyExistsException
  * @throws LocaleNotFoundException
  * @throws PageTitleAlreadyExistsException
  * @throws PageIntroHtmlLengthException
  * @throws \Exception
  */
 public function save(array $values, Page $page = null)
 {
     foreach ($values as $k => $v) {
         $values[$k] = $v === '' ? null : $v;
     }
     if ($values['publishedAt'] === null and $values['saveAsDraft'] === false) {
         throw new PagePublicationTimeMissingException();
     }
     $values['author'] = $this->em->find(User::class, $values['author']->getId());
     try {
         if ($page !== null and $page->getId() !== null) {
             $wasDraft = $page->isDraft();
             $hadOpenedComments = $page->getAllowedComments();
             $this->updatePage($page, $values);
             $this->onSuccessPageEditing($page);
         } else {
             $wasDraft = true;
             $hadOpenedComments = true;
             $page = $this->createNewPage($values, $page);
             $this->onSuccessPageCreation($page);
         }
         if ($wasDraft !== $page->isDraft() and $wasDraft === true) {
             $this->onPageRelease($page);
         }
         if ($hadOpenedComments !== $page->getAllowedComments()) {
             if ($hadOpenedComments === true) {
                 $this->onPageCommentsClosure($page);
             } else {
                 $this->onPageCommentsOpening($page);
             }
         }
     } catch (UrlAlreadyExistsException $u) {
         $this->closeEntityManager();
         throw $u;
     } catch (PageTitleAlreadyExistsException $p) {
         $this->closeEntityManager();
         throw $p;
     } catch (\Exception $e) {
         $this->closeEntityManager();
         throw $e;
     }
     return $page;
 }
Example #3
0
 private function fillFormBy(Page $page)
 {
     $this['pageForm']['url']->setDefaultValue($page->getUrlPath());
     $this['pageForm']['publishedAt']->setDefaultValue($page->getTitle());
     if ($page->getPublishedAt() !== null) {
         $this['pageForm']['publishedAt']->setDefaultValue($page->getPublishedAt()->format('j.n.Y H:i'));
     }
     $this['pageForm']['title']->setDefaultValue($page->getTitle());
     $this['pageForm']['intro']->setDefaultValue($page->getIntro());
     $this['pageForm']['text']->setDefaultValue($page->getText());
     $this['pageForm']['allowedComments']->setDefaultValue($page->getAllowedComments());
     $this['pageForm']['description']->setDefaultValue($page->getMetaDescription());
     $this['pageForm']['keywords']->setDefaultValue($page->getMetaKeywords());
     $this['pageForm']['lang']->setDefaultValue($page->getLocaleName());
 }
Example #4
0
 /**
  * @return bool
  */
 public function areCommentsClosed()
 {
     return !$this->page->getAllowedComments();
 }