Exemple #1
0
 /**
  * @param $conv_id
  * @param $user_id
  * @param bool $newToOld
  * @return Conversation
  */
 public function getConversationMessages($conv_id, $user_id, $newToOld = true)
 {
     if ($newToOld) {
         $orderBy = 'desc';
     } else {
         $orderBy = 'asc';
     }
     $results = DB::select('
         SELECT msg.id as msgId, msg.content, mst.status, msg.created_at, us.' . $this->usersTableKey . ' as userId
         FROM ' . $this->tablePrefix . 'messages_status mst
         INNER JOIN ' . $this->tablePrefix . 'messages msg
         ON mst.msg_id=msg.id
         INNER JOIN ' . $this->usersTable . ' us
         ON msg.sender_id=us.' . $this->usersTableKey . '
         WHERE msg.conv_id=?
         AND mst.user_id = ?
         AND mst.status NOT IN (?,?)
         ORDER BY msg.created_at ' . $orderBy . '
         ', array($conv_id, $user_id, self::DELETED, self::ARCHIVED));
     $conversation = new Conversation();
     foreach ($results as $row) {
         $msg = new Message();
         $msg->setId($row->msgId);
         $msg->setContent($row->content);
         $msg->setCreated($row->created_at);
         $msg->setSender($row->userId);
         $msg->setStatus($row->status);
         $conversation->addMessage($msg);
     }
     $usersInConv = $this->getUsersInConversation($conv_id);
     foreach ($usersInConv as $userInConv) {
         $conversation->addParticipant($userInConv);
     }
     return $conversation;
 }
Exemple #2
0
 /**
  * @param $conv_id
  * @param $user_id
  * @param bool $newToOld
  * @return Conversation
  *
  * return full conversation of user with his specific messages and messages statuses
  */
 public function getConversationMessages($conv_id, $user_id, $newToOld = true)
 {
     $results = $this->tbmRepo->getConversationMessages($conv_id, $user_id, $newToOld);
     $conversation = new Conversation();
     foreach ($results as $row) {
         $msg = new Message();
         $msg->setId($row->msgId);
         $msg->setContent($row->content);
         $msg->setCreated($row->created_at);
         $msg->setSender($row->userId);
         $msg->setStatus($row->status);
         $conversation->addMessage($msg);
     }
     $usersInConv = $this->getUsersInConversation($conv_id);
     foreach ($usersInConv as $userInConv) {
         $conversation->addParticipant($userInConv);
     }
     return $conversation;
 }