Subversion Repositories eFlore/Applications.coel-consultation

Rev

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

Rev 43 Rev 54
Line 7... Line 7...
7
 * @category	Php5
7
 * @category	Php5
8
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
8
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
9
 * @copyright	2010 Tela-Botanica
9
 * @copyright	2010 Tela-Botanica
10
 * @license		http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
10
 * @license		http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
11
 * @license		http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
11
 * @license		http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
12
 * @version		SVN: $Id: Recherche.php 43 2010-04-26 14:46:24Z jpm $
12
 * @version		SVN: $Id: Recherche.php 54 2010-04-29 16:25:44Z jpm $
13
 */
13
 */
14
class Recherche extends ColControleur {
14
class Recherche extends ColControleur {
Line -... Line 15...
-
 
15
	
-
 
16
	private $chaine_recherche = null;
-
 
17
	private static $url_exemple = null;
15
	
18
	
16
	//+----------------------------------------------------------------------------------------------------------------+
19
	//+----------------------------------------------------------------------------------------------------------------+
17
	// Méthodes
20
	// Méthodes
18
	/**
21
	/**
19
	 * Fonction d'affichage par défaut, elle appelle la liste des administrateurs
22
	 * Fonction d'affichage par défaut, elle appelle la liste des administrateurs
Line 27... Line 30...
27
	 */
30
	 */
28
	public function chargerMoteurRecherche() {
31
	public function chargerMoteurRecherche() {
29
		$donnees = array();
32
		$donnees = array();
Line 30... Line 33...
30
		
33
		
31
		// Gestion des données de la requête
-
 
32
		$chaine = $this->obtenirChaineRecherche();
-
 
33
		$this->memoriserChaineRecherche($chaine);
34
		// Gestion des données de la requête
34
		$donnees['recherche'] = htmlspecialchars(stripslashes($chaine));
35
		$donnees['recherche'] = htmlspecialchars($this->obtenirChaineRecherche());
35
		
36
 
36
		// Gestion des urls
37
		// Gestion des urls
37
		$this->url->setVariableRequete('module', 'Recherche');
38
		$this->url->setVariableRequete('module', 'Recherche');
38
		$this->url->setVariableRequete('action', 'rechercher');
39
		$this->url->setVariableRequete('action', 'rechercher');
39
		$donnees['url_form'] = $this->url->getUrl();
40
		$donnees['url_form'] = $this->url->getUrl();
40
		$donnees['url_module'] = 'Recherche';
41
		$donnees['url_module'] = 'Recherche';
41
		$donnees['url_action'] = 'rechercher';
42
		$donnees['url_action'] = 'rechercher';
42
		$this->url->setVariableRequete('recherche', '%s');
43
		$this->url->setVariableRequete('recherche', '%s');
43
		$donnees['url_exemple'] = $this->url->getUrl();
44
		self::$url_exemple = $this->url->getUrl();
Line 44... Line 45...
44
		$this->url->unsetVariablesRequete(array('module', 'action', 'recherche'));
45
		$this->url->unsetVariablesRequete(array('module', 'action', 'recherche'));
45
		
46
		
46
		// Gestion du squelette et de la sortie
47
		// Gestion du squelette et de la sortie
Line 47... Line 48...
47
		$this->setSortie(self::RENDU_TETE, $this->getVue('moteur', $donnees));
48
		$this->setSortie(self::RENDU_TETE, $this->getVue('moteur', $donnees));
48
	}
49
	}
-
 
50
	
-
 
51
	private function obtenirChaineRecherche() {
49
	
52
		$chaine = '';
-
 
53
		if (!is_null($this->chaine_recherche)) {
50
	private function obtenirChaineRecherche() {
54
			$chaine = $this->chaine_recherche;
-
 
55
		} else if (isset($_GET['recherche'])) {
-
 
56
			// Pré-traitement de la chaine de recherche
-
 
57
			$chaine = $_GET['recherche'];
-
 
58
			// Suppression des slash ajouté automatiquement par PHP devant les guillemets
-
 
59
			$chaine = stripslashes($chaine);
-
 
60
			// Mémorisation de la chaine
51
		$chaine = '';
61
			$this->memoriserChaineRecherche($chaine);
52
		if (isset($_GET['recherche'])) {
62
			// Stockage dans la classe pour éviter d'effectuer à nouveau le traitement ci-dessus
53
			$chaine = $_GET['recherche'];
63
			$this->chaine_recherche = $chaine;
54
		} else if (isset($_SESSION['col']['recherche'])) {
64
		} else if (isset($_SESSION['col']['recherche'])) {
55
			$chaine = $_SESSION['col']['recherche'];
65
			$chaine = $_SESSION['col']['recherche'];
Line 56... Line 66...
56
		}
66
		}
57
		return $chaine;
67
		return $chaine;
58
	}
68
	}
-
 
69
	
-
 
70
	private function memoriserChaineRecherche($chaine) {
-
 
71
		$_SESSION['col']['recherche'] = $chaine;
-
 
72
	}
-
 
73
 
-
 
74
	public static function getUrlExemple($chaine) {
-
 
75
		$url = '';
-
 
76
		if (!is_null(self::$url_exemple)) {
-
 
77
			// L'utilisation d'urlencode nécessiate de pré-encodé la chaine dans le format de sortie si nécessaire
-
 
78
			if (Config::get('sortie_encodage') != Config::get('appli_encodage')) {
-
 
79
				$chaine = mb_convert_encoding($chaine, Config::get('sortie_encodage'), Config::get('appli_encodage'));
-
 
80
			}
-
 
81
			$chaine = urlencode($chaine);
Line 59... Line 82...
59
	
82
			$url = sprintf(self::$url_exemple, $chaine);
60
	private function memoriserChaineRecherche($chaine) {
83
		}
61
		$_SESSION['col']['recherche'] = $chaine;
84
		return $url;
62
	}
85
	}
Line 69... Line 92...
69
		$donnees = array();
92
		$donnees = array();
70
		$rechercheDao = $this->getModele('RechercheDao');
93
		$rechercheDao = $this->getModele('RechercheDao');
71
		$parametres = array('mots' => '*');
94
		$parametres = array('mots' => '*');
Line 72... Line 95...
72
		
95
		
73
		// Récupération des paramêtres de l'url
96
		// Récupération des paramêtres de l'url
74
		$chaine_de_recherche = ''; 
97
		$chaine_de_recherche = $this->obtenirChaineRecherche(); 
75
		if (isset($_GET['recherche'])) {
-
 
76
			$chaine_de_recherche = $_GET['recherche'];
98
		if (!empty($chaine_de_recherche)) {
77
			$this->url->setVariableRequete('recherche', $chaine_de_recherche);
99
			$this->url->setVariableRequete('recherche', $chaine_de_recherche);
78
		}
100
		}
Line 79... Line 101...
79
		$parametres = $this->parserChaineDeRecherche($chaine_de_recherche);
101
		$parametres = $this->parserChaineDeRecherche($chaine_de_recherche);
Line 89... Line 111...
89
			'donnees_par_page_choix' => Config::get('resultat_par_page_choix'),
111
			'donnees_par_page_choix' => Config::get('resultat_par_page_choix'),
90
		);
112
		);
91
		$fragmenteur = Composant::fabrique('fragmenteur', $options);
113
		$fragmenteur = Composant::fabrique('fragmenteur', $options);
92
		$donnees['fragmenteur'] = $fragmenteur->executer();
114
		$donnees['fragmenteur'] = $fragmenteur->executer();
93
		list($de, $a) = $fragmenteur->getDeplacementParPageId();
115
		list($de, $a) = $fragmenteur->getDeplacementParPageId();
-
 
116
		$this->url->unsetVariableRequete('recherche');
Line 94... Line 117...
94
 
117
 
95
		// Gestion de l'accès aux données
118
		// Gestion de l'accès aux données
96
		$rechercheDao->setLimitation(($de - 1), $fragmenteur->getDonneesParPage());
119
		$rechercheDao->setLimitation(($de - 1), $fragmenteur->getDonneesParPage());
97
		$rechercheDao->setDistinction(1);
120
		$rechercheDao->setDistinction(1);
Line 127... Line 150...
127
		$resultat = $this->getVue('resultat', $donnees);
150
		$resultat = $this->getVue('resultat', $donnees);
128
		$this->setSortie(self::RENDU_CORPS, $resultat);
151
		$this->setSortie(self::RENDU_CORPS, $resultat);
129
		$this->chargerPiedDePage();
152
		$this->chargerPiedDePage();
130
	}
153
	}
Line 131... Line 154...
131
	
154
	
132
	private function parserChaineDeRecherche($chaine) {
-
 
133
		// Pré-traitement de la chaine de recherche
-
 
134
		// Suppression des slash ajouté automatiquement par PHP
-
 
135
		$chaine = stripslashes($chaine);
-
 
136
		
155
	private function parserChaineDeRecherche($chaine) {		
137
		$mots = preg_split('/ /i', $chaine, -1, PREG_SPLIT_NO_EMPTY);
156
		$mots = preg_split('/ /i', $chaine, -1, PREG_SPLIT_NO_EMPTY);
138
		$parametres = array('mots' => '');
157
		$parametres = array('mots' => '');
139
		$cle_precedente = null;
158
		$cle_precedente = null;
140
		foreach ($mots as $mot) {
159
		foreach ($mots as $mot) {