public function onLoadConsoleList(BASE_CLASS_ConsoleListEvent $event) { $params = $event->getParams(); $userId = OW::getUser()->getId(); if ($params['target'] != self::CONSOLE_ITEM_KEY) { return; } $conversations = $this->service->getConsoleConversationList($userId, 0, 8, $params['console']['time'], $params['ids']); $conversationIdList = array(); foreach ($conversations as $conversationData) { if (!in_array($conversationData['conversationId'], $conversationIdList)) { $conversationIdList[] = $conversationData['conversationId']; } $mode = $this->service->getConversationMode($conversationData['conversationId']); $conversationItem = $this->service->getConversationItem($mode, $conversationData['conversationId']); $item = new MAILBOX_CMP_ConsoleMessageItem($conversationItem); $event->addItem($item->render(), $conversationData['conversationId']); } $this->service->setConversationViewedInConsole($conversationIdList, $userId); }
public function loadList(BASE_CLASS_ConsoleListEvent $event) { $params = $event->getParams(); $data = $event->getData(); $userId = OW::getUser()->getId(); if ($params['target'] != self::CONSOLE_ITEM_KEY) { return; } $loadItemsCount = 10; $notifications = $this->service->findNotificationList($userId, $params['console']['time'], $params['ids'], $loadItemsCount); $notificationIds = array(); $data['listFull'] = count($notifications) < $loadItemsCount; foreach ($notifications as $notification) { $notificationData = $notification->getData(); $itemEvent = new OW_Event('notifications.on_item_render', array('key' => 'notification_' . $notification->id, 'entityType' => $notification->entityType, 'entityId' => $notification->entityId, 'pluginKey' => $notification->pluginKey, 'userId' => $notification->userId, 'viewed' => (bool) $notification->viewed, 'data' => $notificationData), $notificationData); OW::getEventManager()->trigger($itemEvent); $item = $itemEvent->getData(); if (empty($item)) { continue; } $notificationIds[] = $notification->id; $event->addItem($item, $notification->id); } $event->setData($data); $this->service->markNotificationsViewedByIds($notificationIds); }
public function loadList(BASE_CLASS_ConsoleListEvent $event) { $params = $event->getParams(); $userId = OW::getUser()->getId(); if ($params['target'] != self::CONSOLE_ITEM_KEY) { return; } $requests = $this->service->findRequestList($userId, $params['console']['time'], $params['offset'], 10); $requestIds = array(); foreach ($requests as $request) { $avatar = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($request->userId), true, true, true, false); $avatar = $avatar[$request->userId]; $userUrl = OW::getRouter()->urlForRoute('base_user_profile', array('username' => BOL_UserService::getInstance()->getUserName($request->userId))); $displayName = BOL_UserService::getInstance()->getDisplayName($request->userId); $string = OW::getLanguage()->text('friends', 'console_request_item', array('userUrl' => $userUrl, 'displayName' => $displayName)); $item = new FRIENDS_CMP_RequestItem(); $item->setAvatar($avatar); $item->setContent($string); $item->setToolbar(array(array('label' => OW::getLanguage()->text('friends', 'accept_request'), 'id' => 'friend_request_accept_' . $request->userId), array('label' => OW::getLanguage()->text('friends', 'ignore_request'), 'id' => 'friend_request_ignore_' . $request->userId))); if (!$request->viewed) { $item->addClass('ow_console_new_message'); } $js = UTIL_JsGenerator::newInstance(); $js->jQueryEvent('#friend_request_accept_' . $request->userId, 'click', <<<EOT OW.FriendRequest.accept('{$item->getKey()}', {$request->userId}); EOT ); $js->jQueryEvent('#friend_request_ignore_' . $request->userId, 'click', <<<EOT OW.FriendRequest.ignore('{$item->getKey()}', {$request->userId}); EOT ); OW::getDocument()->addOnloadScript($js->generateJs()); $requestIds[] = $request->id; $event->addItem($item->render()); } $this->service->markViewedByIds($requestIds); }
public function loadList(BASE_CLASS_ConsoleListEvent $event) { $params = $event->getParams(); $userId = OW::getUser()->getId(); if ($params['target'] != self::CONSOLE_ITEM_KEY) { return; } $activeModes = json_decode(OW::getConfig()->getValue('mailbox', 'active_modes')); $winks = $this->service->findWinkList($userId, $params['offset'], 10, $activeModes); $viewedIds = array(); $language = OW::getLanguage(); $language->addKeyForJs('winks', 'msg_accept_request'); $language->addKeyForJs('winks', 'msg_ignore_request'); $mode = is_array($activeModes) ? in_array('chat', $activeModes) ? 'chat' : 'mail' : 'chat'; foreach ($winks as $wink) { $viewedIds[] = $wink->getId(); $avatar = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($wink->getUserId()), true, true, true, false); $item = new BASE_CMP_ConsoleListIpcItem(); $item->setAvatar($avatar[$wink->getUserId()]); $item->setKey('wink-item-' . $wink->getId()); $userUrl = OW::getRouter()->urlForRoute('base_user_profile', array('username' => BOL_UserService::getInstance()->getUserName($wink->getUserId()))); $displayName = BOL_UserService::getInstance()->getDisplayName($wink->getUserId()); //OW::getRouter()->addRoute(new OW_Route('mailbox_conversation', 'messages/mail/:convId', 'MAILBOX_CTRL_Messages', 'index')); if ($wink->getUserId() == $userId) { if ($wink->getStatus() == WINKS_BOL_WinksDao::STATUS_ACCEPT && $wink->getWinkback()) { $string = $language->text('winks', 'console_wink_accept_item', array('userUrl' => OW::getRouter()->urlForRoute('base_user_profile', array('username' => BOL_UserService::getInstance()->getUserName($wink->getPartnerId()))), 'displayName' => BOL_UserService::getInstance()->getDisplayName($wink->getPartnerId()))); if ($mode == 'mail' || $wink->messageType == 'mail') { $item->setToolbar(array(array('label' => $language->text('winks', 'send_message'), 'url' => OW::getRouter()->urlForRoute('mailbox_conversation', array('convId' => $wink->getConversationId()))))); } else { $item->setToolbar(array(array('label' => $language->text('winks', 'send_message'), 'onclick' => 'OW.trigger(\'mailbox.open_dialog\',{convId:' . $wink->getConversationId() . ',opponentId:' . $wink->getPartnerId() . ',mode:\'' . $mode . '\'});return false;'))); } } else { continue; } } elseif ($wink->getStatus() == WINKS_BOL_WinksDao::STATUS_ACCEPT) { $string = $language->text('winks', 'console_wink_wait_item', array('userUrl' => $userUrl, 'displayName' => $displayName)); if ($mode == 'mail' || $wink->messageType == 'mail') { $item->setToolbar(array(array('label' => $language->text('winks', 'send_message'), 'url' => OW::getRouter()->urlForRoute('mailbox_conversation', array('convId' => $wink->getConversationId()))))); } else { $item->setToolbar(array(array('label' => $language->text('winks', 'send_message'), 'onclick' => 'OW.trigger(\'mailbox.open_dialog\',{convId:' . $wink->getConversationId() . ',opponentId:' . $wink->getUserId() . ',mode:\'' . $mode . '\'});return false;'))); } } else { $string = OW::getLanguage()->text('winks', 'console_wink_wait_item', array('userUrl' => $userUrl, 'displayName' => $displayName)); $item->setToolbar(array(array('label' => $language->text('winks', 'accept_request'), 'onclick' => 'Winks.accept(\'' . $item->getKey() . '\',' . $wink->getUserId() . ',' . $wink->getPartnerId() . ');'), array('label' => $language->text('winks', 'ignore_request'), 'onclick' => 'Winks.ignore(\'' . $item->getKey() . '\',' . $wink->getUserId() . ',' . $wink->getPartnerId() . ');'), array('label' => $language->text('winks', 'send_message'), 'class' => 'ow_hidden', 'id' => 'send-message-' . $item->getKey()))); } $item->setContent($string); if ($wink->getViewed() === 0) { $item->addClass('ow_console_new_message'); } $event->addItem($item->render()); } $this->service->markViewedByIds($viewedIds); }
public function loadList(BASE_CLASS_ConsoleListEvent $event) { $params = $event->getParams(); $userId = OW::getUser()->getId(); if ($params['target'] != self::CONSOLE_ITEM_KEY) { return; } // if ( !empty($params['ids']) && is_array($params['ids']) && count($params['ids']) >= 30 ) // { // $requests = array(); // } // else // { $requests = $this->service->getConsoleConversationList($userId, 0, 10, $params['console']['time'], $params['ids']); // } $conversationIdList = array(); foreach ($requests as $conversation) { $conversationIdList[] = $conversation['conversationId']; } /* @var $conversation MAILBOX_BOL_Conversation */ $renderedItems = array(); foreach ($requests as $request) { $senderId = 0; $userType = ''; $messageId = 0; if ($request['initiatorId'] == $userId) { $senderId = $request['interlocutorId']; $userType = 'initiator'; $messageId = $request['interlocutorMessageId']; } if ($request['interlocutorId'] == $userId) { $senderId = $request['initiatorId']; $userType = 'interlocutor'; $messageId = $request['initiatorMessageId']; } $avatar = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($senderId), true, true, true, false); $avatar = $avatar[$senderId]; $userUrl = BOL_UserService::getInstance()->getUserUrl($senderId); $displayName = BOL_UserService::getInstance()->getDisplayName($senderId); $subject = $request['subject']; $text = '<span class="error">' . OW::getLanguage()->text('mailbox', 'read_permission_denied') . '</span>'; $conversationUrl = MAILBOX_BOL_ConversationService::getInstance()->getConversationUrl($request['conversationId']); if (OW::getUser()->isAuthorized('mailbox', 'read_message')) { // check credits $eventParams = array('pluginKey' => 'mailbox', 'action' => 'read_message'); $credits = OW::getEventManager()->call('usercredits.check_balance', $eventParams); if ($credits === false && !$request['recipientRead']) { $creditsMsg = OW::getEventManager()->call('usercredits.error_message', $eventParams); $text = '<span class="error">' . $creditsMsg . '</span>'; } else { $text = mb_strlen($request['text']) > 100 ? mb_substr(strip_tags($request['text']), 0, 100) . '...' : $request['text']; $e = new OW_Event('mailbox.message_render', array('conversationId' => $request['conversationId'], 'messageId' => $messageId, 'senderId' => $senderId, 'recipientId' => $userId), array('short' => $text, 'full' => $request['text'])); OW::getEventManager()->trigger($e); $eventData = $e->getData(); $text = $eventData['short']; } } $langVars = array('userUrl' => $userUrl, 'displayName' => $displayName, 'subject' => $subject, 'text' => $text, 'conversationUrl' => $conversationUrl); $string = OW::getLanguage()->text('mailbox', 'console_request_item', $langVars); $item = new MAILBOX_CMP_RequestItem(); $item->setAvatar($avatar); $item->setContent($string); $item->setUrl($conversationUrl); if (empty($request['viewed']) || (!($request['viewed'] & MAILBOX_BOL_ConversationDao::VIEW_INITIATOR) && $userType == 'initiator' || !($request['viewed'] & MAILBOX_BOL_ConversationDao::VIEW_INTERLOCUTOR) && $userType == 'interlocutorId')) { $item->addClass('ow_console_new_message'); } $js = UTIL_JsGenerator::newInstance(); OW::getDocument()->addOnloadScript($js->generateJs()); $event->addItem($item->render(), $request['id']); } $this->service->setConversationViewedInConsole($conversationIdList, $userId); }