Subversion Repositories eFlore/Applications.cel

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2031 aurelien 1
<?php
2
class Dao extends Bdd {
3
 
4
	private $mode;
5
 
6
	private $table_liaison;
7
	private $table_mots_cles;
8
	private $champ_id_element_lie;
9
 
10
	public function __construct($mode) {
11
		parent::__construct();
12
		$this->mode = $mode;
13
 
14
		if($mode == 'obs') {
2057 aurelien 15
			$this->table_liaison = 'cel_mots_cles_obs_liaison';
16
			$this->table_mots_cles = 'cel_arbre_mots_cles_obs';
2031 aurelien 17
		} else {
2057 aurelien 18
			$this->table_liaison = 'cel_mots_cles_images_liaison';
19
			$this->table_mots_cles = 'cel_arbre_mots_cles_images';
2031 aurelien 20
		}
21
	}
22
 
23
	public function viderTables() {
24
		$requete = "TRUNCATE ".$this->table_mots_cles." ";
25
		$vidage = $this->requeter($requete.' -- '.__FILE__.':'.__LINE__);
26
 
27
		$requete = "TRUNCATE ".$this->table_liaison." ";
28
		$vidage = $this->requeter($requete.' -- '.__FILE__.':'.__LINE__);
29
 
30
		return $vidage;
31
	}
32
 
33
	public function obtenirMotsClesOriginaux() {
34
 
35
		if($this->mode == 'obs') {
36
			$requete_arbre = "SELECT id_mot_cle_obs as id_mot_cle, ce_mot_cle_obs_parent as parent, id_utilisateur, mot_cle ".
2068 aurelien 37
								"FROM cel_mots_cles_obs WHERE niveau != 0 AND id_utilisateur != '' ORDER BY id_utilisateur, niveau";
2031 aurelien 38
		} else {
39
			$requete_arbre = "SELECT id_mot_cle_image as id_mot_cle, ce_mot_cle_image_parent as parent, id_utilisateur, mot_cle ".
2068 aurelien 40
								"FROM cel_mots_cles_images WHERE niveau != 0 AND id_utilisateur != '' ORDER BY id_utilisateur, niveau";
2031 aurelien 41
		}
42
 
43
		$mots_cles = $this->recupererTous($requete_arbre);
44
		return $mots_cles;
45
	}
46
 
47
	public function obtenirLiaisonsMotsClesOriginaux() {
48
		if($this->mode == 'obs') {
49
			$requete_liaisons = "SELECT comc.id_observation as id_element_lie, comc.id_mot_cle_obs as id_mot_cle, id_utilisateur as id_utilisateur ".
2057 aurelien 50
															"FROM cel_obs_mots_cles comc ".
2031 aurelien 51
															"INNER JOIN cel_obs o ON o.id_observation = comc.id_observation ";
52
		} else {
53
			$requete_liaisons = "SELECT comc.id_image as id_element_lie, comc.id_mot_cle_image as id_mot_cle, o.ce_utilisateur as id_utilisateur ".
2057 aurelien 54
																		"FROM cel_images_mots_cles comc ".
55
																		"INNER JOIN cel_images o ON o.id_image = comc.id_image ";
2031 aurelien 56
		}
57
		$liaisons = $this->recupererTous($requete_liaisons);
58
		return $liaisons;
59
	}
60
 
61
	public function insererMotsCles($mots_cles) {
2057 aurelien 62
		$requete_insertion_mots_cles = "INSERT INTO ".$this->table_mots_cles." (chemin, id_utilisateur, mot_cle) ".
2031 aurelien 63
						                     			" VALUES ";
64
 
65
		foreach($mots_cles as $cle => $mot_cle) {
66
			$requete_insertion_mots_cles .= "(".
67
			$this->proteger($mot_cle['chemin']).", ".
68
			$this->proteger($mot_cle['id_utilisateur']).", ".
2057 aurelien 69
			$this->proteger($mot_cle['mot_cle'])." ".
2031 aurelien 70
							"), ";
71
		}
72
 
73
		$requete_insertion_mots_cles = rtrim($requete_insertion_mots_cles, ", ");
74
		return $this->requeter($requete_insertion_mots_cles);
75
	}
76
 
77
	public function obtenirInfosNouveauxMotsCles() {
2057 aurelien 78
		$requete = "SELECT id_mot_cle, id_utilisateur, chemin FROM ".$this->table_mots_cles;
2031 aurelien 79
		return $this->recupererTous($requete);
80
	}
81
 
82
	public function insererLiaisonsMotsCles($mots_cles, $liaisons, $correspondances) {
2057 aurelien 83
		$requete_insertion_liaisons = "INSERT INTO ".$this->table_liaison." (id_element_lie, id_mot_cle) ".
2031 aurelien 84
												      " VALUES ";
85
		$lier = false;
86
		$mot_cles_inexistants = 0;
87
 
88
		foreach($liaisons as &$liaison_mot_cle) {
89
			$cle = $liaison_mot_cle['id_mot_cle'].'-'.$liaison_mot_cle['id_utilisateur'];
90
			if(isset($mots_cles[$cle])) {
91
				$cle_id_mot_cle_migre = $mots_cles[$cle]['chemin'].'-'.$liaison_mot_cle['id_utilisateur'];
92
				if(isset($correspondances[$cle_id_mot_cle_migre])) {
2057 aurelien 93
					$id_mot_cle_migre = $correspondances[$cle_id_mot_cle_migre]['id_mot_cle'];
2031 aurelien 94
					$requete_insertion_liaisons .= "(".
95
						$this->proteger($liaison_mot_cle['id_element_lie']).", ".
96
						$this->proteger($id_mot_cle_migre)." ".
97
									"), ";
98
					$lier = true;
99
				} else {
100
					$mot_cles_inexistants++;
101
				}
102
			}
103
		}
104
 
105
		if($lier) {
106
			$requete_insertion_liaisons = rtrim($requete_insertion_liaisons, ", ");
107
			$this->requeter($requete_insertion_liaisons);
108
		}
109
		if($mot_cles_inexistants != 0) {
110
			echo $mot_cles_inexistants."\n";
111
		}
112
	}
113
}