aboutsummaryrefslogtreecommitdiff
path: root/engine/lib/statistics.php
blob: 844cbfa011d0c6253eeabc54e3901036b4340e9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
	/**
	 * Elgg statistics library.
	 * This file contains a number of functions for obtaining statistics about the running system.
	 * These statistics are mainly used by the administration pages, and is also where the basic views for statistics 
	 * are added.
	 * 
	 * @package Elgg
	 * @subpackage Core
	 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
	 * @author Marcus Povey
	 * @copyright Curverider Ltd 2008
	 * @link http://elgg.org/
	 */


	// number of users
	
	// Number of objects broken down into type
		
	// who' s online now
	
	/**
	 * Return an array reporting the number of various entities in the system.
	 * 
	 * @return array
	 */
	function get_entity_statistics()
	{
		global $CONFIG;
		
		$entity_stats = array();
		
		// Get a list of major types
		$types = get_data("SELECT distinct e.type,s.subtype,e.subtype as subtype_id from {$CONFIG->dbprefix}entities e left join {$CONFIG->dbprefix}entity_subtypes s on e.subtype=s.id");
		foreach ($types as $type) {
			if (!is_array($entity_stats[$type->type])) 
				$entity_stats[$type->type] = array(); // assume there are subtypes for now
			
			$query = "SELECT count(*) as count from {$CONFIG->dbprefix}entities where type='{$type->type}'";
			if ($type->subtype) $query.= " and subtype={$type->subtype_id}";
                         
			$subtype_cnt = get_data_row($query);
			
			if ($type->subtype)
				$entity_stats[$type->type][$type->subtype] = $subtype_cnt->count;
			else
				$entity_stats[$type->type]['__base__'] = $subtype_cnt->count;	
		}
		
		return $entity_stats;
	}
         
	/**
	 * Return the number of users registered in the system.
	 *
	 * @return int
	 */
	function get_number_users()
	{
		global $CONFIG;
            
		$result = get_data_row("SELECT count(*) as count from {$CONFIG->dbprefix}entities where type='user'");
            
		if ($result)
			return $result->count;
            
		return false;
	}
        
	/**
	 * Report how many users are currently online
	 *
	 * @return int
	 */
	function get_number_online()
	{
		// TODO: get logged in users somehow
	}
        
	/**
	 * Return a list of how many users are currently online.
	 * 
	 * @param int $limit Number of users to return
 	 */
	function get_online_users($limit = 10)
	{
		// TODO: Writeme
	}
        
    /**
	 * Initialise the statistics admin page.
	 */
	function statistics_init()
	{
		extend_elgg_admin_page('admin/statistics_opt/basic', 'admin/statistics');
		extend_elgg_admin_page('admin/statistics_opt/numentities', 'admin/statistics'); 
		extend_elgg_admin_page('admin/statistics_opt/online', 'admin/statistics'); 
	}
	
	/// Register init function
	register_elgg_event_handler('init','system','statistics_init');
?>