HRDIODB
[ class tree: HRDIODB ] [ index: HRDIODB ] [ all elements ]

Source for file uars_day_class.php

Documentation is available at uars_day_class.php

  1. <?php
  2. /**
  3.  * UARS Day Class.
  4.  * This file contains the uars_day class.
  5.  * @package HRDIODB
  6.  */
  7.  
  8. /**
  9.  * This file is part of HRDIODB.
  10.  *
  11.  * HRDIODB is free software; you can redistribute it and/or modify
  12.  * it under the terms of the GNU General Public License as published by
  13.  * the Free Software Foundation; either version 2 of the License, or
  14.  * (at your option) any later version.
  15.  *
  16.  * HRDIODB is distributed in the hope that it will be useful,
  17.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.  * GNU General Public License for more details.
  20.  *
  21.  * You should have received a copy of the GNU General Public License
  22.  * along with HRDIODB; if not, write to the Free Software
  23.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  24.  */
  25.  
  26. /**
  27.  * UARS day class.
  28.  * An object of this class represents one UARS day.
  29.  * @package HRDIODB
  30.  */
  31. class uars_day {
  32.   /**
  33.    * Any error that gets generated.
  34.    * @var string 
  35.    */
  36.   var $error;
  37.  
  38.   /**
  39.    * HRDI database instance.
  40.    * @var hrdi_db 
  41.    */
  42.   var $hdb;
  43.  
  44.   /**
  45.    * UARS day instance.
  46.    * @var uars_day 
  47.    */
  48.   var $day;
  49.  
  50.   /**
  51.    * The day's unix time stamp.
  52.    * @var integer 
  53.    */
  54.   var $day_ts;
  55.  
  56.   /**
  57.    * The day's data.
  58.    * @var array 
  59.    */
  60.   var $data = array();
  61.  
  62.   /**
  63.    * The day's modes.
  64.    * @var array 
  65.    */
  66.   var $modes = array();
  67.  
  68.   /**
  69.    * Newest UARS day in the database.
  70.    * @var $days 
  71.    */
  72.   var $newest;
  73.  
  74.   /**
  75.    * The day's files.
  76.    * @var array 
  77.    */
  78.   var $files = array();
  79.  
  80.   /**
  81.    * The day's links
  82.    * @var array 
  83.    */
  84.   var $links = array();
  85.  
  86.   /**
  87.    * Constructor.
  88.    * Takes a {@link hrdi_db} class instance and a UARS day as arguments and
  89.    * populates the object with data for that day.
  90.    * @param hrdi_db $hdb The hrdi_db instance
  91.    * @param integer $day The UARS day
  92.    * @return FALSE if an error is encountered
  93.    */
  94.   function uars_day (&$hdb$day{
  95.     global $day1_ts;
  96.  
  97.     $this->hdb = $hdb;
  98.     $this->day = $day;
  99.  
  100.     $this->day_ts = mktime(0,0,0,date('m',$day1_ts),date('d',$day1_ts$this->day - 1,date('Y',$day1_ts));
  101.  
  102.     // Pull day data
  103.     $sql "SELECT *
  104.             FROM HRDI_Days
  105.             WHERE UARS_Day = {$this->day}";
  106.     $this->data = $this->hdb->get_row($sql);
  107.  
  108.     // Pull day modes
  109.     $sql "SELECT *
  110.             FROM HRDI_Modes
  111.             WHERE UARS_Day = {$this->day}
  112.             ORDER BY Process_ID";
  113.     $this->modes = $this->hdb->get_list($sql);
  114.  
  115.     // Get the newest UARS day from the database
  116.     $sql "SELECT UARS_Day
  117.             FROM HRDI_Days
  118.             ORDER BY UARS_Day DESC
  119.             LIMIT 1";
  120.     $this->newest = $this->hdb->get_one($sql)
  121.  
  122.     // Pull day files
  123.     $sql "SELECT F.FilenameFT.Description
  124.             FROM HRDI_Files FHRDI_FileTypes FT
  125.             WHERE F.UARS_Day = {$this->day}
  126.             AND F.Type = FT.ID
  127.             ORDER BY Type";
  128.     $this->files = $this->hdb->get_list($sql);
  129.  
  130.     // Pull day links
  131.     $sql "SELECT *
  132.             FROM HRDI_Links
  133.             WHERE UARS_Day = {$this->day}";
  134.     $this->links = $this->hdb->get_list($sql);
  135.  
  136.     // Perform all the UARS day date math
  137.     $this->data['Year'date('Y'$this->day_ts);
  138.     $this->data['Day_Of_Year'date('z'$this->day_ts1;
  139.     $this->data['Date'date('d-M-Y'$this->day_ts);
  140.     $this->data['Day_Of_Week'date('l'$this->day_ts);
  141.     $this->data['DoW_Numeric'date('w'$this->day_ts);
  142.  
  143.     switch($this->data['Flight_Direction']){
  144.     case "F":
  145.         $this->display_data['Flight_Direction'"Forward";
  146.         break;
  147.     case "B":
  148.         $this->display_data['Flight_Direction'"Backward";
  149.         break;
  150.     case "M":
  151.         $this->display_data['Flight_Direction'"Maneuver";
  152.         break;
  153.     default:
  154.         break;    
  155.     }    
  156.  
  157.     // Populate certain empty field values with the &mdash; entity
  158.     foreach (array_keys($this->dataas $key{
  159.       if (!strncmp($key, "pcnt_", 5) || !strncmp($key, "cov_", 4)) {
  160.     // JMR -- We decided to ignore the 'Data_Valid' field for this display
  161. //         if (!$this->data['Data_Valid'] || ($this->data[$key] == -999.00)) {
  162. //           $this->data[$key] = '&nbsp;&nbsp;&nbsp;&mdash;&nbsp;&nbsp;&nbsp;';
  163. //         }
  164.         if ($this->data[$key== -999.00{
  165.           $this->data[$key'&nbsp;&nbsp;&nbsp;&mdash;&nbsp;&nbsp;&nbsp;';
  166.         }
  167.       }
  168.     }
  169.   }
  170.  
  171.   /**
  172.    * Save updated UARS Day data.
  173.    * This method will save/update a UARS Day with the given data values. It
  174.    * does data verification before processing the update.
  175.    * @param array $data Associate array of key/value pairs
  176.    * @return TRUE|FALSE Status of db update
  177.    */
  178.   function save ($data) {
  179.     if (!isset($data['UARS_Day'])) {
  180.       $this->error = "Not saved! UARS_Day was missing!";
  181.       return FALSE;
  182.     }
  183.  
  184.     if (strlen($data['Beta_Angle']) && !is_numeric($data['Beta_Angle'])) {
  185.       $this->error = "Not saved! Beta Angle must be a number!";
  186.       return FALSE;
  187.     }
  188.  
  189.     // More verifications can/should go here
  190.     
  191.     // Done forget to strip slashes
  192.     $data['Comments'] = stripslashes($data['Comments']);
  193.  
  194.     if ($data['Data_Valid'] == "NULL") {
  195.       $data['Data_Valid'] = NULL;
  196.     }
  197.  
  198.     return $this->hdb->update($data"HRDI_Days""UARS_Day");
  199.   }
  200. }

Documentation generated on Tue, 23 Jan 2007 22:57:53 -0500 by phpDocumentor 1.3.0RC6