Subversion Repositories eFlore/Applications.cel

Rev

Rev 2046 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2046 Rev 2056
Line 55... Line 55...
55
		$ids_enfants = Cel::db()->executerRequete($requete.' -- '.__FILE__.':'.__LINE__);
55
		$ids_enfants = Cel::db()->executerRequete($requete.' -- '.__FILE__.':'.__LINE__);
Line 56... Line 56...
56
 
56
 
57
		return $ids_enfants;
57
		return $ids_enfants;
Line 58... Line 58...
58
	}
58
	}
59
	
59
	
-
 
60
	public function insererParCheminSiInexistant($mot_cle, $chemin_parent, $id_utilisateur) {
-
 
61
		$chemin_mot_cle = self::getCheminHarmonise($chemin_parent, $mot_cle);
-
 
62
		$requete_mot_cle_existe = "SELECT id_mot_cle FROM ".$this->table_mots_cles." ".
Line -... Line 63...
-
 
63
		           "WHERE chemin = ".Cel::db()->proteger($chemin_mot_cle)." AND ".
-
 
64
		           "id_utilisateur = ".Cel::db()->proteger($id_utilisateur);
-
 
65
		
-
 
66
		$infos_mot_cle = Cel::db()->executerRequete($requete_mot_cle_existe.' -- '.__FILE__.':'.__LINE__);
-
 
67
 
-
 
68
		if(!empty($infos_mot_cle)) {
-
 
69
			$id_mot_cle = $infos_mot_cle[0]['id_mot_cle'];
-
 
70
		} else {
-
 
71
			$id_mot_cle = $this->insererParChemin($mot_cle, $chemin_parent, $id_utilisateur);
-
 
72
		}
-
 
73
		return $id_mot_cle;
-
 
74
	}
60
	public function insererParChemin($mot_cle, $chemin_parent, $id_utilisateur) {		
75
	
61
		$chemin_mot_cle = self::getCheminHarmonise($chemin_parent, $mot_cle);
76
	public function insererParChemin($mot_cle, $chemin_parent, $id_utilisateur) {	
62
		
77
		$chemin_mot_cle = self::getCheminHarmonise($chemin_parent, $mot_cle);
63
		$requete = "INSERT IGNORE INTO ".$this->table_mots_cles." (chemin, id_utilisateur, tag) ".
78
		$requete = "INSERT INTO ".$this->table_mots_cles." (chemin, id_utilisateur, mot_cle) ".
64
		           "VALUES (".
79
		           "VALUES (".
65
		           		Cel::db()->proteger($chemin_mot_cle).", ".
80
		           		Cel::db()->proteger($chemin_mot_cle).", ".
66
						Cel::db()->proteger($id_utilisateur).", ".
81
						Cel::db()->proteger($id_utilisateur).", ".
67
						Cel::db()->proteger($mot_cle)." ".
82
						Cel::db()->proteger($mot_cle)." ".
68
		           ")";
83
		           ") ";
69
 
84
		
70
		$insertion = Cel::db()->executer($requete.' -- '.__FILE__.':'.__LINE__);
85
		$insertion = Cel::db()->executer($requete.' -- '.__FILE__.':'.__LINE__);
71
		$resultat = false;
86
		$resultat = false;
Line 149... Line 164...
149
		$requete = "INSERT INTO ".$this->table_liaison." (id_element_lie, id_mot_cle) ".
164
		$requete = "INSERT INTO ".$this->table_liaison." (id_element_lie, id_mot_cle) ".
150
						"VALUES ".
165
						"VALUES ".
151
							implode(',', $combinaisons).' '.
166
							implode(',', $combinaisons).' '.
152
						"ON DUPLICATE KEY UPDATE id_element_lie = id_element_lie ";
167
						"ON DUPLICATE KEY UPDATE id_element_lie = id_element_lie ";
153
		$liaison = Cel::db()->executer($requete.' -- '.__FILE__.':'.__LINE__);
168
		$liaison = Cel::db()->executer($requete.' -- '.__FILE__.':'.__LINE__);
154
	
169
		
155
		return $liaison;
170
		return $liaison;
156
	}
171
	}
Line 157... Line 172...
157
	
172
	
Line 346... Line 361...
346
 
361
 
Line 347... Line 362...
347
		return ($suppression !== false);
362
		return ($suppression !== false);
Line -... Line 363...
-
 
363
		
-
 
364
	}
-
 
365
	
-
 
366
	public function obtenirIdsMotClesPourMotsCles($mots_cles, $id_utilisateur) {
-
 
367
		$mots_cles_p = array();
-
 
368
		foreach($mots_cles as $mot_cle) {
-
 
369
			$mots_cles_p[] = Cel::db()->proteger($mot_cle);
-
 
370
		}
-
 
371
		
-
 
372
		$requete = "SELECT id_mot_cle, mot_cle FROM ".$this->table_mots_cles." ".
-
 
373
		           "WHERE mot_cle IN (".implode(',', $mots_cles_p).") ".
-
 
374
		           "AND id_utilisateur = ".Cel::db()->proteger($id_utilisateur);
-
 
375
 
348
		
376
		return Cel::db()->executer($requete.' -- '.__FILE__.':'.__LINE__);
349
	}
377
	}
350
	
378
	
351
	public function obtenirIdElementsLiesPourChemins($chemins, $id_utilisateur) {
379
	public function obtenirIdElementsLiesPourChemins($chemins, $id_utilisateur) {
Line 448... Line 476...
448
	// fonction de slugification du mot clé
476
	// fonction de slugification du mot clé
449
	// http://stackoverflow.com/questions/2955251/php-function-to-make-slug-url-string
477
	// http://stackoverflow.com/questions/2955251/php-function-to-make-slug-url-string
450
	static public function simplifier($text)
478
	static public function simplifier($text)
451
	{
479
	{
452
		return trim(str_replace(array('\\','/'), '', $text));
480
		return trim(str_replace(array('\\','/'), '', $text));
453
		// replace non letter or digits by -
-
 
454
		$text = preg_replace('~[^\\pL\d]+~u', '-', $text);
-
 
455
	
-
 
456
		// trim
-
 
457
		$text = trim($text, '-');
-
 
458
	
-
 
459
		// transliterate
-
 
460
		$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
-
 
461
	
-
 
462
		// lowercase
-
 
463
		$text = strtolower($text);
-
 
464
	
-
 
465
		// remove unwanted characters
-
 
466
		$text = preg_replace('~[^-\w]+~', '', $text);
-
 
467
	
-
 
468
		if (empty($text))
-
 
469
		{
-
 
470
			return 'n-a';
-
 
471
		}
-
 
472
	
-
 
473
		return $text;
-
 
474
	}
481
	}
Line 475... Line 482...
475
	
482
	
476
	static public function startsWith($haystack, $needle) {
483
	static public function startsWith($haystack, $needle) {
477
		return $needle === "" || strpos($haystack, $needle) === 0;
484
		return $needle === "" || strpos($haystack, $needle) === 0;