Ejemplo n.º 1
0
 function __construct($showingConnectedUserBook, \Sb\Db\Model\UserBook $userBook = null)
 {
     parent::__construct();
     if ($userBook) {
         $this->userBook = $userBook;
         $this->book = $userBook->getBook();
         $this->user = $userBook->getUser();
     }
     $this->showingConnectedUserBook = $showingConnectedUserBook;
 }
Ejemplo n.º 2
0
 public function prepareUserBookEvents(UserBook $oldUserBook, UserBookForm $newUserBook)
 {
     $userEvents = array();
     try {
         if ($oldUserBook->getRating() != $newUserBook->getRating()) {
             $userEvent = new \Sb\Db\Model\UserEvent();
             $userEvent->setItem_id($oldUserBook->getId());
             $userEvent->setUser($oldUserBook->getUser());
             $userEvent->setNew_value($newUserBook->getRating());
             $userEvent->setOld_value($oldUserBook->getRating());
             $userEvent->setType_id(\Sb\Entity\EventTypes::USERBOOK_RATING_CHANGE);
             $userEvents[] = $userEvent;
         }
         if ($oldUserBook->getIsBlowOfHeart() != $newUserBook->getIsBlowOfHeart()) {
             $userEvent = new \Sb\Db\Model\UserEvent();
             $userEvent->setItem_id($oldUserBook->getId());
             $userEvent->setUser($oldUserBook->getUser());
             $userEvent->setNew_value($newUserBook->getIsBlowOfHeart());
             $userEvent->setOld_value($oldUserBook->getIsBlowOfHeart());
             $userEvent->setType_id(\Sb\Entity\EventTypes::USERBOOK_BLOWOFHEART_CHANGE);
             $userEvents[] = $userEvent;
         }
         if ($oldUserBook->getHyperlink() != $newUserBook->getHyperLink()) {
             $userEvent = new \Sb\Db\Model\UserEvent();
             $userEvent->setItem_id($oldUserBook->getId());
             $userEvent->setUser($oldUserBook->getUser());
             // Removing http:// or https:// from url
             $newHyperlink = str_replace("http://", "", $newUserBook->getHyperLink());
             $newHyperlink = str_replace("https://", "", $newHyperlink);
             $userEvent->setNew_value($newHyperlink);
             $userEvent->setOld_value($oldUserBook->getHyperlink());
             $userEvent->setType_id(\Sb\Entity\EventTypes::USERBOOK_HYPERLINK_CHANGE);
             $userEvents[] = $userEvent;
         }
         $oldReadingStateId = $oldUserBook->getReadingState() ? $oldUserBook->getReadingState()->getId() : -1;
         if ($oldReadingStateId != $newUserBook->getReadingStateId()) {
             $userEvent = new \Sb\Db\Model\UserEvent();
             $userEvent->setItem_id($oldUserBook->getId());
             $userEvent->setUser($oldUserBook->getUser());
             $userEvent->setNew_value($newUserBook->getReadingStateId());
             $userEvent->setOld_value($oldUserBook->getReadingState() ? $oldUserBook->getReadingState()->getId() : null);
             $userEvent->setType_id(\Sb\Entity\EventTypes::USERBOOK_READINGSTATE_CHANGE);
             $userEvents[] = $userEvent;
         }
         if ($oldUserBook->getReview() != $newUserBook->getReview()) {
             $userEvent = new \Sb\Db\Model\UserEvent();
             $userEvent->setItem_id($oldUserBook->getId());
             $userEvent->setUser($oldUserBook->getUser());
             $userEvent->setNew_value($newUserBook->getReview());
             $userEvent->setOld_value($oldUserBook->getReview());
             $userEvent->setType_id(\Sb\Entity\EventTypes::USERBOOK_REVIEW_CHANGE);
             $userEvents[] = $userEvent;
         }
         if ($oldUserBook->getIsWished() != $newUserBook->getIsWished()) {
             $userEvent = new \Sb\Db\Model\UserEvent();
             $userEvent->setItem_id($oldUserBook->getId());
             $userEvent->setUser($oldUserBook->getUser());
             $userEvent->setNew_value($newUserBook->getIsWished());
             $userEvent->setOld_value($oldUserBook->getIsWished());
             $userEvent->setType_id(\Sb\Entity\EventTypes::USERBOOK_WISHEDSTATE_CHANGE);
             $userEvents[] = $userEvent;
         }
     } catch (\Exception $exc) {
         Trace::addItem("Une erreur s'est produite lors de la préparation des événements liés au userbook");
     }
     return $userEvents;
 }
Ejemplo n.º 3
0
 /**
  * Add or update a chronicle based on a userbook review
  *
  * @param \Sb\Db\Model\UserBook $userBook
  * @param unknown $groupId
  */
 public function addOrUpdateFromUserBook(\Sb\Db\Model\UserBook $userBook)
 {
     $bloggerGroupId = 2;
     /* @var $user \Sb\Db\Model\User */
     $user = $userBook->getUser();
     /* @var $user \Sb\Db\Model\Book */
     $book = $userBook->getBook();
     /* @var $existingChronicle \Sb\Db\Model\Chronicle */
     $chronicle = $this->getChronicle($user->getId(), $book->getId());
     if (is_null($chronicle)) {
         $chronicle = new Chronicle();
     }
     $chronicle->setUser($user);
     $chronicle->setBook($userBook->getBook());
     $chronicle->setCreation_date(new \DateTime());
     $chronicle->setGroup(\Sb\Db\Dao\GroupDao::getInstance()->get($bloggerGroupId));
     $chronicle->setIs_validated(true);
     $chronicle->setLink($userBook->getHyperlink() ? 'http://' . $userBook->getHyperlink() : '');
     $chronicle->setLink_type(ChronicleLinkType::URL);
     $chronicle->setText($userBook->getReview());
     $chronicle->setTitle($book->getTitle());
     $chronicle->setType_id(ChronicleType::BOOK_CHRONICLE);
     $chronicle->setKeywords($book->getTitle() . ', ' . $book->getOrderableContributors() . ', ' . $book->getPublisher()->getName());
     $tags = $userBook->getTags();
     if (count($tags) > 0) {
         $chronicle->setTag($userBook->getTags()->first());
     }
     $this->getDao()->add($chronicle);
 }
 public function getUser()
 {
     $this->__load();
     return parent::getUser();
 }