コード例 #1
0
 public function submitRecommandAction()
 {
     try {
         $globalContext = new \Sb\Context\Model\Context();
         $user = $globalContext->getConnectedUser();
         // Getting params
         $id = $this->getParam("id");
         $title = $this->getParam("title");
         $message = $this->getParam("message");
         $IdAddressee = $this->getParam("IdAddressee");
         // Getting book
         $book = $this->getBook($id);
         if (!empty($title) && !empty($message) && !empty($IdAddressee)) {
             $titleVal = trim($title);
             $messageVal = trim($message);
             $recipients = $IdAddressee;
             $recipientsIds = explode(",", $recipients);
             foreach ($recipientsIds as $recipientId) {
                 if (trim($recipientId) != "") {
                     $recipient = UserDao::getInstance()->get($recipientId);
                     if ($recipient) {
                         // adding message in db
                         $message = new Message();
                         $message->setSender($user);
                         $message->setRecipient($recipient);
                         $message->setIs_read(false);
                         $message->setTitle($titleVal);
                         $message->setMessage($messageVal);
                         MessageDao::getInstance()->add($message);
                         // Sending email if user authorized it
                         $userSetting = $recipient->getSetting();
                         if ($userSetting->getEmailMe() == 'Yes') {
                             $body = MailHelper::newMessageArrivedBody($user->getUserName());
                             MailSvc::getInstance()->send($recipient->getEmail(), sprintf(__("%s vous recommande %s ", "s1b"), $user->getUserName(), $book->getTitle()), $body);
                         }
                     }
                 }
             }
             Flash::addItem(__("Message envoyé.", "s1b"));
             HTTPHelper::redirect(Urls::USER_HOME);
         } else {
             Flash::addItem(__("Au moins l'un des champs n'est pas rempli", "s1b"));
             HTTPHelper::redirect(Urls::USER_MAILBOX_RECOMMAND, array("message" => $message, "id" => $id));
         }
     } 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");
     }
 }
コード例 #2
0
 public function replyAction()
 {
     return;
     try {
         $globalContext = new \Sb\Context\Model\Context();
         $messageId = ArrayHelper::getSafeFromArray($_GET, 'mid', null);
         $redirect = false;
         if ($messageId) {
             $message = MessageDao::getInstance()->get($messageId);
             $this->view->message = $message;
             if ($message->getRecipient()->getId() != $globalContext->getConnectedUser()->getId()) {
                 Flash::addItem(__("Vous ne pouvez pas répondre à ce message car il ne vous est pas destiné.", "s1b"));
                 $redirect = true;
             }
         } else {
             Flash::addItem(__("Le message auquel vous tentez de répondre n'existe pas.", "s1b"));
             $redirect = true;
         }
         if ($_POST) {
             $title = htmlspecialchars($_POST['Title']);
             $messageContent = htmlspecialchars($_POST['Message']);
             /* test if form is not empty */
             if (!empty($title) && !empty($messageContent)) {
                 // create new message in db
                 $reply = new Message();
                 $reply->setRecipient($message->getSender());
                 $replySender = $globalContext->getConnectedUser();
                 $reply->setSender($replySender);
                 $reply->setDate(new \DateTime());
                 $reply->setTitle($title);
                 $reply->setMessage($messageContent);
                 $reply->setIs_read(false);
                 MessageDao::getInstance()->add($reply);
                 if ($message->getSender()->getSetting()->getEmailMe() == 'Yes') {
                     // send a email to warn the origianl sender of the email
                     $body = MailHelper::newMessageArrivedBody($replySender->getUserName());
                     MailSvc::getInstance()->send($message->getSender()->getEmail(), sprintf(__("Un message vous a été envoyé depuis le site %s", "s1b"), Constants::SITENAME), $body);
                 }
                 Flash::addItem(__("Message envoyé.", "s1b"));
                 $redirect = true;
             } else {
                 Flash::addItem(__("Vous devez renseigné le titre et le contenu du message.", "s1b"));
             }
         }
         if ($redirect) {
             HTTPHelper::redirect(Urls::USER_MAILBOX);
         }
     } 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");
     }
 }
コード例 #3
0
 /**
  * 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");
     }
 }
コード例 #4
0
 public function setRecipient_id($recipient_id)
 {
     $this->__load();
     return parent::setRecipient_id($recipient_id);
 }
コード例 #5
0
ファイル: User.php プロジェクト: berliozd/cherbouquin
 private function isUnReadMessage(\Sb\Db\Model\Message $message)
 {
     if (!$message->getIs_read()) {
         return true;
     }
     return false;
 }