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

Source for file mode_class.php

Documentation is available at mode_class.php

  1. <?php
  2. /**
  3.  * UARS Day mode.
  4.  * This file contains the {@link mode} class, which represents a specific
  5.  * UARS Day mode.
  6.  * @package HRDIODB
  7.  */
  8.  
  9. /**
  10.  * This file is part of HRDIODB.
  11.  *
  12.  * HRDIODB is free software; you can redistribute it and/or modify
  13.  * it under the terms of the GNU General Public License as published by
  14.  * the Free Software Foundation; either version 2 of the License, or
  15.  * (at your option) any later version.
  16.  *
  17.  * HRDIODB is distributed in the hope that it will be useful,
  18.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20.  * GNU General Public License for more details.
  21.  *
  22.  * You should have received a copy of the GNU General Public License
  23.  * along with HRDIODB; if not, write to the Free Software
  24.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  25.  */
  26.  
  27. /**
  28.  * UARS Day mode.
  29.  * The mode class represents a single UARS Day mode. Each mode has a set of
  30.  * data values, as well as a list of all possible Pids.
  31.  * @package HRDIODB
  32.  */
  33. class mode {
  34.   /**
  35.    * HRDI database instance.
  36.    * @var hrdi_db 
  37.    */
  38.   var $hdb;
  39.  
  40.   /**
  41.    * Mode data, pulled from the database.
  42.    * @var array 
  43.    */
  44.   var $data = array();
  45.  
  46.   /**
  47.    * List of valid pids.
  48.    * @var array 
  49.    */
  50.   var $pids = array();
  51.  
  52.   /**
  53.    * Internal fields which must be present during submission verification.
  54.    * @var array 
  55.    */
  56.   var $internal_fields = array("UARS_Day" => "UARS Day",
  57.                                "Process_ID" => "Process ID",
  58.                                "ID" => "Mode ID");
  59.  
  60.   /**
  61.    * Fields which must contain valid numbers during submission verification.
  62.    * @var array 
  63.    */
  64.   var $numeric_fields = array("Azimuth1" => "Azimuth 1",
  65.                               "Azimuth2" => "Azimuth 2",
  66.                               "Azimuth3" => "Azimuth 3",
  67.                               "Azimuth4" => "Azimuth 4",
  68.                               "Planned" => "Planned flag");
  69.  
  70.   /**
  71.    * Constructor.
  72.    * The mode class constructor. It pulls data for the specific mode out of
  73.    * the database, as well as a list of all possible Pids.
  74.    * @param hrdi_db $hdb Instance of the hrdi_db class
  75.    * @param integer $id Mode id
  76.    */
  77.   function mode (&$hdb$id 0{
  78.     $this->hdb = $hdb;
  79.  
  80.     // Pull in the mode data if we have a valid mode id
  81.     if ($id{
  82.       $sql "SELECT *
  83.               FROM HRDI_Modes
  84.               WHERE ID='$id'";
  85.       $this->data = $this->hdb->get_row($sql);
  86.     }
  87.  
  88.     // Pull in the list of valid Pids
  89.     $sql "SELECT *
  90.             FROM HRDI_Pids";
  91.     $this->pids = $this->hdb->get_list($sql);
  92.   }
  93.  
  94.   /**
  95.    * Verifies mode data.
  96.    * The verify function verifies mode data to make sure it's ok to insert
  97.    * a new mode or update an existing mode.
  98.    * @param array $data Mode data
  99.    * @return TRUE|FALSETRUE if verification succeeds, FALSE otherwise
  100.    */
  101.   function verify (&$data{
  102.     // Verify internal field presence and format
  103.     foreach ($this->internal_fields as $k => $v{
  104.       if (isset($data[$k]&& !is_numeric($data[$k])) {
  105.         return error("Inernal error! {$this->internal_fields[$k]} must be a number");
  106.       }
  107.     }
  108.  
  109.     // Verify numeric fields
  110.     foreach ($this->numeric_fields as $k => $v{
  111.       if (strlen($data[$k]&& !is_numeric($data[$k])) {
  112.         return error($this->numeric_fields[$k]." must be a number");
  113.       }
  114.     }
  115.  
  116.     return TRUE;
  117.   }
  118.  
  119.   /**
  120.    * Adds a mode.
  121.    * The add function adds a new mode for a given UARS Day.
  122.    * @param array $data Mode data
  123.    * @return TRUE|FALSE
  124.    */
  125.   function add ($data{
  126.     if ($this->verify($data)) {
  127.       // Get the description for the mode from the current Pid table.
  128.       $data['Description'$this->get_description($data['Process_ID']);
  129.       return $this->hdb->add($data"HRDI_Modes");
  130.     }
  131.   }
  132.  
  133.   /**
  134.    * Updates a mode.
  135.    * The update function updates a given mode for a given UARS Day.
  136.    * @param array $data Mode data
  137.    * @return TRUE|FALSE
  138.    */
  139.   function update ($data{
  140.     if ($this->verify($data)) {
  141.       // Get the description for the mode from the current Pid table.
  142.       $data['Description'$this->get_description($data['Process_ID']);
  143.       return $this->hdb->update($data"HRDI_Modes""ID");
  144.     }
  145.   }
  146.  
  147.   /**
  148.    * Deletes a mode.
  149.    * The delete function deletes a given mode for a given UARS Day.
  150.    * @param array $data Mode data
  151.    * @return TRUE|FALSE
  152.    */
  153.   function delete ($data{
  154.     return $this->hdb->delete($data"HRDI_Modes""ID");
  155.   }
  156.  
  157.   /**
  158.    * Returns a Pid description.
  159.    * The function returns the description for a given Pid. The list of Pids
  160.    * and descriptions is pulled from the database by the mode class
  161.    * constructor.
  162.    * @param integer $p Pid number
  163.    * @return string Pid description
  164.    */
  165.   function get_description ($p{
  166.     foreach ($this->pids as $pid{
  167.       if ($pid['Pid'== $p{
  168.         return $pid['Description'];
  169.       }
  170.     }
  171.   }
  172. }
  173. ?>

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