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') {
|
|
|
15 |
$this->table_liaison = 'cel_obs_tags_path_liaison';
|
|
|
16 |
$this->table_mots_cles = 'cel_obs_tags_path';
|
|
|
17 |
$this->champ_id_element_lie = 'id_obs';
|
|
|
18 |
} else {
|
|
|
19 |
$this->table_liaison = 'cel_images_tags_path_liaison';
|
|
|
20 |
$this->table_mots_cles = 'cel_images_tags_path';
|
|
|
21 |
$this->champ_id_element_lie = 'id_image';
|
|
|
22 |
}
|
|
|
23 |
}
|
|
|
24 |
|
|
|
25 |
public function viderTables() {
|
|
|
26 |
$requete = "TRUNCATE ".$this->table_mots_cles." ";
|
|
|
27 |
$vidage = $this->requeter($requete.' -- '.__FILE__.':'.__LINE__);
|
|
|
28 |
|
|
|
29 |
$requete = "TRUNCATE ".$this->table_liaison." ";
|
|
|
30 |
$vidage = $this->requeter($requete.' -- '.__FILE__.':'.__LINE__);
|
|
|
31 |
|
|
|
32 |
return $vidage;
|
|
|
33 |
}
|
|
|
34 |
|
|
|
35 |
public function obtenirMotsClesOriginaux() {
|
|
|
36 |
|
|
|
37 |
if($this->mode == 'obs') {
|
|
|
38 |
$requete_arbre = "SELECT id_mot_cle_obs as id_mot_cle, ce_mot_cle_obs_parent as parent, id_utilisateur, mot_cle ".
|
|
|
39 |
"FROM cel_mots_cles_obs ORDER BY id_utilisateur, niveau";
|
|
|
40 |
} else {
|
|
|
41 |
$requete_arbre = "SELECT id_mot_cle_image as id_mot_cle, ce_mot_cle_image_parent as parent, id_utilisateur, mot_cle ".
|
|
|
42 |
"FROM cel_mots_cles_images ORDER BY id_utilisateur, niveau";
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
$mots_cles = $this->recupererTous($requete_arbre);
|
|
|
46 |
return $mots_cles;
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
public function obtenirLiaisonsMotsClesOriginaux() {
|
|
|
50 |
if($this->mode == 'obs') {
|
|
|
51 |
$requete_liaisons = "SELECT comc.id_observation as id_element_lie, comc.id_mot_cle_obs as id_mot_cle, id_utilisateur as id_utilisateur ".
|
|
|
52 |
"FROM cel_obs_mots_cles_srv comc ".
|
|
|
53 |
"INNER JOIN cel_obs o ON o.id_observation = comc.id_observation ";
|
|
|
54 |
} else {
|
|
|
55 |
$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 ".
|
|
|
56 |
"FROM cel_images_mots_cles_srv comc ".
|
|
|
57 |
"INNER JOIN cel_images_srv o ON o.id_image = comc.id_image ";
|
|
|
58 |
}
|
|
|
59 |
$liaisons = $this->recupererTous($requete_liaisons);
|
|
|
60 |
return $liaisons;
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
public function insererMotsCles($mots_cles) {
|
|
|
64 |
$requete_insertion_mots_cles = "INSERT INTO ".$this->table_mots_cles." (chemin, id_utilisateur, tag) ".
|
|
|
65 |
" VALUES ";
|
|
|
66 |
|
|
|
67 |
foreach($mots_cles as $cle => $mot_cle) {
|
|
|
68 |
$requete_insertion_mots_cles .= "(".
|
|
|
69 |
$this->proteger($mot_cle['chemin']).", ".
|
|
|
70 |
$this->proteger($mot_cle['id_utilisateur']).", ".
|
|
|
71 |
$this->proteger($mot_cle['tag'])." ".
|
|
|
72 |
"), ";
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
$requete_insertion_mots_cles = rtrim($requete_insertion_mots_cles, ", ");
|
|
|
76 |
return $this->requeter($requete_insertion_mots_cles);
|
|
|
77 |
}
|
|
|
78 |
|
|
|
79 |
public function obtenirInfosNouveauxMotsCles() {
|
|
|
80 |
$requete = "SELECT id_tag, id_utilisateur, chemin FROM ".$this->table_mots_cles;
|
|
|
81 |
return $this->recupererTous($requete);
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
public function insererLiaisonsMotsCles($mots_cles, $liaisons, $correspondances) {
|
|
|
85 |
$requete_insertion_liaisons = "INSERT INTO ".$this->table_liaison." (id_element_lie, id_tag) ".
|
|
|
86 |
" VALUES ";
|
|
|
87 |
$lier = false;
|
|
|
88 |
$mot_cles_inexistants = 0;
|
|
|
89 |
|
|
|
90 |
foreach($liaisons as &$liaison_mot_cle) {
|
|
|
91 |
$cle = $liaison_mot_cle['id_mot_cle'].'-'.$liaison_mot_cle['id_utilisateur'];
|
|
|
92 |
if(isset($mots_cles[$cle])) {
|
|
|
93 |
$cle_id_mot_cle_migre = $mots_cles[$cle]['chemin'].'-'.$liaison_mot_cle['id_utilisateur'];
|
|
|
94 |
if(isset($correspondances[$cle_id_mot_cle_migre])) {
|
|
|
95 |
$id_mot_cle_migre = $correspondances[$cle_id_mot_cle_migre]['id_tag'];
|
|
|
96 |
$requete_insertion_liaisons .= "(".
|
|
|
97 |
$this->proteger($liaison_mot_cle['id_element_lie']).", ".
|
|
|
98 |
$this->proteger($id_mot_cle_migre)." ".
|
|
|
99 |
"), ";
|
|
|
100 |
$lier = true;
|
|
|
101 |
} else {
|
|
|
102 |
$mot_cles_inexistants++;
|
|
|
103 |
}
|
|
|
104 |
}
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
if($lier) {
|
|
|
108 |
$requete_insertion_liaisons = rtrim($requete_insertion_liaisons, ", ");
|
|
|
109 |
$this->requeter($requete_insertion_liaisons);
|
|
|
110 |
}
|
|
|
111 |
if($mot_cles_inexistants != 0) {
|
|
|
112 |
echo $mot_cles_inexistants."\n";
|
|
|
113 |
}
|
|
|
114 |
}
|
|
|
115 |
}
|