* @author Jean-Pascal MILCENT * @author Aurelien PERONNET * @license GPL v3 * @license CECILL v2 * @copyright 1999-2014 Tela Botanica */ class Dao extends Bdd { private $mode; private $table_liaison; private $table_mots_cles; public function __construct($mode) { parent::__construct(); $this->mode = $mode; if ($mode == 'obs') { $this->table_liaison = 'cel_mots_cles_obs_liaison'; $this->table_mots_cles = 'cel_arbre_mots_cles_obs'; } else { $this->table_liaison = 'cel_mots_cles_images_liaison'; $this->table_mots_cles = 'cel_arbre_mots_cles_images'; } } public function viderTables() { $requete = "TRUNCATE ".$this->table_mots_cles." "; $vidage = $this->requeter($requete.' -- '.__FILE__.':'.__LINE__); $requete = "TRUNCATE ".$this->table_liaison." "; $vidage = $this->requeter($requete.' -- '.__FILE__.':'.__LINE__); return $vidage; } public function obtenirMotsClesOriginaux() { if($this->mode == 'obs') { $requete = "SELECT id_mot_cle_obs as id_mot_cle, ce_mot_cle_obs_parent as parent, id_utilisateur, mot_cle ". "FROM cel_mots_cles_obs WHERE niveau != 0 AND id_utilisateur != '' ORDER BY id_utilisateur, niveau"; } else { $requete = "SELECT id_mot_cle_image as id_mot_cle, ce_mot_cle_image_parent as parent, id_utilisateur, mot_cle ". "FROM cel_mots_cles_images WHERE niveau != 0 AND id_utilisateur != '' ORDER BY id_utilisateur, niveau"; } $mots_cles = $this->recupererTous($requete); return $mots_cles; } public function obtenirLiaisonsMotsClesOriginaux() { if ($this->mode == 'obs') { $requete = "SELECT comc.id_observation as id_element_lie, comc.id_mot_cle_obs as id_mot_cle, id_utilisateur as id_utilisateur ". "FROM cel_obs_mots_cles comc ". "INNER JOIN cel_obs o ON o.id_observation = comc.id_observation "; } else { $requete = "SELECT comc.id_image as id_element_lie, comc.id_mot_cle_image as id_mot_cle, o.ce_utilisateur as id_utilisateur ". "FROM cel_images_mots_cles comc ". "INNER JOIN cel_images o ON o.id_image = comc.id_image "; } $liaisons = $this->recupererTous($requete); return $liaisons; } public function insererMotsCles($mots_cles) { $requete = "INSERT INTO ".$this->table_mots_cles." (chemin, id_utilisateur, mot_cle) VALUES "; foreach ($mots_cles as $mot_cle) { $requete .= '('. $this->proteger($mot_cle['chemin']).', '. $this->proteger($mot_cle['id_utilisateur']).', '. $this->proteger($mot_cle['mot_cle']).' '. '), '; } $requete = rtrim($requete, ', '); return $this->requeter($requete); } public function obtenirInfosNouveauxMotsCles() { $requete = "SELECT id_mot_cle, id_utilisateur, chemin FROM ".$this->table_mots_cles; return $this->recupererTous($requete); } public function insererLiaisonsMotsCles($mots_cles, $liaisons, $correspondances) { $requete = "INSERT INTO ".$this->table_liaison." (id_element_lie, id_mot_cle) VALUES "; $lier = false; $mot_cles_inexistants = 0; foreach ($liaisons as &$liaison_mot_cle) { $cle = $liaison_mot_cle['id_mot_cle'].'-'.$liaison_mot_cle['id_utilisateur']; if (isset($mots_cles[$cle])) { $cle_id_mot_cle_migre = $mots_cles[$cle]['chemin'].'-'.$liaison_mot_cle['id_utilisateur']; if(isset($correspondances[$cle_id_mot_cle_migre])) { $id_mot_cle_migre = $correspondances[$cle_id_mot_cle_migre]['id_mot_cle']; $requete .= "(". $this->proteger($liaison_mot_cle['id_element_lie']).", ". $this->proteger($id_mot_cle_migre)." ". "), "; $lier = true; } else { $mot_cles_inexistants++; } } } if ($lier) { $requete = rtrim($requete, ', '); $this->requeter($requete); } if ($mot_cles_inexistants != 0) { echo $mot_cles_inexistants."\n"; } } }