Is it possible use this module to display weather block to taxonomy term with Geofield?

Comments

pixelsweatshop’s picture

I would love to see this as well.

We need to modify the following code to make that happen. @toddy any thoughts?

   case 'geofield':
      if (user_access('access content')) {
        // Set up the node geofield weather block.
        if (arg(0) == 'node' and is_numeric(arg(1))) {
          $node = node_load(arg(1));
          $block['subject'] = t('Weather nearby');
          $block['content'] = '';
          $display = weather_get_display_config('default');
          $display->detailed = FALSE;
          // Get a list of all field names which are geofield fields.
          $geofield_field_names = db_select('field_config', 'fc')
            ->fields('fc', array('field_name'))
            ->condition('type', 'geofield', '=')
            ->execute()
            ->fetchCol();
          foreach ($geofield_field_names as $geofield_field_name) {
            if (isset($node->$geofield_field_name)) {
              // The node has geofield fields, determine if there's usable data.
              // First cycle through the language codes (will mostly be 'und').
              foreach ($node->$geofield_field_name as $language) {
                // Now cycle through the different locations.
                foreach ($language as $location) {
                  if (($location['lat'] != 0) or ($location['lon'] != 0)) {
                    $place = weather_get_nearest_station($location['lat'], $location['lon']);
                    $forecasts = weather_get_weather($place->geoid, $forecast_days, $display->detailed);
                    $weather[0]['forecasts'] = $forecasts['forecasts'];
                    $weather[0]['utc_offset'] = $forecasts['utc_offset'];
                    $weather[0]['name'] = $place->displayed_name;
                    $weather[0]['geoid'] = $place->geoid;
                    $link = _weather_get_link_for_geoid($place->geoid, 'default');
                    $weather[0]['link'] = l($place->displayed_name, $link);
                    $link = _weather_get_link_for_geoid($place->geoid, 'yr.no');
                    $weather[0]['yr.no'] = $link;
                    $weather[0]['station'] = array('distance' => $place->distance, 'bearing' => $place->bearing);
                    $block['content'] = theme('weather_forecast_preprocess',
                      array('weather' => $weather, 'display' => $display));
                  }
                }
              }
            }
          }
          // Do not show block if no lat/long information has been found.
          if (empty($block['content'])) {
            return;
          }
        }
      }
kodo’s picture

Thank you

I add this code to module (hardcode sorry)

function weather_block_info() {
....
  $blocks['geofieldterm'] = array(
    'info' => t('Weather: location of terms (requires Geofield module)'),
  );
....
return $blocks;
}

and

function weather_block_view($delta = '') {
.....
case 'geofieldterm':
      if (user_access('access content')) {
        // Set up the node geofield weather block.
  		if(arg(0) == 'taxonomy' && arg(1) == 'term') {
          $tid = (int)arg(2);
          $term = taxonomy_term_load($tid);
		
//        if (arg(0) == 'node' and is_numeric(arg(1))) {
//          $node = node_load(arg(1));
          $block['subject'] = t('Weather nearby');
          $block['content'] = '';
          $display = weather_get_display_config('default');
          $display->detailed = FALSE;
          // Get a list of all field names which are geofield fields.
          $geofield_field_names = db_select('field_config', 'fc')
            ->fields('fc', array('field_name'))
            ->condition('type', 'geofield', '=')
            ->execute()
            ->fetchCol();
          foreach ($geofield_field_names as $geofield_field_name) {
            if (isset($term->$geofield_field_name)) {
              // The node has geofield fields, determine if there's usable data.
              // First cycle through the language codes (will mostly be 'und').
              foreach ($term->$geofield_field_name as $language) {
                // Now cycle through the different locations.
                foreach ($language as $location) {
                  if (($location['lat'] != 0) or ($location['lon'] != 0)) {
                    $place = weather_get_nearest_station($location['lat'], $location['lon']);
                    $forecasts = weather_get_weather($place->geoid, $forecast_days, $display->detailed);
                    $weather[0]['forecasts'] = $forecasts['forecasts'];
                    $weather[0]['utc_offset'] = $forecasts['utc_offset'];
                    $weather[0]['name'] = $place->displayed_name;
                    $weather[0]['geoid'] = $place->geoid;
                    $link = _weather_get_link_for_geoid($place->geoid, 'default');
                    $weather[0]['link'] = l($place->displayed_name, $link);
                    $link = _weather_get_link_for_geoid($place->geoid, 'yr.no');
                    $weather[0]['yr.no'] = $link;
                    $weather[0]['station'] = array('distance' => $place->distance, 'bearing' => $place->bearing);
                    $block['content'] = theme('weather_forecast_preprocess',
                      array('weather' => $weather, 'display' => $display));
                  }
                }
              }
            }
          }
          // Do not show block if no lat/long information has been found.
          if (empty($block['content'])) {
            return;
          }
        }
      }
      break;
.....

It will be great if Maintainers add term support to this module

toddy’s picture

Assigned: kodo » toddy
Status: Active » Fixed

Hi, this is implemented in the latest release, thanks for providing the patch.

Regards,
Tobias

  • 4dce9e7 committed on 7.x-2.x
    Issue #2390721 by kodo: Add support for location of taxonomy terms
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.