Skip to content

Commit

Permalink
The tickets by source just kept acting freaky. Rebuilt the logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
Coen Coppens committed Jan 9, 2014
1 parent 29ed9df commit 8f7ea20
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 35 deletions.
61 changes: 34 additions & 27 deletions Model/Ticketsource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,51 +33,54 @@ 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;$y<count($newArray[0]);$y++){
$aList[$sSourceName][$sRecordDate] = 0;

$aList['dates'][$y] = $newArray[$x][$y]['Ticketsourcecount']['created'];
if ($y==0){
$aList[$x][$y] = $newArray[$x][$y]['Ticketsource']['name'];
}
}

$aList[$x][$y+1] = $newArray[$x][$y]['Ticketsourcecount']['count'];
$aList[$sSourceName][$sRecordDate] += $aHistoryRecord['Ticketsourcecount']['count'];
// End

}

}

}

}

// End
return $aList;

}
Expand Down
22 changes: 14 additions & 8 deletions View/Elements/Widgets/tickets_by_source.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ Highcharts.setOptions(Highcharts.ticketSource);
xAxis: {
categories: [
<?php
foreach ( $aData['dates'] as $aCount ) {
$ymd = DateTime::createFromFormat('Y-m-d', $aCount)->format('j M');
foreach ($aData['dates'] as $sDate) {
$ymd = DateTime::createFromFormat('Y-m-d', $sDate)->format('j M');
echo "'" . $ymd . "',";
}
?>
Expand Down Expand Up @@ -84,13 +84,19 @@ Highcharts.setOptions(Highcharts.ticketSource);

series: [
<?php
for($x=0;$x<count($aData)-1;$x++){
echo "{name: '" . $aData[$x][0] . "',";
echo "data: [";
for($y=1;$y<count($aData[0]);$y++){
echo $aData[$x][$y] . ", ";
foreach ($aData as $sSourceName => $aRecords) {

if ('dates' != $sSourceName) {

echo "{name: '" . $sSourceName . "',";
echo "data: [";
foreach ($aRecords as $iSourceCount){
echo $iSourceCount . ", ";
}
echo "]},";

}
echo "]},";

}
?>
]
Expand Down

0 comments on commit 8f7ea20

Please sign in to comment.