10
10
PURPOSE. See the above copyright notices for more information.
11
11
=========================================================================*/
12
12
13
+ /**
14
+ * Generates and sends piwik statistics reports to admin users
15
+ */
13
16
class Statistics_ReportComponent extends AppComponent
14
- {
15
- /** geenrate report */
17
+ {
18
+ /** generate report */
16
19
public function generate ()
17
20
{
18
21
$ loader = new MIDAS_ModelLoader ();
19
22
$ errorModel = $ loader ->loadModel ('Errorlog ' );
20
23
$ assetstoreModel = $ loader ->loadModel ('Assetstore ' );
21
24
$ reportContent = '' ;
22
- $ reportContent .= " <b>Midas Report: " .Zend_Registry::get ('configGlobal ' )->application ->name ." </b> " ;
23
- $ reportContent .= " <br/>http:// " .$ _SERVER ['SERVER_NAME ' ];
24
-
25
- $ reportContent .= " <br/><br/><b>Status</b> " ;
26
- $ errors = $ errorModel ->getLog (date ( 'c ' , strtotime ('-1 day ' .date ( 'Y-m-j G:i:s ' ))), date ('c ' ), 'all ' , 2 );
25
+ $ reportContent .= ' <b>Midas Report: ' .Zend_Registry::get ('configGlobal ' )->application ->name .' </b> ' ;
26
+ $ reportContent .= ' <br/>http:// ' .$ _SERVER ['SERVER_NAME ' ];
27
+
28
+ $ reportContent .= ' <br/><br/><b>Status</b> ' ;
29
+ $ errors = $ errorModel ->getLog (date ('c ' , strtotime ('-1 day ' .date ('Y-m-j G:i:s ' ))), date ('c ' ), 'all ' , 2 );
27
30
$ reportContent .= "<br/>Yesterday Errors: " .count ($ errors );
28
31
$ assetstores = $ assetstoreModel ->getAll ();
29
32
foreach ($ assetstores as $ key => $ assetstore )
30
33
{
31
- $ reportContent .= "<br/>Assetstore " .$ assetstore ->getName ().", Free space: " .round ((disk_free_space ($ assetstore ->getPath ()) / disk_total_space ($ assetstore ->getPath ()))*100 , 2 ).'% ' ;
34
+ $ freeSpace = round ((disk_free_space ($ assetstore ->getPath ()) / disk_total_space ($ assetstore ->getPath ())) * 100 , 2 );
35
+ $ reportContent .= '<br/>Assetstore ' .$ assetstore ->getName ().', Free space: ' .$ freeSpace .'% ' ;
32
36
}
33
-
34
- $ reportContent .= " <br/><br/><b>Dashboard</b><br/> " ;
35
- $ dashboard = Zend_Registry::get ('notifier ' )->callback (" CALLBACK_CORE_GET_DASHBOARD " );
37
+
38
+ $ reportContent .= ' <br/><br/><b>Dashboard</b><br/> ' ;
39
+ $ dashboard = Zend_Registry::get ('notifier ' )->callback (' CALLBACK_CORE_GET_DASHBOARD ' );
36
40
ksort ($ dashboard );
37
41
foreach ($ dashboard as $ module => $ dasboard )
38
42
{
39
- $ reportContent .= '- ' .ucfirst ($ module );
40
- $ reportContent .= " <table> " ;
43
+ $ reportContent .= '- ' .ucfirst ($ module );
44
+ $ reportContent .= ' <table> ' ;
41
45
foreach ($ dasboard as $ name => $ status )
42
46
{
43
- $ reportContent .= " <tr> " ;
44
- $ reportContent .= " <td>$ name </td>" ;
47
+ $ reportContent .= ' <tr> ' ;
48
+ $ reportContent .= ' <td>' . $ name. ' </td> ' ;
45
49
if ($ status )
46
50
{
47
- $ reportContent .= " <td>ok</td>" ;
51
+ $ reportContent .= ' <td>ok</td>' ;
48
52
}
49
53
else
50
54
{
51
- $ reportContent .= " <td>Error</td>" ;
55
+ $ reportContent .= ' <td>Error</td>' ;
52
56
}
53
57
if (isset ($ status [1 ]))
54
58
{
55
- $ reportContent .= " <td>$ status [1 ]</td> " ;
59
+ $ reportContent .= ' <td>' . $ status [1 ]. ' </td> ' ;
56
60
}
57
- $ reportContent .= " </tr> " ;
61
+ $ reportContent .= ' </tr> ' ;
58
62
}
59
- $ reportContent .= " </table> " ;
63
+ $ reportContent .= ' </table> ' ;
60
64
}
61
-
65
+
62
66
$ modulesConfig = Zend_Registry::get ('configsModules ' );
63
67
$ content = file_get_contents ($ modulesConfig ['statistics ' ]->piwik ->url .'/?module=API&format=json&method=VisitsSummary.get&period=day&date=yesterday&idSite= ' .$ modulesConfig ['statistics ' ]->piwik ->id .'&token_auth= ' .$ modulesConfig ['statistics ' ]->piwik ->apikey );
64
68
$ piwik = json_decode ($ content );
65
- $ reportContent .= " <br/><b>Statistics (yesterday)</b> " ;
66
- $ reportContent .= " <br/>Number of visit: " .$ piwik ->nb_uniq_visitors ;
67
- $ reportContent .= " <br/>Number of actions: " .$ piwik ->nb_actions ;
68
- $ reportContent .= " <br/>Average time on the website: " .$ piwik ->avg_time_on_site ;
69
+ $ reportContent .= ' <br/><b>Statistics (yesterday)</b> ' ;
70
+ $ reportContent .= ' <br/>Number of visit: ' .$ piwik ->nb_uniq_visitors ;
71
+ $ reportContent .= ' <br/>Number of actions: ' .$ piwik ->nb_actions ;
72
+ $ reportContent .= ' <br/>Average time on the website: ' .$ piwik ->avg_time_on_site ;
69
73
$ this ->report = $ reportContent ;
70
74
return $ reportContent ;
71
75
}//end generate
72
-
73
- /* send a report*/
76
+
77
+ /** send the report to admins */
74
78
public function send ()
75
79
{
76
80
$ loader = new MIDAS_ModelLoader ();
@@ -79,14 +83,14 @@ public function send()
79
83
$ mail ->setBodyHtml ($ this ->report );
80
84
$ mail ->setFrom ('admin@foo.com ' , 'MIDAS ' );
81
85
$ mail ->setSubject ('MIDAS Report ' );
82
-
86
+
83
87
$ admins = $ userModel ->getAdmins ();
84
88
foreach ($ admins as $ admin )
85
89
{
86
90
$ mail ->addTo ($ admin ->getEmail (), $ admin ->getFullName ());
87
91
$ mail ->send ();
88
- }
89
- }//end send
90
-
92
+ }
93
+ }//end send
94
+
91
95
} // end class
92
- ?>
96
+ ?>
0 commit comments