id = $id+0; parent::__construct(); } protected function fetch_datas(){ if($this->id){ //on commence par aller chercher ses infos $query = " select id_cadre_content, cadre_content_hash, cadre_content_num_cadre, cadre_content_data from cms_cadre_content where id_cadre_content = ".$this->id; $result = mysql_query($query); if(mysql_num_rows($result)){ $row = mysql_fetch_object($result); $this->id = $row->id_cadre_content+0; $this->hash = $row->cadre_content_hash; $this->cadre_parent = $row->cadre_content_num_cadre+0; $this->unserialize($row->cadre_content_data); } //on va chercher les infos des sélecteurs... $query = "select id_cadre_content, cadre_content_object from cms_cadre_content where cadre_content_type='selector' and cadre_content_num_cadre_content = ".$this->id; $result = mysql_query($query); if(mysql_num_rows($result)){ while($row=mysql_fetch_object($result)){ $this->selectors[] = array( 'id' => $row->id_cadre_content+0, 'name' => $row->cadre_content_object ); } } } } public function set_module_class_name($module_class_name){ $this->module_class_name = $module_class_name; $this->fetch_managed_datas(); } public static function is_loadable_default(){ return false; } public function set_cadre_parent($id){ $this->cadre_parent = $id+0; } public function get_available_selectors(){ return array(); } public function get_form(){ $selectors = $this->get_available_selectors(); $form = "
"; $form.= $this->get_selectors_list_form(); if($this->parameters['selector']!= "" || count($selectors)==1){ $selector_id = 0; if($this->parameters['selector']!= ""){ for($i=0 ; $iselectors) ; $i++){ if($this->selectors[$i]['name'] == $this->parameters['selector']){ $selector_id = $this->selectors[$i]['id']; break; } } $selector_name = $this->parameters['selector']; }else if(count($selectors)==1){ $selector_name = $selectors[0]; } $form.=" "; } $form.="
"; return $form; } protected function get_selectors_list_form(){ $selectors = $this->get_available_selectors(); if(count($selectors)>1){ $form= "
parameters['selector'] : "" )."' />
"; }else{ $form = "
 
 
"; } $form.="
"; return $form; } public function save_form(){ $selector_choice = $this->class_name."_selector_choice"; global $$selector_choice; $this->parameters['selector'] = $$selector_choice; $this->get_hash(); if($this->id){ $query = "update cms_cadre_content set"; $clause = " where id_cadre_content=".$this->id; }else{ $query = "insert into cms_cadre_content set"; $clause = ""; } $query.= " cadre_content_hash = '".$this->hash."', cadre_content_type = 'condition', cadre_content_object = '".$this->class_name."',". ($this->cadre_parent ? "cadre_content_num_cadre = ".$this->cadre_parent."," : "")." cadre_content_data = '".addslashes($this->serialize())."' ".$clause; $result = mysql_query($query); if($result){ if(!$this->id){ $this->id = mysql_insert_id(); } //sélecteur $selector_id = 0; for($i=0 ; $iselectors) ; $i++){ if($$selector_choice == $this->selectors[$i]['name']){ $selector_id = $this->selectors[$i]['id']; break; } } $selector = new $$selector_choice($selector_id); $selector->set_parent($this->id); $selector->set_cadre_parent($this->cadre_parent); $result = $selector->save_form(); if($result){ if($selector_id==0){ $this->selectors[] = array( 'id' => $selector->id, 'name' => $$selector_choice ); } return true; }else{ //création de la source de donnée ratée, on supprime le hash de la table... $this->delete_hash(); return false; } }else{ //création de la source de donnée ratée, on supprime le hash de la table... $this->delete_hash(); return false; } } protected function get_selected_selector(){ //on va chercher if($this->parameters['selector']!= ""){ $current_selector_id = 0; for($i=0 ; $iselectors) ; $i++){ if($this->selectors[$i]['name'] == $this->parameters['selector']){ return new $this->parameters['selector']($this->selectors[$i]['id']); } } }else{ return false; } } public function delete(){ if($this->id){ //on commence par éliminer le sélecteur associé... $query = "select id_cadre_content,cadre_content_object from cms_cadre_content where cadre_content_num_cadre_content = ".$this->id; $result = mysql_query($query); if(mysql_num_rows($result)){ //la logique voudrait qu'il n'y ai qu'un seul sélecteur (enfin sous-élément, la conception peut évoluer...), mais sauvons les brebis égarées... while($row = mysql_fetch_object($result)){ $sub_elem = new $row->cadre_content_object($row->id_cadre_content); $success = $sub_elem->delete(); if(!$success){ //TODO verbose mode return false; } } } //on est tout seul, éliminons-nous ! $query = "delete from cms_cadre_content where id_cadre_content = ".$this->id; $result = mysql_query($query); if($result){ $this->delete_hash(); return true; }else{ return false; } } //on est tout seul, éliminons-nous ! $query = "delete from cms_cadre_content where id_cadre_content = ".$this->id; $result = mysql_query($query); if($result){ $this->delete_hash(); return true; }else{ return false; } } protected function fetch_managed_datas(){ parent::fetch_managed_datas("conditions"); } protected function get_exported_datas(){ $infos = parent::get_exported_datas(); $infos['type'] = "condition"; return $infos; } }