You are here

function theme_calendar_stripe_legend in Calendar 7.3

Same name and namespace in other branches
  1. 5.2 calendar.theme \theme_calendar_stripe_legend()
  2. 5 calendar.theme \theme_calendar_stripe_legend()
  3. 6.2 theme/theme.inc \theme_calendar_stripe_legend()
  4. 6.2 calendar_multiday/theme/theme.inc \theme_calendar_stripe_legend()
  5. 7 theme/theme.inc \theme_calendar_stripe_legend()
  6. 7 calendar_multiday/theme/theme.inc \theme_calendar_stripe_legend()
  7. 7.2 theme/theme.inc \theme_calendar_stripe_legend()
  8. 7.2 calendar_multiday/theme/theme.inc \theme_calendar_stripe_legend()

Format a node stripe legend.

1 theme call to theme_calendar_stripe_legend()
calendar_block_view in ./calendar.module
Implementation of hook_block_view().

File

theme/theme.inc, line 650
Theme functions for the Calendar module.

Code

function theme_calendar_stripe_legend($vars) {
  if (empty($vars) || !($view = $vars['view'])) {
    return '';
  }
  list($view_name, $display_id) = explode(':', $view);
  $view = views_get_view($view_name);
  $view
    ->set_display($display_id);
  $row_options = $view->display_handler
    ->get_option('row_options');
  $legend_type = $row_options['colors']['legend'];
  $display_options = $row_options['colors']['calendar_colors_' . $legend_type];
  $options = array();
  switch ($legend_type) {
    case 'type':
      $options = node_type_get_names();
      break;
    case 'taxonomy':
      $vocabularies = (array) $row_options['colors']['calendar_colors_vocabulary'];
      foreach ($vocabularies as $field_name => $vid) {
        $vocab = taxonomy_get_tree($vid);
        foreach ($vocab as $key => $term) {
          $options[$term->tid] = $term->name;
        }
      }
      break;
    case 'group':

      // The 7.1 version of OG.
      if (function_exists('og_label')) {
        $gids = og_get_all_group();
        foreach ($gids as $gid) {
          $options[$gid] = check_plain(t(og_label($gid)));
        }
      }
      else {
        $types = og_get_all_group_entity();
        foreach ($types as $entity_type => $name) {
          $gids = og_get_all_group($entity_type);
          $entities = entity_load($entity_type, $gids);
          foreach ($entities as $entity) {
            list($gid) = entity_extract_ids($entity_type, $entity);
            $options[$gid] = check_plain(t(entity_label($entity_type, $entity)));
          }
        }
      }
      break;
  }
  $header = array(
    array(
      'class' => 'calendar-legend',
      'data' => t('Item'),
    ),
    array(
      'class' => 'calendar-legend',
      'data' => t('Key'),
    ),
  );
  $rows = array();
  $output = '';
  foreach ($options as $key => $label) {
    $stripe = array_key_exists($key, $display_options) ? $display_options[$key] : CALENDAR_EMPTY_STRIPE;
    if ($stripe != CALENDAR_EMPTY_STRIPE) {
      $rows[] = array(
        $label,
        '<div style="background-color:' . $stripe . ';color:' . $stripe . '" class="stripe" title="Key: ' . $label . '">&nbsp;</div>',
      );
    }
  }
  if (!empty($rows)) {
    $variables = array(
      'header' => $header,
      'rows' => $rows,
      'attributes' => array(
        'class' => array(
          'mini',
          'calendar-legend',
        ),
      ),
    );
    $output .= theme('table', $variables);
    $output = '<div class="calendar legend">' . $output . '</div>';
  }
  return $output;
}