2019-07-17 20:08:50 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2019-07-17 20:31:04 +00:00
|
|
|
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
|
2019-07-17 20:08:50 +00:00
|
|
|
* @license http://creativecommons.org/licenses/BSD/ BSD License
|
2019-07-17 20:31:04 +00:00
|
|
|
* @author Keyboard Monkeys Ltd.
|
|
|
|
* @since CommunityID 0.9
|
2019-07-17 20:08:50 +00:00
|
|
|
* @package CommunityID
|
|
|
|
* @packager Keyboard Monkeys
|
|
|
|
*/
|
|
|
|
|
2019-07-17 20:31:04 +00:00
|
|
|
class Authorizations extends Stats_Model_Report
|
2019-07-17 20:08:50 +00:00
|
|
|
{
|
2019-07-17 20:31:04 +00:00
|
|
|
public function getPriority()
|
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getTitle()
|
|
|
|
{
|
|
|
|
return $this->view->translate('Authorizations per day');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setTemplateVars()
|
2019-07-17 20:08:50 +00:00
|
|
|
{
|
|
|
|
$this->view->weekSelected = '';
|
|
|
|
$this->view->yearSelected = '';
|
|
|
|
|
2019-07-17 20:31:04 +00:00
|
|
|
switch ($this->_controllerAction->getRequest()->getParam('type')) {
|
2019-07-17 20:08:50 +00:00
|
|
|
case 'year':
|
|
|
|
$this->view->yearSelected = 'selected="true"';
|
|
|
|
$this->view->type = 'year';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$this->view->weekSelected = 'selected="true"';
|
|
|
|
$this->view->type = 'week';
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->view->rand = rand(0, 1000);
|
|
|
|
}
|
|
|
|
|
2019-07-17 20:31:04 +00:00
|
|
|
public function renderGraph()
|
2019-07-17 20:08:50 +00:00
|
|
|
{
|
|
|
|
require_once 'libs/jpgraph/jpgraph.php';
|
|
|
|
require_once 'libs/jpgraph/jpgraph_bar.php';
|
|
|
|
|
|
|
|
$graph = new Graph(300,200 ,'auto');
|
|
|
|
$graph->SetMarginColor('white');
|
|
|
|
$graph->SetFrame(false);
|
|
|
|
$graph->SetScale("textlin");
|
|
|
|
$graph->img->SetMargin(0,30,20,40);
|
|
|
|
$graph->yaxis->scale->SetGrace(20);
|
|
|
|
$graph->yaxis->HideLabels();
|
|
|
|
$graph->yaxis->HideTicks();
|
|
|
|
$graph->ygrid->SetFill(true,'#EFEFEF@0.5','#BBCCFF@0.5');
|
|
|
|
|
|
|
|
$labelsy = array();
|
|
|
|
$datay = array();
|
|
|
|
|
2019-07-17 20:31:04 +00:00
|
|
|
switch ($this->_controllerAction->getRequest()->getParam('type')) {
|
2019-07-17 20:08:50 +00:00
|
|
|
case 'year':
|
|
|
|
$this->_populateYearData($labelsy, $datay);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$this->_populateWeekData($labelsy, $datay);
|
|
|
|
}
|
|
|
|
|
|
|
|
$graph->xaxis->SetTickLabels($labelsy);
|
|
|
|
$bplot = new BarPlot($datay);
|
|
|
|
|
|
|
|
$bplot->SetFillGradient("navy","lightsteelblue",GRAD_WIDE_MIDVER);
|
|
|
|
$bplot->value->Show();
|
|
|
|
$bplot->value->SetFormat('%d');
|
|
|
|
$graph->Add($bplot);
|
|
|
|
|
|
|
|
$graph->Stroke();
|
|
|
|
}
|
|
|
|
|
|
|
|
private function _populateWeekData(&$labelsy, &$datay)
|
|
|
|
{
|
2019-07-17 20:16:19 +00:00
|
|
|
$stats = new Stats_Model_Stats();
|
2019-07-17 20:08:50 +00:00
|
|
|
$authorizations = $stats->getNumAuthorizationsDays(strtotime('-1 week'), time());
|
|
|
|
|
|
|
|
for ($i = -7; $i < 0; $i++) {
|
|
|
|
$time = strtotime("$i days");
|
|
|
|
$date = date('Y-m-d', $time);
|
2019-07-17 20:16:19 +00:00
|
|
|
$labelsy[] = Stats_Model_Stats::$weekDays[date('w', $time)];
|
2019-07-17 20:08:50 +00:00
|
|
|
if (isset($authorizations[$date])) {
|
|
|
|
$datay[] = $authorizations[$date]['entry'];
|
|
|
|
} else {
|
|
|
|
$datay[] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function _populateYearData(&$labelsy, &$datay)
|
|
|
|
{
|
2019-07-17 20:16:19 +00:00
|
|
|
$stats = new Stats_Model_Stats();
|
2019-07-17 20:08:50 +00:00
|
|
|
$firstDayOfMonth = date('Y-' . date('m') . '-01');
|
|
|
|
$authorizations = $stats->getNumAuthorizationsYear(strtotime('-11 months', strtotime($firstDayOfMonth)), time());
|
|
|
|
|
|
|
|
for ($i = -11; $i <= 0; $i++) {
|
|
|
|
$time = strtotime("$i months");
|
|
|
|
$monthNumber = date('n', $time);
|
2019-07-17 20:16:19 +00:00
|
|
|
$labelsy[] = Stats_Model_Stats::$months[$monthNumber];
|
2019-07-17 20:08:50 +00:00
|
|
|
if (isset($authorizations[$monthNumber])) {
|
|
|
|
$datay[] = $authorizations[$monthNumber]['entry'];
|
|
|
|
} else {
|
|
|
|
$datay[] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|