You are here

function timefield_weekly_summary_build_rows in Timefield 1.0.x

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

Add rows to the table

1 call to timefield_weekly_summary_build_rows()
TimeFieldMiniCalendar::viewElements in src/Plugin/Field/FieldFormatter/TimeFieldMiniCalendar.php
Builds a renderable array for a field value.

File

./timefield.module, line 395
Contains timefield.module.

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;
          $start_time = trim(timefield_integer_to_time($settings['display_format'], $v['value']));
          $end_time = trim(timefield_integer_to_time($settings['display_format'], $v['value2']));
          $renderer = \Drupal::service('renderer');
          $t = array(
            '#theme' => 'timefield_weekly_summary_minical_box',
            '#label' => $v['label'],
            '#time' => $start_time . '-' . $end_time,
          );
          $cell_data[$time_index][$index][] = new FormattableMarkup($renderer
            ->renderPlain($t), []);
        }
      }
      $row[$index] = array(
        'data' => [
          '#markup' => !empty($cell_data[$time_index][$index]) ? implode(' ', $cell_data[$time_index][$index]) : '',
        ],
      );
    }
    $rows[] = array(
      'data' => $row,
      'class' => array(
        'row-' . $count,
      ),
    );
    $count += 1;
  }
  return $rows;
}