Plugins  LAST
 All Data Structures Files Functions Variables Pages
class_amortissement_histo_sql.php
Go to the documentation of this file.
1 <?php
2 /*
3  * Copyright 2010 De Bontridder Dany <dany@alchimerys.be>
4  * This file is part of NOALYSS.
5  *
6  * NOALYSS is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * NOALYSS is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with NOALYSS; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20  /**
21  *@file
22  *@brief Manage the table amortissement.amortissement_histo
23  *
24  *
25  Example
26  @code
27 
28  @endcode
29  */
30 require_once NOALYSS_INCLUDE.'/lib/class_database.php';
31 require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
32 
33 
34 
35 /**
36  *@brief Manage the table amortissement.amortissement_histo
37  */
39 {
40  /* example private $variable=array("easy_name"=>column_name,"email"=>"column_name_email","val3"=>0); */
41 
42  protected $variable=array("ha_id"=>"ha_id","a_id"=>"a_id"
43  ,"h_amount"=>"h_amount"
44  ,"jr_internal"=>"jr_internal"
45  ,"h_year"=>"h_year"
46  ,"h_pj"=>"h_pj"
47  );
48  function __construct ( & $p_cn,$p_id=-1)
49  {
50  $this->cn=$p_cn;
51  $this->ha_id=$p_id;
52 
53  if ( $p_id == -1 )
54  {
55  /* Initialize an empty object */
56  foreach ($this->variable as $key=>$value) $this->$value='';
57  $this->ha_id=$p_id;
58  }
59  else
60  {
61  /* load it */
62 
63  $this->load();
64  }
65  }
66  public function get_parameter($p_string)
67  {
68  if ( array_key_exists($p_string,$this->variable) )
69  {
70  $idx=$this->variable[$p_string];
71  return $this->$idx;
72  }
73  else
74  throw new Exception (__FILE__.":".__LINE__.$p_string.'Erreur attribut inexistant');
75  }
76  public function set_parameter($p_string,$p_value)
77  {
78  if ( array_key_exists($p_string,$this->variable) )
79  {
80  $idx=$this->variable[$p_string];
81  $this->$idx=$p_value;
82  }
83  else
84  throw new Exception (__FILE__.":".__LINE__.$p_string.'Erreur attribut inexistant');
85  }
86  public function get_info()
87  {
88  return var_export($this,true);
89  }
90  public function verify()
91  {
92  // Verify that the elt we want to add is correct
93  /* verify only the datatype */
94  if ( settype($this->a_id,'float') == false )
95  throw new Exception('DATATYPE a_id $this->a_id non numerique');
96  if ( settype($this->h_amount,'float') == false )
97  throw new Exception('DATATYPE h_amount $this->h_amount non numerique');
98  if ( settype($this->h_year,'float') == false )
99  throw new Exception('DATATYPE h_year $this->h_year non numerique');
100 
101 
102  }
103  public function save()
104  {
105  /* please adapt */
106  if ( $this->ha_id == -1 )
107  $this->insert();
108  else
109  $this->update();
110  }
111  /**
112  *@brief retrieve array of object thanks a condition
113  *@param $cond condition (where clause) (optional by default all the rows are fetched)
114  * you can use this parameter for the order or subselect
115  *@param $p_array array for the SQL stmt
116  *@see Database::get_array
117  *@return an empty array if nothing is found
118  */
119  public function seek($cond='',$p_array=null)
120  {
121  $sql="select * from amortissement.amortissement_histo $cond";
122  $aobj=array();
123  $array= $this->cn->get_array($sql,$p_array);
124  // map each row in a object
125  $size=$this->cn->count();
126  if ( $size == 0 ) return $aobj;
127  for ($i=0; $i<$size; $i++)
128  {
129  $oobj=new Amortissement_Histo_Sql ($this->cn);
130  foreach ($array[$i] as $idx=>$value)
131  {
132  $oobj->$idx=$value;
133  }
134  $aobj[]=clone $oobj;
135  }
136  return $aobj;
137  }
138  public function insert()
139  {
140  if ( $this->verify() != 0 ) return;
141  if ( $this->ha_id==-1 )
142  {
143  /* please adapt */
144  $sql="insert into amortissement.amortissement_histo(a_id
145  ,h_amount
146  ,jr_internal
147  ,h_year
148  ,h_pj
149  ) values ($1
150  ,$2
151  ,$3
152  ,$4
153  ,$5
154  ) returning ha_id";
155 
156  $this->ha_id=$this->cn->get_value(
157  $sql,
158  array( $this->a_id
159  ,$this->h_amount
160  ,$this->jr_internal
161  ,$this->h_year
162  ,$this->h_pj
163  )
164  );
165  }
166  else
167  {
168  $sql="insert into amortissement.amortissement_histo(a_id
169  ,h_amount
170  ,jr_internal
171  ,h_year
172  ,h_pj
173  ,ha_id) values ($1
174  ,$2
175  ,$3
176  ,$4
177  ,$5
178  ,$6
179  ) returning ha_id";
180 
181  $this->ha_id=$this->cn->get_value(
182  $sql,
183  array( $this->a_id
184  ,$this->h_amount
185  ,$this->jr_internal
186  ,$this->h_year
187  ,$this->h_pj
188  ,$this->ha_id)
189  );
190 
191  }
192 
193  }
194 
195  public function update()
196  {
197  if ( $this->verify() != 0 ) return;
198  /* please adapt */
199  $sql=" update amortissement.amortissement_histo set a_id = $1
200  ,h_amount = $2
201  ,jr_internal = $3
202  ,h_year = $4
203  ,h_pj = $5
204  where ha_id= $6";
205  $res=$this->cn->exec_sql(
206  $sql,
207  array($this->a_id
208  ,$this->h_amount
209  ,$this->jr_internal
210  ,$this->h_year
211  ,$this->h_pj
212  ,$this->ha_id)
213  );
214 
215  }
216  /**
217  *@brief load a object
218  *@return 0 on success -1 the object is not found
219  */
220  public function load()
221  {
222 
223  $sql="select a_id
224  ,h_amount
225  ,jr_internal
226  ,h_year
227  ,h_pj
228  from amortissement.amortissement_histo where ha_id=$1";
229  /* please adapt */
230  $res=$this->cn->get_array(
231  $sql,
232  array($this->ha_id)
233  );
234 
235  if ( count($res) == 0 )
236  {
237  /* Initialize an empty object */
238  foreach ($this->variable as $key=>$value) $this->$key='';
239 
240  return -1;
241  }
242  foreach ($res[0] as $idx=>$value)
243  {
244  $this->$idx=$value;
245  }
246  return 0;
247  }
248 
249  public function delete()
250  {
251  $sql="delete from amortissement.amortissement_histo where ha_id=$1";
252  $res=$this->cn->exec_sql($sql,array($this->ha_id));
253  }
254  /**
255  * Unit test for the class
256  */
257  static function test_me()
258  {
259 
260  }
261 
262 }
263 // Amortissement_Histo_Sql::test_me();
264 ?>
if($p_number->value==0) l les annuités seront recalculées et l pct[] ad_year[] select h_pj
static test_me()
Unit test for the class.
if(isset($_POST['remove'])) $array
Manage the table amortissement.amortissement_histo.
$key
$res
seek($cond='', $p_array=null)
retrieve array of object thanks a condition
$sql
if($p_number->value==0) l les annuités seront recalculées et l pct[] ad_year[] select ha_id
if($p_number->value==0) l les annuités seront recalculées et l pct[] ad_year[] select h_amount from amortissement amortissement_histo where a_id
if($p_number->value==0) l les annuités seront recalculées et l pct[] ad_year[] select jr_internal