public function getTrending($group = null) { $db = JFactory::getDbo(); $my = JXFactory::getUser(); $groupModel = StreamFactory::getModel('groups'); $now = new JXDate(); $nowDate = $now->format('Y-m-d'); // Get the week's top trending tags //$where = 'WHERE YEARWEEK(' . $db->nameQuote('occurrence_date') . ') = YEARWEEK(' . $db->Quote($nowDate) . ')' . ' ' // Get the trending tags for the past n weeks $where = 'WHERE ' . $db->nameQuote('occurrence_date') . ' BETWEEN DATE_SUB(' . $db->Quote($nowDate) . ', INTERVAL 2 WEEK) AND ' . $db->Quote($nowDate) . ' ' . ' AND ' . $db->nameQuote('frequency') . ' > 0' . ' '; // Filter tags in group if (!is_null($group)) { $where .= 'AND ' . $db->nameQuote('group_id') . ' = ' . $db->Quote($group->id) . ' '; } else { // Get the groups joined (including private ones) $groupIJoinCsv = $my->getParam('groups_member', '-1'); // Get the other public groups $otherGroups = $groupModel->getGroups(array('!id' => $groupIJoinCsv, 'access' => 0), 100); $otherGroupsCsv = '0'; if (count($otherGroups)) { foreach ($otherGroups as $group) { $otherGroupsCsv = JXUtility::csvInsert($otherGroupsCsv, $group->id); } } else { $otherGroupsCsv = '-1'; } $myGroupsCsv = JXUtility::csvMerge($otherGroupsCsv, $groupIJoinCsv); $where .= 'AND ' . $db->nameQuote('group_id') . ' IN (' . $myGroupsCsv . ')' . ' '; } // Build the query $query = 'SELECT * FROM ' . $db->nameQuote('#__stream_tags_trend') . ' ' . $where . 'GROUP BY ' . $db->nameQuote('tag') . ' ' . 'ORDER BY ' . $db->nameQuote('frequency') . ' DESC, ' . $db->nameQuote('tag') . ' ASC' . ' ' . 'LIMIT 10'; $db->setQuery($query); $result = $db->loadObjectList(); return $result; }
/** * Get the user joined and followed group IDs * @return string Comma-separated group IDs */ public function getMergedGroupIDs() { $groupIJoin = $this->getParam('groups_member'); $groupIFollow = $this->getParam('groups_follow'); return JXUtility::csvMerge($groupIFollow, $groupIJoin); }
include_once JPATH_ROOT . DS . 'components' . DS . 'com_stream' . DS . 'factory.php'; $option = JRequest::getVar('option'); $view = JRequest::getVar('view'); $task = JRequest::getVar('task'); $group_id = JRequest::getVar('group_id'); $my = JXFactory::getUser(); $lastMessageRead = $my->getParam('message_last_read'); $count = StreamMessage::countMessageSince($lastMessageRead); $streamModel = StreamFactory::getModel('stream'); // Groups // Get the list $groupModel = StreamFactory::getModel('groups'); $groupIJoin = $my->getParam('groups_member'); $groupIFollow = $my->getParam('groups_follow'); $groupIFollow = JXUtility::csvDiff($groupIFollow, $groupIJoin); $myGroupsIds = JXUtility::csvMerge($groupIFollow, $groupIJoin); class StreamGroupSorter { public static function sortLastActive($groupA, $groupB) { $my = JXFactory::getUser(); $diffA = $groupA->getParam('last_message') - $my->getParam('group_' . $groupA->id . '_last'); $diffB = $groupB->getParam('last_message') - $my->getParam('group_' . $groupB->id . '_last'); if ($diffA < $diffB) { return 1; } if ($diffA > $diffB) { return -1; } return 0; }
public function groupxAutocomplete() { $my = JXFactory::getUser(); $groupModel = StreamFactory::getModel('groups'); $groupIJoin = $my->getParam('groups_member'); $groupIFollow = $my->getParam('groups_follow'); $myGroupsIds = JXUtility::csvMerge($groupIFollow, $groupIJoin); $myGroups = $groupModel->getGroups(array('id' => $myGroupsIds), 100); $groupsList = array(); foreach ($myGroups as $group) { $peopleList[] = array('id' => $group->id, 'value' => $group->name); } header('Content-Type: text/json'); echo json_encode($peopleList); exit; }
public static function sendDirectMessageNew() { $funcArgs = func_get_args(); // Get notification type from caller $notificationType = $funcArgs[0]; // Get the group table object from passed in parameter $groupTable = $funcArgs[1]; // Get the stream object from passed in parameter $streamTable = $funcArgs[2]; // Get actor (current login user) $actor = JXFactory::getUser(); if ($groupTable instanceof JTable) { if (self::sentNotificationCheck($notificationType, $actor->id, $streamTable->id) === false) { // Process Members and Followers to merged into UserList $groupMembers = $groupTable->get('members'); $groupFollowers = $groupTable->get('followers'); $processUserList = explode(',', JXUtility::csvMerge($groupMembers, $groupFollowers)); $userList = self::groupUserByLanguage($processUserList, $actor->id, $notificationType); $messageUrl = '#'; $arrParam = array('streamMessage' => $streamTable, 'sender' => $actor); $jConfig = new JConfig(); foreach ($userList as $lang => $bccEmail) { self::loadLanguage($lang); $subject = JText::sprintf('COM_STREAM_NOTIFICATION_PROFILE_POST_DIRECT_SUBJECT', $actor->name); $bodyContent = self::getHeaderContent(JText::_('COM_STREAM_NOTIFICATION_DIRECT_POST_TITLE'), $messageUrl); $bodyContent .= self::getBodyContent('notification.direct', $arrParam); $bodyContent .= self::getFooterContent(); self::sendMail($jConfig->mailfrom, $jConfig->fromname, $jConfig->mailfrom, $subject, $bodyContent, $bccEmail); } } } }
public function notification() { $my = JXFactory::getUser(); $data = array(); // No notification for guest. Trigger a logout in user's browser if (!$my->id) { $data['logout'] = true; echo json_encode($data); exit; } include_once JPATH_LIBRARIES . DS . 'joomla' . DS . 'html' . DS . 'html' . DS . 'string.php'; $phash = JRequest::getVar('pHash'); // public data cache hash $data['notification'] = array(); $data['comments'] = array(); $data['updates'] = array(); // Get my groups $streamModel = StreamFactory::getModel('stream'); $groupsModel = StreamFactory::getModel('groups'); $groupIJoin = $my->getParam('groups_member'); $groupIFollow = $my->getParam('groups_follow'); $myGroups = JXUtility::csvMerge($groupIFollow, $groupIJoin); $myGroups = $groupsModel->getGroups(array('id' => $myGroups)); // Get public notices $lastMessageRead = $my->getParam('message_last_read'); $publicCount = StreamMessage::countMessageSince($lastMessageRead); $data['notification']['company_updates'] = $publicCount; // we can merge this request with the group request so that template are fetched on the same loop but the group content is unique to each group // @todo: optimize the whole request $publicMessageContents = $streamModel->getStream(array('group_id' => 0), $publicCount); $publicMessagesHTML = '<ul>'; foreach ($publicMessageContents as $row) { $tmpl = new StreamTemplate(); $tmpl->set('stream', $row); $publicMessagesHTML .= $tmpl->fetch('notification.message'); $data['updates'][0]['message_id'][] = $row->id; } $publicMessagesHTML .= '</ul>'; $data['data_content'][0] = $publicMessagesHTML; $data['updates'][0]['name'] = 'public'; $data['updates'][0]['notification'] = $publicCount; $data['updates'][0]['content'] = $publicMessagesHTML; // @todo: this is kinda heavy. Optimize further. Otherwise the live update // will kill us $updatedGroups = array(); $updatedGroupsComment = array(); foreach ($myGroups as $group) { $lastReadId = $my->getParam('group_' . $group->id . '_read'); $lastCommentId = $my->getParam('group_' . $group->id . '_comment'); $groupLastMsg = $group->getParam('last_message'); $groupLastComment = $group->getParam('last_comment'); $groupNewMsg = $streamModel->countStream(array('!user_id' => $my->id, 'id_more' => $lastReadId, 'group_id' => $group->id)); $groupNewComment = $streamModel->countComments(array('group_id' => $group->id, 'id_more' => $lastCommentId)); // // the array key is the same as html id element of the <span> that // will take this value $data['notification']['groups_' . $group->id] = intval($groupNewMsg); // rand ( 0 , 20 ); $data['comments']['groups_' . $group->id] = intval($groupNewComment); // rand ( 0 , 20 ); $data['updates'][$group->id]['name'] = $group->name; $data['updates'][$group->id]['notification'] = intval($groupNewMsg); $data['updates'][$group->id]['comments'] = intval($groupNewComment); // Add popover data if ($groupNewMsg > 0) { $updatedGroups[] = $group; } if ($groupNewComment > 0) { $updatedGroupsComment[] = $group; } } // Get the popover data if necessary // This is done saperately to give opportunity for caching if (md5(serialize($data['notification']) . serialize($data['comments'])) != $phash) { if (!empty($updatedGroups)) { foreach ($updatedGroups as $group) { $limit = $data['notification']['groups_' . $group->id]; $newMessages = $streamModel->getStream(array('group_id' => $group->id), $limit); $newMessagesHTML = '<ul>'; foreach ($newMessages as $row) { $tmpl = new StreamTemplate(); $tmpl->set('stream', $row); $newMessagesHTML .= $tmpl->fetch('notification.message'); } $newMessagesHTML .= '</ul>'; $data['data_content']['#groups_' . $group->id . '_link'] = $newMessagesHTML; $data['updates'][$group->id]['content'] = $newMessagesHTML; } } /* if(!empty($updatedGroupsComment)){ foreach($updatedGroupsComment as $group) { $data['data_comment']['#groups_'.$group->id.'_link'] = ''; } } */ } if ($phash == md5(serialize($data['notification']) . serialize($data['comments']))) { $data['data_content'] = array(); $data['notification'] = array(); $data['comments'] = array(); $data['updates'] = array(); } $data['pHash'] = md5(serialize($data['notification']) . serialize($data['comments'])); header('Content-Type: text/json'); echo json_encode($data); exit; }