function __construct() { $this->tags = new ArrayCollection(); $this->lendings = new ArrayCollection(); $this->borrowings = new ArrayCollection(); // assigning not read state $notReadReadingState = \Sb\Db\Dao\ReadingStateDao::getInstance()->get(\Sb\Db\Dao\UserBookDao::NOTREAD_STATE_ID); $this->reading_state = $notReadReadingState; }
public function submitAction() { try { /* @var $globalContext \Sb\Context\Model\Context */ $globalContext = new \Sb\Context\Model\Context(); /* @var $user Sb\Db\Model\User */ $user = $globalContext->getConnectedUser(); // getting form data $userBookForm = new UserBookForm($_POST); // getting userbook in DB $userBook = UserBookDao::getInstance()->get($userBookForm->getId()); // Getting the events related to the userbook changes $userEvents = UserEventSvc::getInstance()->prepareUserBookEvents($userBook, $userBookForm); // On vérifit la correspondance du user if ($user->getId() != $userBook->getUser()->getId()) { Flash::addItem(__("Le livre que vous souhaitez éditer ne correspond pas à l'utilisateur connecté.", "share1book")); HTTPHelper::redirectToLibrary(); } // updating userbook members $userBook->setReview($userBookForm->getReview()); $userBook->setIsBlowOfHeart($userBookForm->getIsBlowOfHeart()); $userBook->setIsOwned($userBookForm->getIsOwned()); $userBook->setIsWished($userBookForm->getIsWished()); $userBook->setRating($userBookForm->getRating()); $userBook->setNb_of_pages($userBookForm->getNb_of_pages()); $userBook->setNb_of_pages_read($userBookForm->getNb_of_pages_read()); $readingState = ReadingStateDao::getInstance()->get($userBookForm->getReadingStateId()); if ($userBookForm->getReadingDate()) { $userBook->setReadingDate($userBookForm->getReadingDate()); } $userBook->setReadingState($readingState); $userBook->setHyperlink($userBookForm->getHyperLink()); if ($userBookForm->getTags()) { $tags = new \Doctrine\Common\Collections\ArrayCollection(); foreach ($userBookForm->getTags() as $tagId) { $tag = TagDao::getInstance()->get($tagId); $tags->add($tag); } $userBook->setTags($tags); } // Mise à jour du UserBook if (UserBookDao::getInstance()->update($userBook)) { // persisting the userevent related to the userbook changes UserEventSvc::getInstance()->persistAll($userEvents); // Add review as chronicle if ($this->_reviewIsModified($userEvents) && $user->IsBlogger()) { ChronicleSvc::getInstance()->addOrUpdateFromUserBook($userBook); } Flash::addItem(sprintf(__('Le livre "%s" a été mis à jour.', "s1b"), urldecode($userBook->getBook()->getTitle()))); } else { Flash::addItem(__('Une erreur s\'est produite lors de la mise à jour de votre fiche de lecture', 's1b')); } $referer = ArrayHelper::getSafeFromArray($_POST, "referer", null); if ($referer) { HTTPHelper::redirectToUrl($referer); } else { HTTPHelper::redirectToLibrary(); } } catch (\Exception $e) { Trace::addItem(sprintf("Une erreur s'est produite dans \"%s->%s\", MESSAGE : %s , TRACE : %s\"", get_class(), __FUNCTION__, $e->getMessage(), $e->getTraceAsString())); $this->forward("error", "error", "default"); } }