You are here

function TimefieldPluginStyleMinical::render in Timefield 7

Renders views

Overrides views_plugin_style::render

File

views/timefield_plugin_style_minical.inc, line 72
This file holds style plugin Timefield MiniCal

Class

TimefieldPluginStyleMinical
@class Extension of the Views Plugin Syle for

Code

function render() {
  $style_options = $this->view->style_options;
  $cal_data = !empty($style_options['data_source']) ? 'field_' . $style_options['data_source'] : NULL;
  $box_data = !empty($style_options['box_source']) ? $style_options['box_source'] : NULL;
  $raw_data = array();
  if ($cal_data) {
    $this
      ->render_fields($this->view->result);
    $raw_data = array();
    foreach ($this->view->result as $id => $result) {
      $times = !empty($result->{$cal_data}) ? $result->{$cal_data} : NULL;
      if (!empty($times)) {
        $description = $box_data ? $this->rendered_fields[$id][$box_data] : '';
        foreach ($times as $item) {
          $item['raw']['label'] = $description;
          $raw_data[] = $item['raw'];
        }
      }
    }
  }
  $settings = array(
    'display_format' => array(
      'separator' => ':',
      'period_separator' => '',
      'period' => 'a',
      'hour' => 'g',
      'minute' => 'i',
    ),
    'column_format' => array(
      'separator' => ':',
      'period_separator' => '',
      'period' => 'a',
      'hour' => 'g',
      'minute' => 'i',
    ),
    'first_day' => 'mon',
    'absolute_start' => '8:00 am',
    'absolute_end' => '10:00 pm',
    'range' => 120,
    'adjust_range' => FALSE,
  );
  if (!empty($raw_data)) {
    $header = _timefield_weekly_summary_build_header($settings['first_day']);
    $rows = timefield_weekly_summary_build_rows($raw_data, $header, $settings);
    $element = array(
      '#header' => $header,
      '#rows' => $rows,
      '#theme' => 'table',
    );
  }
  else {
    $element = array(
      '#markup' => 'No content',
    );
  }
  return drupal_render($element);
}