Elgg  Version 3.0
statistics.php
Go to the documentation of this file.
1 <?php
14 
23 
24  $owner_guid = (int) $owner_guid;
25  $entity_stats = [];
26 
27  $grouped_entities = elgg_get_entities([
28  'selects' => ['COUNT(*) as cnt'],
29  'owner_guids' => ($owner_guid) ? : ELGG_ENTITIES_ANY_VALUE,
30  'group_by' => ['e.type', 'e.subtype'],
31  'limit' => 0,
32  'order_by' => new OrderByClause('cnt', 'DESC'),
33  ]);
34 
35  if (!empty($grouped_entities)) {
36  foreach ($grouped_entities as $entity) {
37  $type = $entity->getType();
38  if (!isset($entity_stats[$type]) || !is_array($entity_stats[$type])) {
39  $entity_stats[$type] = [];
40  }
41  $subtype = $entity->getSubtype();
42  if (!$subtype) {
43  $subtype = '__base__';
44  }
45  $entity_stats[$type][$subtype] = $entity->getVolatileData('select:cnt');
46  }
47  }
48 
49  return $entity_stats;
50 }
51 
59 function get_number_users($show_deactivated = false) {
60 
61  $where = new \Elgg\Database\Clauses\EntityWhereClause();
62  $where->type_subtype_pairs = [
63  'user' => null,
64  ];
65 
66  if ($show_deactivated) {
67  $where->use_enabled_clause = false;
68  }
69 
70  $select = \Elgg\Database\Select::fromTable('entities', 'e');
71  $select->select('COUNT(DISTINCT e.guid) AS count');
72  $select->addClause($where, 'e');
73 
74  $result = _elgg_services()->db->getDataRow($select);
75  if (!empty($result)) {
76  return (int) $result->count;
77  }
78 
79  return 0;
80 }
81 
93 function get_online_users(array $options = []) {
94  $options = array_merge([
95  'seconds' => 600,
96  ], $options);
97 
98  return elgg_list_entities($options, 'find_active_users');
99 }
100 
107 function statistics_init() {
108  elgg_extend_view('core/settings/statistics', 'core/settings/statistics/online');
109  elgg_extend_view('core/settings/statistics', 'core/settings/statistics/numentities');
110 }
111 
115 return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) {
116  $events->registerHandler('init', 'system', 'statistics_init');
117 };
get_entity_statistics($owner_guid=0)
Return an array reporting the number of various entities in the system.
Definition: statistics.php:22
get_online_users(array $options=[])
Render a list of currently online users.
Definition: statistics.php:93
Events service.
$subtype
Definition: delete.php:22
$type
Definition: delete.php:21
elgg_list_entities(array $options=[], $getter= 'elgg_get_entities', $viewer= 'elgg_view_entity_list')
Returns a string of rendered entities.
Definition: entities.php:577
$options
Elgg admin footer.
Definition: footer.php:6
statistics_init()
Initialise the statistics admin page.
Definition: statistics.php:107
$owner_guid
Base class for events and hooks.
$entity
Definition: reset.php:8
elgg_get_entities(array $options=[])
Fetches/counts entities or performs a calculation on their properties.
Definition: entities.php:545
const ELGG_ENTITIES_ANY_VALUE
Definition: constants.php:24
elgg_extend_view($view, $view_extension, $priority=501)
Extends a view with another view.
Definition: views.php:293
Extends QueryBuilder with ORDER BY clauses.
_elgg_services()
Get the global service provider.
Definition: elgglib.php:1292
get_number_users($show_deactivated=false)
Return the number of users registered in the system.
Definition: statistics.php:59
$entity_stats
Definition: numentities.php:3