Create 'usersUpdateVisitorsLoad' and 'usersUpdateVisitorsAlter' events

This commit is contained in:
Dmitriy Simushev 2013-02-08 11:06:53 +00:00
parent a6006211f2
commit 758c727c45

View File

@ -25,6 +25,10 @@
* - usersCallError * - usersCallError
* - usersFunctionCall * - usersFunctionCall
* *
* Also triggers follow events (see description of apiUpdateVisitors method):
* - usersUpdateVisitorsLoad
* - usersUpdateVisitorsAlter
*
* WARNING: * WARNING:
* usersResponseReceived registered but never called because of asynchronous * usersResponseReceived registered but never called because of asynchronous
* nature of Core-to-Window interaction * nature of Core-to-Window interaction
@ -331,7 +335,21 @@ class UsersProcessor extends ClientSideProcessor {
} }
/** /**
* Return updated visitors list. API function * Return updated visitors list. API function.
*
* Triggers following events:
* 1. 'usersUpdateVisitorsLoad': provide the ability to plugins to load,
* sort and limiting visitors list. Associative array pass to event
* lister have following keys:
* - 'visitors': array of visitors arrays. Each visitor array must
* contain at least following keys: 'id', 'userName', 'userAgent',
* 'userIp', 'remote', 'firstTime', 'lastTime', 'invitations',
* 'chats', 'invitationInfo'. If there are no visitors an empty array
* should be used.
*
* 2. 'usersUpdateVisitorsAlter': provide the ability to alter visitors
* list. Associative array pass to event lister have following keys:
* - 'visitors': array of visitors arrays.
* *
* @param array $args Associative array of arguments. It must contains * @param array $args Associative array of arguments. It must contains
* following keys: * following keys:
@ -350,12 +368,23 @@ class UsersProcessor extends ClientSideProcessor {
track_remove_old_visitors(); track_remove_old_visitors();
track_remove_old_tracks(); track_remove_old_tracks();
$db = Database::getInstance(); // Get instance of event dispatcher
$dispatcher = EventDispatcher::getInstance();
// Trigger load event
$arguments = array(
'visitors' => false
);
$dispatcher->triggerEvent('usersUpdateVisitorsLoad', $arguments);
// Check if visiors list loaded by plugins
if (! is_array($arguments['visitors'])) {
// Load visitors list
$db = Database::getInstance();
// Load visitors // Load visitors
$query = "SELECT visitorid, userid, username, firsttime, lasttime, " . $query = "SELECT visitorid, userid, username, firsttime, " .
"entry, details, invited, invitationtime, invitedby, " . "lasttime,entry, details, invited, invitationtime, " .
"invitations, chats " . "invitedby, invitations, chats " .
"FROM {chatsitevisitor} " . "FROM {chatsitevisitor} " .
"WHERE threadid IS NULL " . "WHERE threadid IS NULL " .
"ORDER BY invited, lasttime DESC, invitations"; "ORDER BY invited, lasttime DESC, invitations";
@ -412,9 +441,18 @@ class UsersProcessor extends ClientSideProcessor {
'invitationInfo' => $invitation_info 'invitationInfo' => $invitation_info
); );
} }
} else {
$visitors = $arguments['visitors'];
}
// Provide ability to alter visitors list
$arguments = array(
'visitors' => $visitors
);
$dispatcher->triggerEvent('usersUpdateVisitorsAlter', $arguments);
return array( return array(
'visitors' => $visitors 'visitors' => $arguments['visitors']
); );
} }