Trends

Legend
END; $ds = "var chartdata = { \n"; foreach($table as $class) { $record = DataObject::get($class, "", "Created DESC"); $total = $record->TotalItems(); $props = $record->toArray(); $props = $props[0]->toMap(); $startyear = new DateTime($props['Created']); $startyear = $startyear->Format('Y'); $startmonth = new DateTime($props['Created']); $startmonth = $startmonth->Format('m'); if($filter == "day") { $days = new DateTime($props['Created']); $days = $days->Format('t'); $sum = 0; $ds .= "{$class}: ["; for($i = 1; $i <= $days; $i++) { foreach($record as $v) { $props = $v->toMap(); $currdate = new DateTime($props['Created']); $curryear = $currdate->Format('Y'); $currmonth = $currdate->Format('m'); $currday = $currdate->Format('j'); if($curryear == $startyear && $currmonth == $startmonth && $currday == $i) { $sum++; } } $ds .= "[".($i-1).", {$sum}], "; } $ds .= "[]],\n"; } else if($filter == "month") { $sum = 0; $ds .= "{$class}Set: ["; for($i = 0; $i <= 11; $i++) { $imonth = date('F', mktime(0,0,0,$i+1,1,1)); foreach($record as $v) { $props = $v->toMap(); $currdate = new DateTime($props['Created']); $curryear = $currdate->Format('Y'); $currmonth = $currdate->Format('m'); $currday = $currdate->Format('j'); if($curryear == $startyear && $currmonth == $i) { $sum++; } } $ds .= "[{$i}, {$sum}], "; } $ds .= "[]],\n"; } } $xt = "xTicks: ["; if($filter == "month") { for($i = 0; $i <= 11; $i++) { $imonth = date('F', mktime(0,0,0,$i+1,1,1)); $xt .= "{v:{$i}, label:'{$imonth}'}, "; } } else if($filter == "day") { for($i = 1; $i <= $days; $i++) { $xt .= "{v:".($i-1).", label:'{$i}'}, "; } } $opts = <<