noalyss  Version-8.1
forecast_cat.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_cat, this table contains the categories of forecast
25  * as expense, asset, sales...
26  */
27 /**
28  *@brief this class is called normally from forecast, a forecast contains category
29  * like sales, expenses, each category contains items
30  *@see Forecast
31  *
32  */
34 {
35  /* example private $variable=array("val1"=>1,"val2"=>"Seconde valeur","val3"=>0); */
36  private static $variable=array ("id"=>"fc_id","order"=>"fc_order","desc"=>"fc_desc","forecast"=>"f_id");
37  private $cn;
38  /**
39  * @brief constructor
40  * @param $p_init Database object
41  */
42  function __construct ($p_init,$p_id=0)
43  {
44  $this->cn=$p_init;
45  $this->fc_id=$p_id;
46  }
47  public function get_parameter($p_string)
48  {
49  if ( array_key_exists($p_string,self::$variable) )
50  {
51  $idx=self::$variable[$p_string];
52  return $this->$idx;
53  }
54  else
55  throw new Exception("Attribut inexistant $p_string");
56  }
57  public function set_parameter($p_string,$p_value)
58  {
59  if ( array_key_exists($p_string,self::$variable) )
60  {
61  $idx=self::$variable[$p_string];
62  $this->$idx=$p_value;
63  }
64  else
65  throw new Exception("Attribut inexistant $p_string");
66 
67 
68  }
69  public function get_info()
70  {
71  return var_export(self::$variable,true);
72  }
73  public function verify()
74  {
75  if (strlen(trim($this->fc_order))==0)
76  {
77  $this->fc_order="1";
78  }
79  // Verify that the elt we want to add is correct
80  // the f_name must be unique (case insensitive)
81  return 0;
82  }
83  public function save()
84  {
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_cat (fc_desc,fc_order,f_id) ".
96  " values ($1,$2,$3) returning fc_id";
97  $res=$this->cn->exec_sql(
98  $sql,
99  array($this->fc_desc,$this->fc_order,$this->f_id)
100  );
101  $this->fc_id=Database::fetch_result($res,0,0);
102  }
103 
104  public function update()
105  {
106  if ( $this->verify() != 0 ) return;
107 
108  $sql="update forecast_cat set fc_desc=$1,f_id=$2,fc_order=$3 ".
109  " where fc_id = $4";
110  $res=$this->cn->exec_sql(
111  $sql,
112  array($this->fc_desc,$this->f_id, $this->fc_order,$this->fc_id)
113  );
114  }
115  /**
116  *@brief Load all the cat. for a given forecast and return them into a array
117  *@param $p_cn database connx
118  *@param $p_id is the forecast id (f_id)
119  *@return an array with all the data
120  */
121  public static function load_all($p_cn,$p_id)
122  {
123  $sql="select fc_id,fc_desc,fc_order from forecast_cat where f_id=$1";
124 
125  $res=$p_cn->get_array($sql,array($p_id));
126 
127  return $res;
128  }
129  public function load()
130  {
131 
132  $sql="select fc_desc, f_id,fc_order from forecast_cat where fc_id=$1";
133 
134  $res=$this->cn->exec_sql(
135  $sql,
136  array($this->fc_id)
137  );
138 
139  if ( Database::num_row($res) == 0 ) return;
141  foreach ($row as $idx=>$value)
142  {
143  $this->$idx=$value;
144  }
145 
146  }
147  /**
148  *@brief Make a array for a ISelect of the available cat
149  *@param $id is forecast::f_id
150  *@return array for ISelect
151  *@see ISelect
152  */
153  public function make_array($id)
154  {
155  $sql="select fc_id,fc_desc from forecast_cat where f_id=$id";
156  $ret=$this->cn->make_array($sql);
157  return $ret;
158  }
159  public function delete()
160  {
161  $sql="delete from forecast_cat where fc_id=$1";
162  $res=$this->cn->exec_sql($sql,array($this->fc_id));
163  }
164  /**
165  * @brief unit test
166  */
167  static function test_me()
168  {}
169 
170 }
171 
172 ?>
$ret
$ret
Definition: ajax_display_letter.php:52
Forecast_Cat\$cn
$cn
Definition: forecast_cat.class.php:37
Forecast_Cat\get_info
get_info()
Definition: forecast_cat.class.php:69
cn
$input_from cn
Definition: balance.inc.php:73
DatabaseCore\fetch_array
static fetch_array($ret, $p_indice=0)
wrapper for the function pg_fetch_array
Definition: database_core.class.php:727
Forecast_Cat\insert
insert()
Definition: forecast_cat.class.php:91
$id
$id
Definition: ajax_fiche_def_detail.php:35
$sql
$sql
Definition: ajax_add_concerned_card.php:103
Forecast_Cat\__construct
__construct($p_init, $p_id=0)
constructor
Definition: forecast_cat.class.php:42
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_Cat\load_all
static load_all($p_cn, $p_id)
Load all the cat.
Definition: forecast_cat.class.php:121
Forecast_Cat\save
save()
Definition: forecast_cat.class.php:83
$idx
$idx
Definition: ajax_bookmark.php:79
Forecast_Cat\make_array
make_array($id)
Make a array for a ISelect of the available cat.
Definition: forecast_cat.class.php:153
Forecast_Cat\set_parameter
set_parameter($p_string, $p_value)
Definition: forecast_cat.class.php:57
Forecast_Cat\load
load()
Definition: forecast_cat.class.php:129
$row
$row
Definition: ajax_anc_detail_operation.php:33
Forecast_Cat\update
update()
Definition: forecast_cat.class.php:104
Forecast_Cat\verify
verify()
Definition: forecast_cat.class.php:73
Forecast_Cat\$variable
static $variable
Definition: forecast_cat.class.php:36
$p_id
$p_id
Definition: ajax_accounting.php:33
$res
$res
Definition: ajax_preference.php:56
Forecast_Cat
this class is called normally from forecast, a forecast contains category like sales,...
Definition: forecast_cat.class.php:33
Forecast_Cat\get_parameter
get_parameter($p_string)
Definition: forecast_cat.class.php:47
Forecast_Cat\test_me
static test_me()
unit test
Definition: forecast_cat.class.php:167