Changeset 90


Ignore:
Timestamp:
06/01/07 18:31:43 (5 years ago)
Author:
nigel
Message:

Added settings screen and improved _page hook

File:
1 edited

Legend:

Unmodified
Added
Removed
  • openweather/openweather.module

    r89 r90  
    121121} 
    122122 
     123/** 
     124 * _page hook 
     125 * Display official stats, and a list of weather stations w/ stats 
     126 */ 
    123127function openweather_page() { 
    124128  global $user; 
     
    127131 
    128132  // If there is official weather get it 
    129   $radarURL = get_variable('openweather_radar', null); 
     133  $radarURL = variable_get('openweather_radar', null); 
    130134  if ($radarURL != null) $output .= "<img src='$radarURL'/>"; 
    131135 
     
    136140  $output .= '<ul>'; 
    137141  while ($node = db_fetch_object($result)) { 
    138     $output .= '<li>'. l($node->title, "node/$node->nid") .'</li>'; 
     142    $output .= '<li>'. l($node->title, "node/$node->nid").openweather_summary($node->nid) .'</li>'; 
    139143  } 
    140144  $output .= '</ul>'; 
    141145  $output .= theme("pager", NULL, 15); 
    142146  return $output; 
     147} 
     148 
     149function openweather_settings() { 
     150  $form['openweather_radar'] = array( 
     151    '#type'=>'textfield', 
     152    '#title'=>t('URL for weather radar'), 
     153    '#default_value'=>variable_get('openweather_radar', '')); 
     154 
     155  return $form; 
    143156} 
    144157 
     
    195208 
    196209/** 
     210  * Summary table of weather station feed 
     211  */ 
     212function openweather_summary($nid){ 
     213  $data = db_query("SELECT * FROM {openweather_readings} WHERE nid = $nid ORDER BY `time` DESC LIMIT 1"); 
     214  $data = db_fetch_object($data); 
     215 
     216  $output .= "<table>"; 
     217  $output .= "<tr><th>Temperature</th><td>$data->temp_out dec C</td><th>Humidity</th><td>$data->rel_hum_out %</td></tr>"; 
     218  $output .= "<tr><th>Wind speed</th><td>$data->windspeed kMh</td><th>Wind direction</th><td>".openweather_to_direction($data->wind_angle)."($data->wind_angle)</td></tr>"; 
     219  $output .= "<tr><th>Relative pressure</th><td>$data->rel_pressure</td><th>Timestamp</th><td>$data->time</td></tr>"; 
     220  $output .= "</table>"; 
     221  return $output; 
     222} 
     223 
     224/** 
    197225 * Implementation of hook_view(). 
    198226 * 
     
    209237  $links[] = l(t('export readings'), 'node/'.$node->nid.'/csv_readings',array('title'=>'Export the openweather readings as CSV')); 
    210238 
    211   $data = db_query("SELECT * FROM {openweather_readings} WHERE nid = $node->nid ORDER BY `time` DESC LIMIT 1"); 
    212   $data = db_fetch_object($data); 
    213  
    214   $output .= "<table>"; 
    215   $output .= "<tr><th>Temperature</th><td>$data->temp_out dec C</td><th>Humidity</th><td>$data->rel_hum_out %</td></tr>"; 
    216   $output .= "<tr><th>Wind speed</th><td>$data->windspeed kMh</td><th>Wind direction</th><td>".openweather_to_direction($data->wind_angle)."($data->wind_angle)</td></tr>"; 
    217   $output .= "<tr><th>Relative pressure</th><td>$data->rel_pressure</td><th></th><td></td></tr>"; 
    218   $output .= "</table>"; 
     239  $output .= openweather_summary($node->nid); 
    219240 
    220241  $output .= "<img src='?q=node/".$node->nid."/graph/temp_out' />"; 
Note: See TracChangeset for help on using the changeset viewer.