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 require_once('class_database.php');
00031 require_once('ac_common.php');
00032
00033
00034
00035
00036
00037 class Profile_Menu_sql
00038 {
00039
00040
00041 protected $variable=array("pm_id"=>"pm_id","me_code"=>"me_code"
00042 ,"me_code_dep"=>"me_code_dep"
00043 ,"p_id"=>"p_id"
00044 ,"p_order"=>"p_order"
00045 ,"p_type_display"=>"p_type_display"
00046 ,"pm_default"=>"pm_default"
00047 );
00048 function __construct ( & $p_cn,$p_id=-1) {
00049 $this->cn=$p_cn;
00050 $this->pm_id=$p_id;
00051
00052 if ( $p_id == -1 ) {
00053
00054 foreach ($this->variable as $key=>$value) $this->$value=null;
00055 $this->pm_id=$p_id;
00056 } else {
00057
00058
00059 $this->load();
00060 }
00061 }
00062 public function get_parameter($p_string) {
00063 if ( array_key_exists($p_string,$this->variable) ) {
00064 $idx=$this->variable[$p_string];
00065 return $this->$idx;
00066 }
00067 else
00068 throw new Exception (__FILE__.":".__LINE__.$p_string.'Erreur attribut inexistant');
00069 }
00070 public function set_parameter($p_string,$p_value) {
00071 if ( array_key_exists($p_string,$this->variable) ) {
00072 $idx=$this->variable[$p_string];
00073 $this->$idx=$p_value;
00074 }
00075 else
00076 throw new Exception (__FILE__.":".__LINE__.$p_string.'Erreur attribut inexistant');
00077 }
00078 public function get_info() { return var_export($this,true); }
00079 public function verify() {
00080
00081
00082 if ( trim($this->me_code) == '') $this->me_code=null;
00083 if ( trim($this->me_code_dep) == '') $this->me_code_dep=null;
00084 if ( trim($this->p_id) == '') $this->p_id=null;
00085 if ( $this->p_id!== null && settype($this->p_id,'float') == false )
00086 throw new Exception('DATATYPE p_id $this->p_id non numerique');
00087 if ( trim($this->p_order) == '') $this->p_order=null;
00088 if ( $this->p_order!== null && settype($this->p_order,'float') == false )
00089 throw new Exception('DATATYPE p_order $this->p_order non numerique');
00090 if ( trim($this->p_type_display) == '') $this->p_type_display=null;
00091 if ( trim($this->pm_default) == '') $this->pm_default=null;
00092 if ( $this->pm_default!== null && settype($this->pm_default,'float') == false )
00093 throw new Exception('DATATYPE pm_default $this->pm_default non numerique');
00094
00095
00096 }
00097 public function save() {
00098
00099 if ( $this->pm_id == -1 )
00100 $this->insert();
00101 else
00102 $this->update();
00103 }
00104
00105
00106
00107
00108
00109
00110
00111
00112 public function seek($cond='',$p_array=null)
00113 {
00114 $sql="select * from public.profile_menu $cond";
00115 $aobj=array();
00116 $ret= $this->cn->exec_sql($sql,$p_array);
00117 return $ret;
00118 }
00119
00120
00121
00122
00123
00124
00125
00126
00127 public function get_object($p_ret,$idx)
00128 {
00129
00130 $oobj=new Profile_Menu_sql ($this->cn);
00131 $array=Database::fetch_array($p_ret,$idx);
00132 foreach ($array as $idx=>$value) { $oobj->$idx=$value; }
00133 return $oobj;
00134 }
00135 public function insert() {
00136 if ( $this->verify() != 0 ) return;
00137 if( $this->pm_id==-1 ){
00138
00139 $sql="insert into public.profile_menu(me_code
00140 ,me_code_dep
00141 ,p_id
00142 ,p_order
00143 ,p_type_display
00144 ,pm_default
00145 ) values ($1
00146 ,$2
00147 ,$3
00148 ,$4
00149 ,$5
00150 ,$6
00151 ) returning pm_id";
00152
00153 $this->pm_id=$this->cn->get_value(
00154 $sql,
00155 array( $this->me_code
00156 ,$this->me_code_dep
00157 ,$this->p_id
00158 ,$this->p_order
00159 ,$this->p_type_display
00160 ,$this->pm_default
00161 )
00162 );
00163 } else {
00164 $sql="insert into public.profile_menu(me_code
00165 ,me_code_dep
00166 ,p_id
00167 ,p_order
00168 ,p_type_display
00169 ,pm_default
00170 ,pm_id) values ($1
00171 ,$2
00172 ,$3
00173 ,$4
00174 ,$5
00175 ,$6
00176 ,$7
00177 ) returning pm_id";
00178
00179 $this->pm_id=$this->cn->get_value(
00180 $sql,
00181 array( $this->me_code
00182 ,$this->me_code_dep
00183 ,$this->p_id
00184 ,$this->p_order
00185 ,$this->p_type_display
00186 ,$this->pm_default
00187 ,$this->pm_id)
00188 );
00189
00190 }
00191
00192 }
00193
00194 public function update() {
00195 if ( $this->verify() != 0 ) return;
00196
00197 $sql=" update public.profile_menu set me_code = $1
00198 ,me_code_dep = $2
00199 ,p_id = $3
00200 ,p_order = $4
00201 ,p_type_display = $5
00202 ,pm_default = $6
00203 where pm_id= $7";
00204 $res=$this->cn->exec_sql(
00205 $sql,
00206 array($this->me_code
00207 ,$this->me_code_dep
00208 ,$this->p_id
00209 ,$this->p_order
00210 ,$this->p_type_display
00211 ,$this->pm_default
00212 ,$this->pm_id)
00213 );
00214
00215 }
00216
00217
00218
00219
00220 public function load() {
00221
00222 $sql="select me_code
00223 ,me_code_dep
00224 ,p_id
00225 ,p_order
00226 ,p_type_display
00227 ,pm_default
00228 from public.profile_menu where pm_id=$1";
00229
00230 $res=$this->cn->get_array(
00231 $sql,
00232 array($this->pm_id)
00233 );
00234
00235 if ( count($res) == 0 ) {
00236
00237 foreach ($this->variable as $key=>$value) $this->$key='';
00238
00239 return -1;
00240 }
00241 foreach ($res[0] as $idx=>$value) { $this->$idx=$value; }
00242 return 0;
00243 }
00244
00245 public function delete() {
00246 $sql="delete from public.profile_menu where pm_id=$1";
00247 $res=$this->cn->exec_sql($sql,array($this->pm_id));
00248 }
00249
00250
00251
00252 static function test_me() {
00253 $cn=new Database(25);
00254 $cn->start();
00255 echo h2info('Test object vide');
00256 $obj=new Profile_Menu_sql($cn);
00257 var_dump($obj);
00258
00259 echo h2info('Test object NON vide');
00260 $obj->set_parameter('j_id',3);
00261 $obj->load();
00262 var_dump($obj);
00263
00264 echo h2info('Update');
00265 $obj->set_parameter('j_qcode','NOUVEAU CODE');
00266 $obj->save();
00267 $obj->load();
00268 var_dump($obj);
00269
00270 echo h2info('Insert');
00271 $obj->set_parameter('j_id',0);
00272 $obj->save();
00273 $obj->load();
00274 var_dump($obj);
00275
00276 echo h2info('Delete');
00277 $obj->delete();
00278 echo (($obj->load()==0)?'Trouve':'non trouve');
00279 var_dump($obj);
00280 $cn->rollback();
00281
00282 }
00283
00284 }
00285
00286 ?>