2025 |
aurelien |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* @package jrest
|
|
|
4 |
* @author Aurélien Peronnet <aurelien@tela-botania.org>
|
|
|
5 |
* @copyright 2010, 2013 Tela-Botanica
|
|
|
6 |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
|
|
|
7 |
*
|
|
|
8 |
* Librairie de liaison d'images et d'observation à des mots clés en utilisant la méthode
|
|
|
9 |
* path enumeration
|
|
|
10 |
*/
|
|
|
11 |
|
|
|
12 |
class GestionMotsClesChemin {
|
|
|
13 |
|
|
|
14 |
private $config;
|
|
|
15 |
private $mode;
|
|
|
16 |
|
|
|
17 |
private $table_liaison;
|
|
|
18 |
private $table_mots_cles;
|
|
|
19 |
|
2032 |
aurelien |
20 |
//TODO: trigger pour les tables liaisons
|
|
|
21 |
|
2026 |
aurelien |
22 |
public function GestionMotsClesChemin($config, $mode = 'obs') {
|
2025 |
aurelien |
23 |
$this->config = $config;
|
|
|
24 |
//TODO: switch suivant mode
|
2027 |
aurelien |
25 |
$this->mode = $mode;
|
|
|
26 |
|
|
|
27 |
if($mode == 'obs') {
|
2042 |
aurelien |
28 |
$this->table_liaison = 'cel_mots_cles_obs_liaison';
|
|
|
29 |
$this->table_mots_cles = 'cel_arbre_mots_cles_obs';
|
2027 |
aurelien |
30 |
} else {
|
2042 |
aurelien |
31 |
$this->table_liaison = 'cel_mots_cles_images_liaison';
|
|
|
32 |
$this->table_mots_cles = 'cel_arbre_mots_cles_images';
|
2027 |
aurelien |
33 |
}
|
2025 |
aurelien |
34 |
}
|
2026 |
aurelien |
35 |
|
2027 |
aurelien |
36 |
public function construireRequeteOr($mots_cles) {
|
|
|
37 |
return $this->construireRequete($mots_cles, 'OR');
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
public function construireRequeteCheminOr($mots_cles) {
|
|
|
41 |
return $this->construireRequeteChemin($mots_cles, 'OR');
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
public function construireRequeteAnd($mots_cles) {
|
|
|
45 |
return $this->construireRequete($mots_cles, 'AND');
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
public function construireRequeteCheminAnd($mots_cles) {
|
|
|
49 |
return $this->construireRequeteChemin($mots_cles, 'AND');
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
public function construireRequete($mots_cles, $operateur = 'AND') {
|
|
|
53 |
$criteres = array();
|
|
|
54 |
$premier = array_pop($mots_cles);
|
2032 |
aurelien |
55 |
$requete = "SELECT * FROM ".$this->table_liaison." lmc ".
|
|
|
56 |
"INNER JOIN ".$this->table_mots_cles." mc ".
|
2042 |
aurelien |
57 |
"ON mc.tag = ".Cel::db()->proteger($premier)." AND lmc.id_mot_cle = mc.id_mot_cle ";
|
2027 |
aurelien |
58 |
foreach ($mots_cles as $mot_cle) {
|
2032 |
aurelien |
59 |
$requete .= " ".$operateur." id_element_lie IN (SELECT id_element_lie FROM ".$this->table_liaison." lmc ".
|
|
|
60 |
"INNER JOIN ".$this->table_mots_cles." mc ".
|
2042 |
aurelien |
61 |
"ON mc.tag = ".Cel::db()->proteger($mot_cle)." AND lmc.id_mot_cle = mc.id_mot_cle ".
|
2032 |
aurelien |
62 |
") ";
|
2027 |
aurelien |
63 |
}
|
2032 |
aurelien |
64 |
|
2027 |
aurelien |
65 |
$images = Cel::db()->requeter($requete);
|
|
|
66 |
return $images;
|
|
|
67 |
}
|
|
|
68 |
|
2042 |
aurelien |
69 |
private function construireRequeteChemin($mots_cles, $operateur = 'AND') {
|
|
|
70 |
$criteres = array();
|
2027 |
aurelien |
71 |
$premier = array_pop($mots_cles);
|
2032 |
aurelien |
72 |
$requete = "SELECT * FROM ".$this->table_liaison." lmc ".
|
|
|
73 |
"INNER JOIN ".$this->table_mots_cles." mc ".
|
2042 |
aurelien |
74 |
"ON mc.chemin LIKE ".Cel::db()->proteger('%'.$premier.'%')." AND lmc.id_mot_cle = mc.id_mot_cle ";
|
2027 |
aurelien |
75 |
foreach ($mots_cles as $mot_cle) {
|
2032 |
aurelien |
76 |
$requete .= " ".$operateur." id_element_lie IN (SELECT id_element_lie FROM ".$this->table_liaison." lmc ".
|
|
|
77 |
"INNER JOIN ".$this->table_mots_cles." mc ".
|
2042 |
aurelien |
78 |
"ON mc.chemin LIKE ".Cel::db()->proteger('%'.$mot_cle.'%')." AND lmc.id_mot_cle = mc.id_mot_cle ".
|
2032 |
aurelien |
79 |
") ";
|
2027 |
aurelien |
80 |
}
|
2032 |
aurelien |
81 |
|
2027 |
aurelien |
82 |
$images = Cel::db()->requeter($requete);
|
|
|
83 |
return $images;
|
|
|
84 |
}
|
|
|
85 |
|
2025 |
aurelien |
86 |
public function obtenirArbre($id_utilisateur, $chemin = "/") {
|
|
|
87 |
$requete = "SELECT * FROM ".$this->table_mots_cles." ".
|
|
|
88 |
"WHERE id_utilisateur = ".Cel::db()->proteger($id_utilisateur)." AND ".
|
2026 |
aurelien |
89 |
"chemin LIKE ".Cel::db()->proteger($chemin."%")." ".
|
|
|
90 |
"ORDER BY chemin";
|
2025 |
aurelien |
91 |
|
2026 |
aurelien |
92 |
$arbre = Cel::db()->requeter($requete.' -- '.__FILE__.':'.__LINE__);
|
|
|
93 |
usort($arbre, array('GestionMotsClesChemin', 'comparerProfNoeuds'));
|
2025 |
aurelien |
94 |
|
|
|
95 |
return $arbre;
|
|
|
96 |
}
|
|
|
97 |
|
2042 |
aurelien |
98 |
public function obtenirIdsMotsClesParIdParent($id_utilisateur, $id_mot_cle) {
|
|
|
99 |
$requete = "SELECT id_mot_cle FROM ".$this->table_mots_cles." ".
|
|
|
100 |
"WHERE chemin LIKE CONCAT(".
|
|
|
101 |
"(SELECT chemin FROM ".$this->table_mots_cles." ".
|
|
|
102 |
"WHERE id_mot_cle = ".Cel::db()->proteger($id_mot_cle)."), ".
|
|
|
103 |
"'%')";
|
|
|
104 |
|
|
|
105 |
$ids_enfants = Cel::db()->requeter($requete.' -- '.__FILE__.':'.__LINE__);
|
|
|
106 |
|
|
|
107 |
return $ids_enfants;
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
public function insererParChemin($mot_cle, $chemin_parent, $id_utilisateur) {
|
2026 |
aurelien |
111 |
$chemin_mot_cle = self::getCheminHarmonise($chemin_parent, $mot_cle);
|
2025 |
aurelien |
112 |
|
2032 |
aurelien |
113 |
$requete = "INSERT IGNORE INTO ".$this->table_mots_cles." (chemin, id_utilisateur, tag) ".
|
2025 |
aurelien |
114 |
"VALUES (".
|
|
|
115 |
Cel::db()->proteger($chemin_mot_cle).", ".
|
|
|
116 |
Cel::db()->proteger($id_utilisateur).", ".
|
2026 |
aurelien |
117 |
Cel::db()->proteger($mot_cle)." ".
|
2025 |
aurelien |
118 |
")";
|
2032 |
aurelien |
119 |
|
2025 |
aurelien |
120 |
$insertion = Cel::db()->executer($requete.' -- '.__FILE__.':'.__LINE__);
|
2042 |
aurelien |
121 |
$resultat = false;
|
|
|
122 |
if($insertion !== false) {
|
|
|
123 |
$resultat = Cel::db()->obtenirDernierId();
|
|
|
124 |
}
|
2025 |
aurelien |
125 |
|
2042 |
aurelien |
126 |
return $resultat;
|
2025 |
aurelien |
127 |
}
|
|
|
128 |
|
2042 |
aurelien |
129 |
public function insererParIdParent($mot_cle, $id_parent, $id_utilisateur) {
|
2025 |
aurelien |
130 |
$mot_cle_simp = self::simplifier($mot_cle);
|
|
|
131 |
|
2042 |
aurelien |
132 |
if($id_parent != "") {
|
|
|
133 |
$sous_requete_chemin = "(SELECT chemin FROM ".$this->table_mots_cles." ctp ".
|
|
|
134 |
"WHERE ctp.id_mot_cle = ".Cel::db()->proteger($id_parent).")";
|
|
|
135 |
} else {
|
|
|
136 |
$sous_requete_chemin = Cel::db()->proteger("/");
|
|
|
137 |
}
|
2025 |
aurelien |
138 |
|
2042 |
aurelien |
139 |
$requete = "INSERT INTO ".$this->table_mots_cles."(chemin, id_utilisateur, mot_cle) ".
|
2025 |
aurelien |
140 |
"VALUES (".
|
2032 |
aurelien |
141 |
"CONCAT(".$sous_requete_chemin.",".Cel::db()->proteger($mot_cle_simp).",'/'), ".
|
2025 |
aurelien |
142 |
Cel::db()->proteger($id_utilisateur).", ".
|
2032 |
aurelien |
143 |
Cel::db()->proteger($mot_cle)." ".
|
2025 |
aurelien |
144 |
")";
|
|
|
145 |
|
|
|
146 |
$insertion = Cel::db()->executer($requete.' -- '.__FILE__.':'.__LINE__);
|
|
|
147 |
|
2042 |
aurelien |
148 |
if($insertion !== false) {
|
|
|
149 |
$resultat = Cel::db()->obtenirDernierId();
|
|
|
150 |
}
|
|
|
151 |
|
|
|
152 |
return $resultat;
|
2025 |
aurelien |
153 |
}
|
|
|
154 |
|
2032 |
aurelien |
155 |
public function lierParId($id_mot_cle, $id_element_lie) {
|
|
|
156 |
|
2042 |
aurelien |
157 |
$requete = "INSERT INTO ".$this->table_liaison." (id_element_lie, id_mot_cle) ".
|
2025 |
aurelien |
158 |
"VALUES (".
|
2032 |
aurelien |
159 |
Cel::db()->proteger($id_element_lie).", ".
|
|
|
160 |
Cel::db()->proteger($id_mot_cle)." ".
|
2025 |
aurelien |
161 |
") ".
|
2032 |
aurelien |
162 |
"ON DUPLICATE KEY UPDATE id_element_lie = id_element_lie ";
|
2025 |
aurelien |
163 |
|
|
|
164 |
$liaison = Cel::db()->executer($requete.' -- '.__FILE__.':'.__LINE__);
|
|
|
165 |
|
|
|
166 |
return $liaison;
|
|
|
167 |
}
|
|
|
168 |
|
2032 |
aurelien |
169 |
public function lierParChemin($chemin, $id_element_lie, $id_utilisateur) {
|
|
|
170 |
|
2042 |
aurelien |
171 |
$sous_requete_chemin = '(SELECT id_mot_cle FROM '.$this->table_mots_cles.' '.
|
2032 |
aurelien |
172 |
'WHERE chemin = '.Cel::db()->proteger(self::harmoniserChemin($chemin)).' '.
|
|
|
173 |
'AND id_utilisateur = '.Cel::db()->proteger($id_utilisateur).' '.
|
|
|
174 |
')';
|
|
|
175 |
|
2042 |
aurelien |
176 |
$requete = "INSERT INTO ".$this->table_liaison." (id_element_lie, id_mot_cle) ".
|
2025 |
aurelien |
177 |
"VALUES (".
|
2032 |
aurelien |
178 |
Cel::db()->proteger($id_element_lie).", ".
|
|
|
179 |
$sous_requete_chemin." ".
|
2025 |
aurelien |
180 |
") ".
|
2032 |
aurelien |
181 |
"ON DUPLICATE KEY UPDATE id_element_lie = id_element_lie ";
|
2025 |
aurelien |
182 |
|
|
|
183 |
$liaison = Cel::db()->executer($requete.' -- '.__FILE__.':'.__LINE__);
|
|
|
184 |
|
|
|
185 |
return $liaison;
|
|
|
186 |
}
|
|
|
187 |
|
2042 |
aurelien |
188 |
public function lierParTableaux($ids_mots_cles, $ids_elements_lies, $id_utilisateur) {
|
|
|
189 |
|
|
|
190 |
|
|
|
191 |
foreach($ids_mots_cles as $id_mot_cle) {
|
|
|
192 |
foreach($ids_elements_lies as $id_element_lie) {
|
|
|
193 |
$combinaisons[] = '('.
|
|
|
194 |
Cel::db()->proteger($id_element_lie).', '.
|
|
|
195 |
Cel::db()->proteger($id_mot_cle).
|
|
|
196 |
')';
|
|
|
197 |
}
|
|
|
198 |
}
|
|
|
199 |
|
|
|
200 |
$requete = "INSERT INTO ".$this->table_liaison." (id_element_lie, id_mot_cle) ".
|
|
|
201 |
"VALUES ".
|
|
|
202 |
implode(',', $combinaisons).' '.
|
|
|
203 |
"ON DUPLICATE KEY UPDATE id_element_lie = id_element_lie ";
|
|
|
204 |
$liaison = Cel::db()->executer($requete.' -- '.__FILE__.':'.__LINE__);
|
2032 |
aurelien |
205 |
|
2042 |
aurelien |
206 |
return $liaison;
|
|
|
207 |
}
|
|
|
208 |
|
|
|
209 |
public function supprimerLiaisonsMotsCles($ids_mots_cles, $ids_elements_lies, $id_utilisateur) {
|
|
|
210 |
|
|
|
211 |
$requete = 'DELETE FROM '.$this->table_liaison.' WHERE ';
|
|
|
212 |
$combinaisons = array();
|
|
|
213 |
foreach($ids_mots_cles as $id_mot_cle) {
|
|
|
214 |
foreach($ids_elements_lies as $id_element_lie) {
|
|
|
215 |
$combinaisons[] = '('.
|
|
|
216 |
'id_element_lie = '.Cel::db()->proteger($id_element_lie).' AND '.
|
|
|
217 |
'id_mot_cle = '.Cel::db()->proteger($id_mot_cle).
|
|
|
218 |
')';
|
|
|
219 |
}
|
|
|
220 |
}
|
|
|
221 |
$requete .= implode(' OR ', $combinaisons);
|
|
|
222 |
$suppression = Cel::db()->executer($requete.' -- '.__FILE__.':'.__LINE__);
|
|
|
223 |
|
|
|
224 |
return $suppression;
|
|
|
225 |
}
|
|
|
226 |
|
|
|
227 |
public function supprimerToutesLiaisonsPourIdsElementsLies($ids_elements_lies, $id_utilisateur) {
|
|
|
228 |
|
|
|
229 |
foreach($ids_elements_lies as &$id_element_lie) {
|
|
|
230 |
$id_element_lie = Cel::db()->proteger($id_element_lie);
|
|
|
231 |
}
|
|
|
232 |
$requete = 'DELETE FROM '.$this->table_liaison.' '.
|
|
|
233 |
'WHERE id_element_lie IN ('.implode(',', $ids_elements_lies).')';
|
|
|
234 |
|
|
|
235 |
$suppression = Cel::db()->executer($requete.' -- '.__FILE__.':'.__LINE__);
|
|
|
236 |
return $suppression;
|
|
|
237 |
}
|
|
|
238 |
|
|
|
239 |
public function supprimerToutesLiaisonsIdsMotsCles($ids_mots_cles, $id_utilisateur) {
|
|
|
240 |
|
|
|
241 |
foreach($ids_mots_cles as &$id_mot_cle) {
|
|
|
242 |
$id_mot_cle = Cel::db()->proteger($id_mot_cle);
|
|
|
243 |
}
|
|
|
244 |
$requete = 'DELETE FROM '.$this->table_liaison.' '.
|
|
|
245 |
'WHERE id_mot_cle IN ('.implode(',', $ids_mots_cles).') ';
|
|
|
246 |
|
|
|
247 |
$suppression = Cel::db()->executer($requete.' -- '.__FILE__.':'.__LINE__);
|
|
|
248 |
return $suppression;
|
|
|
249 |
}
|
|
|
250 |
|
|
|
251 |
public function renommerMotCle($id_mot_cle, $nouveau_nom) {
|
|
|
252 |
|
|
|
253 |
$requete_ancien_chemin = 'SELECT chemin, id_utilisateur FROM '.$this->table_mots_cles.' '.
|
|
|
254 |
'WHERE id_mot_cle = '.Cel::db()->proteger($id_mot_cle);
|
|
|
255 |
$res_ancien_chemin = Cel::db()->requeter($requete_ancien_chemin.' -- '.__FILE__.':'.__LINE__);
|
|
|
256 |
|
|
|
257 |
$ancien_chemin = $res_ancien_chemin[0]['chemin'];
|
|
|
258 |
$id_utilisateur = $res_ancien_chemin[0]['id_utilisateur'];
|
|
|
259 |
|
|
|
260 |
$tab_chemin = explode('/', $ancien_chemin);
|
|
|
261 |
|
|
|
262 |
// le dernier élément du tableau est vide (à cause du / terminal)
|
|
|
263 |
// c'est également le cas pour le premier (à cause du / qui commence le chemin)
|
|
|
264 |
$tab_chemin[count($tab_chemin) - 2] = $nouveau_nom;
|
|
|
265 |
$nouveau_chemin = implode('/', $tab_chemin);
|
|
|
266 |
|
|
|
267 |
$requete = 'UPDATE '.$this->table_mots_cles.' '.
|
|
|
268 |
'SET mot_cle = '.Cel::db()->proteger($nouveau_nom).' '.
|
|
|
269 |
'WHERE id_mot_cle = '.Cel::db()->proteger($id_mot_cle).' ';
|
|
|
270 |
|
|
|
271 |
$renommage = Cel::db()->executer($requete.' -- '.__FILE__.':'.__LINE__);
|
|
|
272 |
|
|
|
273 |
$this->renommerChemin($ancien_chemin, $nouveau_chemin, $id_utilisateur);
|
|
|
274 |
|
|
|
275 |
return $renommage;
|
|
|
276 |
}
|
|
|
277 |
|
|
|
278 |
public function deplacerMotCle($id_mot_cle, $id_pere, $id_utilisateur) {
|
|
|
279 |
|
|
|
280 |
$selection_chemin_pere = 'SELECT chemin FROM '.$this->table_mots_cles.' '.
|
|
|
281 |
'WHERE id_mot_cle = '.Cel::db()->proteger($id_pere);
|
|
|
282 |
|
|
|
283 |
$chemin_pere = Cel::db()->requeter($selection_chemin_pere.' -- '.__FILE__.':'.__LINE__);
|
|
|
284 |
$chemin_pere = $chemin_pere[0]['chemin'];
|
|
|
285 |
|
|
|
286 |
$selection_infos_mot_cle = 'SELECT chemin, mot_cle FROM '.$this->table_mots_cles.' '.
|
|
|
287 |
'WHERE id_mot_cle = '.Cel::db()->proteger($id_mot_cle);
|
|
|
288 |
|
|
|
289 |
$infos_mot_cle = Cel::db()->requeter($selection_infos_mot_cle.' -- '.__FILE__.':'.__LINE__);
|
|
|
290 |
$ancien_chemin = $infos_mot_cle[0]['chemin'];
|
|
|
291 |
|
|
|
292 |
$nouveau_chemin = $chemin_pere.'/'.$infos_mot_cle[0]['mot_cle'];
|
|
|
293 |
|
|
|
294 |
return $this->renommerChemin($ancien_chemin, $nouveau_chemin, $id_utilisateur);
|
|
|
295 |
}
|
|
|
296 |
|
2025 |
aurelien |
297 |
public function renommerChemin($ancien_chemin, $nouveau_chemin, $id_utilisateur) {
|
2026 |
aurelien |
298 |
|
|
|
299 |
$ancien_chemin = self::harmoniserChemin($ancien_chemin);
|
|
|
300 |
$nouveau_chemin = self::harmoniserChemin($nouveau_chemin);
|
|
|
301 |
|
|
|
302 |
$ancien_chemin_p = Cel::db()->proteger($ancien_chemin);
|
|
|
303 |
$nouveau_chemin_p = Cel::db()->proteger($nouveau_chemin);
|
|
|
304 |
|
2042 |
aurelien |
305 |
$condition_chemin = Cel::db()->proteger($ancien_chemin.'%');
|
|
|
306 |
|
2026 |
aurelien |
307 |
$requete = "UPDATE ".$this->table_mots_cles." ".
|
2042 |
aurelien |
308 |
"SET chemin = REPLACE(chemin,".$ancien_chemin_p.", ".$nouveau_chemin_p.") ".
|
|
|
309 |
"WHERE chemin LIKE ".$condition_chemin." AND ".
|
|
|
310 |
"id_utilisateur = ".$id_utilisateur." ";
|
2032 |
aurelien |
311 |
|
2042 |
aurelien |
312 |
return Cel::db()->executer($requete.' -- '.__FILE__.':'.__LINE__);
|
2025 |
aurelien |
313 |
}
|
|
|
314 |
|
|
|
315 |
public function supprimerChemin($chemin, $id_utilisateur) {
|
|
|
316 |
// TODO : triggers pour les tables liées ?
|
|
|
317 |
$requete = "DELETE FROM ".$this->$table_mots_cles." ".
|
|
|
318 |
"WHERE chemin LIKE ".Cel::db()->proteger($chemin."%")." AND ".
|
|
|
319 |
"id_utilisateur = ".Cel::db()->proteger($id_utilisateur)." ";
|
|
|
320 |
|
2042 |
aurelien |
321 |
return Cel::db()->executer($requete.' -- '.__FILE__.':'.__LINE__);
|
|
|
322 |
}
|
|
|
323 |
|
|
|
324 |
public function supprimerMotCleEtEnfantsParId($id_mot_cle, $id_utilisateur) {
|
2025 |
aurelien |
325 |
|
2042 |
aurelien |
326 |
$selection_chemin = 'SELECT chemin FROM '.$this->table_mots_cles.' '.
|
|
|
327 |
'WHERE id_mot_cle = '.Cel::db()->proteger($id_mot_cle);
|
|
|
328 |
$chemin = Cel::db()->requeter($selection_chemin.' -- '.__FILE__.':'.__LINE__);
|
|
|
329 |
$chemin = $chemin[0]['chemin'];
|
|
|
330 |
|
|
|
331 |
$requete = "DELETE FROM ".$this->table_mots_cles." WHERE chemin LIKE ".
|
|
|
332 |
Cel::db()->proteger($chemin.'%')." ".
|
|
|
333 |
"AND id_utilisateur =".Cel::db()->proteger($id_utilisateur);
|
|
|
334 |
|
|
|
335 |
return Cel::db()->executer($requete.' -- '.__FILE__.':'.__LINE__);
|
|
|
336 |
|
2025 |
aurelien |
337 |
}
|
|
|
338 |
|
2042 |
aurelien |
339 |
public function obtenirIdElementsLiesPourChemins($chemins) {
|
|
|
340 |
foreach($chemins as &$chemin) {
|
|
|
341 |
$chemin = Cel::db()->proteger(self::harmoniserChemin($chemin));
|
|
|
342 |
}
|
|
|
343 |
|
|
|
344 |
$requete = 'SELECT id_element_lie FROM '.$this->table_liaison.' cl '.
|
|
|
345 |
'INNER JOIN '.$this->table_mots_cles.' cm '.
|
|
|
346 |
'ON cm.id_mot_cle = cl.id_mot_cle AND chemin IN ('.implode(',', $chemin).')';
|
|
|
347 |
|
|
|
348 |
$ids_pour_chemin = Cel::db()->executer($requete.' -- '.__FILE__.':'.__LINE__);
|
|
|
349 |
|
|
|
350 |
return $ids_pour_chemin;
|
|
|
351 |
}
|
|
|
352 |
|
|
|
353 |
public function obtenirIdElementsLiesPourIds($ids_mots_cles) {
|
|
|
354 |
|
|
|
355 |
foreach($ids_mots_cles as $id_mot_cle) {
|
|
|
356 |
$id_mot_cle = Cel::db()->proteger($id_mot_cle);
|
|
|
357 |
}
|
|
|
358 |
|
|
|
359 |
$requete = 'SELECT id_element_lie FROM '.$this->table_liaison.' '.
|
|
|
360 |
'WHERE id_mot_cle IN ('.implode(',', $ids_mots_cles).')';
|
|
|
361 |
|
|
|
362 |
$ids_elements_lies = Cel::db()->executer($requete.' -- '.__FILE__.':'.__LINE__);
|
|
|
363 |
|
|
|
364 |
return $ids_elements_lies;
|
|
|
365 |
}
|
|
|
366 |
|
|
|
367 |
public static function obtenirTemplateRequeteMotsClesTexte($mode) {
|
|
|
368 |
|
|
|
369 |
if($mode == 'obs') {
|
|
|
370 |
$table_liaison = 'cel_mots_cles_obs_liaison';
|
|
|
371 |
$table_mots_cles = 'cel_arbre_mots_cles_obs';
|
|
|
372 |
} else {
|
|
|
373 |
$table_liaison = 'cel_mots_cles_images_liaison';
|
|
|
374 |
$table_mots_cles = 'cel_arbre_mots_cles_images';
|
|
|
375 |
}
|
|
|
376 |
|
|
|
377 |
// renvoie un template de requete pour selectionner la concatenation
|
|
|
378 |
// de mots clé pour un element donné (utilisable avec sprintf)
|
|
|
379 |
return 'SELECT GROUP_CONCAT(mot_cle) '.
|
|
|
380 |
'FROM '.$table_mots_cles.' cm '.
|
|
|
381 |
'INNER JOIN '.$table_liaison.' cml '.
|
|
|
382 |
'ON cml.id_mot_cle = cm.id_mot_cle '.
|
|
|
383 |
'AND cml.id_element_lie = %s ';
|
|
|
384 |
}
|
|
|
385 |
|
2025 |
aurelien |
386 |
// Fonctions utilitaires
|
|
|
387 |
static public function comparerProfNoeuds($a, $b) {
|
|
|
388 |
|
|
|
389 |
$nb_slashs_a = substr_count($a['chemin'], '/');
|
|
|
390 |
$nb_slashs_b = substr_count($a['chemin'], '/');
|
|
|
391 |
$cmp = 0;
|
|
|
392 |
|
|
|
393 |
if($nb_slashs_a == $nb_slashs_b) {
|
|
|
394 |
$cmp = strcmp($a['chemin'], $b['chemin']);
|
|
|
395 |
} else {
|
|
|
396 |
$cmp = ($a['chemin'] > $b['chemin']) ? +1 : -1;
|
|
|
397 |
}
|
|
|
398 |
|
|
|
399 |
return $cmp;
|
|
|
400 |
}
|
|
|
401 |
|
2026 |
aurelien |
402 |
static public function getCheminHarmonise($chemin_parent, $mot_cle) {
|
|
|
403 |
return self::harmoniserChemin($chemin_parent.'/'.self::simplifier($mot_cle).'/');
|
|
|
404 |
}
|
|
|
405 |
|
|
|
406 |
static public function harmoniserChemin($chemin) {
|
|
|
407 |
$chemin = self::startsWith($chemin,'/') ? $chemin : '/'.$chemin;
|
|
|
408 |
$chemin = self::endsWith($chemin,'/') ? $chemin : $chemin.'/';
|
|
|
409 |
return str_replace('//', '/', $chemin);
|
|
|
410 |
}
|
|
|
411 |
|
2025 |
aurelien |
412 |
// fonction de slugification du mot clé
|
|
|
413 |
// http://stackoverflow.com/questions/2955251/php-function-to-make-slug-url-string
|
|
|
414 |
static public function simplifier($text)
|
|
|
415 |
{
|
2026 |
aurelien |
416 |
return trim(str_replace(array('\\','/'), '', $text));
|
2025 |
aurelien |
417 |
// replace non letter or digits by -
|
|
|
418 |
$text = preg_replace('~[^\\pL\d]+~u', '-', $text);
|
|
|
419 |
|
|
|
420 |
// trim
|
|
|
421 |
$text = trim($text, '-');
|
|
|
422 |
|
|
|
423 |
// transliterate
|
|
|
424 |
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
|
|
|
425 |
|
|
|
426 |
// lowercase
|
|
|
427 |
$text = strtolower($text);
|
|
|
428 |
|
|
|
429 |
// remove unwanted characters
|
|
|
430 |
$text = preg_replace('~[^-\w]+~', '', $text);
|
|
|
431 |
|
|
|
432 |
if (empty($text))
|
|
|
433 |
{
|
|
|
434 |
return 'n-a';
|
|
|
435 |
}
|
|
|
436 |
|
|
|
437 |
return $text;
|
|
|
438 |
}
|
2026 |
aurelien |
439 |
|
|
|
440 |
static public function startsWith($haystack, $needle) {
|
|
|
441 |
return $needle === "" || strpos($haystack, $needle) === 0;
|
|
|
442 |
}
|
|
|
443 |
|
|
|
444 |
static public function endsWith($haystack, $needle) {
|
|
|
445 |
return $needle === "" || substr($haystack, -strlen($needle)) === $needle;
|
|
|
446 |
}
|
2025 |
aurelien |
447 |
}
|
|
|
448 |
?>
|