1
|
|
|
<?php defined('SYSPATH') OR die('No direct script access.'); |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* The basic class for managing analytics data. |
5
|
|
|
* Adds basic consistent timerange setting |
6
|
|
|
* |
7
|
|
|
* @package Despark/services-manager |
8
|
|
|
* @author Ivan Kerin |
9
|
|
|
* @copyright (c) 2012 Despark Ltd. |
10
|
|
|
* @license http://creativecommons.org/licenses/by-sa/3.0/legalcode |
11
|
|
|
*/ |
12
|
|
|
abstract class Kohana_Report |
13
|
|
|
{ |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Get the report. Configuration is in the services-manager under the same name. |
17
|
|
|
* The driver name is named the same as the report name |
18
|
|
|
* |
19
|
|
|
* @param string $report_name |
20
|
|
|
* @return Report |
21
|
|
|
*/ |
22
|
|
|
static public function factory($report_name) |
23
|
|
|
{ |
24
|
|
|
$class = 'Report_'.ucfirst($report_name); |
25
|
|
|
|
26
|
|
|
return new $class(); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
protected $_start_date; |
30
|
|
|
protected $_end_date; |
31
|
|
|
protected $_date_template = 'Y-m-d H:i:s'; |
32
|
|
|
|
33
|
|
|
function __construct() |
|
|
|
|
34
|
|
|
{ |
35
|
|
|
$this |
36
|
|
|
->start_date('1 month ago') |
37
|
|
|
->end_date('today'); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Getter / Setter |
42
|
|
|
* Set the timerange start date, defaults to 1 month ago. Normalizes the date to Y-m-d H:i:s |
43
|
|
|
* |
44
|
|
|
* @param string $start_date |
45
|
|
|
* @return string|$this |
46
|
|
|
*/ |
47
|
|
|
public function start_date($start_date = NULL) |
48
|
|
|
{ |
49
|
|
|
if ($start_date !== NULL) |
50
|
|
|
{ |
51
|
|
|
$this->_start_date = date($this->_date_template, (is_numeric($start_date) ? $start_date : strtotime($start_date))); |
52
|
|
|
return $this; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
return $this->_start_date; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Getter / Setter |
60
|
|
|
* Set the timerange end date, defaults to today. Normalizes the date to Y-m-d H:i:s |
61
|
|
|
* |
62
|
|
|
* @param string $end_date |
63
|
|
|
* @return string|$this |
64
|
|
|
*/ |
65
|
|
|
public function end_date($end_date = NULL) |
66
|
|
|
{ |
67
|
|
|
if ($end_date !== NULL) |
68
|
|
|
{ |
69
|
|
|
$this->_end_date = date($this->_date_template, (is_numeric($end_date) ? $end_date : strtotime($end_date))); |
70
|
|
|
return $this; |
71
|
|
|
} |
72
|
|
|
return $this->_end_date; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
abstract public function total(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.