]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
added find_active_users hook
authorbenbro <ben.browitt@gmail.com>
Mon, 20 Jun 2011 05:43:09 +0000 (08:43 +0300)
committerCash Costello <cash.costello@gmail.com>
Fri, 24 Jun 2011 12:00:20 +0000 (08:00 -0400)
engine/lib/statistics.php
engine/lib/users.php

index cd2b7a6a1219f4147869925b1a9d20b0f34d3adb..1232c6128c98b03622d122174dc582f19b84174e 100644 (file)
@@ -96,7 +96,7 @@ function get_number_users($show_deactivated = false) {
   */
 function get_online_users() {
        $offset = get_input('offset', 0);
-       $count = count(find_active_users(600, 9999));
+       $count = find_active_users(600, 10, $offset, true);
        $objects = find_active_users(600, 10, $offset);
 
        if ($objects) {
index 59bfa1259149bf5aacc0242bccc071948ded7f94..e7e1a57f017d832b9853cb3b4551949185bfbcaf 100644 (file)
@@ -625,31 +625,37 @@ function get_user_by_email($email) {
 
 /**
  * A function that returns a maximum of $limit users who have done something within the last
- * $seconds seconds.
+ * $seconds seconds or the total count of active users.
  *
  * @param int $seconds Number of seconds (default 600 = 10min)
  * @param int $limit   Limit, default 10.
- * @param int $offset  Offset, defualt 0.
+ * @param int $offset  Offset, default 0.
+ * @param bool $count  Count, default false.
  *
  * @return mixed
  */
-function find_active_users($seconds = 600, $limit = 10, $offset = 0) {
-       global $CONFIG;
-
+function find_active_users($seconds = 600, $limit = 10, $offset = 0, $count = false) {
        $seconds = (int)$seconds;
        $limit = (int)$limit;
        $offset = (int)$offset;
+       $params = array('seconds' => $seconds, 'limit' => $limit, 'offset' => $offset, 'count' => $count);
+       $data = elgg_trigger_plugin_hook('find_active_users', 'system', $params, NULL);
+       if (!$data) {
+               global $CONFIG;
 
-       $time = time() - $seconds;
-
-       $access = get_access_sql_suffix("e");
-
-       $query = "SELECT distinct e.* from {$CONFIG->dbprefix}entities e
-               join {$CONFIG->dbprefix}users_entity u on e.guid = u.guid
-               where u.last_action >= {$time} and $access
-               order by u.last_action desc limit {$offset}, {$limit}";
+               $time = time() - $seconds;
 
-       return get_data($query, "entity_row_to_elggstar");
+               $data = elgg_get_entities(array(
+                       'type' => 'user', 
+                       'limit' => $limit,
+                       'offset' => $offset,
+                       'count' => $count,
+                       'joins' => array("join {$CONFIG->dbprefix}users_entity u on e.guid = u.guid"),
+                       'wheres' => array("u.last_action >= {$time}"),
+                       'order_by' => "u.last_action desc"
+               ));
+       }
+       return $data;
 }
 
 /**