Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 class Forecast_Cat
00034 {
00035
00036 private static $variable=array ("id"=>"fc_id","order"=>"fc_order","desc"=>"fc_desc","forecast"=>"f_id");
00037 private $cn;
00038
00039
00040
00041
00042 function __construct ($p_init,$p_id=0)
00043 {
00044 $this->cn=$p_init;
00045 $this->fc_id=$p_id;
00046 }
00047 public function get_parameter($p_string)
00048 {
00049 if ( array_key_exists($p_string,self::$variable) )
00050 {
00051 $idx=self::$variable[$p_string];
00052 return $this->$idx;
00053 }
00054 else
00055 exit (__FILE__.":".__LINE__."[$p_string]".'Erreur attribut inexistant');
00056 }
00057 public function set_parameter($p_string,$p_value)
00058 {
00059 if ( array_key_exists($p_string,self::$variable) )
00060 {
00061 $idx=self::$variable[$p_string];
00062 $this->$idx=$p_value;
00063 }
00064 else
00065 exit (__FILE__.":".__LINE__."[$p_string]".'Erreur attribut inexistant');
00066
00067
00068 }
00069 public function get_info()
00070 {
00071 return var_export(self::$variable,true);
00072 }
00073 public function verify()
00074 {
00075 if (strlen(trim($this->fc_order))==0)
00076 {
00077 $this->fc_order="1";
00078 }
00079
00080
00081 return 0;
00082 }
00083 public function save()
00084 {
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_cat (fc_desc,fc_order,f_id) ".
00096 " values ($1,$2,$3) returning fc_id";
00097 $res=$this->cn->exec_sql(
00098 $sql,
00099 array($this->fc_desc,$this->fc_order,$this->f_id)
00100 );
00101 $this->fc_id=Database::fetch_result($res,0,0);
00102 }
00103
00104 public function update()
00105 {
00106 if ( $this->verify() != 0 ) return;
00107
00108 $sql="update forecast_cat set fc_desc=$1,f_id=$2,fc_order=$3 ".
00109 " where fc_id = $4";
00110 $res=$this->cn->exec_sql(
00111 $sql,
00112 array($this->fc_desc,$this->f_id, $this->fc_order,$this->fc_id)
00113 );
00114 }
00115
00116
00117
00118
00119
00120
00121 public static function load_all($p_cn,$p_id)
00122 {
00123 $sql="select fc_id,fc_desc,fc_order from forecast_cat where f_id=$1";
00124
00125 $res=$p_cn->get_array($sql,array($p_id));
00126
00127 return $res;
00128 }
00129 public function load()
00130 {
00131
00132 $sql="select fc_desc, f_id,fc_order from forecast_cat where fc_id=$1";
00133
00134 $res=$this->cn->exec_sql(
00135 $sql,
00136 array($this->fc_id)
00137 );
00138
00139 if ( Database::num_row($res) == 0 ) return;
00140 $row=Database::fetch_array($res,0);
00141 foreach ($row as $idx=>$value)
00142 {
00143 $this->$idx=$value;
00144 }
00145
00146 }
00147
00148
00149
00150
00151
00152
00153 public function make_array($id)
00154 {
00155 $sql="select fc_id,fc_desc from forecast_cat where f_id=$id";
00156 $ret=$this->cn->make_array($sql);
00157 return $ret;
00158 }
00159 public function delete()
00160 {
00161 $sql="delete from forecast_cat where fc_id=$1";
00162 $res=$this->cn->exec_sql($sql,array($this->fc_id));
00163 }
00164
00165
00166
00167 static function test_me()
00168 {}
00169
00170 }
00171
00172 ?>