public function indexAction()
 {
     try {
         $globalContext = new \Sb\Context\Model\Context();
         // post for deleting messages
         if ($_POST) {
             $messagesToDeleteIds = ArrayHelper::getSafeFromArray($_POST, 'delete', null);
             if ($messagesToDeleteIds) {
                 $messagesToDelete = array();
                 foreach ($messagesToDeleteIds as $messagesToDeleteId) {
                     $message = MessageDao::getInstance()->get($messagesToDeleteId);
                     if ($message) {
                         $messagesToDelete[] = $message;
                     }
                 }
             }
             if ($messagesToDelete && count($messagesToDelete > 0)) {
                 MessageDao::getInstance()->bulkRemove($messagesToDelete);
                 Flash::addItem(__("Le ou les messages ont été supprimés.", "s1b"));
             }
         }
         $user = $globalContext->getConnectedUser();
         $messages = MessageDao::getInstance()->getAll(array("recipient" => $user), array("date" => ArrayHelper::getSafeFromArray($_GET, "sortby", "DESC")));
         $this->view->dateCSSClass = ArrayHelper::getSafeFromArray($_GET, "sortby", "DESC");
         if ($messages && count($messages) > 0) {
             // preparing pagination
             $paginatedList = new PaginatedList($messages, 4);
             $this->view->firstItemIdx = $paginatedList->getFirstPage();
             $this->view->lastItemIdx = $paginatedList->getLastPage();
             $this->view->nbItemsTot = $paginatedList->getTotalPages();
             $this->view->navigation = $paginatedList->getNavigationBar();
             $this->view->messages = $paginatedList->getItems();
         }
     } 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");
     }
 }
 /**
  * Show friends of friends list of user
  */
 public function friendsOfFriendsAction()
 {
     try {
         $globalContext = new \Sb\Context\Model\Context();
         $user = $globalContext->getConnectedUser();
         $friendsFriendShips = \Sb\Db\Dao\FriendShipDao::getInstance()->getFriendsFriendShips($user->getId());
         $friendsFriends = array_map(array(&$this, "getTargetUser"), $friendsFriendShips);
         $friendsFriends = array_filter($friendsFriends, array(&$this, "isNotMe"));
         $friendsFriends = array_filter($friendsFriends, array(&$this, "isNotDeleted"));
         $allUsers = UserDao::getInstance()->getAll();
         $allUsers = array_filter($allUsers, array(&$this, "isNotDeleted"));
         $this->view->nbUsers = count($allUsers);
         if ($friendsFriends && count($friendsFriends) > 0) {
             // preparing pagination
             $paginatedList = new \Sb\Lists\PaginatedList($friendsFriends, 9);
             $this->view->firstItemIdx = $paginatedList->getFirstPage();
             $this->view->lastItemIdx = $paginatedList->getLastPage();
             $this->view->nbItemsTot = $paginatedList->getTotalPages();
             $this->view->navigation = $paginatedList->getNavigationBar();
             $this->view->friendsFriends = $paginatedList->getItems();
         }
     } 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");
     }
 }
 /**
  * Show pending friends request and allow to accepet or refuse it
  */
 public function pendingRequestsAction()
 {
     try {
         $globalContext = new \Sb\Context\Model\Context();
         $user = $globalContext->getConnectedUser();
         $this->view->user = $user;
         // Show pending requests
         if (!$_POST) {
             $totalPendingRequests = $user->getPendingFriendShips();
             if ($totalPendingRequests && count($totalPendingRequests) > 0) {
                 // Preparing pagination
                 $paginatedList = new PaginatedList($totalPendingRequests, 6);
                 $this->view->firstItemIdx = $paginatedList->getFirstPage();
                 $this->view->lastItemIdx = $paginatedList->getLastPage();
                 $this->view->nbItemsTot = $paginatedList->getTotalPages();
                 $this->view->navigation = $paginatedList->getNavigationBar();
                 $this->view->pendingRequests = $paginatedList->getItems();
             }
         } else {
             $friendShipId = ArrayHelper::getSafeFromArray($_POST, 'friendShipId', null);
             $Title = ArrayHelper::getSafeFromArray($_POST, 'Title', null);
             $Message = ArrayHelper::getSafeFromArray($_POST, 'Message', null);
             $Refused = ArrayHelper::getSafeFromArray($_POST, 'Refused', null);
             if ($friendShipId) {
                 if ($Refused == 0) {
                     // Update the requested friendship
                     $friendShip = FriendShipDao::getInstance()->get($friendShipId);
                     if ($friendShip) {
                         $friendShip->setAccepted(true);
                         $friendShip->setValidated(true);
                         if (FriendShipDao::getInstance()->update($friendShip)) {
                             // Add the userEvent
                             try {
                                 $userEvent = new UserEvent();
                                 $userEvent->setNew_value($user->getId());
                                 $userEvent->setType_id(EventTypes::USER_ADD_FRIEND);
                                 $userEvent->setUser($friendShip->getUser_source());
                                 UserEventDao::getInstance()->add($userEvent);
                             } catch (\Exception $exc) {
                                 Trace::addItem("Erreur lors de l'ajout de l'événement : " . $exc->getMEssage());
                             }
                         }
                     }
                     // Create a friendship on the other side
                     $inverseFriendShip = new FriendShip();
                     $inverseFriendShip->setAccepted(true);
                     $inverseFriendShip->setValidated(true);
                     $inverseFriendShip->setCreationDate(new \DateTime());
                     $inverseFriendShip->setUser_source($user);
                     $inverseFriendShip->setUser_target($friendShip->getUser_source());
                     if (FriendShipDao::getInstance()->add($inverseFriendShip)) {
                         // Add the userEvent
                         try {
                             $userEvent = new UserEvent();
                             $userEvent->setNew_value($friendShip->getUser_source()->getId());
                             $userEvent->setType_id(EventTypes::USER_ADD_FRIEND);
                             $userEvent->setUser($user);
                             UserEventDao::getInstance()->add($userEvent);
                         } catch (\Exception $exc) {
                             Trace::addItem("Erreur lors de l'ajout de l'événement : " . $exc->getMEssage());
                         }
                     }
                     // Send email to the requesting user
                     MailSvc::getInstance()->send($friendShip->getUser_source()->getEmail(), __("Demande d'ami", "s1b"), MailHelper::friendShipAcceptationEmailBody($user->getFirstName() . " " . $user->getLastName()));
                     // add a message in requesting user internal mailbox
                     $message = new \Sb\Db\Model\Message();
                     $message->setDate(new \DateTime());
                     $message->setMessage($Message);
                     $message->setTitle($Title);
                     $message->setRecipient($friendShip->getUser_source());
                     $message->setSender($user);
                     MessageDao::getInstance()->add($message);
                     // redirect to pending request page
                     Flash::addItem("Demande acceptée.");
                     HTTPHelper::redirect(Urls::USER_FRIENDS_PENDING_REQUEST);
                 } elseif ($Refused == 1) {
                     // update the requested friendship
                     $friendShip = FriendShipDao::getInstance()->get($friendShipId);
                     if ($friendShip) {
                         $friendShip->setAccepted(false);
                         $friendShip->setValidated(true);
                         FriendShipDao::getInstance()->update($friendShip);
                     }
                     // send email to the requesting user
                     MailSvc::getInstance()->send($friendShip->getUser_source()->getEmail(), __("Votre demande d'ami a été refusée", "s1b"), MailHelper::friendShipDenyEmailBody($user->getFirstName() . " " . $user->getLastName()));
                     // add a message in requesting user internal mailbox
                     $message = new Message();
                     $message->setDate(new \DateTime());
                     $message->setMessage($Message);
                     $message->setTitle($Title);
                     $message->setRecipient($friendShip->getUser_source());
                     $message->setSender($user);
                     MessageDao::getInstance()->add($message);
                     // redirect to pending request page
                     Flash::addItem(__("Demande refusée.", "s1b"));
                     HTTPHelper::redirect(Urls::USER_FRIENDS_PENDING_REQUEST);
                 }
             } else {
                 Flash::addItem(__("Vous devez sélectionner une demande d'ami.", "s1b"));
                 HTTPHelper::redirect(Urls::USER_FRIENDS_PENDING_REQUEST);
             }
         }
     } 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");
     }
 }
 /**
  * Add common item to view model for list actions
  * @param String $key the page key (last chronicles, bloggers, bookstores)
  * @param Array of ChronicleModelView $chronicles the array of ChronicleViewModel to display
  * @param int $pageNumber the page number
  * @param String $navigationParamName the page navigation param name
  */
 private function addCommonListItemsToModelView($key, $chronicles, $pageNumber, $tagId, $searchTerm, $initUrl)
 {
     switch ($key) {
         case self::PAGE_KEY_ANY_GROUPS:
             $title = __("Dernières chroniques", "s1b");
             break;
         case self::PAGE_KEY_BLOGGERS:
             $title = __("En direct des blogs", "s1b");
             break;
         case self::PAGE_KEY_BOOKSTORES:
             $title = __("Le mot des libraires", "s1b");
             break;
     }
     // Add title list to model view
     $this->view->title = $title;
     // Get tags and add it to model view
     $tags = TagSvc::getInstance()->getTagsForChronicles();
     $this->view->tags = $tags;
     // Get search content form and add it to model view
     $contentSearch = new ContentSearch("/default/chronicle/search", $tags, $tagId, __("Rechercher une chronique", "s1b"), $key, $searchTerm, $initUrl);
     $this->view->contentSearch = $contentSearch->get();
     if (!$pageNumber) {
         $pageNumber = 1;
     }
     $chroniclesPaginated = new PaginatedList($chronicles, 5, $this->navigationParamName, $pageNumber);
     $chroniclesPage = $chroniclesPaginated->getItems();
     $chroniclesAdapter = new ChronicleListAdapter();
     $chroniclesAdapter->setChronicles($chroniclesPage);
     // Get as a chronicle view model list with 2 similar chronicles
     $chronicleDetailViewModelList = $chroniclesAdapter->getAsChronicleViewModelList(2);
     // Add chronicleDetailViewModel list to model view
     $this->view->chronicleDetailViewModelList = $chronicleDetailViewModelList;
     // Add navigation bar to view model
     $this->view->navigationBar = $chroniclesPaginated->getNavigationBar();
     // Add more seen chronicles to model view
     $nbMoreSeenChronicles = 5;
     $orderArray = array("nb_views", "DESC");
     switch ($key) {
         case self::PAGE_KEY_ANY_GROUPS:
             $moreSeenChronicles = ChronicleSvc::getInstance()->getLastChronicles($nbMoreSeenChronicles, null, GroupTypes::BLOGGER . "," . GroupTypes::BOOK_STORE, true, null, $orderArray);
             break;
         case self::PAGE_KEY_BLOGGERS:
             $moreSeenChronicles = ChronicleSvc::getInstance()->getLastChronicles($nbMoreSeenChronicles, GroupTypes::BLOGGER, null, true, null, $orderArray);
             break;
         case self::PAGE_KEY_BOOKSTORES:
             $moreSeenChronicles = ChronicleSvc::getInstance()->getLastChronicles($nbMoreSeenChronicles, GroupTypes::BOOK_STORE, null, true, null, $orderArray);
             break;
     }
     if ($moreSeenChronicles) {
         $chroniclesAdapter->setChronicles($moreSeenChronicles);
         $moreSeenChroniclesView = new ChroniclesBlock($chroniclesAdapter->getAsChronicleViewModelLightList(), __("<strong>Chroniques</strong> les plus en vues", "s1b"));
         $this->view->moreSeenChronicles = $moreSeenChroniclesView->get();
     }
     // Get books with press reviews
     $this->view->placeholder('footer')->append("<script src=\"" . BASE_URL . 'Resources/js/waterwheel-carousel/jquery.waterwheelCarousel.min.js' . "\"></script>\n");
     $this->view->placeholder('footer')->append("<script>\$(function () {initCoverFlip('booksWithPressReviews', 30)});</script>\n");
     $books = BookSvc::getInstance()->getListWithPressReviews(15);
     $booksCoverFlip = new BookCoverFlip($books, __("Les livres dont parlent <strong>les médias</strong>", "s1b"), "booksWithPressReviews", "");
     $this->view->booksCoverFlip = $booksCoverFlip->get();
     // Add SEO (title, meta description and keywords)
     $routeName = Zend_Controller_Front::getInstance()->getRouter()->getCurrentRouteName();
     $headerInformation = HeaderInformationSvc::getInstance()->getByRouteName($routeName);
     $this->view->tagTitle = $headerInformation->getTitle();
     $this->view->metaDescription = $headerInformation->getDescription();
     $this->view->metaKeywords = $headerInformation->getKeywords();
 }