Exemple #1
0
 public static function getUsers()
 {
     if ($_SESSION['user']['name']) {
         $user = new ChatUser(array('name' => $_SESSION['user']['name']));
         $user->update();
     }
     // Deleting chats older than 5 minutes and users inactive for 30 seconds
     //DB::query("DELETE FROM webchat_lines WHERE ts < SUBTIME(NOW(),'0:25:0')");
     DB::query("DELETE FROM webchat_users WHERE last_activity < SUBTIME(NOW(),'0:15:30')");
     $result = DB::query('SELECT * FROM webchat_users WHERE gravatar<>"' . $_SESSION['user_id'] . '" ORDER BY name ASC LIMIT 18');
     $users = array();
     $us = array();
     while ($user = $result->fetch_object()) {
         $user->gravatar = $user->gravatar;
         $ilejest = 0;
         if ($_COOKIE['chat_0'] != "off") {
             $ilejest = DB::query('SELECT COUNT(*) as asd FROM webchat_lines WHERE tss>"' . DB::esc($_COOKIE['chat_' . $user->gravatar . '']) . '" and room_do="' . $user->gravatar . '" and room="' . $_SESSION['user_id'] . '" and czyt="0"')->fetch_object()->asd;
             if ($ilejest >= 1) {
                 $user->ile_a = '<span class="ilejest" id="user_ile_' . $user->gravatar . '">(' . $ilejest . ')</span>';
             } else {
                 $user->ile_a = '';
             }
         }
         $us[] = $user->gravatar;
         $users[] = $user;
     }
     $ile_u = DB::query('SELECT COUNT(*) as cnt FROM webchat_users')->fetch_object()->cnt;
     if ($ile_u >= 1) {
         $ile_u = $ile_u - 1;
     }
     $result = DB::query('SELECT * FROM webchat_lines WHERE czyt=0 and room="' . $_SESSION['user_id'] . '" GROUP by author');
     while ($use = $result->fetch_object()) {
         if (!in_array($use->room_do, $us)) {
             $user->gravatar = $use->room_do;
             $user->name = $use->author;
             $ilejest = 0;
             if ($_COOKIE['chat_0'] != "off") {
                 $ilejest = DB::query('SELECT COUNT(*) as asd FROM webchat_lines WHERE  room_do="' . $user->gravatar . '" and room="' . $_SESSION['user_id'] . '" and czyt="0"')->fetch_object()->asd;
                 if ($ilejest >= 1) {
                     $user->ile_a = '<span class="ilejest" id="user_ile_' . $user->gravatar . '">(' . $ilejest . ')</span>';
                 } else {
                     $user->ile_a = '';
                 }
             }
             $users[] = $user;
         }
     }
     return array('users' => $users, 'ile_a' => $ile_a, 'total' => $ile_u);
 }
Exemple #2
0
 public static function getUsers()
 {
     if ($_SESSION['user']['name']) {
         $user = new ChatUser(array('name' => $_SESSION['user']['name']));
         $user->update();
     }
     DB::query("DELETE FROM webchat_lines WHERE ts < SUBTIME(NOW(),'0:5:0')");
     DB::query("DELETE FROM webchat_users WHERE last_activity < SUBTIME(NOW(),'0:0:30')");
     $result = DB::query('SELECT * FROM webchat_users ORDER BY name ASC LIMIT 18');
     $users = array();
     while ($user = $result->fetch_object()) {
         $user->gravatar = Chat::gravatarFromHash($user->gravatar, 30);
         $users[] = $user;
     }
     return array('users' => $users, 'total' => DB::query('SELECT COUNT(*) as cnt FROM webchat_users')->fetch_object()->cnt);
 }
 protected function getChatSessionObject($sessionRow, $myUserId = null)
 {
     if (empty($sessionRow) or !is_array($sessionRow)) {
         throw new InvalidArgumentException("Invalid \$sessionRow specified!");
     }
     $chatSession = new ChatSession();
     if ($myUserId !== null) {
         if ($sessionRow['inviter_user_id'] == $myUserId) {
             $interlocutorUserId = $sessionRow['invited_user_id'];
         } else {
             $interlocutorUserId = $sessionRow['inviter_user_id'];
         }
         $chatSession->chatterUser = ChatUser::getObject($myUserId);
         $chatSession->interlocutorUser = ChatUser::getObject($interlocutorUserId);
     } else {
         $chatSession->chatterUser = ChatUser::getObject($sessionRow['inviter_user_id']);
         $chatSession->interlocutorUser = ChatUser::getObject($sessionRow['invited_user_id']);
     }
     $chatSession->id = $sessionRow['id'];
     $chatSession->startDate = $sessionRow['date'];
     $chatSession->closed = $sessionRow['closed'];
     $chatSession->closedBy = $sessionRow['closed_by'];
     $chatSession->closedReason = $sessionRow['closed_reason'];
     $chatSession->closedDate = $sessionRow['closed_date'];
     return $chatSession;
 }
Exemple #4
0
 public static function getUsers()
 {
     if (Yii::app()->user->name) {
         $user = new ChatUser(array('name' => Yii::app()->user->name));
         $user->update();
     }
     // Deleting chats older than 5 minutes and users inactive for 30 seconds
     DB::query("DELETE FROM webchat_lines WHERE ts < SUBTIME(NOW(),'0:5:0')");
     DB::query("DELETE FROM webchat_users WHERE last_activity < SUBTIME(NOW(),'0:0:30')");
     $result = DB::query('SELECT * FROM webchat_users ORDER BY name ASC LIMIT 18');
     $users = array();
     while ($user = $result->fetch_object()) {
         $user->gravatar = Chat::gravatarFromHash($user->gravatar, 30);
         $users[] = $user;
     }
     return array('users' => $users, 'total' => DB::query('SELECT COUNT(*) as cnt FROM webchat_users')->fetch_object()->cnt);
 }
 protected function getChatMessage($messageRow)
 {
     $chatMessage = new ChatMessage();
     $chatMessage->id = $messageRow['id'];
     $chatMessage->senderUser = ChatUser::getObject($messageRow['sender_user_id']);
     $chatMessage->receiverUser = ChatUser::getObject($messageRow['receiver_user_id']);
     $chatMessage->datetime = $messageRow['datetime'];
     $chatMessage->message = nl2br(htmlentities($messageRow['message'], ENT_COMPAT, 'UTF-8'));
     $chatMessage->is_system = $messageRow['is_system'];
     return $chatMessage;
 }
 protected function getInvitationObject($invitationRow)
 {
     if (empty($invitationRow) or !is_array($invitationRow)) {
         throw new InvalidArgumentException("Invalid \$invitationRow specified!");
     }
     $invitation = new ChatInvitation();
     $invitation->id = $invitationRow['id'];
     $invitation->inviterUser = ChatUser::getObject($invitationRow['sender_user_id']);
     $invitation->invitedUser = ChatUser::getObject($invitationRow['receiver_user_id']);
     $invitation->invitationMessage = $invitationRow['invitation_message'];
     $invitation->status = $invitationRow['status'];
     return $invitation;
 }
 public function getChatSessionsLog(MysqlPager $pager = null, $myUserId = null, $cacheMinutes = 0)
 {
     $sessions = array();
     $qb = new QueryBuilder();
     $qb->select(new Field("*", "chat_sess_log"))->from(Tbl::get('TBL_CHAT_SESSIONS_LOG'), "chat_sess_log");
     if ($myUserId !== null) {
         $orClause = new Orx();
         $orClause->add($qb->expr()->equal(new Field("user1_id", "chat_sess_log"), $myUserId));
         $orClause->add($qb->expr()->equal(new Field("user2_id", "chat_sess_log"), $myUserId));
         $qb->andWhere($orClause);
     }
     $qb->orderBy(new Field("datetime", "chat_sess_log"), MySqlDatabase::ORDER_DESC);
     $sqlQuery = $qb->getSQL();
     if ($pager !== null) {
         $this->query = $pager->executePagedSQL($sqlQuery, $cacheMinutes);
     } else {
         $this->query->exec($sqlQuery, $cacheMinutes);
     }
     if ($this->query->countRecords()) {
         while (($sesLogRow = $this->query->fetchRecord()) != null) {
             $chatSession = new ChatSessionLog();
             $chatSession->user1 = ChatUser::getObject($sesLogRow['user1_id']);
             $chatSession->user2 = ChatUser::getObject($sesLogRow['user2_id']);
             $chatSession->id = $sesLogRow['id'];
             $chatSession->closedDate = $sesLogRow['datetime'];
             array_push($sessions, $chatSession);
         }
     }
     return $sessions;
 }
Exemple #8
0
 public function doChangeName(\ChatUser $user, $message)
 {
     $old_name = $user->name;
     if ($old_name == $message->body) {
         return;
     }
     $user->name = $message->body;
     $user_array = $user->toArray();
     $user_array['old_name'] = $old_name;
     // Broadcast user name change
     \Whippy\Client::broadcast(new ChatMessage($user_array, ChatMessage::USER_CHANGE));
 }
Exemple #9
0
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      ChatUser $value A ChatUser object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(ChatUser $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }