noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
class_forecast_item.php
Go to the documentation of this file.
00001 <?php
00002 /*
00003  *   This file is part of NOALYSS.
00004  *
00005  *   NOALYSS is free software; you can redistribute it and/or modify
00006  *   it under the terms of the GNU General Public License as published by
00007  *   the Free Software Foundation; either version 2 of the License, or
00008  *   (at your option) any later version.
00009  *
00010  *   NOALYSS is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *   GNU General Public License for more details.
00014  *
00015  *   You should have received a copy of the GNU General Public License
00016  *   along with NOALYSS; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 
00020 // Copyright Author Dany De Bontridder danydb@aevalys.eu
00021 
00022 /**
00023 * @file
00024  * @brief manage the table forecast_item  contains the items, the item are part of category of forecast_cat, which are
00025  *  part of Forecast
00026  */
00027 /**
00028  *@brief manage the table forecast_item  contains the items, the item are part of category of forecast_cat, which are
00029  *  part of Forecast
00030  * @see Forecast Forecast_Cat
00031  *
00032  *
00033  */
00034 class Forecast_Item
00035 {
00036     /* example private $variable=array("val1"=>1,"val2"=>"Seconde valeur","val3"=>0); */
00037     private static $variable=array ("id"=>"fi_id","text"=>"fi_text","account"=>"fi_account",
00038                                     "card"=>"fi_card","order"=>"fi_order","cat_id"=>"fc_id","amount"=>"fi_amount","debit"=>"fi_debit","periode"=>"fi_pid");
00039     private $cn;
00040     /**
00041      * @brief constructor
00042      * @param $p_init Database object
00043      */
00044     function __construct ($p_init,$p_id=0)
00045     {
00046         $this->cn=$p_init;
00047         $this->fi_id=$p_id;
00048     }
00049     public function get_parameter($p_string)
00050     {
00051         if ( array_key_exists($p_string,self::$variable) )
00052         {
00053             $idx=self::$variable[$p_string];
00054             return $this->$idx;
00055         }
00056         else
00057             exit (__FILE__.":".__LINE__."[$p_string]".'Erreur attribut inexistant');
00058     }
00059     public function set_parameter($p_string,$p_value)
00060     {
00061         if ( array_key_exists($p_string,self::$variable) )
00062         {
00063             $idx=self::$variable[$p_string];
00064             $this->$idx=$p_value;
00065         }
00066         else
00067             exit (__FILE__.":".__LINE__."[$p_string]".'Erreur attribut inexistant');
00068 
00069 
00070     }
00071     public function get_info()
00072     {
00073         return var_export(self::$variable,true);
00074     }
00075     public function verify()
00076     {
00077                 $this->fi_account=  str_replace(" ", "", $this->fi_account);
00078         // Verify that the elt we want to add is correct
00079         // the f_name must be unique (case insensitive)
00080         return 0;
00081     }
00082     public function save()
00083     {
00084         /* please adapt */
00085         if (  $this->get_parameter("id") == 0 )
00086             $this->insert();
00087         else
00088             $this->update();
00089     }
00090 
00091     public function insert()
00092     {
00093         if ( $this->verify() != 0 ) return;
00094 
00095         $sql="INSERT INTO forecast_item(
00096              fi_text, fi_account, fi_card, fi_order, fc_id, fi_amount,
00097              fi_debit,fi_pid)
00098              VALUES ($1, $2, $3, $4, $5, $6, $7,$8) returning fi_id;";
00099         $res=$this->cn->exec_sql(
00100                  $sql,
00101                  array($this->fi_text,$this->fi_account,$this->fi_card,$this->fi_order,$this->fc_id,$this->fi_amount,$this->fi_debit,$this->fi_pid)
00102              );
00103         $this->fi_id=Database::fetch_result($res,0,0);
00104     }
00105 
00106     public function update()
00107     {
00108         if ( $this->verify() != 0 ) return;
00109 
00110         $sql="UPDATE forecast_item
00111              SET  fi_text=$1, fi_account=$2, fi_card=$3, fi_order=$4, fc_id=$5,
00112              fi_amount=$6, fi_debit=$7,fi_pid=$8
00113              WHERE fi_id=$9;";
00114         $res=$this->cn->exec_sql($sql,
00115                                  array($this->fi_text,
00116                                        $this->fi_account,
00117                                        $this->fi_card,
00118                                        $this->fi_order,
00119                                        $this->fc_id,
00120                                        $this->fi_amount,
00121                                        $this->fi_debit,
00122                                        $this->fi_pid,
00123                                        $this->fi_id)
00124                                 );
00125 
00126     }
00127 
00128     public function load()
00129     {
00130 
00131         $sql="SELECT fi_id, fi_text, fi_account, fi_card, fi_order, fc_id, fi_amount,
00132              fi_debit,fi_pid
00133              FROM forecast_item where fi_id=$1";
00134 
00135         $res=$this->cn->exec_sql(
00136                  $sql,
00137                  array($this->fi_id)
00138              );
00139 
00140         if ( Database::num_row($res) == 0 ) return;
00141         $row=Database::fetch_array($res,0);
00142         foreach ($row as $idx=>$value)
00143         {
00144             $this->$idx=$value;
00145         }
00146 
00147     }
00148 
00149 
00150 
00151 
00152     public function delete()
00153     {
00154         $sql="delete from forecast_item where fi_id=$1";
00155         $res=$this->cn->exec_sql($sql,array($this->fi_id));
00156     }
00157     /**
00158      * @brief unit test
00159      */
00160     static function test_me()
00161     {}
00162 
00163 }
00164 
00165 ?>
 All Data Structures Namespaces Files Functions Variables Enumerations