num_cadre_content = (int) $id; } public function set_filter($filter) { $this->used_external_filters = true; $this->external_filters[] = $filter; } /* * Récupération des informations en base */ 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 sous-sources $query = "select id_cadre_content, cadre_content_object from cms_cadre_content where cadre_content_type='datasource' and cadre_content_num_cadre != 0 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->datasources[] = array( 'id' => (int) $row->id_cadre_content, 'name' => $row->cadre_content_object ); } } } } /* * Méthode de génération du formulaire... */ public function get_form(){ $datasources = $this->get_available_datasources(); $form = "
"; $form.=$this->get_hash_form(); $form.= $this->get_datasources_list_form(); $form.="
"; return $form; } /* * Formulaire de sélection d'un sélecteur */ protected function get_datasources_list_form(){ global $base_path; $datasources = $this->get_available_datasources(); $form= "
"; if(count($this->parameters['datasources_name'])>0){ $form.=" "; } return $form; } /* * Sauvegarde des infos depuis un formulaire... */ public function save_form(){ global $dbh; $this->parameters['datasources_name'] = $this->get_value_from_form('datasources_name'); $this->parameters['datasources_id'] = $this->get_value_from_form('datasources_id'); //TODO A REPRENDRE $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 = 'datasource', 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(); } //on supprime les anciennes sources de données... $query = "select id_cadre_content,cadre_content_object from cms_cadre_content where id_cadre_content != '".$this->id."' and cadre_content_type='datasource' and cadre_content_num_cadre = '".$this->cadre_parent."' and cadre_content_num_cadre_content=0"; $result = pmb_mysql_query($query,$dbh); if(pmb_mysql_num_rows($result)){ while($row= pmb_mysql_fetch_object($result)){ $obj = new $row->cadre_content_object($row->id_cadre_content); $obj->delete(); } } //sous-sources for($i=0 ; $iparameters['datasources_name']) ; $i++){ $datasource = new $this->parameters['datasources_name'][$i]($this->parameters['datasources_id'][$i]); $datasource->set_cadre_parent($this->cadre_parent); $datasource->set_num_cadre_content($this->id); $datasource->set_brothers($this->parameters['datasources_id']); $result = $datasource->save_form(); $this->parameters['datasources_id'][$i] = $datasource->id; } //On nettoie les sous sources absentes du cadres//on supprime les anciennes sources de données... $query = "select id_cadre_content,cadre_content_object from cms_cadre_content where "; if(count($this->parameters['datasources_id'])){ $query.= "id_cadre_content not in (".implode(",",$this->parameters['datasources_id']).") and "; } $query.= "cadre_content_type='datasource' and cadre_content_num_cadre = '".$this->cadre_parent."' 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)){ $obj = new $row->cadre_content_object($row->id_cadre_content); $obj->delete(); } } //on remet à jour la liste des sous-sources dans la source multiple $query = "update cms_cadre_content set cadre_content_data = '".addslashes($this->serialize())."' where id_cadre_content='".$this->id."'"; $result = pmb_mysql_query($query,$dbh); 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; } } /* * Méthode de suppression */ 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; } } } /* * Méthode pour renvoyer les données tel que défini par le sélecteur */ public function get_datas(){ $datas = array(); for($i=0 ; $iparameters['datasources_name']) ; $i++){ $datasource = new $this->parameters['datasources_name'][$i]($this->parameters['datasources_id'][$i]); $datas = array_merge_recursive($datas,$datasource->get_datas()); } return $datas; } public function get_headers($datas=array()){ $headers=array(); if($this->parameters['datasource']){ $datasource = $this->get_selected_datasource(); $headers = array_merge($headers,$datasource->get_headers($datas)); $headers = array_unique($headers); } return $headers; } protected function get_selected_datasource(){ //on va chercher if($this->parameters['datasource']!= ""){ $current_datasource_id = 0; for($i=0 ; $idatasources) ; $i++){ if($this->datasources[$i]['name'] == $this->parameters['datasource']){ return new $this->parameters['datasource']($this->datasources[$i]['id']); } } }else{ return false; } } public function get_format_data_structure(){ return array(); } }