From 8f7ea2005ac6b10b28b474d2a9d7d199cd47b74d Mon Sep 17 00:00:00 2001 From: Coen Coppens Date: Thu, 9 Jan 2014 15:39:27 +0100 Subject: [PATCH] The tickets by source just kept acting freaky. Rebuilt the logic. --- Model/Ticketsource.php | 61 ++++++++++++--------- View/Elements/Widgets/tickets_by_source.ctp | 22 +++++--- 2 files changed, 48 insertions(+), 35 deletions(-) diff --git a/Model/Ticketsource.php b/Model/Ticketsource.php index 1b7edd0..ef982ef 100644 --- a/Model/Ticketsource.php +++ b/Model/Ticketsource.php @@ -15,6 +15,10 @@ class Ticketsource extends AutotaskAppModel { public function getTotals(Array $aQueueIds) { + $aList = array( + 'dates' => array() + ); + $iDaysToGoBack = Configure::read('Widget.RollingWeek.daysOfHistory')-1; if (-1 == $iDaysToGoBack) { $iDaysToGoBack = 6; @@ -29,43 +33,47 @@ public function getTotals(Array $aQueueIds) { ) )); - $iAmountOfSources = count($aSourceList); + if (!empty($aSourceList)) { - $newArray = array(); + foreach ($aSourceList as $aSource) { - for ($x=0;$x<$iAmountOfSources;$x++) { + $aHistory = $this->Ticketsourcecount->find('all', array( + 'conditions' => array( + 'ticketsource_id' => $aSource['Ticketsource']['id'] + , 'created >=' => date('Y-m-d', strtotime("-" . $iDaysToGoBack . " days")) + , 'queue_id' => $aQueueIds + ) + , 'order' => array( + 'created ASC' + ) + )); - $aHistory = $this->Ticketsourcecount->find('all', array( - 'conditions' => array( - 'ticketsource_id' => $aSourceList[$x]['Ticketsource']['id'] - , 'created >=' => date('Y-m-d', strtotime("-" . $iDaysToGoBack . " days")) - , 'queue_id' => $aQueueIds - ) - , 'order' => array( - 'created ASC' - ) - )); + if (!empty($aHistory)) { - if (!empty($aHistory)) { - array_unshift($newArray,$aHistory); - } + foreach ($aHistory as $aHistoryRecord) { - } + // Add the date to the list of available dates. + // You should only have to do this for the first source - all other sources have the same dates (I know, assumption..) + $sRecordDate = $aHistoryRecord['Ticketsourcecount']['created']; - $aList = array(); + if (!in_array($sRecordDate, $aList['dates'])) { + $aList['dates'][] = $sRecordDate; + } + // End - if (!empty($newArray[0])) { + // Add the # of tickets for the source to the list. + $sSourceName = $aHistoryRecord['Ticketsource']['name']; - for ($x=0;$x<$iAmountOfSources;$x++){ + if (!isset($aList[$sSourceName][$sRecordDate])) { - for ($y=0;$yformat('j M'); + foreach ($aData['dates'] as $sDate) { + $ymd = DateTime::createFromFormat('Y-m-d', $sDate)->format('j M'); echo "'" . $ymd . "',"; } ?> @@ -84,13 +84,19 @@ Highcharts.setOptions(Highcharts.ticketSource); series: [ $aRecords) { + + if ('dates' != $sSourceName) { + + echo "{name: '" . $sSourceName . "',"; + echo "data: ["; + foreach ($aRecords as $iSourceCount){ + echo $iSourceCount . ", "; + } + echo "]},"; + } - echo "]},"; + } ?> ]