/lenasys/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/lenasys/trunk
64.1.1 by b11johgu
ExamplesController:
1
<?php
72.1.1 by Daniel Hermansson
Fixed and optimized the stats model.
2
	class Stats extends CI_Model {
3
	
4
		function __construct() {
5
			parent::__construct();
6
			$this->load->library('user_agent');
7
		}
8
9
10
		/*
11
		 *	This function returns an array with user stats.
12
		 */ 
13
		 		
14
		public function getUserStats() {
15
			//Dummy-array to be filled
16
			$userStats = array(
124.1.1 by Erik Wikström
Added display of statistics in the sidepane
17
				'agentType' => '[unknown]',
18
				'agentName' => '[unknown]',
19
				'agentVersion' => '[unknown]',
20
				'agentPlatform' => '[unknown]',
21
				'agentString' => '[unknown]'	
72.1.1 by Daniel Hermansson
Fixed and optimized the stats model.
22
			);
23
		
24
			//If user is using a web browser
25
			if($this->agent->is_browser()) {
124.1.1 by Erik Wikström
Added display of statistics in the sidepane
26
				$userStats['agentType'] = 'Desktop';
72.1.1 by Daniel Hermansson
Fixed and optimized the stats model.
27
				$userStats['agentName'] = $this->agent->browser();
28
				$userStats['agentVersion'] = $this->agent->version();
29
			}
30
			//If user is using a mobile browser
31
			elseif ($this->agent->is_mobile()) {
124.1.1 by Erik Wikström
Added display of statistics in the sidepane
32
				$userStats['agentType'] = 'Mobile';
72.1.1 by Daniel Hermansson
Fixed and optimized the stats model.
33
				$userStats['agentName'] = $this->agent->mobile();
34
			}
35
			//If user is a robot
36
			elseif ($this->agent->is_robot()) {
124.1.1 by Erik Wikström
Added display of statistics in the sidepane
37
				$userStats['agentType'] = 'Robot';
72.1.1 by Daniel Hermansson
Fixed and optimized the stats model.
38
				$userStats['agentName'] = $this->agent->robot();
39
			}
40
			
41
			//Common stats
42
			$userStats['agentPlatform'] = $this->agent->platform();
43
			$userStats['agentString'] = $this->agent->agent_string();
44
			
45
			//Return result
46
			return $userStats;
47
		}
48
		
49
		
50
		/*
51
		 *	This function returns an array with system stats.
52
		 */ 		
53
		
54
		public function getSystemStats() {
55
			//Dummy-array to be filled
56
			$systemStats = array(
124.1.1 by Erik Wikström
Added display of statistics in the sidepane
57
				'courseAmount' => '[unknown]',
58
				'exampleAmount' => '[unknown]',
59
				'quizAmount' => '[unknown]'	
72.1.1 by Daniel Hermansson
Fixed and optimized the stats model.
60
			);
61
			
62
			//Get amount of courses
124.1.1 by Erik Wikström
Added display of statistics in the sidepane
63
			$systemStats['courseAmount'] = $this->db->count_all('Courses');
72.1.1 by Daniel Hermansson
Fixed and optimized the stats model.
64
			
65
			//Get amount of examples
124.1.1 by Erik Wikström
Added display of statistics in the sidepane
66
			$systemStats['exampleAmount'] = $this->db->count_all('Examples');
72.1.1 by Daniel Hermansson
Fixed and optimized the stats model.
67
			
68
			//Get amount of quizzes
124.1.1 by Erik Wikström
Added display of statistics in the sidepane
69
			$systemStats['quizAmount'] = $this->db->count_all('Quizzes');
72.1.1 by Daniel Hermansson
Fixed and optimized the stats model.
70
			
71
			//Return result
72
			return $systemStats;
73
		}
74
		
75
		
76
		/*
77
		 *	This function returns an array with course stats.
78
		 */ 
79
		
124.1.1 by Erik Wikström
Added display of statistics in the sidepane
80
		public function getCourseStats($courseID) {
72.1.1 by Daniel Hermansson
Fixed and optimized the stats model.
81
			//Dummy-array to be filled
82
			$courseStats = array(
124.1.1 by Erik Wikström
Added display of statistics in the sidepane
83
				'exampleAmount' => '[unknown]',
84
				'quizAmount' => '[unknown]'	
72.1.1 by Daniel Hermansson
Fixed and optimized the stats model.
85
			);
86
			
124.1.1 by Erik Wikström
Added display of statistics in the sidepane
87
			$this->db->where('courseID', $courseID);
88
			$this->db->from('Examples');
89
			$courseStats['exampleAmount'] = $this->db->count_all_results();
90
			
91
			$this->db->where('courseID', $courseID);
92
			$this->db->from('Quizzes');
93
			$courseStats['quizAmount'] = $this->db->count_all_results();
94
			
72.1.1 by Daniel Hermansson
Fixed and optimized the stats model.
95
			//Return result
96
			return $courseStats;	
97
		}
98
	}
99
?>