asked on
$data = pf::getAppData('/app/accounttimeline');
$timeline = AccountTimelines::getAccountTimeline($accountid); //the SELECT statement that produces the sample data I've got listed above
$data['timeline'] = array();
$txnGroup = array();
for ($i=0; $i < count($timeline); $i++) {
$event = $timeline[$i];
$event['demo'] = ($data['badge']['practiceid'] == '63'?$accountid : false);
if ($event['eventtype']=='transaction') {
$thisDate = Date('mdy', strToTime($event['eventdate']));
$nextDate = (isset($timeline[$i+1])&&$timeline[$i+1]['eventtype']=='transaction')?Date('mdy', strToTime($timeline[$i+1]['eventdate'])):null;
array_push($txnGroup, $event);
if ($thisDate != $nextDate) {
//add to data
if (count($txnGroup)!=1) {
array_push($data['timeline'], array(
'eventdate'=>Date('m/d/Y', strToTime($event['eventdate'])),
'eventtype'=>'transactions',
'runningbal'=>$event['runningbal'],
'transactions'=>$txnGroup
));
} else {
array_push($data['timeline'], $event);
}
$txnGroup = array();
}
if ($event['eventtype']=='transaction') {//if the eventtype is a "transaction," then...
$thisDate = Date('mdy', strToTime($event['eventdate'])); //set up $thisDate as a strtotime variable
$nextDate = (isset($timeline[$i+1])&&$timeline[$i+1]['eventtype']=='transaction')?Date('mdy', strToTime($timeline[$i+1]['eventdate'])):null;//[b]if the next eventtype in the recordset is also a "transaction," then...not sure what this is doing[/b]
array_push($txnGroup, $event);// you're using array_push to add everything that's currently compiled in the $event index to the $txnGroup array
if ($thisDate != $nextDate) {//[b]if $thisData is not equal to $nextDate, then you've got a potential group of transactions as opposed to something that's flying solo[/b]
//add to data
if (count($txnGroup)!=1) {//if the there's more than one transaction in the $txnGroup, then we're going to make the eventtype "transactions," rather than "transaction"
array_push($data['timeline'], array(//push all of the following into the $txnGroup array
'eventdate'=>Date('m/d/Y', strToTime($event['eventdate'])),
'eventtype'=>'transactions',
'runningbal'=>$event['runningbal'],
'transactions'=>$txnGroup
));
}
}else {//if the eventtype is not a "transaction," then simply push what's there into the $event
array_push($data['timeline'], $event);
}
$txnGroup = array();//I think what's happening here is that I'm resetting the $txnGroup array to "". Rather than it being populated with anything, I'm starting fresh with the next round of $I in my "for" loop