noalyss Version-9
Public Member Functions | Static Public Member Functions | Private Attributes | Static Private Attributes
Forecast Class Reference

manage the table forecast More...

+ Collaboration diagram for Forecast:

Public Member Functions

 __construct ($p_init, $p_id=0)
 constructor More...
 
 delete ()
 
 get_info ()
 
 get_parameter ($p_string)
 
 insert ()
 
 load ()
 load from db More...
 
 object_clone ()
 
 save ()
 
 set_parameter ($p_string, $p_value)
 
 update ()
 update the forecast table More...
 
 verify ()
 

Static Public Member Functions

static load_all ($p_cn)
 load all the existing forecast More...
 

Private Attributes

 $cn
 

Static Private Attributes

static $variable
 

Detailed Description

manage the table forecast

Definition at line 28 of file forecast.class.php.

Constructor & Destructor Documentation

◆ __construct()

Forecast::__construct (   $p_init,
  $p_id = 0 
)

constructor

Parameters
$p_initDatabase object

Definition at line 38 of file forecast.class.php.

39 {
40 $this->cn=$p_init;
41 $this->f_id=$p_id;
42 }
$input_from cn
Definition: balance.inc.php:66

References $p_id, and cn.

Member Function Documentation

◆ delete()

Forecast::delete ( )

Definition at line 143 of file forecast.class.php.

144 {
145 $sql="delete from forecast where f_id=$1";
146 $res=$this->cn->exec_sql($sql,array($this->f_id));
147 }

References $res, $sql, and cn.

◆ get_info()

Forecast::get_info ( )

Definition at line 63 of file forecast.class.php.

64 {
65 return var_export(self::$variable,true);
66 }

References $variable.

◆ get_parameter()

Forecast::get_parameter (   $p_string)

Definition at line 43 of file forecast.class.php.

44 {
45 if ( array_key_exists($p_string,self::$variable) )
46 {
47 $idx=self::$variable[$p_string];
48 return $this->$idx;
49 }
50 else
51 throw new Exception("Attribut inexistant $p_string");
52 }
$idx

References $idx, and $variable.

Referenced by save().

◆ insert()

Forecast::insert ( )

Definition at line 85 of file forecast.class.php.

86 {
87 if ( $this->verify() != 0 ) return;
88 $sql="insert into forecast (f_name,f_start_date,f_end_date) ".
89 " values ($1,$2,$3) returning f_id";
90 $res=$this->cn->exec_sql(
91 $sql,
92 array($this->f_name,$this->f_start_date,$this->f_end_date)
93 );
94 $this->f_id=Database::fetch_result($res,0,0);
95 }
static fetch_result($ret, $p_row=0, $p_col=0)
wrapper for the function pg_fetch_all

References $res, $sql, cn, DatabaseCore\fetch_result(), and verify().

Referenced by save().

+ Here is the call graph for this function:

◆ load()

Forecast::load ( )

load from db

Returns
boolean true if found else false

Definition at line 127 of file forecast.class.php.

127 :bool
128 {
129 $sql="select f_id, f_name,f_start_date ,f_end_date from forecast where f_id=$1";
130 $res=$this->cn->exec_sql(
131 $sql,
132 array($this->f_id)
133 );
134 if ( Database::num_row($res) == 0 ) return false;
136 $a_index=array_values(self::$variable);
137 foreach ( $a_index as $idx)
138 {
139 $this->$idx=$row[$idx];
140 }
141 return true;
142 }
static fetch_array($ret, $p_indice=0, $p_mode=PGSQL_ASSOC)
wrapper for the function pg_fetch_array
static num_row($ret)
wrapper for the function pg_num_rows

References $idx, $res, $row, $sql, $variable, cn, DatabaseCore\fetch_array(), and DatabaseCore\num_row().

Referenced by object_clone().

+ Here is the call graph for this function:

◆ load_all()

static Forecast::load_all (   $p_cn)
static

load all the existing forecast

Parameters
$p_cnis an Database object
Returns
array of f_id and f_name

Definition at line 117 of file forecast.class.php.

118 {
119 $sql="select f_id, f_name,f_start_date,f_end_date from forecast order by 2 desc";
120 $ret=$p_cn->get_array($sql);
121 return $ret;
122 }

References $ret, and $sql.

◆ object_clone()

Forecast::object_clone ( )

Definition at line 148 of file forecast.class.php.

149 {
150 $this->load();
151 /* save into the table forecast */
152 $sql="insert into forecast(f_name,f_start_date,f_end_date) select 'clone '||f_name,f_start_date,f_end_date from forecast where f_id=$1 returning f_id";
153 $new=$this->cn->get_value($sql,array($this->f_id));
154
155 /* save into forecast_cat */
156 $sql="insert into forecast_cat(fc_desc,f_id,fc_order) select fc_desc,$1,fc_order from forecast_cat where f_id=$2 returning fc_id" ;
157 $array=$this->cn->get_array($sql,array($new,$this->f_id));
158
159 $old=$this->cn->get_array("select fc_id from forecast_cat where f_id=$1",array($this->f_id));
160 /* save into forecast_item */
161 for ($i=0;$i<count($array);$i++)
162 {
163 $this->cn->exec_sql("insert into forecast_item (fi_text,fi_account,fi_order,fc_id,fi_amount,fi_pid) ".
164 " select fi_text,fi_account,fi_order,$1,fi_amount,fi_pid ".
165 " from forecast_item where fc_id=$2",array($array[$i]['fc_id'],$old[$i]['fc_id']));
166 }
167 }
load()
load from db

References $array, $i, $old, $sql, cn, and load().

+ Here is the call graph for this function:

◆ save()

Forecast::save ( )

Definition at line 76 of file forecast.class.php.

77 {
78 /* please adapt */
79 if ( $this->get_parameter("id") == 0 )
80 $this->insert();
81 else
82 $this->update();
83 }
update()
update the forecast table
get_parameter($p_string)

References get_parameter(), insert(), and update().

+ Here is the call graph for this function:

◆ set_parameter()

Forecast::set_parameter (   $p_string,
  $p_value 
)

Definition at line 53 of file forecast.class.php.

54 {
55 if ( array_key_exists($p_string,self::$variable) )
56 {
57 $idx=self::$variable[$p_string];
58 $this->$idx=$p_value;
59 }
60 else
61 throw new Exception("Attribut inexistant $p_string");
62 }

References $idx, and $variable.

◆ update()

Forecast::update ( )

update the forecast table

Definition at line 100 of file forecast.class.php.

101 {
102 if ( $this->verify() != 0 ) return;
103
104 $sql="update forecast set f_name=$1,f_start_date=$2,f_end_date=$3 ".
105 " where f_id = $4";
106 $res=$this->cn->exec_sql(
107 $sql,
108 array($this->f_name,$this->f_start_date,$this->f_end_date, $this->f_id)
109 );
110
111 }

References $res, $sql, cn, and verify().

Referenced by save().

+ Here is the call graph for this function:

◆ verify()

Forecast::verify ( )

Definition at line 68 of file forecast.class.php.

69 {
70 // Verify that the elt we want to add is correct
71 // the f_name must be unique (case insensitive)
72 if ( noalyss_strlentrim($this->f_name)==0) throw new Exception(_('Le nom ne peut pas ĂȘtre vide'));
73
74 return 0;
75 }
noalyss_strlentrim($p_string)
Definition: ac_common.php:1549

References noalyss_strlentrim().

Referenced by insert(), and update().

+ Here is the call graph for this function:

Field Documentation

◆ $cn

Forecast::$cn
private

Definition at line 33 of file forecast.class.php.

◆ $variable

Forecast::$variable
staticprivate
Initial value:
=array ("id"=>"f_id",
"name"=>"f_name","start_date"=>"f_start_date","end_date"=>"f_end_date"
)

Definition at line 30 of file forecast.class.php.


The documentation for this class was generated from the following file: