db=$p_cn; $this->ga_id=null; $this->ga_description=null; $this->pa_id=null; } /*! * \brief insert into the database an object * \return message with error otherwise an empty string */ function insert() { $sql=" insert into groupe_analytique (ga_id,ga_description,pa_id) values ('%s','%s',%d)"; $sql=sprintf($sql,Database::escape_string($this->ga_id), Database::escape_string($this->ga_description), $this->pa_id); try { $this->db->exec_sql($sql); } catch (Exception $a) { return 'Doublon !!'; } return ""; } /*! * \brief remove from the database */ function remove() { $this->ga_id=str_replace(' ','',$this->ga_id); $this->ga_id=strtoupper($this->ga_id); $sql=" delete from groupe_analytique where ga_id='".Database::escape_string($this->ga_id)."'"; $this->db->exec_sql($sql); } /*! * \brief load from the database and make an object */ function load() { $sql="select ga_id, ga_description,pa_id from groupe_analytique where". " ga_id = ".$this->ga_id; $res=$this->db->exec_sql($sql); $array=Database::fetch_all($res); if ( ! empty($array) ) { $this->ga_id=$array['ga_id']; $this->ga_description=$array['ga_description']; $this->pa_id=$array['pa_id']; } } /*! * \brief fill the object thanks an array * \param array */ function get_from_array($p_array) { $this->ga_id=$p_array['ga_id']; $this->pa_id=$p_array['pa_id']; $this->ga_description=$p_array['ga_description']; } function myList() { $sql=" select ga_id,groupe_analytique.pa_id,pa_name,ga_description ". " from groupe_analytique ". " join plan_analytique using (pa_id)"; $r=$this->db->exec_sql($sql); $array=Database::fetch_all($r); $res=array(); if ( ! empty($array)) { foreach ($array as $m ) { $obj= new Anc_Group($this->db); $obj->get_from_array($m); $obj->pa_name=$m['pa_name']; $res[]=clone $obj; } } return $res; } static function test_me() { $cn=new Database(dossier::id()); print_r($cn); $o=new Anc_Group($cn); $r=$o->myList(); print_r($r); echo '