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

manage the table forecast More...

Public Member Functions

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

Static Public Member Functions

static load_all ($p_cn)
 load all the existing forecast
static test_me ()
 unit test

Private Attributes

 $cn

Static Private Attributes

static $variable = array ("id"=>"f_id","name"=>"f_name","start_date"=>"f_start_date","end_date"=>"f_end_date")

Detailed Description

manage the table forecast

Definition at line 28 of file class_forecast.php.


Constructor & Destructor Documentation

Forecast::__construct ( p_init,
p_id = 0 
)

constructor

Parameters:
$p_initDatabase object

Definition at line 36 of file class_forecast.php.

References cn.

    {
        $this->cn=$p_init;
        $this->f_id=$p_id;
    }

Member Function Documentation

Definition at line 136 of file class_forecast.php.

References $res, $sql, and cn.

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

Definition at line 61 of file class_forecast.php.

    {
        return var_export(self::$variable,true);
    }
Forecast::get_parameter ( p_string)

Definition at line 41 of file class_forecast.php.

References $idx, and exit.

Referenced by save().

    {
        if ( array_key_exists($p_string,self::$variable) )
        {
            $idx=self::$variable[$p_string];
            return $this->$idx;
        }
        else
            exit (__FILE__.":".__LINE__."[$p_string]".'Erreur attribut inexistant');
    }

Definition at line 83 of file class_forecast.php.

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

Referenced by save().

    {
        if ( $this->verify() != 0 ) return;
        $sql="insert into forecast (f_name,f_start_date,f_end_date) ".
             " values ($1,$2,$3)  returning f_id";
        $res=$this->cn->exec_sql(
                 $sql,
                 array($this->f_name,$this->f_start_date,$this->f_end_date)
             );
        $this->f_id=Database::fetch_result($res,0,0);
    }

Definition at line 121 of file class_forecast.php.

References $idx, $res, $row, $sql, $value, cn, Database\fetch_array(), and Database\num_row().

Referenced by object_clone().

    {
        $sql="select f_name,f_start_date ,f_end_date from forecast where f_id=$1";
        $res=$this->cn->exec_sql(
                 $sql,
                 array($this->f_id)
             );
        if ( Database::num_row($res) == 0 ) return -1;
        $row=Database::fetch_array($res,0);
        foreach ($row as $idx=>$value)
        {
            $this->$idx=$value;
        }

    }
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 115 of file class_forecast.php.

References $ret, and $sql.

    {
        $sql="select f_id, f_name,f_start_date,f_end_date from forecast";
        $ret=$p_cn->get_array($sql);
        return $ret;
    }

Definition at line 141 of file class_forecast.php.

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

    {
      $this->load();
      /* save into the table forecast */
      $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";
      $new=$this->cn->get_value($sql,array($this->f_id));

      /* save into forecast_cat */
      $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" ;
      $array=$this->cn->get_array($sql,array($new,$this->f_id));

      $old=$this->cn->get_array("select fc_id from forecast_cat where f_id=$1",array($this->f_id));
      /* save into forecast_item */
      for ($i=0;$i<count($array);$i++)
        {
          $this->cn->exec_sql("insert into forecast_item (fi_text,fi_account,fi_card,fi_order,fc_id,fi_amount,fi_debit,fi_pid) ".
                              " select fi_text,fi_account,fi_card,fi_order,$1,fi_amount,fi_debit,fi_pid ".
                              " from forecast_item where fc_id=$2",array($array[$i]['fc_id'],$old[$i]['fc_id']));
        }
    }

Definition at line 74 of file class_forecast.php.

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

    {
        /* please adapt */
        if (  $this->get_parameter("id") == 0 )
            $this->insert();
        else
            $this->update();
    }
Forecast::set_parameter ( p_string,
p_value 
)

Definition at line 51 of file class_forecast.php.

References $idx, and exit.

    {
        if ( array_key_exists($p_string,self::$variable) )
        {
            $idx=self::$variable[$p_string];
            $this->$idx=$p_value;
        }
        else
            exit (__FILE__.":".__LINE__."[$p_string]".'Erreur attribut inexistant');
    }
static Forecast::test_me ( ) [static]

unit test

Definition at line 164 of file class_forecast.php.

    {}

update the forecast table

Definition at line 98 of file class_forecast.php.

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

Referenced by save().

    {
        if ( $this->verify() != 0 ) return;

        $sql="update forecast set f_name=$1,f_start_date=$2,f_end_date=$3 ".
             " where f_id = $4";
        $res=$this->cn->exec_sql(
                 $sql,
                 array($this->f_name,$this->f_start_date,$this->f_end_date, $this->f_id)
             );

    }

Definition at line 66 of file class_forecast.php.

References trim().

Referenced by insert(), and update().

    {
        // Verify that the elt we want to add is correct
        // the f_name must be unique (case insensitive)
        if ( strlen(trim($this->f_name))==0) throw new Exception(_('Le nom ne peut pas ĂȘtre vide'));

        return 0;
    }

Field Documentation

Forecast::$cn [private]

Definition at line 31 of file class_forecast.php.

Forecast::$variable = array ("id"=>"f_id","name"=>"f_name","start_date"=>"f_start_date","end_date"=>"f_end_date") [static, private]

Definition at line 30 of file class_forecast.php.


The documentation for this class was generated from the following file:
 All Data Structures Namespaces Files Functions Variables Enumerations