function _quant_build_data_single in Quant 6
Generate chart data for a singular data point across a time period
See also
File
- includes/
data.inc, line 70 - Functions used to convert Drupal data into chart format
Code
function _quant_build_data_single(&$quant) {
// Extract the days
$days = $quant->days;
// Extract the period
$period = $quant->period;
// Determine when the starting time is
$start = is_array($period) ? $period[1] : time();
// The date() format to use. We compare by month if there are more than 183 days.
$format = $days > 183 ? QUANT_DATE_MONTH_FORMAT : QUANT_DATE_DAY_FORMAT;
// Whether or not to jump by day or month
$interval = $days > 183 ? 2629743 : 86400;
// Possibly convert days to months
$steps = $days > 183 ? $days / 30 : $days;
// Extract the database field
$field = $quant->field;
// Create a new array that's preformatted with a key for
// every single time period
$dates = _quant_build_date_array($start, $steps, $interval, $format);
// Calculate the amount of occurrences per time period
while ($item = db_fetch_object($quant->items)) {
if (isset($dates[date($format, $item->{$field})])) {
$dates[date($format, $item->{$field})]++;
}
}
// Set in ascending order
$dates = array_reverse($dates);
// Remove the database resource
unset($quant->items);
$quant->data = $dates;
}