id = (int) $id; parent::__construct(); } protected function fetch_datas(){ global $dbh; 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 = pmb_mysql_query($query,$dbh); if(pmb_mysql_num_rows($result)){ $row = pmb_mysql_fetch_object($result); $this->id = (int) $row->id_cadre_content; $this->hash = $row->cadre_content_hash; $this->cadre_parent = (int) $row->cadre_content_num_cadre; $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 = pmb_mysql_query($query,$dbh); if(pmb_mysql_num_rows($result)){ while($row=pmb_mysql_fetch_object($result)){ $this->selectors[] = array( 'id' => (int) $row->id_cadre_content, '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 = (int) $id; } public function get_available_selectors(){ return array(); } public function get_form(){ $selectors = $this->get_available_selectors(); $form = $this->get_hash_form(); $form.= "
"; $form.= $this->get_selectors_list_form(); if((isset($this->parameters['selector']) && $this->parameters['selector']!= "") || count($selectors)==1){ $selector_id = 0; if(isset($this->parameters['selector']) && $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.="
id.", '".$this->class_name."');\"/>
"; return $form; } public function save_form(){ global $dbh; $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 = pmb_mysql_query($query,$dbh); if($result){ if(!$this->id){ $this->id = pmb_mysql_insert_id(); } //sélecteur $selector_id = 0; if (!empty($this->selectors)) { 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(){ global $dbh; 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 = pmb_mysql_query($query,$dbh); if(pmb_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 = pmb_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 = pmb_mysql_query($query,$dbh); 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 = pmb_mysql_query($query,$dbh); if($result){ $this->delete_hash(); return true; }else{ return false; } } protected function fetch_managed_datas($type="conditions"){ parent::fetch_managed_datas($type); } protected function get_exported_datas(){ $infos = parent::get_exported_datas(); $infos['type'] = "condition"; return $infos; } //fonction qui détermine si un cadre utilisant cette condition peut être caché! public static function use_cache(){ return true; } }