db=$p_cn;
$this->id=$p_id;
$this->name="";
$this->description="";
$this->get();
}
/*!\brief get the list of all existing PA
* \return an array of PA (not object)
*
*/
function get_list($p_order=" order by pa_name")
{
$array=array();
$sql="select pa_id as id,pa_name as name,".
"pa_description as description from plan_analytique $p_order";
$ret=$this->db->exec_sql($sql);
$array=Database::fetch_all($ret);
return $array;
}
function get()
{
if ( $this->id==0) return;
$sql="select pa_name,pa_description from plan_analytique where pa_id=".$this->id;
$ret= $this->db->exec_sql($sql);
if ( Database::num_row($ret) == 0)
{
return;
}
$a= Database::fetch_array($ret,0);
$this->name=$a['pa_name'];
$this->description=$a['pa_description'];
}
function delete()
{
if ( $this->id == 0 ) return;
$this->db->exec_sql("delete from plan_analytique where pa_id=".$this->id);
}
function update()
{
if ( $this->id==0) return;
$name=sql_string($this->name);
if ( strlen($name) == 0)
return;
$description=sql_string($this->description);
$this->db->exec_sql("update plan_analytique set pa_name=$1,
pa_description=$2 where pa_id=$3",array($name,$description,$this->id));
}
function add()
{
$name=sql_string($this->name);
if ( strlen($name) == 0)
return;
if ( $this->isAppend() == false) return;
$description=sql_string($this->description);
$this->db->exec_sql("insert into plan_analytique(pa_name,pa_description)".
" values (".
"'".$name."',".
"'".$description."')");
$this->id=$this->db->get_current_seq('plan_analytique_pa_id_seq');
}
function form()
{
$wName=new IText('pa_name',$this->name);
$wName->table=1;
$wDescription=new IText('pa_description',$this->description);
$wDescription->table=1;
$wId=new IHidden("pa_id",$this->id);
$ret="
";
$ret.=''.td(_('Nom')).$wName->input().'
';
$ret.="".td(_('Description')).$wDescription->input()."
";
$ret.="
";
$ret.=$wId->input();
return $ret;
}
function isAppend()
{
$count=$this->db->get_value("select count(pa_id) from plan_analytique");
if ( $count > 10 )
return false;
else
return true;
}
/*!\brief get all the poste related to the current
* Analytic plan
* \return an array of Poste_analytic object
*/
function get_poste_analytique($p_order="")
{
$sql="select po_id,po_name from poste_analytique where pa_id=".$this->id." $p_order";
$r=$this->db->exec_sql($sql);
$ret=array();
if ( Database::num_row($r) == 0 )
return $ret;
$all=Database::fetch_all($r);
foreach ($all as $line)
{
$obj=new Anc_Account($this->db,$line['po_id']);
$obj->get_by_id();
$ret[]=clone $obj;
}
return $ret;
}
/*!\brief show the header for a table for PA
* \return string like name | ...
*/
function header()
{
$res="";
$a_plan=$this->get_list(" order by pa_id");
if ( empty($a_plan)) return "";
foreach ($a_plan as $r_plan)
{
$res.="".h($r_plan['name'])." | ";
}
return $res;
}
function count()
{
$a=$this->db->count_sql("select pa_id from plan_analytique");
return $a;
}
function exist()
{
$a=$this->db->count_sql("select pa_id from plan_analytique where pa_id=".
Database::escape_string($this->pa_id));
return ($a==0)?false:true;
}
/**
*@brief return an HTML string containing hidden input type to
* hold the differant PA_ID
*@param $p_array contains a array, it is the result of the fct
* Anc_Plan::get_list
*@return html string
*@see Anc_Plan::get_list
*/
static function hidden($p_array)
{
$r='';
for ($i_anc=0;$i_anc Plan analytique : test";
echo "clean";
$cn->exec_sql("delete from plan_analytique");
$p=new Anc_Plan($cn);
echo "Add
";
$p->name="Nouveau 1";
$p->description="C'est un test";
echo "Add
";
$p->add();
$p->name="Nouveau 2";
$p->add();
$pa_id=$p->id;
echo $p->id."/";
$p->name="Nouveau 3";
$p->add();
echo $p->id."/";
$p->name="Nouveau 4";
$p->add();
echo $p->id;
echo "get
";
$p->get();
var_dump($p);
echo "Update
";
$p->name="Update ";
$p->description="c'est change";
$p->update();
$p->get();
var_dump($p);
echo "get_list
";
$a=$p->get_list();
var_dump($a);
echo "delete
";
$p->delete();
}
}
?>