Subversion Repositories eFlore/Applications.coel-consultation

Rev

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

Rev 10 Rev 15
1
<?php
1
<?php
2
// declare(encoding='UTF-8');
2
// declare(encoding='UTF-8');
3
/**
3
/**
4
 * classe Controleur du module Recherche.
4
 * classe Controleur du module Recherche.
5
 *
5
 *
6
 * @package		Collection
6
 * @package		Collection
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 10 2010-03-05 14:15:42Z jpm $$
12
 * @version		SVN: $$Id: Recherche.php 15 2010-03-19 17:55:16Z jpm $$
13
 */
13
 */
14
class Recherche extends ColControleur {
14
class Recherche extends ColControleur {
15
	
15
	
16
	//+----------------------------------------------------------------------------------------------------------------+
16
	//+----------------------------------------------------------------------------------------------------------------+
17
	// Méthodes
17
	// Méthodes
18
	/**
18
	/**
19
	 * Fonction d'affichage par défaut, elle appelle la liste des administrateurs
19
	 * Fonction d'affichage par défaut, elle appelle la liste des administrateurs
20
	 */
20
	 */
21
	public function executerActionParDefaut() {
21
	public function executerActionParDefaut() {
22
		return $this->rechercher();
22
		return $this->rechercher();
23
	}
23
	}
24
	
24
	
25
	/**
25
	/**
26
	 * Charge le moteur de recherche et l'envoie à la vue.
26
	 * Charge le moteur de recherche et l'envoie à la vue.
27
	 */
27
	 */
28
	public function chargerMoteurRecherche() {
28
	public function chargerMoteurRecherche() {
29
		$donnees = array();
29
		$donnees = array();
30
		
30
		
31
		// Gestion des données de la requête
31
		// Gestion des données de la requête
-
 
32
		$chaine = $this->obtenirChaineRecherche();
-
 
33
		$this->memoriserChaineRecherche($chaine);
32
		$donnees['recherche'] = (isset($_GET['recherche']) ? $_GET['recherche'] : '');
34
		$donnees['recherche'] = $chaine;
33
		
35
		
34
		// Gestion de l'url
36
		// Gestion de l'url
35
		$this->url->setVariableRequete('module', 'Recherche');
37
		$this->url->setVariableRequete('module', 'Recherche');
36
		$this->url->setVariableRequete('action', 'rechercher');
38
		$this->url->setVariableRequete('action', 'rechercher');
37
		$donnees['url_form'] = $this->url->getUrl();
39
		$donnees['url_form'] = $this->url->getUrl();
38
		$donnees['url_module'] = 'Recherche';
40
		$donnees['url_module'] = 'Recherche';
39
		$donnees['url_action'] = 'rechercher';
41
		$donnees['url_action'] = 'rechercher';
40
		
42
		
41
		// Gestion du squelette et de la sortie
43
		// Gestion du squelette et de la sortie
42
		$this->setSortie(self::RENDU_TETE, $this->getVue('moteur', $donnees));
44
		$this->setSortie(self::RENDU_TETE, $this->getVue('moteur', $donnees));
43
	}
45
	}
-
 
46
	
-
 
47
	private function obtenirChaineRecherche() {
-
 
48
		$chaine = '';
-
 
49
		if (isset($_GET['recherche'])) {
-
 
50
			$chaine = $_GET['recherche'];
-
 
51
		} else if (isset($_SESSION['col']['recherche'])) {
-
 
52
			$chaine = $_SESSION['col']['recherche'];
-
 
53
		}
-
 
54
		return $chaine;
-
 
55
	}
-
 
56
	
-
 
57
	private function memoriserChaineRecherche($chaine) {
-
 
58
		$_SESSION['col']['recherche'] = $chaine;
-
 
59
	}
44
	
60
	
45
	/**
61
	/**
46
	 * Recherche des collections.
62
	 * Recherche des collections.
47
	 * @return string la vue correspondante
63
	 * @return string la vue correspondante
48
	 */
64
	 */
49
	public function rechercher() {
65
	public function rechercher() {
50
		$donnees = array();
66
		$donnees = array();
51
		$rechercheDao = $this->getModele('RechercheDao');
67
		$rechercheDao = $this->getModele('RechercheDao');
52
		$parametres = array('mots' => '');
68
		$parametres = array('mots' => '');
53
		
69
		
54
		// Récupération des paramêtres de l'url
70
		// Récupération des paramêtres de l'url
55
		if (isset($_GET['recherche'])) {
71
		if (isset($_GET['recherche'])) {
56
			$parametres['mots'] = $_GET['recherche'];
72
			$parametres['mots'] = $_GET['recherche'];
57
		}
73
		}
58
 
74
 
59
		// Gestion du nombre de résultats
75
		// Gestion du nombre de résultats
60
		$donnees_total = $rechercheDao->chercherStructureNbre($parametres);
76
		$donnees_total = $rechercheDao->chercherStructureNbre($parametres);
61
		
77
		
62
		// Gestion du fragmenteur
78
		// Gestion du fragmenteur
63
		$options = array(
79
		$options = array(
64
			'url' => $this->url, 
80
			'url' => $this->url, 
65
			'donnees_total' => $donnees_total);
81
			'donnees_total' => $donnees_total);
66
		$fragmenteur = Composant::fabrique('fragmenteur', $options);
82
		$fragmenteur = Composant::fabrique('fragmenteur', $options);
67
		$donnees['fragmenteur'] = $fragmenteur->executer();
83
		$donnees['fragmenteur'] = $fragmenteur->executer();
68
		list($de, $a) = $fragmenteur->getDeplacementParPageId();
84
		list($de, $a) = $fragmenteur->getDeplacementParPageId();
69
 
85
 
70
		// Gestion de l'accès aux données
86
		// Gestion de l'accès aux données
71
		$rechercheDao->setLimitation(($de - 1), $fragmenteur->getDonneesParPage());
87
		$rechercheDao->setLimitation(($de - 1), $fragmenteur->getDonneesParPage());
72
		$resultats = $rechercheDao->chercher($parametres);
88
		$resultats = $rechercheDao->chercher($parametres);
73
		
89
		
74
		// Post-traitement des résultats pour l'affichage
90
		// Post-traitement des résultats pour l'affichage
75
		$this->url->setVariableRequete('module', 'Fiche');
91
		$this->url->setVariableRequete('module', 'Fiche');
76
		foreach ($resultats as $resultat) {
92
		foreach ($resultats as $resultat) {
77
			$structure_id = $resultat['cs_id_structure'];
93
			$structure_id = $resultat['cs_id_structure'];
78
			if (!isset($donnees['infos'][$structure_id])) {
94
			if (!isset($donnees['infos'][$structure_id])) {
79
				$this->url->setVariableRequete('action', 'afficherStructure');
95
				$this->url->setVariableRequete('action', 'afficherStructure');
80
				$this->url->setVariableRequete('id', $resultat['cs_id_structure']);
96
				$this->url->setVariableRequete('id', $resultat['cs_id_structure']);
81
				$structure = array(
97
				$structure = array(
82
					'nom' => $resultat['cs_nom'],
98
					'nom' => $resultat['cs_nom'],
83
					'ville' => $resultat['cs_ville'],
99
					'ville' => $resultat['cs_ville'],
84
					'url' => $this->url->getURL());
100
					'url' => $this->url->getURL());
85
				$this->url->unsetVariableRequete('action');
101
				$this->url->unsetVariableRequete('action');
86
				$this->url->unsetVariableRequete('id'); 
102
				$this->url->unsetVariableRequete('id'); 
87
				$donnees['infos'][$structure_id]['structure'] = $structure;
103
				$donnees['infos'][$structure_id]['structure'] = $structure;
88
			}
104
			}
89
			$this->url->setVariableRequete('action', 'afficherCollection');
105
			$this->url->setVariableRequete('action', 'afficherCollection');
90
			$this->url->setVariableRequete('id', $resultat['cc_id_collection']);
106
			$this->url->setVariableRequete('id', $resultat['cc_id_collection']);
91
			$collection = array('nom' => $resultat['cc_nom'],
107
			$collection = array('nom' => $resultat['cc_nom'],
92
				'url' => $this->url->getURL());
108
				'url' => $this->url->getURL());
93
			$this->url->unsetVariableRequete('action');
109
			$this->url->unsetVariableRequete('action');
94
			$this->url->unsetVariableRequete('id');
110
			$this->url->unsetVariableRequete('id');
95
			$donnees['infos'][$structure_id]['collections'][] = $collection;
111
			$donnees['infos'][$structure_id]['collections'][] = $collection;
96
		}
112
		}
97
		$this->url->unsetVariableRequete('module');
113
		$this->url->unsetVariableRequete('module');
98
		
114
		
99
		// Gestion des squelettes
115
		// Gestion des squelettes
100
		$this->chargerMoteurRecherche();
116
		$this->chargerMoteurRecherche();
101
		$resultat = $this->getVue('resultat', $donnees);
117
		$resultat = $this->getVue('resultat', $donnees);
102
		$this->setSortie(self::RENDU_CORPS, $resultat);
118
		$this->setSortie(self::RENDU_CORPS, $resultat);
103
		$this->chargerPiedDePage();
119
		$this->chargerPiedDePage();
104
	}
120
	}
105
	
121
	
106
	/**
122
	/**
107
	 * Recherche des collections.
123
	 * Recherche des collections.
108
	 * @return string la vue correspondante
124
	 * @return string la vue correspondante
109
	 */
125
	 */
110
	public function chargerPiedDePage() {
126
	public function chargerPiedDePage() {
111
		$this->setSortie(self::RENDU_PIED, $this->getVue('pied'));
127
		$this->setSortie(self::RENDU_PIED, $this->getVue('pied'));
112
	}
128
	}
113
}
129
}