/branches/v1.5-cisaille/jrest/services/CelWidgetSaisie.php |
---|
106,8 → 106,8 |
$this->debug[] = 'Nbre obs ajoutée : '.count($observations); |
// Insertion dans la base |
$obs_a_taguer = array(); |
$img_a_taguer = array(); |
$obs_a_taguer_ordres = array(); |
$img_a_taguer_ids = array(); |
foreach ($observations as $infos) { |
$obs = $infos['obs']; |
$img = $infos['img']; |
127,7 → 127,7 |
if ($idImg !== false) { |
$liaisonOk = $this->lierObsEtImg($idImg, $img['id_utilisateur'], $img['id_obs']); |
if ($liaisonOk === true) { |
$img_a_taguer[] = $idImg; |
$img_a_taguer_ids[] = $idImg; |
} |
} |
} |
139,11 → 139,11 |
if ($this->executerRequeteSimple($requete) === false) { |
$this->messages[] = "Un problème est survenu lors de l'insertion de l'obs dans la base de données."; |
} else { |
$obs_a_taguer[] = trim($obs['ordre'], "'"); |
$obs_a_taguer_ordres[] = trim($obs['ordre'], "'"); |
} |
} |
$this->taguerObs($obs_a_taguer); |
$this->taguerImg($img_a_taguer); |
$this->taguerObs($obs_a_taguer_ordres); |
$this->taguerImg($img_a_taguer_ids); |
} else { |
$this->messages[] = "Un nouveau numéro d'ordre d'observation n'a pu être généré."; |
} |
195,11 → 195,11 |
return $dateMysql; |
} |
private function taguerObs($obs_a_taguer) { |
if (count($obs_a_taguer) > 0) { |
private function taguerObs($obs_a_taguer_ordres) { |
if (count($obs_a_taguer_ordres) > 0) { |
foreach ($this->tagsObs as $hierarchieTag) { |
$tagsALier = explode('>', $hierarchieTag); |
$liaisonOk = $this->lierObsAMotsCles($obs_a_taguer, $tagsALier); |
$liaisonOk = $this->lierObsAMotsCles($obs_a_taguer_ordres, $tagsALier); |
if ($liaisonOk === false) { |
$e = "Toutes les observations n'ont pas pu être liées aux mots-clés : $hierarchieTag"; |
$this->messages[] = $e; |
208,32 → 208,29 |
} |
} |
private function lierObsAMotsCles($observations, $tags) { |
$hierarchieIdsTags = array(self::OBS_RACINE_ID); |
private function lierObsAMotsCles($observations_ordres, $tags) { |
$idTagParent = self::OBS_RACINE_ID; |
$listeIdsTags = array(); |
foreach ($tags as $tag) { |
$tag = $this->nettoyerTag($tag); |
$tagTranslit = $this->translitererTag($tag); |
if ($tagTranslit != '') { |
$idTagParent = implode('.', $hierarchieIdsTags); |
$hierarchieIdsTags[] = $tagTranslit; |
$idTag = implode('.', $hierarchieIdsTags); |
$ajout_mot_cle_ok = $this->ajouterMotCleObs($this->utilisateur_id, $tag, $idTag, $idTagParent); |
if ($ajout_mot_cle_ok) { |
$listeIdsTags[] = $idTag; |
if ($tag != '') { |
$id_mot_cle = $this->ajouterMotCleObs($this->utilisateur_id, $tag, $idTagParent); |
if ($id_mot_cle !== false) { |
$listeIdsTags[] = $id_mot_cle; |
$idTagParent = $id_mot_cle; |
} |
} |
} |
$liaison_ok = $this->lierMotCleObs($this->utilisateur_id, $listeIdsTags, $observations); |
$liaison_ok = $this->lierMotCleObs($this->utilisateur_id, $listeIdsTags, $observations_ordres); |
return $liaison_ok; |
} |
private function taguerImg($img_a_taguer) { |
if (count($img_a_taguer) > 0) { |
private function taguerImg($img_a_taguer_ids) { |
if (count($img_a_taguer_ids) > 0) { |
$this->debug[] = "Tags img : ".print_r($this->tagsImg, true); |
foreach ($this->tagsImg as $hierarchieTag) { |
$tagsALier = explode('>', $hierarchieTag); |
$liaisonOk = $this->lierImgAMotsCles($img_a_taguer, $tagsALier); |
$liaisonOk = $this->lierImgAMotsCles($img_a_taguer_ids, $tagsALier); |
if ($liaisonOk === false) { |
$e = "Toutes les images n'ont pas pu être liées aux mots-clés : $hierarchieTag"; |
$this->messages[] = $e; |
242,23 → 239,20 |
} |
} |
private function lierImgAMotsCles($images, $tags) { |
$hierarchieIdsTags = array(self::IMG_RACINE_ID); |
private function lierImgAMotsCles($images_ids, $tags) { |
$idTagParent = self::IMG_RACINE_ID; |
$listeIdsTags = array(); |
foreach ($tags as $tag) { |
$tag = $this->nettoyerTag($tag); |
$tagTranslit = $this->translitererTag($tag); |
if ($tagTranslit != '') { |
$idTagParent = implode('.', $hierarchieIdsTags); |
$hierarchieIdsTags[] = $tagTranslit; |
$idTag = implode('.', $hierarchieIdsTags); |
$ajout_mot_cle_ok = $this->ajouterMotCleImg($this->utilisateur_id, $tag, $idTag, $idTagParent); |
if ($ajout_mot_cle_ok) { |
$listeIdsTags[] = $idTag; |
if ($tag != '') { |
$id_mot_cle = $this->ajouterMotCleImg($this->utilisateur_id, $tag, $idTagParent); |
if ($id_mot_cle !== false) { |
$listeIdsTags[] = $id_mot_cle; |
$idTagParent = $id_mot_cle; |
} |
} |
} |
$liaison_ok = $this->lierMotCleImg($this->utilisateur_id, $listeIdsTags, $images); |
$liaison_ok = $this->lierMotCleImg($this->utilisateur_id, $listeIdsTags, $images_ids); |
return $liaison_ok; |
} |
268,28 → 262,6 |
return $tag; |
} |
private function translitererTag($tag) { |
$tag = mb_strtolower($tag, 'UTF-8'); |
$tag = preg_replace('/[:!?]+/', ' ', $tag); |
$tag = str_replace(' ', '-', $tag); |
$caracteres_accentues = array( |
'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ñ', |
'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ', 'ā', 'ă', 'ą', 'ć', 'ĉ', 'ċ', 'č', |
'ď', 'đ', 'ē', 'ĕ', 'ė', 'ę', 'ě', 'ĝ', 'ğ', 'ġ', 'ģ', 'ĥ', 'ħ', 'ĩ', 'ī', 'ĭ', 'į', 'ı', 'ij', |
'ĵ', 'ķ', 'ĺ', 'ļ', 'ľ', 'ŀ', 'ł', 'ń', 'ņ', 'ň', 'ʼn', 'ō', 'ŏ', 'ő', 'œ', 'ŕ', 'ŗ', 'ř', |
'ś', 'ŝ', 'ş', 'š', 'ţ', 'ť', 'ŧ', 'ũ', 'ū', 'ŭ', 'ů', 'ű', 'ų', 'ŵ', 'ŷ', 'ź', 'ż', 'ž', 'ſ', |
'ƒ', 'ơ', 'ư', 'ǎ', 'ǐ', 'ǒ', 'ǔ', 'ǖ', 'ǘ', 'ǚ', 'ǜ', 'ǻ', 'ǽ', 'ǿ'); |
$caracteres_normaux = array( |
'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'n', |
'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'y', 'a', 'a', 'a', 'c', 'c', 'c', 'c', |
'd', 'd', 'e', 'e', 'e', 'e', 'e', 'g', 'g', 'g', 'g', 'h', 'h', 'i', 'i', 'i', 'i', 'i', 'ij', |
'j', 'k', 'l', 'l', 'l', 'l', 'l', 'n', 'n', 'n', 'n', 'o', 'o', 'o','oe', 'r', 'r', 'r', |
's', 's', 's', 's', 't', 't', 't', 'u', 'u', 'u', 'u', 'u', 'u', 'w', 'y', 'z', 'z', 'z', 's', |
'f', 'o', 'u', 'a', 'i', 'o', 'u', 'u', 'u', 'u', 'u', 'a', 'ae', 'o'); |
$tag = str_replace($caracteres_accentues, $caracteres_normaux, $tag); |
return $tag; |
} |
private function traiterNomFichierImage($fichierNom) { |
$fichierNom = preg_replace('/[.](jpeg|jpg)$/i', '.jpg', strtolower(trim($fichierNom))); |
return $fichierNom; |
/branches/v1.5-cisaille/jrest/services/CelMotCle.php |
---|
85,7 → 85,7 |
* |
* @param String $utilisateur_id identifiant de l'utilisateur. |
* @param String $mot_cle texte du mot-clé. |
* @param Array $ordres_obs un tableau d'odre d'observation (int) pour lesquels nous devons ajouter le mot-clé. |
* @param Array $images_ids un tableau d'id d'images (int) pour lesquels nous devons ajouter le mot-clé. |
*/ |
public function lierMotCleImg($utilisateur_id, Array $mots_cles_ids, Array $images_ids) { |
$retour = false; |
228,22 → 228,24 |
return $valeur; |
} |
public function ajouterMotCleObs($utilisateur_id, $mot_cle, $mot_cle_id, $mot_cle_parent_id) { |
public function ajouterMotCleObs($utilisateur_id, $mot_cle, $mot_cle_parent_id) { |
$this->suffix = self::OBS_TABLE_SUFFIXE; |
$this->utilisateur_id = $utilisateur_id; |
return $this->ajouterMotCle($mot_cle, $mot_cle_id, $mot_cle_parent_id); |
return $this->ajouterMotCle($mot_cle, $mot_cle_parent_id); |
} |
public function ajouterMotCleImg($utilisateur_id, $mot_cle, $mot_cle_id, $mot_cle_parent_id) { |
public function ajouterMotCleImg($utilisateur_id, $mot_cle, $mot_cle_parent_id) { |
$this->suffix = self::IMG_TABLE_SUFFIXE; |
$this->utilisateur_id = $utilisateur_id; |
return $this->ajouterMotCle($mot_cle, $mot_cle_id, $mot_cle_parent_id); |
return $this->ajouterMotCle($mot_cle, $mot_cle_parent_id); |
} |
private function ajouterMotCle($mot_cle, $mot_cle_id, $mot_cle_parent_id) { |
private function ajouterMotCle($mot_cle, $mot_cle_parent_id) { |
$retour = true; |
$this->ajouterMotCleRacine(); |
if ($this->verifierAbscence($mot_cle_id)) { |
if ($this->verifierAbscence($mot_cle, $mot_cle_parent_id)) { |
$mot_cle_id = $this->genererTagId($mot_cle); |
$this->commencerTransaction(); |
$bornes = $this->retrouverBornesEtNiveau($mot_cle_parent_id); |
253,20 → 255,20 |
$bd = $bg + 1; |
$mot_cle_encode = $this->encoderMotCle($mot_cle); |
$mot_cle = $this->proteger($mot_cle); |
$mot_cle_protege = $this->proteger($mot_cle); |
$bg = $this->proteger($bg); |
$bd = $this->proteger($bd); |
$mot_cle_encode = $this->proteger($mot_cle_encode); |
$mot_cle_id = $this->proteger($mot_cle_id); |
$id_utilisateur = $this->proteger($this->utilisateur_id); |
$mot_cle_parent_id = $this->proteger($mot_cle_parent_id); |
$mot_cle_parent_id_protege = $this->proteger($mot_cle_parent_id); |
$niveau = $this->proteger($niveau); |
$transaction_reussie_1 = $this->decalerBornesPlusDeux($borne_pere) ? true : false; |
$requete = "INSERT INTO cel_mots_cles{$this->suffix} ". |
"VALUES ( $mot_cle, $bg, $bd, $mot_cle_encode, $mot_cle_id, ". |
" $id_utilisateur, $mot_cle_parent_id, $niveau) "; |
"VALUES ( $mot_cle_protege, $bg, $bd, $mot_cle_encode, $mot_cle_id, ". |
" $id_utilisateur, $mot_cle_parent_id_protege, $niveau) "; |
$transaction_reussie_2 = $this->executerSQL($requete); |
if (!$transaction_reussie_2) { |
$e = "Échec d'insertion du mot-clé : $requete "; |
273,7 → 275,6 |
$this->messages[] = $e; |
} |
$retour = null; |
if ($transaction_reussie_1 && $transaction_reussie_2) { |
$retour = $this->completerTransaction(); |
} else { |
280,16 → 281,32 |
$retour = $this->annulerTransaction(); |
} |
} else { |
$e = "Le mot-clé '$mot_cle' ayant l'id '$mot_cle_id' existe déjà dans la table cel_mots_cles{$this->suffix}."; |
$e = "Le mot-clé '$mot_cle' existe déjà dans la table cel_mots_cles{$this->suffix}."; |
$this->debug[] = $e; |
} |
return $retour; |
$id = ($retour) ? $this->getIdMotCle($mot_cle, $mot_cle_parent_id) : false; |
return $id; |
} |
private function genererTagId($tag) { |
$id = ($this->getHashCode($tag) + ((mt_rand() / (double)mt_getrandmax()) * 10000)); |
$id = str_replace(',', '.', $id); |
return $id; |
} |
private function getHashCode($chaine){ |
$hash = 0; |
$stringLength = strlen($chaine); |
for ($i = 0; $i < $stringLength; $i++) { |
$hash = 31 * $hash + $chaine[$i]; |
} |
return $hash; |
} |
private function ajouterMotCleRacine() { |
$nbre_mots_cles = $this->compterMotsCles(); |
$this->debug[] = $nbre_mots_cles; |
$this->debug[] = "Nbre de mots-clés : $nbre_mots_cles"; |
if ($nbre_mots_cles == 0) { |
switch ($this->suffix) { |
case self::OBS_TABLE_SUFFIXE : |
310,7 → 327,6 |
$id_utilisateur = $this->proteger($this->utilisateur_id); |
$requete = "INSERT INTO cel_mots_cles{$this->suffix} ". |
"VALUES ($nom_racine, 1, 2, $id_racine, $id_racine, $id_utilisateur, '', 0) "; |
$this->debug[] = $requete; |
if ($this->executerSQL($requete) === false) { |
$e = "La requête d'insertion du mot-clé racine a échoué."; |
$this->messages[] = $e; |
318,14 → 334,16 |
} |
} |
private function verifierAbscence($mot_cle_id) { |
private function verifierAbscence($mot_cle, $mot_cle_parent_id) { |
$absence = false; |
$mot_cle_id = $this->proteger($mot_cle_id); |
$mot_cle = $this->proteger($mot_cle); |
$mot_cle_parent_id = $this->proteger($mot_cle_parent_id); |
$id_utilisateur = $this->proteger($this->utilisateur_id); |
$requete = 'SELECT COUNT(*) AS nbre '. |
"FROM cel_mots_cles{$this->suffix} ". |
"WHERE cmc_id_mot_cle_utilisateur = $mot_cle_id ". |
" AND cmc_id_proprietaire = $id_utilisateur "; |
"WHERE cmc_mot_cle = $mot_cle ". |
" AND cmc_id_proprietaire = $id_utilisateur ". |
" AND cmc_id_parent = $mot_cle_parent_id"; |
$nbre = $this->recupererValeur($requete); |
if ($nbre === false) { |
$e = "La requête de vérification d'abscence d'un mot-clé a échoué."; |
336,6 → 354,20 |
return $absence; |
} |
private function getIdMotCle($mot_cle, $mot_cle_parent_id) { |
$mot_cle = $this->proteger($mot_cle); |
$mot_cle_parent_id = $this->proteger($mot_cle_parent_id); |
$id_utilisateur = $this->proteger($this->utilisateur_id); |
$requete = 'SELECT cmc_id_mot_cle_utilisateur AS id '. |
"FROM cel_mots_cles{$this->suffix} ". |
"WHERE cmc_mot_cle = $mot_cle ". |
" AND cmc_id_proprietaire = $id_utilisateur ". |
" AND cmc_id_parent = $mot_cle_parent_id"; |
$resultat = $this->recupererResultat($requete); |
$mot_cle_id = ($resultat) ? $resultat['id'] : false; |
return $mot_cle_id; |
} |
private function compterMotsCles() { |
$nbre = 0; |
$id_utilisateur = $this->proteger($this->utilisateur_id); |