Skip to content

Commit

Permalink
Allow setting the tablename, phpdoc.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrubinsk committed Aug 9, 2016
1 parent db2618c commit 08c24ab
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions framework/Service_Weather/lib/Horde/Service/Weather/Metar.php
Expand Up @@ -28,20 +28,31 @@ class Horde_Service_Weather_Metar extends Horde_Service_Weather_Base
{
/**
* Database handle. Expects to have the following table available:
* - metarAirports
* - icao, name, country.
*
* @var Horde_Db_Adapter_Base
*/
protected $_db;

/**
* Name of table containing the NOAA METAR database.
*
* @var string
*/
protected $_tableName = 'horde_metar_airports';

/**
* Default paths to download weather data.
*
* @var string
*/
protected $_metar_path = 'http://tgftp.nws.noaa.gov/data/observations/metar/stations';
protected $_taf_path = 'http://tgftp.nws.noaa.gov/data/forecasts/taf/stations';

/**
* Local cache of locations.
*
* @var array
*/
protected $_locations;

/**
Expand Down Expand Up @@ -72,6 +83,9 @@ public function __construct(array $params = array())
if (!empty($params['taf_path'])) {
$this->_taf_path = $params['taf_path'];
}
if (!empty($params['table_name'])) {
$this->_tableName = $params['table_name'];
}
}

/**
Expand Down Expand Up @@ -176,6 +190,11 @@ public function getSupportedForecastLengths()
return array();
}

/**
* Return an array containing all available METAR locations/airports.
*
* @return array
*/
public function getLocations()
{
if (empty($this->_locations)) {
Expand All @@ -185,12 +204,17 @@ public function getLocations()
return $this->_locations;
}

/**
* Perform DB query to obtain list of airport codes.
*
* @return array
*/
protected function _getLocations()
{
if (empty($this->_db)) {
return array();
}
$sql = 'SELECT icao, name, country FROM metarAirports ORDER BY country';
$sql = 'SELECT icao, name, country FROM ' . $this->_tableName . ' ORDER BY country';
try {
return $this->_db->selectAll($sql);
} catch (Horde_Exception $e) {
Expand Down

0 comments on commit 08c24ab

Please sign in to comment.