aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engine/lib/statistics.php13
-rw-r--r--engine/lib/users.php23
-rw-r--r--views/default/admin/statistics_opt/online.php5
3 files changed, 33 insertions, 8 deletions
diff --git a/engine/lib/statistics.php b/engine/lib/statistics.php
index 844cbfa01..8744db4ab 100644
--- a/engine/lib/statistics.php
+++ b/engine/lib/statistics.php
@@ -79,13 +79,16 @@
}
/**
- * Return a list of how many users are currently online.
- *
- * @param int $limit Number of users to return
+ * Return a list of how many users are currently online, rendered as a view.
*/
- function get_online_users($limit = 10)
+ function get_online_users()
{
- // TODO: Writeme
+ $objects = find_active_users();
+
+ if ($objects)
+ {
+ return elgg_view_entity_list($objects, count($objects), 0, 10);
+ }
}
/**
diff --git a/engine/lib/users.php b/engine/lib/users.php
index 51cb748c5..3bd87dbff 100644
--- a/engine/lib/users.php
+++ b/engine/lib/users.php
@@ -726,6 +726,29 @@
}
return false;
}
+
+ /**
+ * A function that returns a maximum of $limit users who have done something within the last
+ * $seconds seconds.
+ *
+ * @param int $seconds Number of seconds (default 600 = 10min)
+ * @param int $limit Limit, default 10.
+ * @param int $offset Offset, defualt 0.
+ */
+ function find_active_users($seconds = 600, $limit = 10, $offset = 0)
+ {
+ global $CONFIG;
+
+ $seconds = (int)$seconds;
+ $limit = (int)$limit;
+ $offset = (int)$offset;
+
+ $time = time() - $seconds;
+
+ $query = "SELECT * from {$CONFIG->dbprefix}entities where type='user' and time_updated>=$time order by time_updated desc limit $offset, $limit";
+
+ return get_data($query, "entity_row_to_elggstar");
+ }
/**
* Registers a user, returning false if the username already exists
diff --git a/views/default/admin/statistics_opt/online.php b/views/default/admin/statistics_opt/online.php
index 1c86c21d1..ab418734a 100644
--- a/views/default/admin/statistics_opt/online.php
+++ b/views/default/admin/statistics_opt/online.php
@@ -11,11 +11,10 @@
*/
// users online
- $users_online = get_number_online();
+ $users_online = get_online_users();
?>
<div>
<h2><?php echo sprintf(elgg_echo('admin:statistics:label:onlineusers'), 10); ?></h2>
+ <?php echo $users_online; ?>
</div>
-
-TODO: Writeme \ No newline at end of file