Elgg  Version 1.9
statistics.php
Go to the documentation of this file.
1 <?php
22 
23  $entity_stats = array();
24  $owner_guid = (int)$owner_guid;
25 
26  $query = "SELECT distinct e.type,s.subtype,e.subtype as subtype_id
27  from {$CONFIG->dbprefix}entities e left
28  join {$CONFIG->dbprefix}entity_subtypes s on e.subtype=s.id";
29 
30  $owner_query = "";
31  if ($owner_guid) {
32  $query .= " where owner_guid=$owner_guid";
33  $owner_query = "and owner_guid=$owner_guid ";
34  }
35 
36  // Get a list of major types
37 
38  $types = get_data($query);
39  foreach ($types as $type) {
40  // assume there are subtypes for now
41  if (!isset($entity_stats[$type->type]) || !is_array($entity_stats[$type->type])) {
42  $entity_stats[$type->type] = array();
43  }
44 
45  $query = "SELECT count(*) as count
46  from {$CONFIG->dbprefix}entities where type='{$type->type}' $owner_query";
47 
48  if ($type->subtype) {
49  $query .= " and subtype={$type->subtype_id}";
50  }
51 
52  $subtype_cnt = get_data_row($query);
53 
54  if ($type->subtype) {
55  $entity_stats[$type->type][$type->subtype] = $subtype_cnt->count;
56  } else {
57  $entity_stats[$type->type]['__base__'] = $subtype_cnt->count;
58  }
59  }
60 
61  return $entity_stats;
62 }
63 
71 function get_number_users($show_deactivated = false) {
73 
74  $access = "";
75 
76  if (!$show_deactivated) {
77  $access = "and " . _elgg_get_access_where_sql(array('table_alias' => ''));
78  }
79 
80  $query = "SELECT count(*) as count
81  from {$CONFIG->dbprefix}entities where type='user' $access";
82 
83  $result = get_data_row($query);
84 
85  if ($result) {
86  return $result->count;
87  }
88 
89  return false;
90 }
91 
103 function get_online_users(array $options = array()) {
104  $options = array_merge(array(
105  'seconds' => 600,
106  ), $options);
107 
108  return elgg_list_entities($options, 'find_active_users');
109 }
110 
117 function statistics_init() {
118  elgg_extend_view('core/settings/statistics', 'core/settings/statistics/online');
119  elgg_extend_view('core/settings/statistics', 'core/settings/statistics/numentities');
120 }
121 
123 elgg_register_event_handler('init', 'system', 'statistics_init');
get_entity_statistics($owner_guid=0)
Return an array reporting the number of various entities in the system.
Definition: statistics.php:20
get_data_row($query, $callback="")
Retrieve a single row from the database.
Definition: database.php:66
$options
Definition: index.php:14
statistics_init()
Initialise the statistics admin page.
Definition: statistics.php:117
$owner_guid
get_online_users(array $options=array())
Render a list of currently online users.
Definition: statistics.php:103
global $CONFIG
elgg_extend_view($view, $view_extension, $priority=501, $viewtype= '')
Extends a view with another view.
Definition: views.php:401
$entity_stats
Definition: numentities.php:3
elgg global
Pointer to the global context.
Definition: elgglib.js:12
$type
Definition: add.php:8
elgg_register_event_handler($event, $object_type, $callback, $priority=500)
Register a callback as an Elgg event handler.
Definition: elgglib.php:669
elgg_list_entities(array $options=array(), $getter= 'elgg_get_entities', $viewer= 'elgg_view_entity_list')
Returns a string of rendered entities.
Definition: entities.php:1343
get_data($query, $callback="")
Retrieve rows from the database.
Definition: database.php:50
get_number_users($show_deactivated=false)
Return the number of users registered in the system.
Definition: statistics.php:71
_elgg_get_access_where_sql(array $options=array())
Returns the SQL where clause for enforcing read access to data.
Definition: access.php:343
$access
Definition: save.php:15