Elgg  Version master
OnlineUsersCount.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Controllers;
4 
7 use Elgg\Request;
8 use Elgg\Values;
9 
16 
24  public function __invoke(Request $request) {
25  $online_users_count = max(1, elgg_count_entities([
26  'type' => 'user',
27  'wheres' => [
28  function(QueryBuilder $qb, $main_alias) {
29  return $qb->compare("{$main_alias}.last_action", '>=', Values::normalizeTimestamp('-10 minutes'), ELGG_VALUE_TIMESTAMP);
30  }
31  ],
32  ]));
33 
34  return elgg_ok_response([
35  'number' => $online_users_count,
36  'formatted' => Values::shortFormatOutput($online_users_count),
37  ]);
38  }
39 }
Saves user notification settings.
elgg_ok_response($content= '', string|array $message= '', string $forward_url=null, int $status_code=ELGG_HTTP_OK)
Prepares a successful response to be returned by a page or an action handler.
$request
Definition: livesearch.php:12
Database abstraction query builder.
static normalizeTimestamp($time)
Returns timestamp value of the time representation.
Definition: Values.php:63
static shortFormatOutput($n, $precision=0)
Use to convert large positive numbers in to short form like 1K, 1M, 1B or 1T Example: shortFormatOutp...
Definition: Values.php:211
compare(string $x, string $comparison, $y=null, string $type=null, bool $case_sensitive=null)
Build value comparison clause.
elgg_count_entities(array $options=[])
Returns a count of entities.
Definition: entities.php:518
__invoke(Request $request)
Returns the online users count.
const ELGG_VALUE_TIMESTAMP
Definition: constants.php:115
Request container.
Definition: Request.php:12
Returns the online user count.
$qb
Definition: queue.php:12