| Line 83... |
Line 83... |
| 83 |
/**
|
83 |
/**
|
| 84 |
* Lie un mot-clé à une ou plusieurs images.
|
84 |
* Lie un mot-clé à une ou plusieurs images.
|
| 85 |
*
|
85 |
*
|
| 86 |
* @param String $utilisateur_id identifiant de l'utilisateur.
|
86 |
* @param String $utilisateur_id identifiant de l'utilisateur.
|
| 87 |
* @param String $mot_cle texte du mot-clé.
|
87 |
* @param String $mot_cle texte du mot-clé.
|
| 88 |
* @param Array $ordres_obs un tableau d'odre d'observation (int) pour lesquels nous devons ajouter le mot-clé.
|
88 |
* @param Array $images_ids un tableau d'id d'images (int) pour lesquels nous devons ajouter le mot-clé.
|
| 89 |
*/
|
89 |
*/
|
| 90 |
public function lierMotCleImg($utilisateur_id, Array $mots_cles_ids, Array $images_ids) {
|
90 |
public function lierMotCleImg($utilisateur_id, Array $mots_cles_ids, Array $images_ids) {
|
| 91 |
$retour = false;
|
91 |
$retour = false;
|
| Line 92... |
Line 92... |
| 92 |
|
92 |
|
| Line 226... |
Line 226... |
| 226 |
$valeur = trim($valeur, ';;');
|
226 |
$valeur = trim($valeur, ';;');
|
| Line 227... |
Line 227... |
| 227 |
|
227 |
|
| 228 |
return $valeur;
|
228 |
return $valeur;
|
| Line 229... |
Line 229... |
| 229 |
}
|
229 |
}
|
| 230 |
|
230 |
|
| 231 |
public function ajouterMotCleObs($utilisateur_id, $mot_cle, $mot_cle_id, $mot_cle_parent_id) {
|
231 |
public function ajouterMotCleObs($utilisateur_id, $mot_cle, $mot_cle_parent_id) {
|
| 232 |
$this->suffix = self::OBS_TABLE_SUFFIXE;
|
232 |
$this->suffix = self::OBS_TABLE_SUFFIXE;
|
| 233 |
$this->utilisateur_id = $utilisateur_id;
|
233 |
$this->utilisateur_id = $utilisateur_id;
|
| Line 234... |
Line 234... |
| 234 |
return $this->ajouterMotCle($mot_cle, $mot_cle_id, $mot_cle_parent_id);
|
234 |
return $this->ajouterMotCle($mot_cle, $mot_cle_parent_id);
|
| 235 |
}
|
235 |
}
|
| 236 |
|
236 |
|
| 237 |
public function ajouterMotCleImg($utilisateur_id, $mot_cle, $mot_cle_id, $mot_cle_parent_id) {
|
237 |
public function ajouterMotCleImg($utilisateur_id, $mot_cle, $mot_cle_parent_id) {
|
| 238 |
$this->suffix = self::IMG_TABLE_SUFFIXE;
|
238 |
$this->suffix = self::IMG_TABLE_SUFFIXE;
|
| Line 239... |
Line 239... |
| 239 |
$this->utilisateur_id = $utilisateur_id;
|
239 |
$this->utilisateur_id = $utilisateur_id;
|
| 240 |
return $this->ajouterMotCle($mot_cle, $mot_cle_id, $mot_cle_parent_id);
|
240 |
return $this->ajouterMotCle($mot_cle, $mot_cle_parent_id);
|
| 241 |
}
|
241 |
}
|
| 242 |
|
242 |
|
| - |
|
243 |
private function ajouterMotCle($mot_cle, $mot_cle_parent_id) {
|
| - |
|
244 |
$retour = true;
|
| 243 |
private function ajouterMotCle($mot_cle, $mot_cle_id, $mot_cle_parent_id) {
|
245 |
$this->ajouterMotCleRacine();
|
| Line 244... |
Line 246... |
| 244 |
$retour = true;
|
246 |
if ($this->verifierAbscence($mot_cle, $mot_cle_parent_id)) {
|
| 245 |
$this->ajouterMotCleRacine();
|
247 |
$mot_cle_id = $this->genererTagId($mot_cle);
|
| 246 |
if ($this->verifierAbscence($mot_cle_id)) {
|
248 |
|
| 247 |
$this->commencerTransaction();
|
249 |
$this->commencerTransaction();
|
| 248 |
|
250 |
|
| 249 |
$bornes = $this->retrouverBornesEtNiveau($mot_cle_parent_id);
|
251 |
$bornes = $this->retrouverBornesEtNiveau($mot_cle_parent_id);
|
| Line 250... |
Line 252... |
| 250 |
$borne_pere = $bornes['cmc_bd'];
|
252 |
$borne_pere = $bornes['cmc_bd'];
|
| 251 |
$niveau = $bornes['cmc_niveau'] + 1;
|
253 |
$niveau = $bornes['cmc_niveau'] + 1;
|
| 252 |
$bg = $bornes['cmc_bd'];
|
254 |
$bg = $bornes['cmc_bd'];
|
| 253 |
$bd = $bg + 1;
|
255 |
$bd = $bg + 1;
|
| 254 |
$mot_cle_encode = $this->encoderMotCle($mot_cle);
|
256 |
$mot_cle_encode = $this->encoderMotCle($mot_cle);
|
| 255 |
|
257 |
|
| 256 |
$mot_cle = $this->proteger($mot_cle);
|
258 |
$mot_cle_protege = $this->proteger($mot_cle);
|
| 257 |
$bg = $this->proteger($bg);
|
259 |
$bg = $this->proteger($bg);
|
| Line 258... |
Line 260... |
| 258 |
$bd = $this->proteger($bd);
|
260 |
$bd = $this->proteger($bd);
|
| Line 259... |
Line 261... |
| 259 |
$mot_cle_encode = $this->proteger($mot_cle_encode);
|
261 |
$mot_cle_encode = $this->proteger($mot_cle_encode);
|
| 260 |
$mot_cle_id = $this->proteger($mot_cle_id);
|
262 |
$mot_cle_id = $this->proteger($mot_cle_id);
|
| 261 |
$id_utilisateur = $this->proteger($this->utilisateur_id);
|
263 |
$id_utilisateur = $this->proteger($this->utilisateur_id);
|
| 262 |
$mot_cle_parent_id = $this->proteger($mot_cle_parent_id);
|
264 |
$mot_cle_parent_id_protege = $this->proteger($mot_cle_parent_id);
|
| 263 |
$niveau = $this->proteger($niveau);
|
265 |
$niveau = $this->proteger($niveau);
|
| 264 |
|
266 |
|
| 265 |
$transaction_reussie_1 = $this->decalerBornesPlusDeux($borne_pere) ? true : false;
|
267 |
$transaction_reussie_1 = $this->decalerBornesPlusDeux($borne_pere) ? true : false;
|
| 266 |
|
268 |
|
| Line 267... |
Line -... |
| 267 |
$requete = "INSERT INTO cel_mots_cles{$this->suffix} ".
|
- |
|
| 268 |
"VALUES ( $mot_cle, $bg, $bd, $mot_cle_encode, $mot_cle_id, ".
|
269 |
$requete = "INSERT INTO cel_mots_cles{$this->suffix} ".
|
| 269 |
" $id_utilisateur, $mot_cle_parent_id, $niveau) ";
|
270 |
"VALUES ( $mot_cle_protege, $bg, $bd, $mot_cle_encode, $mot_cle_id, ".
|
| 270 |
$transaction_reussie_2 = $this->executerSQL($requete);
|
271 |
" $id_utilisateur, $mot_cle_parent_id_protege, $niveau) ";
|
| 271 |
if (!$transaction_reussie_2) {
|
272 |
$transaction_reussie_2 = $this->executerSQL($requete);
|
| 272 |
$e = "Échec d'insertion du mot-clé : $requete ";
|
273 |
if (!$transaction_reussie_2) {
|
| 273 |
$this->messages[] = $e;
|
274 |
$e = "Échec d'insertion du mot-clé : $requete ";
|
| 274 |
}
|
275 |
$this->messages[] = $e;
|
| 275 |
|
276 |
}
|
| 276 |
$retour = null;
|
277 |
|
| Line -... |
Line 278... |
| - |
|
278 |
if ($transaction_reussie_1 && $transaction_reussie_2) {
|
| 277 |
if ($transaction_reussie_1 && $transaction_reussie_2) {
|
279 |
$retour = $this->completerTransaction();
|
| - |
|
280 |
} else {
|
| - |
|
281 |
$retour = $this->annulerTransaction();
|
| - |
|
282 |
}
|
| - |
|
283 |
} else {
|
| - |
|
284 |
$e = "Le mot-clé '$mot_cle' existe déjà dans la table cel_mots_cles{$this->suffix}.";
|
| - |
|
285 |
$this->debug[] = $e;
|
| 278 |
$retour = $this->completerTransaction();
|
286 |
}
|
| Line -... |
Line 287... |
| - |
|
287 |
|
| - |
|
288 |
$id = ($retour) ? $this->getIdMotCle($mot_cle, $mot_cle_parent_id) : false;
|
| - |
|
289 |
return $id;
|
| - |
|
290 |
}
|
| - |
|
291 |
|
| - |
|
292 |
private function genererTagId($tag) {
|
| - |
|
293 |
$id = ($this->getHashCode($tag) + ((mt_rand() / (double)mt_getrandmax()) * 10000));
|
| - |
|
294 |
$id = str_replace(',', '.', $id);
|
| - |
|
295 |
return $id;
|
| 279 |
} else {
|
296 |
}
|
| 280 |
$retour = $this->annulerTransaction();
|
297 |
|
| 281 |
}
|
298 |
private function getHashCode($chaine){
|
| 282 |
} else {
|
299 |
$hash = 0;
|
| 283 |
$e = "Le mot-clé '$mot_cle' ayant l'id '$mot_cle_id' existe déjà dans la table cel_mots_cles{$this->suffix}.";
|
300 |
$stringLength = strlen($chaine);
|
| 284 |
$this->debug[] = $e;
|
301 |
for ($i = 0; $i < $stringLength; $i++) {
|
| 285 |
}
|
302 |
$hash = 31 * $hash + $chaine[$i];
|
| 286 |
|
303 |
}
|
| Line 308... |
Line 325... |
| 308 |
$nom_racine = $this->proteger($nom_racine);
|
325 |
$nom_racine = $this->proteger($nom_racine);
|
| 309 |
$id_racine = $this->proteger($id_racine);
|
326 |
$id_racine = $this->proteger($id_racine);
|
| 310 |
$id_utilisateur = $this->proteger($this->utilisateur_id);
|
327 |
$id_utilisateur = $this->proteger($this->utilisateur_id);
|
| 311 |
$requete = "INSERT INTO cel_mots_cles{$this->suffix} ".
|
328 |
$requete = "INSERT INTO cel_mots_cles{$this->suffix} ".
|
| 312 |
"VALUES ($nom_racine, 1, 2, $id_racine, $id_racine, $id_utilisateur, '', 0) ";
|
329 |
"VALUES ($nom_racine, 1, 2, $id_racine, $id_racine, $id_utilisateur, '', 0) ";
|
| 313 |
$this->debug[] = $requete;
|
- |
|
| 314 |
if ($this->executerSQL($requete) === false) {
|
330 |
if ($this->executerSQL($requete) === false) {
|
| 315 |
$e = "La requête d'insertion du mot-clé racine a échoué.";
|
331 |
$e = "La requête d'insertion du mot-clé racine a échoué.";
|
| 316 |
$this->messages[] = $e;
|
332 |
$this->messages[] = $e;
|
| 317 |
}
|
333 |
}
|
| 318 |
}
|
334 |
}
|
| 319 |
}
|
335 |
}
|
| Line 320... |
Line 336... |
| 320 |
|
336 |
|
| 321 |
private function verifierAbscence($mot_cle_id) {
|
337 |
private function verifierAbscence($mot_cle, $mot_cle_parent_id) {
|
| 322 |
$absence = false;
|
338 |
$absence = false;
|
| - |
|
339 |
$mot_cle = $this->proteger($mot_cle);
|
| 323 |
$mot_cle_id = $this->proteger($mot_cle_id);
|
340 |
$mot_cle_parent_id = $this->proteger($mot_cle_parent_id);
|
| 324 |
$id_utilisateur = $this->proteger($this->utilisateur_id);
|
341 |
$id_utilisateur = $this->proteger($this->utilisateur_id);
|
| 325 |
$requete = 'SELECT COUNT(*) AS nbre '.
|
342 |
$requete = 'SELECT COUNT(*) AS nbre '.
|
| 326 |
"FROM cel_mots_cles{$this->suffix} ".
|
343 |
"FROM cel_mots_cles{$this->suffix} ".
|
| 327 |
"WHERE cmc_id_mot_cle_utilisateur = $mot_cle_id ".
|
344 |
"WHERE cmc_mot_cle = $mot_cle ".
|
| - |
|
345 |
" AND cmc_id_proprietaire = $id_utilisateur ".
|
| 328 |
" AND cmc_id_proprietaire = $id_utilisateur ";
|
346 |
" AND cmc_id_parent = $mot_cle_parent_id";
|
| 329 |
$nbre = $this->recupererValeur($requete);
|
347 |
$nbre = $this->recupererValeur($requete);
|
| 330 |
if ($nbre === false) {
|
348 |
if ($nbre === false) {
|
| 331 |
$e = "La requête de vérification d'abscence d'un mot-clé a échoué.";
|
349 |
$e = "La requête de vérification d'abscence d'un mot-clé a échoué.";
|
| 332 |
$this->messages[] = $e;
|
350 |
$this->messages[] = $e;
|
| 333 |
} else if ($nbre == 0) {
|
351 |
} else if ($nbre == 0) {
|
| 334 |
$absence = true;
|
352 |
$absence = true;
|
| 335 |
}
|
353 |
}
|
| 336 |
return $absence;
|
354 |
return $absence;
|
| Line -... |
Line 355... |
| - |
|
355 |
}
|
| - |
|
356 |
|
| - |
|
357 |
private function getIdMotCle($mot_cle, $mot_cle_parent_id) {
|
| - |
|
358 |
$mot_cle = $this->proteger($mot_cle);
|
| - |
|
359 |
$mot_cle_parent_id = $this->proteger($mot_cle_parent_id);
|
| - |
|
360 |
$id_utilisateur = $this->proteger($this->utilisateur_id);
|
| - |
|
361 |
$requete = 'SELECT cmc_id_mot_cle_utilisateur AS id '.
|
| - |
|
362 |
"FROM cel_mots_cles{$this->suffix} ".
|
| - |
|
363 |
"WHERE cmc_mot_cle = $mot_cle ".
|
| - |
|
364 |
" AND cmc_id_proprietaire = $id_utilisateur ".
|
| - |
|
365 |
" AND cmc_id_parent = $mot_cle_parent_id";
|
| - |
|
366 |
$resultat = $this->recupererResultat($requete);
|
| - |
|
367 |
$mot_cle_id = ($resultat) ? $resultat['id'] : false;
|
| - |
|
368 |
return $mot_cle_id;
|
| 337 |
}
|
369 |
}
|
| 338 |
|
370 |
|
| 339 |
private function compterMotsCles() {
|
371 |
private function compterMotsCles() {
|
| 340 |
$nbre = 0;
|
372 |
$nbre = 0;
|
| 341 |
$id_utilisateur = $this->proteger($this->utilisateur_id);
|
373 |
$id_utilisateur = $this->proteger($this->utilisateur_id);
|