You are here

function yr_verdata_block_info in Yr Weatherdata 7

Implementation of hook_block_info().

File

./yr_verdata.module, line 298
yr_verdata.module This file contains the code for getting the forecast from yr.no and displaying it on a Drupal site.

Code

function yr_verdata_block_info() {

  // The default block.
  $blocks['yr_verdata_block'] = array(
    'info' => t('Yr weather forecast for all locations'),
    'cache' => DRUPAL_CACHE_PER_ROLE,
    'visibility' => 0,
    'pages' => 'forecast*',
  );

  // If multiple blocks are enabled, create a block for each location.
  if (variable_get('yr_verdata_multiblocks', 'off') == 'on') {
    $result = db_query("SELECT * FROM {yr_verdata} ORDER BY name ASC");
    $records = $result
      ->fetchAll();
    foreach ($records as $record) {
      $load = yr_verdata_load_location($record->yid);
      $location = $load['data'];
      $name = yr_verdata_resolve_name($record);
      if ($load['status'] == TRUE) {
        $blocks['yr_verdata_block_' . $record->yid] = array(
          'info' => t('Yr weather forecast for @location', array(
            '@location' => $name,
          )),
          'cache' => DRUPAL_CACHE_PER_ROLE,
          'visibility' => 0,
          'pages' => 'forecast*',
        );
      }
    }
  }

  // If the random block option is enabled, show that one as well.
  if (variable_get('yr_verdata_randomblock', 'off') == 'on') {
    $blocks['yr_verdata_randomblock'] = array(
      'info' => t('Yr random weather forecast'),
      'visibility' => 0,
      'pages' => 'forecast*',
      'cache' => DRUPAL_NO_CACHE,
    );
  }
  return $blocks;
}