1010PURPOSE. See the above copyright notices for more information.
1111=========================================================================*/
1212
13+ /**
14+ * Generates and sends piwik statistics reports to admin users
15+ */
1316class Statistics_ReportComponent extends AppComponent
14- {
15- /** geenrate report */
17+ {
18+ /** generate report */
1619 public function generate ()
1720 {
1821 $ loader = new MIDAS_ModelLoader ();
1922 $ errorModel = $ loader ->loadModel ('Errorlog ' );
2023 $ assetstoreModel = $ loader ->loadModel ('Assetstore ' );
2124 $ 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 );
2730 $ reportContent .= "<br/>Yesterday Errors: " .count ($ errors );
2831 $ assetstores = $ assetstoreModel ->getAll ();
2932 foreach ($ assetstores as $ key => $ assetstore )
3033 {
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 .'% ' ;
3236 }
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 ' );
3640 ksort ($ dashboard );
3741 foreach ($ dashboard as $ module => $ dasboard )
3842 {
39- $ reportContent .= '- ' .ucfirst ($ module );
40- $ reportContent .= " <table> " ;
43+ $ reportContent .= '- ' .ucfirst ($ module );
44+ $ reportContent .= ' <table> ' ;
4145 foreach ($ dasboard as $ name => $ status )
4246 {
43- $ reportContent .= " <tr> " ;
44- $ reportContent .= " <td>$ name </td>" ;
47+ $ reportContent .= ' <tr> ' ;
48+ $ reportContent .= ' <td>' . $ name. ' </td> ' ;
4549 if ($ status )
4650 {
47- $ reportContent .= " <td>ok</td>" ;
51+ $ reportContent .= ' <td>ok</td>' ;
4852 }
4953 else
5054 {
51- $ reportContent .= " <td>Error</td>" ;
55+ $ reportContent .= ' <td>Error</td>' ;
5256 }
5357 if (isset ($ status [1 ]))
5458 {
55- $ reportContent .= " <td>$ status [1 ]</td> " ;
59+ $ reportContent .= ' <td>' . $ status [1 ]. ' </td> ' ;
5660 }
57- $ reportContent .= " </tr> " ;
61+ $ reportContent .= ' </tr> ' ;
5862 }
59- $ reportContent .= " </table> " ;
63+ $ reportContent .= ' </table> ' ;
6064 }
61-
65+
6266 $ modulesConfig = Zend_Registry::get ('configsModules ' );
6367 $ 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 );
6468 $ 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 ;
6973 $ this ->report = $ reportContent ;
7074 return $ reportContent ;
7175 }//end generate
72-
73- /* send a report*/
76+
77+ /** send the report to admins */
7478 public function send ()
7579 {
7680 $ loader = new MIDAS_ModelLoader ();
@@ -79,14 +83,14 @@ public function send()
7983 $ mail ->setBodyHtml ($ this ->report );
8084 $ mail ->setFrom ('admin@foo.com ' , 'MIDAS ' );
8185 $ mail ->setSubject ('MIDAS Report ' );
82-
86+
8387 $ admins = $ userModel ->getAdmins ();
8488 foreach ($ admins as $ admin )
8589 {
8690 $ mail ->addTo ($ admin ->getEmail (), $ admin ->getFullName ());
8791 $ mail ->send ();
88- }
89- }//end send
90-
92+ }
93+ }//end send
94+
9195} // end class
92- ?>
96+ ?>
0 commit comments