I have this module working great on a Drupal 5 site and I want to reduce the number of weather blocks displayed. I would like the weather block to switch between the node weather (if the node is locationally enabled), the user weather (if they have set their location) and finally the site weather.

To make it more clear: If the node has a location I want the only node weather to be displayed and take priority over all other weather blocks. If the node does not have a location and the user has set their location I want it to show the user weather block. If both the node and the user have no location I want it to show the site weather block.

Basically I only want to show one weather block per page but I want it to select based upon information that is available. Can you help?

Comments

keithmorr’s picture

I think that the solution to this is simply present all three of the blocks on the site and use PHP code to turn off the two that are not necessary. I think the code should be placed int the "Page specific visibility settings" section of the block but I cannot find the variables to use to turn it on or off. Like Node lat/lon, User lat/lon. These variable do not seem to be available at the block level. Can anyone help?

toddy’s picture

Status: Active » Closed (fixed)
scalp’s picture

I was looking for a solution to this and was able to make it work. I know this issue is closed, but hopefully it will help someone that finds it. I don't know if it will work on 5.x or not. This solution is being used in 6.x. This can be dropped into the "Show if the following PHP code returns TRUE" under "Show block on specific pages". Change the conditions as needed. I wanted to hide the site-wide weather block if a user had specified a location. I'm not sure what it does in the case of someone using the location module and the integration provided by this one. In my case I just needed it to check if someone had entered a location in the "My weather" tab of the user account page provided by this module.

<?php
global $user;
$val = TRUE;
$configs_in_use = _weather_get_configs_in_use($user->uid); //this checks for locations added by the user
      if (count($configs_in_use) > 0) {
        $val = FALSE;
      }
return $val;
?>
picacsso’s picture

This is great! Thank you scalp!

Since you're on the roll with this one, i wanted see if i could pick your brain for a minute or two if possible.

What I'm trying to accomplish is this:

Without creating new blocks for each location, how would you go about writing some code to display weather information based on users location(icao)? For example: I have two users, one in St. Louis, MO the other in Oklahoma City, OK. When MO user logs on the the website I want the weather block to display him St. Louis weather. If user is from OK and logs on, he should see Oklahoma City weather. I need one site-wide block to control all that.

I have user all over the states and creating blocks for each city wouldn't be a good option right now because of user volume.

Any suggestions/ideas will be highly appreciated.

Thanks again for the previous code block :)

scalp’s picture

ememic,

I'm glad that snippet helped. Unfortunately, I don't have a solution for you. I was originally actually trying to do the same thing, but never managed to get it to work. I ended up just adding a link to the bottom of the block that says "add/edit location" that takes the user to their weather page. If you come up with anything better definitely post back. It would be a great feature request if one hasn't been posted about it already.