Skip to content

Commit bf10a40

Browse files
author
Nicholas K. Dionysopoulos
committed
~ Slightly less wonky backend downloads graph
1 parent 0aebd72 commit bf10a40

File tree

3 files changed

+22
-26
lines changed

3 files changed

+22
-26
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
* Protection of all component and plugin folders against direct web access
66
* Update for new FOF 3 behavior regarding backend and frontend caching
7+
* Slightly less wonky backend downloads graph
78

89
**Bug fixes**
910

component/backend/Model/ControlPanel.php

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -408,27 +408,18 @@ public function getMonthlyStats()
408408
{
409409
$db = $this->container->db;
410410

411-
$now = $this->container->platform->getDate();
412-
413-
// I need to do this since if I'm on March 30th and I go back of a month I would got February 30th
414-
// that will we shifted to March 2nd. This is not a bug (!!!) it's the expected behavior of PHP (!!!!!!!)
415-
if (date('d') > date('d', strtotime('last day of -1 month')))
416-
{
417-
$last_month = $this->container->platform->getDate(date('Y-m-d', strtotime('last day of -1 month')));
418-
}
419-
else
420-
{
421-
$last_month = $this->container->platform->getDate(date('Y-m-d', strtotime('-1 month')));
422-
}
411+
$now = $this->container->platform->getDate();
412+
$last_month = $this->container->platform->getDate();
413+
$last_month->sub(new \DateInterval('P35D'));
423414

424415
$query = $db->getQuery(true)
425-
->select(array(
426-
'DATE(' . $db->qn('accessed_on') . ') AS ' . $db->qn('day'),
427-
'COUNT(*) AS ' . $db->qn('dl')
428-
))
429-
->from($db->qn('#__ars_log'))
430-
->where($db->qn('accessed_on') . ' BETWEEN ' . $db->q($last_month->toSql()) . ' AND ' . $db->q($now->toSql()))
431-
->order($db->qn('accessed_on') . ' ASC');
416+
->select([
417+
'DATE(' . $db->qn('accessed_on') . ') AS ' . $db->qn('day'),
418+
'COUNT(*) AS ' . $db->qn('dl'),
419+
])
420+
->from($db->qn('#__ars_log'))
421+
->where($db->qn('accessed_on') . ' BETWEEN ' . $db->q($last_month->toSql()) . ' AND ' . $db->q($now->toSql()))
422+
->order($db->qn('accessed_on') . ' ASC');
432423

433424
if ($db->name == 'postgresql')
434425
{
@@ -444,12 +435,12 @@ public function getMonthlyStats()
444435

445436
if (is_null($data))
446437
{
447-
$data = array();
438+
$data = [];
448439
}
449440

450441
$nowParts = getdate();
451-
$today = mktime(0, 0, 0, $nowParts['mon'], $nowParts['mday'], $nowParts['year']);
452-
$ret = array();
442+
$today = mktime(0, 0, 0, $nowParts['mon'], $nowParts['mday'], $nowParts['year']);
443+
$ret = [];
453444

454445
for ($i = 30; $i >= 0; $i--)
455446
{

component/backend/View/ControlPanel/tmpl/graphs.blade.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,20 @@
1010
/** @var \Akeeba\ReleaseSystem\Admin\View\ControlPanel\Html $this */
1111
1212
$pointsJavascript = '';
13+
$min = null;
14+
$max = null;
1315
1416
foreach ($this->monthlyDailyReport as $pointDate => $pointDownloads)
1517
{
18+
$min = is_null($min) ? $pointDate : $min;
19+
$max = $pointDate;
1620
$pointDate = $this->escape($pointDate);
17-
$pointDownloads = (int)$pointDownloads;
21+
$pointDownloads = (int) $pointDownloads;
1822
1923
$pointsJavascript .= <<< JS
2024
dlPoints.push(['$pointDate', parseInt('$pointDownloads' * 100) * 1 / 100]);
2125
2226
JS;
23-
2427
}
2528
2629
$js = <<< JS
@@ -36,8 +39,9 @@
3639
show: true,
3740
axes: {
3841
xaxis: {
39-
renderer: $.jqplot.DateAxisRenderer,
40-
tickInterval: '1 week'
42+
min: '{$min}',
43+
max: '{$max}',
44+
renderer: $.jqplot.DateAxisRenderer
4145
},
4246
yaxis: {min: 0, tickOptions: {formatString: '%u'}}
4347
},

0 commit comments

Comments
 (0)