/**
  * Show member home page action
  * @global type $globalContextMe
  */
 public function indexAction()
 {
     try {
         $globalContext = new \Sb\Context\Model\Context();
         $globalConfig = new Sb\Config\Model\Config();
         /* @var $connectedUser User */
         $connectedUser = $globalContext->getConnectedUser();
         // Getting friends boh
         $blowOfHeartFriendsBooks = BookDao::getInstance()->getListBOHFriends($connectedUser->getId());
         $this->view->isShowingFriendsBOH = false;
         if (!$blowOfHeartFriendsBooks || count($blowOfHeartFriendsBooks) < 5) {
             // Setting class property with array of friend boh books ids to use it in "notInArray" function below
             $this->blowOfHeartFriendsBooksId = array_map(array(&$this, "getId"), $blowOfHeartFriendsBooks);
             // Getting all users boh
             $blowOfHeartBooks = BookSvc::getInstance()->getBOHForUserHomePage();
             $blowOfHeartBooks = array_filter($blowOfHeartBooks, array(&$this, "notInArray"));
             // Merging 2 arrays
             if ($blowOfHeartFriendsBooks && $blowOfHeartBooks) {
                 $blowOfHeartBooks = array_merge($blowOfHeartFriendsBooks, $blowOfHeartBooks);
             }
             $blowOfHeartBooks = array_slice($blowOfHeartBooks, 0, 5);
         } else {
             $this->view->isShowingFriendsBOH = true;
             $blowOfHeartBooks = $blowOfHeartFriendsBooks;
         }
         $this->view->blowOfHeartBooks = $blowOfHeartBooks;
         // Getting friends user events
         $this->view->userEvents = UserEventDao::getInstance()->getListUserFriendsUserEvents($connectedUser->getId());
         // Getting top books
         $this->view->topsBooks = BookSvc::getInstance()->getTopsUserHomePage();
         // Getting last review by friends
         $lastReviews = UserEventSvc::getInstance()->getFriendsLastEventsOfType($connectedUser->getId(), EventTypes::USERBOOK_REVIEW_CHANGE);
         $this->view->lastReviews = $lastReviews;
         $this->view->lastReviewsView = new LastReviews($lastReviews, __("<strong>Dernières critiques postées par vos amis</strong>", "s1b"));
         // Getting User Reading Widget
         $allCurrentlyReadingUserBooks = UserBookDao::getInstance()->getCurrentlyReadingsNow($connectedUser->getId());
         $userReading = new UserReadingWidget($connectedUser, $allCurrentlyReadingUserBooks, true);
         // If more than one book as 'being read', we need to set the javascript carousel
         if (count($allCurrentlyReadingUserBooks) > 1) {
             $this->view->placeholder('footer')->append("<script src=\"" . $globalContext->getBaseUrl() . 'Resources/js/simple-carousel/simple.carousel.js' . "\"></script>\n");
             $this->view->placeholder('footer')->append("<script>\$(function() {initCarousel('carousel-currentreadings', 270, 210)});</script>\n");
         }
         $this->view->userReading = $userReading;
         // Getting user wished books widget
         $userWishedBooks = new UserWishedBooksWidget($connectedUser, true);
         $this->view->userWishedBooks = $userWishedBooks;
         // Getting wish list search widget
         $this->view->wishListSearchWidget = new WishListSearchWidget();
         // Getting the ad (second paramters is not used anymore)
         $this->view->ad = new Ad("user_homepage", "6697829998");
         // Getting twitter widget
         $this->view->twitter = new TwitterWidget(TwitterSvc::getInstance($globalConfig));
         // Getting facebook frame
         $this->view->facebookFrame = new FacebookFrame();
         // Get create chronicle links widget
         if ($connectedUser->getIs_partner() && $connectedUser->getGroupusers()) {
             $createChroniclesLink = new CreateChroniclesLinks($connectedUser->getGroupusers());
             $this->view->createChroniclesLinkView = $createChroniclesLink->get();
         }
     } catch (\Exception $e) {
         Trace::addItem(sprintf("Une erreur s'est produite dans \"%s->%s\", TRACE : %s\"", get_class(), __FUNCTION__, $e->getTraceAsString()));
         $this->forward("error", "error", "default");
     }
 }
 public function profileAction()
 {
     $globalContext = new \Sb\Context\Model\Context();
     // Users profile are only accessible for connected users
     AuthentificationSvc::getInstance()->checkUserIsConnected();
     $noUser = true;
     $friendId = $this->_getParam("uid");
     if ($friendId) {
         $friend = UserDao::getInstance()->get($friendId);
         $this->view->friend = $friend;
         if ($friend) {
             $noUser = false;
             if ($friend->getId() == $globalContext->getConnectedUser()->getId()) {
                 Flash::addItem(__("Il s'agit de votre profil!", "s1b"));
                 HTTPHelper::redirectToReferer();
             } else {
                 $requestingUser = $globalContext->getConnectedUser();
                 if (SecurityHelper::IsUserAccessible($friend, $requestingUser)) {
                     $this->view->friendSetting = $friend->getSetting();
                     $this->view->isFriend = UserSvc::getInstance()->areUsersFriends($globalContext->getConnectedUser(), $friend);
                     // getting currently reading or lastly read books
                     $currentlyReading = UserBookDao::getInstance()->getReadingNow($friend->getId());
                     $lastlyReads = UserBookDao::getInstance()->getListLastlyRead($friend->getId());
                     if ($currentlyReading && $lastlyReads) {
                         $this->view->currentlyReadingOrLastlyReadBooks = array_merge(array($currentlyReading), $lastlyReads);
                     } elseif ($lastlyReads) {
                         $this->view->currentlyReadingOrLastlyReadBooks = $lastlyReads;
                     } elseif ($currentlyReading) {
                         $this->view->currentlyReadingOrLastlyReadBooks = array($currentlyReading);
                     }
                     // Getting friend currently reading user books
                     $this->view->allCurrentlyReadingUserBooks = UserBookDao::getInstance()->getCurrentlyReadingsNow($friend->getId());
                     if (count($this->view->allCurrentlyReadingUserBooks) > 1) {
                         $this->view->placeholder('footer')->append("<script src=\"" . $globalContext->getBaseUrl() . 'Resources/js/simple-carousel/simple.carousel.js' . "\"></script>\n");
                         $this->view->placeholder('footer')->append("<script>\$(function() {initCarousel('carousel-currentreadings', 298, 190)});</script>\n");
                     }
                     // Getting friend last boh books
                     $bohUserBooks = UserBookDao::getInstance()->getListUserBOH($friend->getId());
                     $this->view->bohBooks = array_map(array($this, "getBook"), $bohUserBooks);
                     // Getting books friend could like
                     $this->view->booksHeCouldLikes = BookSvc::getInstance()->getBooksUserCouldLike($friend->getId());
                     if ($this->view->booksHeCouldLikes && count($this->view->booksHeCouldLikes) > 0) {
                         $this->view->placeholder('footer')->append("<script src=\"" . $globalContext->getBaseUrl() . 'Resources/js/waterwheel-carousel/jquery.waterwheelCarousel.min.js' . "\"></script>\n");
                         $this->view->placeholder('footer')->append("<script>\$(function() {initCoverFlip('bookUserCouldLike', 90)});</script>\n");
                     }
                     // Getting friend's friends last reviews
                     $this->view->friendLastReviews = UserEventSvc::getInstance()->getUserLastEventsOfType($friend->getId(), EventTypes::USERBOOK_REVIEW_CHANGE);
                     // Getting friend last friends added events
                     $this->view->friendLastFriendsAddedEvents = UserEventSvc::getInstance()->getUserLastEventsOfType($friend->getId(), EventTypes::USER_ADD_FRIEND);
                     if (count($this->view->friendLastFriendsAddedEvents) > 1) {
                         $this->view->placeholder('footer')->append("<script src=\"" . $globalContext->getBaseUrl() . 'Resources/js/simple-carousel/simple.carousel.js' . "\"></script>\n");
                         $this->view->placeholder('footer')->append("<script>\$(function() {initCarousel('carousel-friendlastfriends', 298, 85)});</script>\n");
                     }
                     // Getting friend last events
                     $this->view->friendLastEvents = UserEventSvc::getInstance()->getUserLastEventsOfType($friend->getId(), null, 15);
                     $this->view->placeholder('footer')->append("<script>\n\n                            toInit.push(\"attachUserEventsExpandCollapse()\");\n\n                            function attachUserEventsExpandCollapse() {_attachExpandCollapseBehavior(\"js_userLastEvents\", \"userEvent\", \"Voir moins d'activités\", \"Voir plus d'activités\");}\n\n                        </script>\n");
                 } else {
                     Flash::addItem(__("Vous ne pouvez pas accéder à ce profil.", "s1b"));
                     HTTPHelper::redirectToReferer();
                 }
             }
         }
     }
     if ($noUser) {
         Flash::addItem(__("Cet utilisateur n'existe pas.", "s1b"));
         HTTPHelper::redirectToReferer();
     }
 }
 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");
     }
 }