Ejemplo n.º 1
0
 /**
  * Class constructor
  */
 private function __construct()
 {
     $this->conversationDao = MAILBOX_BOL_ConversationDao::getInstance();
     $this->lastMessageDao = MAILBOX_BOL_LastMessageDao::getInstance();
     $this->messageDao = MAILBOX_BOL_MessageDao::getInstance();
     $this->attachmentDao = MAILBOX_BOL_AttachmentDao::getInstance();
 }
Ejemplo n.º 2
0
 public function getMenu($userId, $type = 'main')
 {
     $items = array();
     $pm = OW::getPluginManager();
     switch ($type) {
         case 'main':
             if ($pm->isPluginActive("usearch")) {
                 $items[] = array('key' => 'Search', 'label' => 'Search', 'counter' => 0);
             }
             if ($pm->isPluginActive('mailbox')) {
                 $activeModes = MAILBOX_BOL_ConversationService::getInstance()->getActiveModeList();
                 $messageList = MAILBOX_BOL_MessageDao::getInstance()->findUnreadMessages($userId, array(), time(), $activeModes);
                 $count = count($messageList);
                 // Hot fix. TODO refactor
                 //$count = MAILBOX_BOL_ConversationService::getInstance()->getUnreadMessageCount($userId);
                 $items[] = array('key' => 'Mailbox', 'label' => 'Messages', 'counter' => $count);
             }
             if ($pm->isPluginActive('matchmaking')) {
                 $items[] = array('key' => 'Matches', 'label' => 'My Matches', 'counter' => 0);
                 if ($pm->isPluginActive("googlelocation")) {
                     $items[] = array('key' => 'SpeedMatch', 'label' => 'SpeedMatch', 'counter' => 0);
                 }
             }
             if ($pm->isPluginActive('ocsguests')) {
                 $count = OW::getEventManager()->call('guests.get_new_guests_count', array('userId' => $userId));
                 $items[] = array('key' => 'Guests', 'label' => 'Guests', 'counter' => $count);
             }
             if ($pm->isPluginActive('bookmarks')) {
                 $items[] = array('key' => 'Bookmarks', 'label' => 'Bookmarks', 'counter' => 0);
             }
             if (SKADATEIOS_ABOL_Service::getInstance()->isBillingEnabled()) {
                 $label = 'Membership & Credits';
                 if (!$pm->isPluginActive("usercredits")) {
                     $label = "membership";
                 }
                 if (!$pm->isPluginActive("membership")) {
                     $label = "credits";
                 }
                 $items[] = array('key' => 'Billing', 'label' => $label, 'counter' => 0);
             } else {
                 $items[] = array('key' => 'About', 'label' => 'About', 'counter' => 0);
             }
             break;
         case 'bottom':
             //$items[] = array('key' => 'Desktop', 'label' => 'Desktop Version', 'url' => OW_URL_HOME . 'desktop-version');
             $items[] = array('key' => 'Terms', 'label' => 'Terms & Policies', 'custom' => true);
             break;
     }
     return $items;
 }
Ejemplo n.º 3
0
 public function getMenu($userId)
 {
     $items = array();
     $pluginManager = OW::getPluginManager();
     $items[] = array("type" => self::MENU_TYPE_AVATAR, "key" => "user", "label" => $this->userService->getDisplayName($userId), "avatarUrl" => BOL_AvatarService::getInstance()->getAvatarUrl($userId, 2));
     if ($pluginManager->isPluginActive('usearch')) {
         $items[] = array("type" => self::MENU_TYPE_MAIN, "key" => "search", "count" => 0);
     }
     if ($pluginManager->isPluginActive('mailbox')) {
         $modes = OW::getEventManager()->call('mailbox.get_active_mode_list');
         $count = MAILBOX_BOL_MessageDao::getInstance()->findUnreadMessages($userId, array(), time(), $modes);
         $count = count($count);
         //            $count = OW::getEventManager()->call("mailbox.get_unread_message_count", array(
         //                "userId" => $userId
         //            ));
         //            $count = MAILBOX_BOL_ConversationService::getInstance()->getUnreadMessageCount($userId);
         $items[] = array("type" => self::MENU_TYPE_MAIN, 'key' => 'mailbox', 'label' => $this->text("main_menu_messages"), 'count' => $count);
     }
     if ($pluginManager->isPluginActive('matchmaking')) {
         $items[] = array("type" => self::MENU_TYPE_MAIN, "key" => "matches", "count" => 0);
     }
     $items[] = array("type" => self::MENU_TYPE_MAIN, "key" => "speed_match", "count" => 0);
     if ($pluginManager->isPluginActive('ocsguests')) {
         $count = OW::getEventManager()->call("guests.get_new_guests_count", array("userId" => $userId));
         $items[] = array("type" => self::MENU_TYPE_MAIN, "key" => "guests", "count" => $count);
     }
     if ($pluginManager->isPluginActive("bookmarks")) {
         $items[] = array("type" => self::MENU_TYPE_MAIN, "key" => "bookmarks", "count" => 0);
     }
     if ($this->isBillingEnabled()) {
         if ($pluginManager->isPluginActive("membership") && $pluginManager->isPluginActive("usercredits")) {
             $items[] = array("type" => self::MENU_TYPE_MAIN, "key" => "memberships_and_credits", "count" => 0);
         } else {
             if ($pluginManager->isPluginActive("membership")) {
                 $items[] = array("type" => self::MENU_TYPE_MAIN, "key" => "memberships", "count" => 0);
             } else {
                 if ($pluginManager->isPluginActive("usercredits")) {
                     $items[] = array("type" => self::MENU_TYPE_MAIN, "key" => "credits", "count" => 0);
                 }
             }
         }
     }
     //$items[] = array("type" => self::MENU_TYPE_MAIN, "key" => "subscribe", "count" => 0);
     $items[] = array("type" => self::MENU_TYPE_MAIN, "key" => "about", "count" => 0);
     $items[] = array("type" => self::MENU_TYPE_BOTTOM, 'key' => "terms");
     $items[] = array("type" => self::MENU_TYPE_BOTTOM, 'key' => "logout");
     return $items;
 }
Ejemplo n.º 4
0
 public function onUserUnregister(OW_Event $event)
 {
     $params = $event->getParams();
     MAILBOX_BOL_ConversationService::getInstance()->resetAllUsersLastData();
     $userId = (int) $params['userId'];
     $messageList = MAILBOX_BOL_MessageDao::getInstance()->findUserSentUnreadMessages($userId);
     $messageIdList = array();
     /**
      * @var MAILBOX_BOL_Message $message
      */
     foreach ($messageList as $message) {
         MAILBOX_BOL_ConversationService::getInstance()->markMessageIdListReadByUser(array($message->id), $message->recipientId);
     }
 }
Ejemplo n.º 5
0
 /**
  *
  * @param array $conversationIdList
  * @return array
  */
 public function findAttachmentstByConversationList(array $conversationIdList)
 {
     if (empty($conversationIdList)) {
         return array();
     }
     $messageDao = MAILBOX_BOL_MessageDao::getInstance();
     $query = "\n            SELECT a.*, `m`.`conversationId`\n            FROM `" . $this->getTableName() . "` AS `a`\n            INNER JOIN `" . $messageDao->getTableName() . "` AS `m` ON (`a`.`messageId`=`m`.`id`)\n            WHERE `m`.`conversationId` IN (" . $this->dbo->mergeInClause($conversationIdList) . ")\n            ORDER BY `m`.`conversationId`, a.id\n        ";
     $result = $this->dbo->queryForList($query);
     return $result;
 }
Ejemplo n.º 6
0
 public function markConversationAsRead($userId, array $conversationIdList)
 {
     if (empty($userId) || empty($conversationIdList)) {
         return null;
     }
     $result = OW::getEventManager()->call('mailbox.mark_unread', array('userId' => $userId, 'conversationId' => $conversationIdList));
     if ($result) {
         $messageIdList = array();
         foreach ($conversationIdList as $conversationId) {
             $count = MAILBOX_BOL_MessageDao::getInstance()->getConversationLength($conversationId);
             if ($count) {
                 $messages = MAILBOX_BOL_MessageDao::getInstance()->findListByConversationId($conversationId, (int) $count);
                 foreach ($messages as $message) {
                     $messageIdList[] = $message->id;
                 }
             }
         }
         if (!empty($messageIdList)) {
             MAILBOX_BOL_ConversationService::getInstance()->markMessageIdListRead($messageIdList);
         }
     }
     return $result;
 }
Ejemplo n.º 7
0
 public function findConversationByKeyword($kw, $limit = null, $from = 0)
 {
     $questionName = OW::getConfig()->getValue('base', 'display_name_question');
     $questionDataTable = BOL_QuestionDataDao::getInstance()->getTableName();
     $userId = OW::getUser()->getId();
     $limitStr = $limit === null ? '' : 'LIMIT ' . intval($from) . ', ' . intval($limit);
     //TODO get by username
     if ($questionName == 'username') {
         $join = "INNER JOIN `" . BOL_UserDao::getInstance()->getTableName() . "` AS us ON ( `us`.`id` = IF (`conv`.`initiatorId`=:user, `conv`.`interlocutorId`, `conv`.`initiatorId`)   )";
         $where = " `us`.`username` LIKE :kw ";
     } else {
         $join = "INNER JOIN `" . $questionDataTable . "` AS qd ON ( `qd`.`userId` = IF (`conv`.`initiatorId`=:user, `conv`.`interlocutorId`, `conv`.`initiatorId`)  )";
         $where = " `qd`.`questionName`=:name AND `qd`.`textValue` LIKE :kw ";
     }
     $query = " SELECT `conv`.`id`,\n                        `conv`.`initiatorId`,\n                        `conv`.`interlocutorId`,\n                        `conv`.`subject`,\n                        `conv`.`read`,\n                        `conv`.`viewed`,\n                        `conv`.`lastMessageTimestamp`,\n\n                        `message`.`id` as lastMessageId,\n                        `message`.`text` as lastMessageText,\n                        `message`.`recipientRead` as lastMessageRecipientRead,\n                        `message`.`isSystem` as lastMessageIsSystem,\n                        `message`.`senderId` as lastMessageSenderId,\n                        `message`.`recipientId` as lastMessageRecipientId,\n                        `message`.`wasAuthorized` as lastMessageWasAuthorized\n\n                 FROM `" . $this->getTableName() . "` AS `conv`\n\n\t\t\t\t INNER JOIN `" . MAILBOX_BOL_MessageDao::getInstance()->getTableName() . "` AS `message`\n\t\t\t\t \tON ( `conv`.`lastMessageId` = `message`.`id` )\n\n                 {$join}\n\n\t\t\t\t WHERE ( {$where} ) AND (( `conv`.`initiatorId` = :user AND (`conv`.`deleted` != " . self::DELETED_INITIATOR . " OR `message`.`timeStamp`>`conv`.`initiatorDeletedTimestamp` )  )\n\t\t\t\t\t \tOR ( `conv`.`interlocutorId` = :user AND (`conv`.`deleted` != " . self::DELETED_INTERLOCUTOR . " OR `message`.`timeStamp`>`conv`.`interlocutorDeletedTimestamp` ) ))\n\n                UNION\n\n                SELECT `conv`.`id`,\n                        `conv`.`initiatorId`,\n                        `conv`.`interlocutorId`,\n                        `conv`.`subject`,\n                        `conv`.`read`,\n                        `conv`.`viewed`,\n                        `conv`.`lastMessageTimestamp`,\n\n                        `message`.`id` as lastMessageId,\n                        `message`.`text` as lastMessageText,\n                        `message`.`recipientRead` as lastMessageRecipientRead,\n                        `message`.`isSystem` as lastMessageIsSystem,\n                        `message`.`senderId` as lastMessageSenderId,\n                        `message`.`recipientId` as lastMessageRecipientId,\n                        `message`.`wasAuthorized` as lastMessageWasAuthorized\n\n                 FROM `" . $this->getTableName() . "` AS `conv`\n\n\t\t\t\t INNER JOIN `" . MAILBOX_BOL_MessageDao::getInstance()->getTableName() . "` AS `message`\n\t\t\t\t \tON ( `conv`.`lastMessageId` = `message`.`id` )\n\n\t\t\t\t WHERE conv.subject LIKE :kw AND ( `conv`.`initiatorId` = :user AND (`conv`.`deleted` != " . self::DELETED_INITIATOR . " OR `message`.`timeStamp`>`conv`.`initiatorDeletedTimestamp` )  )\n\n\n                UNION\n\n                SELECT `conv`.`id`,\n                        `conv`.`initiatorId`,\n                        `conv`.`interlocutorId`,\n                        `conv`.`subject`,\n                        `conv`.`read`,\n                        `conv`.`viewed`,\n                        `conv`.`lastMessageTimestamp`,\n\n                        `message`.`id` as lastMessageId,\n                        `message`.`text` as lastMessageText,\n                        `message`.`recipientRead` as lastMessageRecipientRead,\n                        `message`.`isSystem` as lastMessageIsSystem,\n                        `message`.`senderId` as lastMessageSenderId,\n                        `message`.`recipientId` as lastMessageRecipientId,\n                        `message`.`wasAuthorized` as lastMessageWasAuthorized\n\n                 FROM `" . $this->getTableName() . "` AS `conv`\n\n\t\t\t\t INNER JOIN `" . MAILBOX_BOL_MessageDao::getInstance()->getTableName() . "` AS `message`\n\t\t\t\t \tON ( `conv`.`lastMessageId` = `message`.`id` )\n\n\t\t\t\t WHERE conv.subject LIKE :kw AND (  `conv`.`interlocutorId` = :user AND (`conv`.`deleted` != " . self::DELETED_INTERLOCUTOR . " OR `message`.`timeStamp`>`conv`.`interlocutorDeletedTimestamp` ))\n\n\n                GROUP BY 1\n                ORDER BY 7 DESC\n\n                " . $limitStr;
     //print_r($query);
     //        $query = " SELECT `conv`.`id`,
     //                        `conv`.`initiatorId`,
     //                        `conv`.`interlocutorId`,
     //                        `conv`.`subject`,
     //                        `conv`.`read`,
     //                        `conv`.`viewed`,
     //
     //                        `last_m`.`initiatorMessageId`,
     //                        `initiatorMessage`.`id` as initiatorLastMessageId,
     //                        `initiatorMessage`.`text` as initiatorText,
     //                        `initiatorMessage`.`recipientRead` as initiatorRecipientRead,
     //                        `initiatorMessage`.`isSystem` as initiatorMessageIsSystem,
     //                        `initiatorMessage`.`senderId` as `initiatorMessageSenderId`,
     //                        `initiatorMessage`.`recipientId` as `initiatorMessageRecipientId`,
     //                        `initiatorMessage`.`wasAuthorized` as `initiatorMessageWasAuthorized`,
     //                        `initiatorMessage`.`timeStamp` as `initiatorMessageTimestamp`,
     //
     //                        `last_m`.`interlocutorMessageId`,
     //                        `interlocutorMessage`.`id` as interlocutorLastMessageId,
     //                        `interlocutorMessage`.`text` as interlocutorText,
     //                        `interlocutorMessage`.`recipientRead` as interlocutorRecipientRead,
     //                        `interlocutorMessage`.`isSystem` as interlocutorMessageIsSystem,
     //                        `interlocutorMessage`.`senderId` as `interlocutorMessageSenderId`,
     //                        `interlocutorMessage`.`recipientId` as `interlocutorMessageRecipientId`,
     //                        `interlocutorMessage`.`wasAuthorized` as `interlocutorMessageWasAuthorized`,
     //                        `interlocutorMessage`.`timeStamp` as `interlocutorMessageTimestamp`
     //
     //                 FROM `" . $this->getTableName() . "` AS `conv`
     //
     //				 INNER JOIN `" . MAILBOX_BOL_LastMessageDao::getInstance()->getTableName() . "` AS `last_m`
     //					 ON ( `last_m`.`conversationId` = `conv`.`id` )
     //
     //				 LEFT JOIN `" . MAILBOX_BOL_MessageDao::getInstance()->getTableName() . "` AS `interlocutorMessage`
     //				 	ON ( `conv`.`id` = `interlocutorMessage`.conversationId AND `last_m`.`interlocutorMessageId` = `interlocutorMessage`.`id` )
     //
     //				 LEFT JOIN `" . MAILBOX_BOL_MessageDao::getInstance()->getTableName() . "` AS `initiatorMessage`
     //				 	ON ( `conv`.`id` = `initiatorMessage`.conversationId AND `last_m`.`initiatorMessageId` = `initiatorMessage`.`id` )
     //
     //                 {$join}
     //
     //				 WHERE ( {$where} ) AND (( `conv`.`initiatorId` = :user AND (`conv`.`deleted` != " . self::DELETED_INITIATOR . " OR `initiatorMessage`.`timeStamp`>`conv`.`initiatorDeletedTimestamp` )  )
     //					 	OR ( `conv`.`interlocutorId` = :user AND (`conv`.`deleted` != "  . self::DELETED_INTERLOCUTOR .  " OR `interlocutorMessage`.`timeStamp`>`conv`.`interlocutorDeletedTimestamp` ) )) AND `last_m`.`id` IS NOT NULL
     //
     //                GROUP BY `conv`.`id`
     //
     //                ORDER BY GREATEST( COALESCE(`initiatorMessage`.`timeStamp`, 0), COALESCE(`interlocutorMessage`.`timeStamp`, 0) ) DESC
     //
     //                ".$limitStr;
     $conversationItemList = OW::getDbo()->queryForList($query, array('kw' => '%' . $kw . '%', 'user' => $userId, 'name' => $questionName));
     foreach ($conversationItemList as $i => $conversation) {
         $conversationItemList[$i]['timeStamp'] = (int) $conversation['lastMessageTimestamp'];
         $conversationItemList[$i]['lastMessageSenderId'] = $conversation['lastMessageSenderId'];
         $conversationItemList[$i]['isSystem'] = $conversation['lastMessageIsSystem'];
         $conversationItemList[$i]['text'] = $conversation['lastMessageText'];
         $conversationItemList[$i]['lastMessageId'] = $conversation['lastMessageId'];
         $conversationItemList[$i]['recipientRead'] = $conversation['lastMessageRecipientRead'];
         $conversationItemList[$i]['lastMessageRecipientId'] = $conversation['lastMessageRecipientId'];
         $conversationItemList[$i]['lastMessageWasAuthorized'] = $conversation['lastMessageWasAuthorized'];
     }
     //        foreach($conversationItemList as $i => $conversation)
     //        {
     //            if ((int)$conversation['initiatorMessageTimestamp'] > (int)$conversation['interlocutorMessageTimestamp'])
     //            {
     //                $conversationItemList[$i]['timeStamp'] = (int)$conversation['initiatorMessageTimestamp'];
     //                $conversationItemList[$i]['lastMessageSenderId'] = $conversation['initiatorMessageSenderId'];
     //                $conversationItemList[$i]['isSystem'] = $conversation['initiatorMessageIsSystem'];
     //                $conversationItemList[$i]['text'] = $conversation['initiatorText'];
     //
     //                $conversationItemList[$i]['lastMessageId'] = $conversation['initiatorLastMessageId'];
     //                $conversationItemList[$i]['recipientRead'] = $conversation['initiatorRecipientRead'];
     //                $conversationItemList[$i]['lastMessageRecipientId'] = $conversation['initiatorMessageRecipientId'];
     //                $conversationItemList[$i]['lastMessageWasAuthorized'] = $conversation['initiatorMessageWasAuthorized'];
     //            }
     //            else
     //            {
     //                $conversationItemList[$i]['timeStamp'] = (int)$conversation['interlocutorMessageTimestamp'];
     //                $conversationItemList[$i]['lastMessageSenderId'] = $conversation['interlocutorMessageSenderId'];
     //                $conversationItemList[$i]['isSystem'] = $conversation['interlocutorMessageIsSystem'];
     //                $conversationItemList[$i]['text'] = $conversation['interlocutorText'];
     //
     //                $conversationItemList[$i]['lastMessageId'] = $conversation['interlocutorLastMessageId'];
     //                $conversationItemList[$i]['recipientRead'] = $conversation['interlocutorRecipientRead'];
     //                $conversationItemList[$i]['lastMessageRecipientId'] = $conversation['interlocutorMessageRecipientId'];
     //                $conversationItemList[$i]['lastMessageWasAuthorized'] = $conversation['interlocutorMessageWasAuthorized'];
     //            }
     //        }
     return $conversationItemList;
 }
Ejemplo n.º 8
0
 /**
  *
  * @param array $userId
  * @return array
  */
 public function getNewConversationListForConsoleNotificationMailer($userIdList)
 {
     if (empty($userIdList)) {
         return array();
     }
     $userList = $this->dbo->mergeInClause($userIdList);
     $sql = " SELECT mess.*, `conv`.* FROM `" . $this->getTableName() . "` AS `conv`\n\n\t\t\t\t INNER JOIN `" . MAILBOX_BOL_LastMessageDao::getInstance()->getTableName() . "` AS `last_m`\n\t\t\t\t\t ON (`last_m`.`conversationId` = `conv`.`id`)\n\n            \t INNER JOIN `" . MAILBOX_BOL_MessageDao::getInstance()->getTableName() . "` AS `mess`\n\t\t\t\t \tON ( `last_m`.`initiatorMessageId` = `mess`.id AND ( `last_m`.`initiatorMessageId` > `last_m`.interlocutorMessageId )\n                    OR `last_m`.`interlocutorMessageId` = `mess`.id AND ( `last_m`.`initiatorMessageId` < `last_m`.interlocutorMessageId ) )\n\n\t\t\t     WHERE  `conv`.`notificationSent` = 0 AND ( ( `conv`.`initiatorId` IN ( {$userList} ) AND `last_m`.`interlocutorMessageId` > 0 AND `conv`.`deleted` != " . self::DELETED_INITIATOR . " AND NOT `conv`.`read` & " . self::READ_INITIATOR . "  AND NOT `conv`.`viewed` &  " . self::VIEW_INITIATOR . " )\n\t\t\t\t\t \tOR ( `conv`.`interlocutorId` IN ( {$userList} ) AND `conv`.`deleted` != " . self::DELETED_INTERLOCUTOR . "  AND  NOT `conv`.`read` & " . self::READ_INTERLOCUTOR . " AND NOT `conv`.`viewed` &  " . self::VIEW_INTERLOCUTOR . " ) ) \n        ";
     $conversationList = $this->dbo->queryForList($sql);
     $resultList = array();
     foreach ($conversationList as $conversation) {
         $userId = $conversation['recipientId'];
         $resultList[$userId][] = $conversation;
     }
     return $resultList;
 }
Ejemplo n.º 9
0
 public function findConversationsWithAttachmentFromConversationList($conversationIdList)
 {
     $condition = $this->dbo->mergeInClause($conversationIdList);
     $sql = "SELECT `m`.`conversationId` FROM `" . MAILBOX_BOL_AttachmentDao::getInstance()->getTableName() . "` as a\nINNER JOIN `" . MAILBOX_BOL_MessageDao::getInstance()->getTableName() . "` as m ON `m`.`id` = `a`.`messageId`\nWHERE conversationId IN ({$condition})\nGROUP BY `m`.`conversationId`";
     return $this->dbo->queryForColumnList($sql);
 }
Ejemplo n.º 10
0
 public function getAttachmentForDelete()
 {
     $sql = "SELECT `attach`.* \n                  FROM {$this->getTableName()} AS attach\n                  LEFT OUTER JOIN `" . MAILBOX_BOL_MessageDao::getInstance()->getTableName() . "` AS msg ON `attach`.`messageId` = `msg`.`id`\n                  WHERE `msg`.`id` IS NULL\n                  LIMIT 100";
     return $this->dbo->queryForObjectList($sql, $this->getDtoClassName());
 }