You are here

function yr_verdata_block in Yr Weatherdata 6

Same name and namespace in other branches
  1. 6.2 yr_verdata.module \yr_verdata_block()

Implementation of hook_block().

File

./yr_verdata.module, line 115
yr_verdata.module This file provides the yr_verdata forecast module.

Code

function yr_verdata_block($op = 'list', $delta = 0, $edit = array()) {
  $rows = yr_verdata_locations();
  switch ($op) {
    case 'list':
      if (variable_get('yr_verdata_multiblock', 'off') == 'on') {
        foreach ($rows as $location) {
          $loc_name = $location->subregion . ', ' . $location->region . ', ' . $location->country;
          if (!empty($location->location)) {
            $loc_name = $location->location . ', ' . $loc_name;
          }
          $blocks[$location->yid]['info'] = t('Forecast for ') . $loc_name;
        }
      }
      $blocks[0]['info'] = t('Yr.no Weather Forecast');
      return $blocks;
    case 'view':
      if (user_access('access content')) {
        if (variable_get('yr_verdata_multiblock', 'off') == 'on') {
          foreach ($rows as $row) {
            if ($delta == $row->yid) {
              $loc_name = empty($row->location) ? $row->subregion : $row->location;
              $block['subject'] = t('Forecast for ') . $loc_name;
              $block['content'] = theme('yr_verdata_location_block', $row);
            }
          }
        }
        if ($delta == 0) {
          $block['subject'] = t('Weather Forecast');
          $block['content'] = theme('yr_verdata_location_block', $rows);
        }
      }
      return $block;
  }
}