noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
class_menu_ref_sql.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 // Copyright Author Dany De Bontridder danydb@aevalys.eu
00020 
00021 /**
00022  * @file
00023  * @brief Manage the table public.menu_ref
00024  *
00025  *
00026  */
00027 require_once('class_database.php');
00028 require_once('ac_common.php');
00029 
00030 /**
00031  * @brief Manage the table public.menu_ref
00032  */
00033 class Menu_Ref_sql
00034 {
00035         /* example private $variable=array("easy_name"=>column_name,"email"=>"column_name_email","val3"=>0); */
00036 
00037         protected $variable = array(
00038                 "me_code" => "me_code"
00039                 , "me_menu" => "me_menu"
00040                 , "me_file" => "me_file"
00041                 , "me_url" => "me_url"
00042                 , "me_description" => "me_description"
00043                 , "me_parameter" => "me_parameter"
00044                 , "me_javascript" => "me_javascript"
00045                 , "me_type" => "me_type"
00046         );
00047 
00048         function __construct(& $p_cn, $p_id=-1)
00049         {
00050                 $this->cn = $p_cn;
00051                 $this->me_code = $p_id;
00052 
00053                 if ($p_id == -1)
00054                 {
00055                         /* Initialize an empty object */
00056                         foreach ($this->variable as $key => $value)
00057                                 $this->$value = null;
00058                         $this->me_code = $p_id;
00059                 }
00060                 else
00061                 {
00062                         /* load it */
00063 
00064                         $this->load();
00065                 }
00066         }
00067 
00068         public function get_parameter($p_string)
00069         {
00070                 if (array_key_exists($p_string, $this->variable))
00071                 {
00072                         $idx = $this->variable[$p_string];
00073                         return $this->$idx;
00074                 }
00075                 else
00076                         throw new Exception(__FILE__ . ":" . __LINE__ . $p_string . 'Erreur attribut inexistant');
00077         }
00078 
00079         public function set_parameter($p_string, $p_value)
00080         {
00081                 if (array_key_exists($p_string, $this->variable))
00082                 {
00083                         $idx = $this->variable[$p_string];
00084                         $this->$idx = $p_value;
00085                 }
00086                 else
00087                         throw new Exception(__FILE__ . ":" . __LINE__ . $p_string . 'Erreur attribut inexistant');
00088         }
00089 
00090         public function get_info()
00091         {
00092                 return var_export($this, true);
00093         }
00094 
00095         public function verify()
00096         {
00097                 // Verify that the elt we want to add is correct
00098                 /* verify only the datatype */
00099                 if (trim($this->me_menu) == '')
00100                         $this->me_menu = null;
00101                 if (trim($this->me_file) == '')
00102                         $this->me_file = null;
00103                 if (trim($this->me_url) == '')
00104                         $this->me_url = null;
00105                 if (trim($this->me_description) == '')
00106                         $this->me_description = null;
00107                 if (trim($this->me_parameter) == '')
00108                         $this->me_parameter = null;
00109                 if (trim($this->me_javascript) == '')
00110                         $this->me_javascript = null;
00111                 if (trim($this->me_type) == '')
00112                         $this->me_type = null;
00113         }
00114 
00115         /**
00116          * @brief retrieve array of object thanks a condition
00117          * @param $cond condition (where clause) (optional by default all the rows are fetched)
00118          * you can use this parameter for the order or subselect
00119          * @param $p_array array for the SQL stmt
00120          * @see Database::exec_sql get_object  Database::num_row
00121          * @return the return value of exec_sql
00122          */
00123         public function seek($cond='', $p_array=null)
00124         {
00125                 $sql = "select * from public.menu_ref  $cond";
00126                 $aobj = array();
00127                 $ret = $this->cn->exec_sql($sql, $p_array);
00128                 return $ret;
00129         }
00130 
00131         /**
00132          * get_seek return the next object, the return of the query must have all the column
00133          * of the object
00134          * @param $p_ret is the return value of an exec_sql
00135          * @param $idx is the index
00136          * @see seek
00137          * @return object
00138          */
00139         public function get_object($p_ret, $idx)
00140         {
00141                 // map each row in a object
00142                 $oobj = new Menu_Ref_sql($this->cn);
00143                 $array = Database::fetch_array($p_ret, $idx);
00144                 foreach ($array as $idx => $value)
00145                 {
00146                         $oobj->$idx = $value;
00147                 }
00148                 return $oobj;
00149         }
00150 
00151         public function insert()
00152         {
00153                 if ($this->verify() != 0)
00154                         return;
00155 
00156                         $sql = "insert into public.menu_ref(me_menu
00157                                         ,me_file
00158                                         ,me_url
00159                                         ,me_description
00160                                         ,me_parameter
00161                                         ,me_javascript
00162                                         ,me_type
00163                                         ,me_code) values ($1
00164                                         ,$2
00165                                         ,$3
00166                                         ,$4
00167                                         ,$5
00168                                         ,$6
00169                                         ,$7
00170                                         ,$8
00171                                         ) returning me_code";
00172 
00173                         $this->me_code = $this->cn->get_value(
00174                                         $sql, array($this->me_menu
00175                                 , $this->me_file
00176                                 , $this->me_url
00177                                 , $this->me_description
00178                                 , $this->me_parameter
00179                                 , $this->me_javascript
00180                                 , $this->me_type
00181                                 , $this->me_code)
00182                         );
00183 
00184         }
00185 
00186         public function update()
00187         {
00188                 if ($this->verify() != 0)
00189                         return;
00190                 /*   please adapt */
00191                 $sql = " update public.menu_ref set me_menu = $1
00192                                         ,me_file = $2
00193                                         ,me_url = $3
00194                                         ,me_description = $4
00195                                         ,me_parameter = $5
00196                                         ,me_javascript = $6
00197                                         ,me_type = $7
00198                                          where me_code= $8";
00199                 $res = $this->cn->exec_sql(
00200                                 $sql, array($this->me_menu
00201                         , $this->me_file
00202                         , $this->me_url
00203                         , $this->me_description
00204                         , $this->me_parameter
00205                         , $this->me_javascript
00206                         , $this->me_type
00207                         , $this->me_code)
00208                 );
00209         }
00210 
00211         /**
00212          * @brief load a object
00213          * @return 0 on success -1 the object is not found
00214          */
00215         public function load()
00216         {
00217 
00218                 $sql = "select me_menu
00219                                                 ,me_file
00220                                                 ,me_url
00221                                                 ,me_description
00222                                                 ,me_parameter
00223                                                 ,me_javascript
00224                                                 ,me_type
00225                                                  from public.menu_ref where me_code=$1";
00226                 /* please adapt */
00227                 $res = $this->cn->get_array(
00228                                 $sql, array($this->me_code)
00229                 );
00230 
00231                 if (count($res) == 0)
00232                 {
00233                         /* Initialize an empty object */
00234                         foreach ($this->variable as $key => $value)
00235                                 $this->$key = '';
00236 
00237                         return -1;
00238                 }
00239                 foreach ($res[0] as $idx => $value)
00240                 {
00241                         $this->$idx = $value;
00242                 }
00243                 return 0;
00244         }
00245 
00246         public function delete()
00247         {
00248                 $sql = "delete from public.menu_ref where me_code=$1";
00249                 $res = $this->cn->exec_sql($sql, array($this->me_code));
00250         }
00251 
00252         /**
00253          * Unit test for the class
00254          */
00255         static function test_me()
00256         {
00257         }
00258 
00259 }
00260 
00261 // Menu_Ref_sql::test_me();
00262 ?>
 All Data Structures Namespaces Files Functions Variables Enumerations