noalyss  Version-8.1
forecast_item.class.php
Go to the documentation of this file.
1 <?php
2 /*
3  * This file is part of NOALYSS.
4  *
5  * NOALYSS is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * NOALYSS is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with NOALYSS; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 
20 // Copyright Author Dany De Bontridder danydb@aevalys.eu
21 
22 /**
23 * @file
24  * @brief manage the table forecast_item contains the items, the item are part of category of forecast_cat, which are
25  * part of Forecast
26  */
27 /**
28  *@brief manage the table forecast_item contains the items, the item are part of category of forecast_cat, which are
29  * part of Forecast
30  * @see Forecast Forecast_Cat
31  *
32  *
33  */
35 {
36  /* example private $variable=array("val1"=>1,"val2"=>"Seconde valeur","val3"=>0); */
37  private static $variable=array ("id"=>"fi_id","text"=>"fi_text","account"=>"fi_account",
38  "card"=>"fi_card","order"=>"fi_order","cat_id"=>"fc_id","amount"=>"fi_amount","debit"=>"fi_debit","periode"=>"fi_pid");
39  private $cn;
40  /**
41  * @brief constructor
42  * @param $p_init Database object
43  */
44  function __construct ($p_init,$p_id=0)
45  {
46  $this->cn=$p_init;
47  $this->fi_id=$p_id;
48  }
49  public function get_parameter($p_string)
50  {
51  if ( array_key_exists($p_string,self::$variable) )
52  {
53  $idx=self::$variable[$p_string];
54  return $this->$idx;
55  }
56  else
57  throw new Exception("Attribut inexistant $p_string");
58  }
59  public function set_parameter($p_string,$p_value)
60  {
61  if ( array_key_exists($p_string,self::$variable) )
62  {
63  $idx=self::$variable[$p_string];
64  $this->$idx=$p_value;
65  }
66  else
67  throw new Exception("Attribut inexistant $p_string");
68 
69 
70  }
71  public function get_info()
72  {
73  return var_export(self::$variable,true);
74  }
75  public function verify()
76  {
77  $this->fi_account= str_replace(" ", "", $this->fi_account);
78  // Verify that the elt we want to add is correct
79  // the f_name must be unique (case insensitive)
80  return 0;
81  }
82  public function save()
83  {
84  /* please adapt */
85  if ( $this->get_parameter("id") == 0 )
86  $this->insert();
87  else
88  $this->update();
89  }
90 
91  public function insert()
92  {
93  if ( $this->verify() != 0 ) return;
94 
95  $sql="INSERT INTO forecast_item(
96  fi_text, fi_account, fi_card, fi_order, fc_id, fi_amount,
97  fi_debit,fi_pid)
98  VALUES ($1, $2, $3, $4, $5, $6, $7,$8) returning fi_id;";
99  $res=$this->cn->exec_sql(
100  $sql,
101  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)
102  );
103  $this->fi_id=Database::fetch_result($res,0,0);
104  }
105 
106  public function update()
107  {
108  if ( $this->verify() != 0 ) return;
109 
110  $sql="UPDATE forecast_item
111  SET fi_text=$1, fi_account=$2, fi_card=$3, fi_order=$4, fc_id=$5,
112  fi_amount=$6, fi_debit=$7,fi_pid=$8
113  WHERE fi_id=$9;";
114  $res=$this->cn->exec_sql($sql,
115  array($this->fi_text,
116  $this->fi_account,
117  $this->fi_card,
118  $this->fi_order,
119  $this->fc_id,
120  $this->fi_amount,
121  $this->fi_debit,
122  $this->fi_pid,
123  $this->fi_id)
124  );
125 
126  }
127 
128  public function load()
129  {
130 
131  $sql="SELECT fi_id, fi_text, fi_account, fi_card, fi_order, fc_id, fi_amount,
132  fi_debit,fi_pid
133  FROM forecast_item where fi_id=$1";
134 
135  $res=$this->cn->exec_sql(
136  $sql,
137  array($this->fi_id)
138  );
139 
140  if ( Database::num_row($res) == 0 ) return;
142  foreach ($row as $idx=>$value)
143  {
144  $this->$idx=$value;
145  }
146 
147  }
148 
149 
150 
151 
152  public function delete()
153  {
154  $sql="delete from forecast_item where fi_id=$1";
155  $res=$this->cn->exec_sql($sql,array($this->fi_id));
156  }
157  /**
158  * @brief unit test
159  */
160  static function test_me()
161  {}
162 
163 }
164 
165 ?>
Forecast_Item\get_info
get_info()
Definition: forecast_item.class.php:71
Forecast_Item\insert
insert()
Definition: forecast_item.class.php:91
Forecast_Item\get_parameter
get_parameter($p_string)
Definition: forecast_item.class.php:49
cn
$input_from cn
Definition: balance.inc.php:73
Forecast_Item\$variable
static $variable
Definition: forecast_item.class.php:37
Forecast_Item\load
load()
Definition: forecast_item.class.php:128
DatabaseCore\fetch_array
static fetch_array($ret, $p_indice=0)
wrapper for the function pg_fetch_array
Definition: database_core.class.php:727
$sql
$sql
Definition: ajax_add_concerned_card.php:103
Forecast_Item\set_parameter
set_parameter($p_string, $p_value)
Definition: forecast_item.class.php:59
Forecast_Item\verify
verify()
Definition: forecast_item.class.php:75
Forecast_Item\__construct
__construct($p_init, $p_id=0)
constructor
Definition: forecast_item.class.php:44
DatabaseCore\fetch_result
static fetch_result($ret, $p_row=0, $p_col=0)
wrapper for the function pg_fetch_all
Definition: database_core.class.php:749
$value
$value
Definition: export_document.php:38
DatabaseCore\num_row
static num_row($ret)
wrapper for the function pg_NumRows
Definition: database_core.class.php:716
Forecast_Item\$cn
$cn
Definition: forecast_item.class.php:39
$idx
$idx
Definition: ajax_bookmark.php:79
Forecast_Item
manage the table forecast_item contains the items, the item are part of category of forecast_cat,...
Definition: forecast_item.class.php:34
Forecast_Item\test_me
static test_me()
unit test
Definition: forecast_item.class.php:160
$row
$row
Definition: ajax_anc_detail_operation.php:33
$p_id
$p_id
Definition: ajax_accounting.php:33
$res
$res
Definition: ajax_preference.php:56
Forecast_Item\update
update()
Definition: forecast_item.class.php:106
Forecast_Item\save
save()
Definition: forecast_item.class.php:82