Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 798 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 798 Rev 931
1
<?php
1
<?php
2
class AlphabVernaFormateur implements Formateur {
2
class AlphabVernaFormateur implements Formateur {
3
 
3
 
4
	const TPL_VUE = 'liste_noms_verna';
4
	const TPL_VUE = 'liste_noms_verna';
5
 
5
 
6
	private $parametres = null;
6
	private $parametres = null;
7
	private $surligneur = null;
7
	private $surligneur = null;
8
	private $trieur = null;
8
	private $trieur = null;
9
	private $urls = null;
9
	private $urls = null;
10
	private $fusioneur = null;
10
	private $fusioneur = null;
11
	private $manipulateurDeChaine = null;
11
	private $manipulateurDeChaine = null;
12
	private $imagesService = null;
12
	private $imagesService = null;
13
 
13
 
14
	private $motsASurligner = array();
14
	private $motsASurligner = array();
15
	private $noms = array();
15
	private $noms = array();
16
	private $infosPourTpl = array();
16
	private $infosPourTpl = array();
17
 
17
 
18
	public function __construct(ParametresResultats $parametres, Array $resultats,
18
	public function __construct(ParametresResultats $parametres, Array $resultats,
19
		Surligneur $surligneur = null, Trieur $trieur = null, AppUrls $urls = null,
19
		Surligneur $surligneur = null, Trieur $trieur = null, AppUrls $urls = null,
20
		ChaineManipulateur $manipulateurDeChaine = null, Images $imagesService = null) {
20
		ChaineManipulateur $manipulateurDeChaine = null, Images $imagesService = null) {
21
 
21
 
22
		$this->parametres = $parametres;
22
		$this->parametres = $parametres;
23
		$this->noms = $resultats['resultat'];
23
		$this->noms = $resultats['resultat'];
24
		$this->surligneur = (is_null($surligneur)) ? new Surligneur() : $surligneur;
24
		$this->surligneur = (is_null($surligneur)) ? new Surligneur() : $surligneur;
25
		$this->trieur = (is_null($trieur)) ? new Trieur() : $trieur;
25
		$this->trieur = (is_null($trieur)) ? new Trieur() : $trieur;
26
		$this->urls = (is_null($urls)) ? new AppUrls() : $urls;
26
		$this->urls = (is_null($urls)) ? new AppUrls() : $urls;
27
		$this->manipulateurDeChaine = is_null($manipulateurDeChaine) ? new ChaineManipulateur() : $manipulateurDeChaine;
27
		$this->manipulateurDeChaine = is_null($manipulateurDeChaine) ? new ChaineManipulateur() : $manipulateurDeChaine;
28
		$this->imagesService = is_null($imagesService) ? new Images($this->parametres->projetImg) : $imagesService;
28
		$this->imagesService = is_null($imagesService) ? new Images($this->parametres->projetImg) : $imagesService;
29
	}
29
	}
30
 
30
 
31
	public function getTplInfos() {
31
	public function getTplInfos() {
32
		return $this->infosPourTpl;
32
		return $this->infosPourTpl;
33
	}
33
	}
34
 
34
 
35
	public function getTplNom() {
35
	public function getTplNom() {
36
		return self::TPL_VUE;
36
		return self::TPL_VUE;
37
	}
37
	}
38
	
38
	
39
	private function supprimerCodeReftaxAvecNn($nn) {
39
	private function supprimerCodeReftaxAvecNn($nn) {
40
		$codeReftax = $this->parametres->reftaxCourant.'.nn:';
40
		$codeReftax = $this->parametres->reftaxCourant.'.nn:';
41
		return str_replace($codeReftax, '', $nn);
41
		return str_replace($codeReftax, '', $nn);
42
	}
42
	}
43
	
43
	
44
	
44
	
45
	private function renvoyerInfoVerna($nn, $valeurs) {
45
	private function renvoyerInfoVerna($nn, $valeurs) {
46
		$infosDuNom = array();
46
		$infosDuNom = array();
47
		$infosDuNom['nomSci'] = $valeurs['taxon'];
47
		$infosDuNom['nomSci'] = $valeurs['taxon'];
48
		$infosDuNom['nomVerna'] = $valeurs['nom_vernaculaire'];
48
		$infosDuNom['nomVerna'] = $valeurs['nom_vernaculaire'];
49
		$infosDuNom['langue'] = $valeurs['code_langue'];
49
		$infosDuNom['langue'] = $valeurs['code_langue'];
50
		$infosDuNom['urlFiche'] = $this->urls->obtenirUrlFiche($nn, $this->parametres->typeNom,  $this->parametres->masqueRecherche);
50
		$infosDuNom['urlFiche'] = $this->urls->obtenirUrlFiche($nn, $this->parametres->typeNom,  $this->parametres->masqueRecherche);
51
		return $infosDuNom ;
51
		return $infosDuNom ;
52
	}
52
	}
53
 
53
 
54
	function supprimerAccents($chaine){
54
	function supprimerAccents($chaine){
55
		return strtr($chaine,array('à' => 'a','á' => 'a','â' => 'a','ã' => 'a','ä' => 'a',
55
		return strtr($chaine,array('à' => 'a','á' => 'a','â' => 'a','ã' => 'a','ä' => 'a',
56
									'ç' => 'c',
56
									'ç' => 'c',
57
									'è' => 'e','é' => 'e','ê' => 'e','ë' => 'e',
57
									'è' => 'e','é' => 'e','ê' => 'e','ë' => 'e',
58
									'ì' => 'i','í' => 'i','î' => 'i','ï' => 'i',
58
									'ì' => 'i','í' => 'i','î' => 'i','ï' => 'i',
59
									'ñ' => 'n',
59
									'ñ' => 'n',
60
									'ò' => 'o', 'ó' => 'o' , 'ô' => 'o', 'õ' => 'o', 'ö' => 'o', 
60
									'ò' => 'o', 'ó' => 'o' , 'ô' => 'o', 'õ' => 'o', 'ö' => 'o', 
61
									'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'ü' => 'u', 
61
									'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'ü' => 'u', 
62
									'ý' => 'y', 'ÿ' => 'y'));
62
									'ý' => 'y', 'ÿ' => 'y'));
63
	}
63
	}
64
	
64
	
65
	public function formater() {
65
	public function formater() {
66
	$nomVerna = array();
66
	$nomVerna = array();
67
	foreach ($this->noms as $id => $nom) {
67
	foreach ($this->noms as $id => $nom) {
68
			$nn = $this->supprimerCodeReftaxAvecNn($nom['nom_retenu.code']);
68
			$nn = $this->supprimerCodeReftaxAvecNn($nom['nom_retenu.code']);
69
			$nom_min = strtolower($nom['nom_vernaculaire']);
69
			$nom_min = strtolower($nom['nom_vernaculaire']);
70
			$nom_ss_accent = $this->supprimerAccents($nom_min); 
70
			$nom_ss_accent = $this->supprimerAccents($nom_min); 
71
			if (preg_match('/^'.strtolower($this->parametres->masqueRecherche).' |^'.strtolower($this->parametres->masqueRecherche).'$/',  $nom_ss_accent)) {
71
			if (preg_match('/^'.strtolower($this->parametres->masqueRecherche).' |^'.strtolower($this->parametres->masqueRecherche).'$/',  $nom_ss_accent)) {
72
				$nomVerna[0][$id] = $this->renvoyerInfoVerna($nn, $nom);
72
				$nomVerna[0][$id] = $this->renvoyerInfoVerna($nn, $nom);
73
			} else {
73
			} else {
74
				$nomVerna[1][$id] = $this->renvoyerInfoVerna($nn, $nom);
74
				$nomVerna[1][$id] = $this->renvoyerInfoVerna($nn, $nom);
75
			}
75
			}
76
		}
76
		}
77
		ksort($nomVerna);
77
		ksort($nomVerna);
78
		$this->infosPourTpl['noms'] = isset($nomVerna)  ? $nomVerna : false;
78
		$this->infosPourTpl['noms'] = isset($nomVerna)  ? $nomVerna : false;
79
	}
79
	}
80
 
80
 
81
		public function trier() {
81
		public function trier() {
82
			$verna = array();
82
			$verna = array();
83
			foreach ($this->infosPourTpl['noms'] as $categorie => $valeurs) {
83
			foreach ($this->infosPourTpl['noms'] as $categorie => $valeurs) {
84
				$verna += $this->classerAlphabetiquement('nomVerna', $valeurs);
84
				$verna += $this->classerAlphabetiquement('nomVerna', $valeurs);
85
			}
85
			}
86
			$this->infosPourTpl['noms'] = $verna;
86
			$this->infosPourTpl['noms'] = $verna;
87
	}
87
	}
88
	
88
	
89
	private function classerAlphabetiquement($champs, $valeurs) {
89
	private function classerAlphabetiquement($champs, $valeurs) {
90
		$this->trieur->setTableau($valeurs);
90
		$this->trieur->setTableau($valeurs);
91
		$this->trieur->setChampsEtOrdres(array($champs => SORT_NATURAL));
91
		$this->trieur->setChampsEtOrdres(array($champs => 'nat'));
92
		return $this->trieur->trier();
92
		return $this->trieur->trier();
93
	}
93
	}
94
 
94
 
95
	public function surligner() {
95
	public function surligner() {
96
		$this->definirMotsASurligner();
96
		$this->definirMotsASurligner();
97
		foreach ($this->infosPourTpl['noms'] as $idNom => $nom) {
97
		foreach ($this->infosPourTpl['noms'] as $idNom => $nom) {
98
			$this->infosPourTpl['noms'][$idNom]['nomVerna'] = $this->surlignerMotsMasqueRecherche($nom['nomVerna']);
98
			$this->infosPourTpl['noms'][$idNom]['nomVerna'] = $this->surlignerMotsMasqueRecherche($nom['nomVerna']);
99
		}
99
		}
100
	}
100
	}
101
 
101
 
102
	private function definirMotsASurligner() {
102
	private function definirMotsASurligner() {
103
		$this->motsASurligner = explode(' ', $this->parametres->masqueRecherche);
103
		$this->motsASurligner = explode(' ', $this->parametres->masqueRecherche);
104
 
104
 
105
	}
105
	}
106
 
106
 
107
	private function surlignerMotsMasqueRecherche($nom) {
107
	private function surlignerMotsMasqueRecherche($nom) {
108
		$this->surligneur->setTexte($nom);
108
		$this->surligneur->setTexte($nom);
109
		$nom = $this->surligneur->surlignerMots($this->motsASurligner);
109
		$nom = $this->surligneur->surlignerMots($this->motsASurligner);
110
		return $nom;
110
		return $nom;
111
	}
111
	}
112
}
112
}
113
?>
113
?>