11<?php
2- /**
3- * Active Metric
4- */
52namespace Minds \Core \Analytics \Metrics ;
63
74use Minds \Helpers ;
85use Minds \Core ;
96use Minds \Core \Analytics \Timestamps ;
107use Minds \Interfaces \AnalyticsMetric ;
118
9+ /**
10+ * Active Metric
11+ */
1212class Active implements AnalyticsMetric
1313{
1414 private $ db ;
@@ -28,16 +28,28 @@ public function __construct($db = null)
2828 }
2929 }
3030
31+ /**
32+ * Sets the current namespace
33+ * @param string $namesapce
34+ */
3135 public function setNamespace ($ namesapce )
3236 {
3337 //$this->namespace = $namespace . ":";
3438 }
3539
40+ /**
41+ * Sets the current key
42+ * @param string $key
43+ */
3644 public function setKey ($ key )
3745 {
3846 $ this ->key = $ key ;
3947 }
4048
49+ /**
50+ * Increments metric counter
51+ * @return bool
52+ */
4153 public function increment ()
4254 {
4355 foreach (Timestamps::get (array ('day ' , 'month ' )) as $ p => $ ts ) {
@@ -46,27 +58,31 @@ public function increment()
4658 return true ;
4759 }
4860
49- /**
50- * Return a set of analytics for a timespan
51- * @param int $span - eg. 3 (will return 3 units, eg 3 day, 3 months)
52- * @param string $unit - eg. day, month, year
53- * @param int $timestamp (optional) - sets the base to work off
54- * @return array
55- */
56- public function get ($ span = 3 , $ unit = 'day ' , $ timestamp = null )
57- {
58- $ timestamps = Timestamps::span ($ span , $ unit );
59- $ data = array ();
60- foreach ($ timestamps as $ ts ) {
61- $ data [] = array (
62- 'timestamp ' => $ ts ,
63- 'date ' => date ('d-m-Y ' , $ ts ),
64- 'total ' => $ this ->db ->countRow ("{$ this ->namespace }active: $ unit: $ ts " )
65- );
66- }
67- return $ data ;
68- }
61+ /**
62+ * Return a set of analytics for a timespan
63+ * @param int $span - eg. 3 (will return 3 units, eg 3 day, 3 months)
64+ * @param string $unit - eg. day, month, year
65+ * @param int $timestamp (optional) - sets the base to work off
66+ * @return array
67+ */
68+ public function get ($ span = 3 , $ unit = 'day ' , $ timestamp = null )
69+ {
70+ $ timestamps = Timestamps::span ($ span , $ unit );
71+ $ data = array ();
72+ foreach ($ timestamps as $ ts ) {
73+ $ data [] = array (
74+ 'timestamp ' => $ ts ,
75+ 'date ' => date ('d-m-Y ' , $ ts ),
76+ 'total ' => $ this ->db ->countRow ("{$ this ->namespace }active: $ unit: $ ts " )
77+ );
78+ }
79+ return $ data ;
80+ }
6981
82+ /**
83+ * Returns total metric counter
84+ * @return int
85+ */
7086 public function total ()
7187 {
7288 return 0 ;
0 commit comments