Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit 75bd3a9

Browse files
committed
STYLE: refs #0339. Add style tests to statistics module
1 parent bf4909d commit 75bd3a9

File tree

11 files changed

+97
-92
lines changed

11 files changed

+97
-92
lines changed

modules/statistics/Notification.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,38 @@
33
class Statistics_Notification extends MIDAS_Notification
44
{
55
public $moduleName = 'statistics';
6-
public $_moduleModels=array('Download');
7-
public $_moduleComponents=array('Report');
8-
6+
public $_moduleModels = array('Download');
7+
public $_moduleComponents = array('Report');
8+
99
/** init notification process*/
1010
public function init()
1111
{
1212
$this->addCallBack('CALLBACK_CORE_GET_FOOTER_LAYOUT', 'getFooter');
1313
$this->addCallBack('CALLBACK_CORE_GET_USER_MENU', 'getUserMenu');
1414
$this->addCallBack('CALLBACK_CORE_PLUS_ONE_DOWNLOAD', 'addDownload');
15-
16-
$this->addTask("TASK_STATISTICS_SEND_REPORT", 'sendReport', "Send a daily report");
15+
16+
$this->addTask('TASK_STATISTICS_SEND_REPORT', 'sendReport', 'Send a daily report');
1717
}//end init
18-
18+
19+
/** send the batch report to admins */
1920
public function sendReport()
2021
{
2122
echo $this->ModuleComponent->Report->generate();
2223
$this->ModuleComponent->Report->send();
2324
}
24-
25+
2526
/** add download stat*/
2627
public function addDownload($params)
2728
{
2829
$item = $params['item'];
2930
$user = $this->userSession->Dao;
3031
$this->Statistics_Download->addDownload($item, $user);
3132
}
32-
33+
3334
/** user Menu link */
3435
public function getUserMenu()
3536
{
36-
if($this->logged && $this->userSession->Dao->getAdmin()==1)
37+
if($this->logged && $this->userSession->Dao->getAdmin() == 1)
3738
{
3839
$fc = Zend_Controller_Front::getInstance();
3940
$moduleWebroot = $fc->getBaseUrl().'/statistics';
@@ -44,15 +45,15 @@ public function getUserMenu()
4445
return null;
4546
}
4647
}
47-
48+
4849
/** get layout footer */
4950
public function getFooter()
5051
{
5152
$modulesConfig = Zend_Registry::get('configsModules');
5253
$url = $modulesConfig['statistics']->piwik->url;
5354
$id = $modulesConfig['statistics']->piwik->id;
5455
return "
55-
<!-- Piwik -->
56+
<!-- Piwik -->
5657
<script type=\"text/javascript\">
5758
var pkBaseURL = '".$url."/';
5859
document.write(unescape(\"%3Cscript src='\" + pkBaseURL + \"piwik.js' type='text/javascript'%3E%3C/script%3E\"));
@@ -64,7 +65,7 @@ public function getFooter()
6465
} catch( err ) {}
6566
</script><noscript><p><img src=\"".$url."/piwik.php?idsite=".$id."\" style=\"border:0\" alt=\"\" /></p></noscript>
6667
<!-- End Piwik Tracking Code -->
67-
";
68+
";
6869
}
6970
} //end class
7071
?>

modules/statistics/controllers/ConfigController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ function indexAction()
7070
$job->setTask('TASK_STATISTICS_SEND_REPORT');
7171
$job->setPriority('1');
7272
$job->setRunOnlyOnce(false);
73-
$job->setFireTime(date('Y-m-j', strtotime ('+1 day'.date( 'Y-m-j G:i:s'))).' 1:00:00');
73+
$job->setFireTime(date('Y-m-j', strtotime('+1 day'.date('Y-m-j G:i:s'))).' 1:00:00');
7474
$job->setTimeInterval(24 * 60 * 60);
7575
$job->setStatus(SCHEDULER_JOB_STATUS_TORUN);
7676
$job->setParams(JsonComponent::encode(array()));

modules/statistics/controllers/IndexController.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
<?php
22

3+
/** Index controller for the statistics module */
34
class Statistics_IndexController extends Statistics_AppController
45
{
5-
public $_moduleModels=array('Download');
6-
public $_models=array('Errorlog', 'Assetstore');
6+
public $_moduleModels = array('Download');
7+
public $_models = array('Errorlog', 'Assetstore');
78
public $_components = array('Utility');
89

910
/** index action*/
1011
function indexAction()
1112
{
12-
if(!$this->logged||!$this->userSession->Dao->getAdmin()==1)
13+
if(!$this->logged || !$this->userSession->Dao->getAdmin() == 1)
1314
{
1415
throw new Zend_Exception("You should be an administrator");
1516
}
@@ -24,8 +25,8 @@ function indexAction()
2425
$assetstores[$key]->totalSpace = disk_total_space($assetstore->getPath());
2526
$assetstores[$key]->usedSpace = disk_total_space($assetstore->getPath()) - disk_free_space($assetstore->getPath());
2627
$assetstores[$key]->freeSpace = disk_free_space($assetstore->getPath());
27-
$assetstores[$key]->usedSpaceText = round(($assetstores[$key]->usedSpace / $assetstores[$key]->totalSpace)*100, 2) ;
28-
$assetstores[$key]->freeSpaceText = round((disk_free_space($assetstore->getPath()) / $assetstores[$key]->totalSpace)*100, 2) ;
28+
$assetstores[$key]->usedSpaceText = round(($assetstores[$key]->usedSpace / $assetstores[$key]->totalSpace) * 100, 2);
29+
$assetstores[$key]->freeSpaceText = round((disk_free_space($assetstore->getPath()) / $assetstores[$key]->totalSpace) * 100, 2);
2930
}
3031
else
3132
{
@@ -45,18 +46,18 @@ function indexAction()
4546
);
4647
}
4748

48-
$errors = $this->Errorlog->getLog(date( 'c', strtotime ('-20 day'.date( 'Y-m-j G:i:s'))), date('c'), 'all', 2);
49+
$errors = $this->Errorlog->getLog(date('c', strtotime('-20 day'.date('Y-m-j G:i:s'))), date('c'), 'all', 2);
4950
$arrayErrors = array();
5051

5152
$format = 'Y-m-j';
52-
for($i = 0; $i<21; $i++)
53+
for($i = 0; $i < 21; $i++)
5354
{
54-
$key = date($format, strtotime(date( 'c', strtotime ('-'.$i.' day'.date( 'Y-m-j G:i:s')))));
55+
$key = date($format, strtotime(date('c', strtotime('-'.$i.' day'.date('Y-m-j G:i:s')))));
5556
$arrayErrors[$key] = 0;
5657
}
5758
foreach($errors as $error)
5859
{
59-
$key = date($format, strtotime($error->getDatetime()));
60+
$key = date($format, strtotime($error->getDatetime()));
6061
$arrayErrors[$key]++;
6162
}
6263

modules/statistics/controllers/ItemController.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
/** Controller for statistics about an item */
44
class Statistics_ItemController extends Statistics_AppController
55
{
6-
public $_moduleModels = array('Download');
7-
public $_models = array('Item');
8-
public $_components = array('Utility');
6+
public $_moduleModels = array('Download');
7+
public $_models = array('Item');
8+
public $_components = array('Utility');
99

10-
/** index action*/
11-
function indexAction()
10+
/** index action*/
11+
function indexAction()
1212
{
13-
1413
$item = $this->Item->load($_GET['id']);
1514
if(!$item)
1615
{

modules/statistics/controllers/components/ReportComponent.php

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,67 +10,71 @@
1010
PURPOSE. See the above copyright notices for more information.
1111
=========================================================================*/
1212

13+
/**
14+
* Generates and sends piwik statistics reports to admin users
15+
*/
1316
class 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+
?>

modules/statistics/controllers/forms/ConfigForm.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
2+
/** Form for configuring the statistics module */
23
class Statistics_ConfigForm extends AppForm
34
{
4-
55
/** create form */
66
public function createConfigForm()
77
{
@@ -24,4 +24,4 @@ public function createConfigForm()
2424
}
2525

2626
} // end class
27-
?>
27+
?>

modules/statistics/models/AppDao.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22

3+
/** Dao base class for the statistics module */
34
class Statistics_AppDao extends MIDAS_GlobalDao
4-
{
5-
public $_module='statistics';
6-
7-
} //end class
5+
{
6+
public $_module = 'statistics';
7+
} //end class
88

99
?>

modules/statistics/models/AppModel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
PURPOSE. See the above copyright notices for more information.
1111
=========================================================================*/
1212

13+
/** Base class for models in the statistics module */
1314
class Statistics_AppModel extends MIDASModel
1415
{
15-
public $moduleName='statistics';
16-
16+
public $moduleName = 'statistics';
1717
}
1818
?>

modules/statistics/models/base/DownloadBase.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,21 @@
1313
/** Download model base */
1414
class Statistics_DownloadModelBase extends Statistics_AppModel
1515
{
16-
16+
/** constructor */
1717
public function __construct()
1818
{
1919
parent::__construct();
2020
$this->_name = 'statistics_download';
2121
$this->_key = 'job_id';
2222

23-
$this->_mainData= array(
24-
'download_id'=> array('type'=>MIDAS_DATA),
25-
'item_id'=> array('type'=>MIDAS_DATA),
26-
'user_id'=> array('type'=>MIDAS_DATA),
27-
'ip'=> array('type'=>MIDAS_DATA),
28-
'date'=> array('type'=>MIDAS_DATA),
29-
'latitude'=> array('type'=>MIDAS_DATA),
30-
'longitude'=> array('type'=>MIDAS_DATA),
23+
$this->_mainData = array(
24+
'download_id' => array('type' => MIDAS_DATA),
25+
'item_id' => array('type' => MIDAS_DATA),
26+
'user_id' => array('type' => MIDAS_DATA),
27+
'ip' => array('type' => MIDAS_DATA),
28+
'date' => array('type' => MIDAS_DATA),
29+
'latitude' => array('type' => MIDAS_DATA),
30+
'longitude' => array('type' => MIDAS_DATA),
3131
'item' => array('type' => MIDAS_MANY_TO_ONE, 'model' => 'Item', 'parent_column' => 'item_id', 'child_column' => 'item_id'),
3232
'user' => array('type' => MIDAS_MANY_TO_ONE, 'model' => 'User', 'parent_column' => 'user_id', 'child_column' => 'user_id')
3333
);
@@ -76,15 +76,15 @@ public function addDownload($item, $user)
7676
private function _getGeolocation($ip)
7777
{
7878
if(function_exists('curl_init') == false)
79-
{
80-
$location['latitude'] = '';
81-
$location['longitude'] = '';
82-
return $location;
83-
}
79+
{
80+
$location['latitude'] = '';
81+
$location['longitude'] = '';
82+
return $location;
83+
}
8484

8585
$applicationConfig = parse_ini_file(BASE_PATH.'/core/configs/'.$this->moduleName.'.local.ini', true);
8686
$apiKey = $applicationConfig['global']['ipinfodb.apikey'];
87-
$url = "http://api.ipinfodb.com/v3/ip-city/?key=$apiKey&ip=$ip&format=json";
87+
$url = 'http://api.ipinfodb.com/v3/ip-city/?key='.$apiKey.'&ip='.$ip.'&format=json';
8888

8989
$curl = curl_init();
9090
curl_setopt($curl, CURLOPT_URL, $url);

modules/statistics/models/dao/DownloadDao.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
PURPOSE. See the above copyright notices for more information.
1111
=========================================================================*/
1212

13+
/** dao for the statistics_download model */
1314
class Statistics_DownloadDao extends Statistics_AppDao
14-
{
15-
public $_model='Download';
16-
17-
}
15+
{
16+
public $_model = 'Download';
17+
}
1818
?>

0 commit comments

Comments
 (0)