Elgg  Version 2.2
 All Classes Namespaces Files Functions Variables Pages
statistics.php
Go to the documentation of this file.
1 <?php
21 
22  $owner_guid = (int) $owner_guid;
23  $entity_stats = array();
24 
25  $grouped_entities = elgg_get_entities(array(
26  'selects' => array('COUNT(*) as cnt'),
27  'owner_guids' => ($owner_guid) ? : ELGG_ENTITIES_ANY_VALUE,
28  'group_by' => 'e.type, e.subtype',
29  'limit' => 0,
30  'order_by' => 'cnt DESC',
31  ));
32 
33  if (!empty($grouped_entities)) {
34  foreach ($grouped_entities as $entity) {
35  $type = $entity->getType();
36  if (!isset($entity_stats[$type]) || !is_array($entity_stats[$type])) {
37  $entity_stats[$type] = array();
38  }
39  $subtype = $entity->getSubtype();
40  if (!$subtype) {
41  $subtype = '__base__';
42  }
43  $entity_stats[$type][$subtype] = $entity->getVolatileData('select:cnt');
44  }
45  }
46 
47  return $entity_stats;
48 }
49 
57 function get_number_users($show_deactivated = false) {
58  global $CONFIG;
59 
60  $access = "";
61 
62  if (!$show_deactivated) {
63  $access = "and " . _elgg_get_access_where_sql(array('table_alias' => ''));
64  }
65 
66  $query = "SELECT count(*) as count
67  from {$CONFIG->dbprefix}entities where type='user' $access";
68 
69  $result = get_data_row($query);
70 
71  if ($result) {
72  return $result->count;
73  }
74 
75  return false;
76 }
77 
89 function get_online_users(array $options = array()) {
90  $options = array_merge(array(
91  'seconds' => 600,
92  ), $options);
93 
94  return elgg_list_entities($options, 'find_active_users');
95 }
96 
103 function statistics_init() {
104  elgg_extend_view('core/settings/statistics', 'core/settings/statistics/online');
105  elgg_extend_view('core/settings/statistics', 'core/settings/statistics/numentities');
106 }
107 
108 return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) {
109  $events->registerHandler('init', 'system', 'statistics_init');
110 };
get_entity_statistics($owner_guid=0)
Return an array reporting the number of various entities in the system.
Definition: statistics.php:20
$subtype
Definition: delete.php:28
$options
Elgg admin footer.
Definition: footer.php:6
statistics_init()
Initialise the statistics admin page.
Definition: statistics.php:103
$owner_guid
get_online_users(array $options=array())
Render a list of currently online users.
Definition: statistics.php:89
get_data_row($query, $callback=null, array $params=[])
Retrieve a single row from the database.
Definition: database.php:72
global $CONFIG
const ELGG_ENTITIES_ANY_VALUE
Definition: elgglib.php:2001
elgg_get_entities(array $options=array())
Returns an array of entities with optional filtering.
Definition: entities.php:316
$entity_stats
Definition: numentities.php:3
elgg_extend_view($view, $view_extension, $priority=501)
Extends a view with another view.
Definition: views.php:386
elgg_list_entities(array $options=array(), $getter= 'elgg_get_entities', $viewer= 'elgg_view_entity_list')
Returns a string of rendered entities.
Definition: entities.php:382
$entity
Definition: delete.php:7
get_number_users($show_deactivated=false)
Return the number of users registered in the system.
Definition: statistics.php:57
_elgg_get_access_where_sql(array $options=array())
Returns the SQL where clause for enforcing read access to data.
Definition: access.php:214
$access
Definition: save.php:15
if(!$display_name) $type
Definition: delete.php:27