function _quant_build_data_multiple in Quant 6
Generate chart data for a multiple data point over a time period
See also
File
- includes/
data.inc, line 14 - Functions used to convert Drupal data into chart format
Code
function _quant_build_data_multiple(&$quant) {
$data = array();
$dates = array();
// 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 96 days.
$format = $days > 75 ? QUANT_DATE_MONTH_FORMAT : QUANT_DATE_DAY_FORMAT;
// Whether or not to jump by day or month
$interval = $days > 75 ? 2629743 : 86400;
// Possibly convert days to months
$steps = $days > 75 ? $days / 30 : $days;
// Extract the field
$field = $quant->field;
// Extract the group field
$group = $quant->group;
// Place the items into an array for initial grouping by $group
// For example: $data['page'] = array('May 10', 'May 18');
while ($item = db_fetch_object($quant->items)) {
$data[$item->{$group}][] = date($format, $item->{$field});
}
// Iterate through each group of items and calculate the amount of
// items for each time period
foreach ($data as $type => $values) {
// Create a new array that's preformatted with a key for
// every single time period
$dates[$type] = _quant_build_date_array($start, $steps, $interval, $format);
// Increment for each time period
foreach ($values as $value) {
if (isset($dates[$type][$value])) {
$dates[$type][$value]++;
}
}
// Set in ascending order
$dates[$type] = array_reverse($dates[$type]);
}
// Remove the database resource
unset($quant->items);
$quant->data = $dates;
}