You are here

function timefield_weekly_summary_build_rows in Timefield 7

Same name and namespace in other branches
  1. 1.0.x timefield.module \timefield_weekly_summary_build_rows()

Add rows to the table

2 calls to timefield_weekly_summary_build_rows()
TimefieldPluginStyleMinical::render in views/timefield_plugin_style_minical.inc
Renders views
timefield_field_formatter_view in ./timefield.module
Implements hook_field_formatter_view().

File

./timefield.module, line 1352
Defines a Field API field for time

Code

function timefield_weekly_summary_build_rows($item, $header, $settings) {
  _timefield_weekly_summary_explode_items($item);
  $times = _timefield_weekly_summary_build_time_column($settings);
  $abs_start = timefield_time_to_integer($settings['absolute_start']);
  $abs_end = timefield_time_to_integer($settings['absolute_end']);
  $total_range = $abs_end - $abs_start;
  $cell_data = array();
  $count = 0;
  foreach ($times as $time_index => $time) {
    $row['time'] = array(
      'data' => $time['display'],
    );
    if (!isset($cell_data[$time_index])) {
      $cell_data[$time_index] = array();
    }
    foreach ($header as $index => $label) {
      if ($index == 'time') {
        continue;
      }
      if (!isset($cell_data[$time_index][$index])) {
        $cell_data[$time_index][$index] = array();
      }
      foreach ($item as $i => $v) {
        if ($v['value'] >= $time['start'] && $v['value'] < $time['stop'] && $v[$index] == '1') {
          $row_data = array(
            'element' => $v,
            'settings' => $settings,
            'day' => array(
              $index => $label,
            ),
          );
          $row_data['span_time'] = ($v['value2'] - $v['value']) / $total_range * 100;
          $row_data['offset_time'] = ($v['value'] - $abs_start) / $total_range * 100;
          $cell_data[$time_index][$index][] = theme('timefield_weekly_summary_minical_box', $row_data);
        }
      }
      $row[$index] = array(
        'data' => !empty($cell_data[$time_index][$index]) ? implode(' ', $cell_data[$time_index][$index]) : '',
      );
    }
    $rows[] = array(
      'data' => $row,
      'class' => array(
        'row-' . $count,
      ),
    );
    $count += 1;
  }
  return $rows;
}