Subversion Repositories Applications.referentiel

Rev

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

Rev 70 Rev 72
Line 3... Line 3...
3
/**
3
/**
4
 * classe Controleur du module Recherche.
4
 * classe Controleur du module Recherche.
5
 *
5
 *
6
 * @package		Referentiel
6
 * @package		Referentiel
7
 * @category	Php5
7
 * @category	Php5
-
 
8
 * @author		Delphine CAUQUIL <delphine@tela-botanica.org>
8
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
9
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
9
 * @copyright	2010 Tela-Botanica
10
 * @copyright	2010 Tela-Botanica
10
 * @license		http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
11
 * @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
12
 * @license		http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
12
 * @version		SVN: $Id: Recherche.php 147 2010-09-06 09:37:22Z jpm $
13
 * @version		SVN: $Id: Recherche.php 147 2010-09-06 09:37:22Z jpm $
Line 14... Line 15...
14
class Recherche extends AppliControleur {
15
class Recherche extends AppliControleur {
Line 15... Line 16...
15
	
16
	
16
	private $chaine_recherche = null;
17
	private $chaine_recherche = null;
17
	private static $url_exemple = null;
18
	private static $url_exemple = null;
-
 
19
	private $referentiel = null;
-
 
20
	private $donnees_par_page;
Line 18... Line 21...
18
	private $referentiel = null;
21
	private $donnees_par_page_choix;
19
	
22
	
20
	//+----------------------------------------------------------------------------------------------------------------+
23
	//+----------------------------------------------------------------------------------------------------------------+
21
	// Méthodes
24
	// Méthodes
22
	/**
25
	/**
23
	 * Fonction d'affichage par défaut, elle appelle la liste des administrateurs
26
	 * Fonction d'affichage par défaut
24
	 */
27
	 */
25
	public function executerActionParDefaut() {
28
	public function executerActionParDefaut() {
Line 38... Line 41...
38
		// Gestion des urls
41
		// Gestion des urls
39
		$donnees['url_form'] = $this->obtenirUrlRecherche($this->referentiel);
42
		$donnees['url_form'] = $this->obtenirUrlRecherche($this->referentiel);
40
		$donnees['url_referentiel'] = $this->referentiel;
43
		$donnees['url_referentiel'] = $this->referentiel;
41
		$donnees['url_module'] = 'Recherche';
44
		$donnees['url_module'] = 'Recherche';
42
		$donnees['url_action'] = 'rechercher';
45
		$donnees['url_action'] = 'rechercher';
43
		self::$url_exemple = $this->obtenirUrlRecherche('BDNFM','%s');
46
		self::$url_exemple = $this->obtenirUrlRecherche('bdnff','%s');
Line 44... Line 47...
44
		
47
		
45
		// Gestion du squelette et de la sortie
48
		// Gestion du squelette et de la sortie
46
		$this->setSortie(self::RENDU_TETE, $this->getVue('moteur', $donnees));
49
		$this->setSortie(self::RENDU_TETE, $this->getVue('moteur', $donnees));
Line 85... Line 88...
85
	/**
88
	/**
86
	 * Recherche sur référentiel.
89
	 * Recherche sur référentiel.
87
	 * @return string la vue correspondante
90
	 * @return string la vue correspondante
88
	 */
91
	 */
89
	public function rechercher() {
92
	public function rechercher() {
-
 
93
		$this->donnees_par_page = Config::get('resultat_par_page_defaut');
-
 
94
		$this->donnees_par_page_choix = Config::get('resultat_par_page_choix');
90
		$donnees = array();
95
		$donnees = array();
91
		$rechercheDao =  new RechercheDao();
96
		$rechercheDao =  new RechercheDao();
92
		$parametres = array('mots' => '*');
97
		$parametres = array('mots' => '*');
93
		if (isset($_GET['ref'])) { // code du projet courrant
98
		if (isset($_GET['ref'])) { // code du projet courant
94
			$this->referentiel = strtolower($_GET['ref']);
99
			$this->referentiel = strtolower($_GET['ref']);
95
		}
100
		}
96
		$this->definirCommeModulePrincipal(get_class($this));
101
		$this->definirCommeModulePrincipal(get_class($this));
97
		$this->construireMenu($this->referentiel);
102
		$this->construireMenu($this->referentiel);
98
		$this->construireFilAriane($this->referentiel);
103
		$this->construireFilAriane($this->referentiel);
Line 99... Line 104...
99
		
104
		
100
		// Récupération des paramêtres de l'url
105
		// Récupération des paramètres de l'url
101
		$chaine_de_recherche = $this->obtenirChaineRecherche(); 
106
		$chaine_de_recherche = $this->obtenirChaineRecherche(); 
102
		if (!empty($chaine_de_recherche)) {
107
		if (!empty($chaine_de_recherche)) {
103
			$this->url->setVariablesRequete(array('module' => 'Recherche',
108
			$this->url->setVariablesRequete(array('module' => 'Recherche',
104
				'action' => 'rechercher',
109
				'action' => 'rechercher',
105
				'ref' => $this->referentiel,
110
				'ref' => $this->referentiel,
106
				'recherche' => $chaine_de_recherche));
111
				'recherche' => $chaine_de_recherche));
107
		}
112
		}
108
		$parametres = $this->parserChaineDeRecherche($chaine_de_recherche);
113
		$parametres = $this->parserChaineDeRecherche($chaine_de_recherche);
-
 
114
		$parametres['ref'] = $this->referentiel;
-
 
115
		
-
 
116
		if (isset($parametres['tax']) && ($parametres['tax'] == 1)) {
-
 
117
			$this->donnees_par_page = 2;
-
 
118
			$this->donnees_par_page_choix = '1,2,5,10'; 
-
 
119
			$donnees['fragmenteur'] = $this->gererFragmenteur($rechercheDao, $parametres, 'NombreTaxon');
-
 
120
			$resultats = $rechercheDao->chercher('ParTaxon', $parametres);
-
 
121
			foreach ($resultats as $res) {
-
 
122
				if ($res['num_nom'] == $res['num_nom_retenu']) {
-
 
123
					$donnees['resultats']['nom_retenu'][$res['num_nom_retenu']] = $res;
-
 
124
				} else {
-
 
125
					$donnees['resultats'][$res['num_nom_retenu']][$res['num_nom']] = $res;
-
 
126
				}
-
 
127
			}
-
 
128
			$resultat = $this->getVue('resultat_recherche_taxon', $donnees);
-
 
129
		} else {
-
 
130
			$donnees['fragmenteur'] = $this->gererFragmenteur($rechercheDao, $parametres);
-
 
131
			$donnees['resultats'] = $rechercheDao->chercher('ParDefaut', $parametres);
-
 
132
			$resultat = $this->getVue('resultat_recherche', $donnees);
-
 
133
		}
-
 
134
		
-
 
135
		// Gestion des squelettes
-
 
136
		$this->chargerMoteurRecherche($this->referentiel);
-
 
137
		$this->setSortie(self::RENDU_CORPS, $resultat);
-
 
138
	}
-
 
139
	
109
		$parametres['ref'] = $this->referentiel;
140
	private function gererFragmenteur($rechercheDao, $parametres, $type = 'Nombre') {
110
		// Gestion du nombre de résultats
141
		// Gestion du nombre de résultats
Line 111... Line 142...
111
		$donnees_total = $rechercheDao->chercherStructureNbre($parametres);
142
		$donnees_total = $rechercheDao->chercherStructureNbre($type, $parametres);
112
		
143
		
113
		// Gestion du fragmenteur
144
		// Gestion du fragmenteur
114
		$options = array(
145
		$options = array(
115
			'url' => $this->url, 
146
			'url' => $this->url, 
116
			'donnees_total' => $donnees_total,
147
			'donnees_total' => $donnees_total,
117
			'donnees_par_page' => Config::get('resultat_par_page_defaut'),
-
 
118
			'donnees_par_page_choix' => Config::get('resultat_par_page_choix'),
148
			'donnees_par_page' => $this->donnees_par_page,
119
		);
149
			'donnees_par_page_choix' => $this->donnees_par_page_choix);
120
		$fragmenteur = Composant::fabrique('fragmenteur', $options);
150
		$fragmenteur = Composant::fabrique('fragmenteur', $options);
121
		$donnees['fragmenteur'] = $fragmenteur->executer();
151
		$donnees['fragmenteur'] = $fragmenteur->executer();
Line 122... Line 152...
122
		list($de, $a) = $fragmenteur->getDeplacementParPageId();
152
		list($de, $a) = $fragmenteur->getDeplacementParPageId();
123
		$this->url->unsetVariablesRequete(array('recherche', 'page'));
153
		$this->url->unsetVariablesRequete(array('recherche', 'page'));
124
		
154
		
125
		// Gestion de l'accès aux données
-
 
126
		$rechercheDao->setLimitation(($de - 1), $fragmenteur->getDonneesParPage());
-
 
127
		$rechercheDao->setDistinction(1);
-
 
128
		$donnees['resultats'] = $rechercheDao->chercher($parametres);
155
		// Gestion de l'accès aux données
129
		
-
 
130
		
-
 
131
		// Gestion des squelettes
-
 
132
		$this->chargerMoteurRecherche($this->referentiel);
156
		$rechercheDao->setLimitation(($de - 1), $fragmenteur->getDonneesParPage());
Line 133... Line 157...
133
		$resultat = $this->getVue('resultat_recherche', $donnees);
157
		$rechercheDao->setDistinction(1);
134
		$this->setSortie(self::RENDU_CORPS, $resultat);
158
		return $donnees['fragmenteur'];
135
	}
159
	}
Line 151... Line 175...
151
					$parametres['mots'] = $mot;
175
					$parametres['mots'] = $mot;
152
				} else {
176
				} else {
153
					$parametres['mots'] .= ' '.$mot;
177
					$parametres['mots'] .= ' '.$mot;
154
				}
178
				}
155
			}
179
			}
156
		}
180
		}		
157
		$this->remplacerAbreviationParId($parametres);
-
 
158
		
-
 
159
		return $parametres;
181
		return $parametres;
160
	}
182
	}
161
	
-
 
162
	private function remplacerAbreviationParId(&$parametres) {
-
 
163
		// liste 27 : Liste des relations entre une collection et une personne (id:1030)
-
 
164
		// liste 80 : Liste des types de collection botanique (id:1083)
-
 
165
		$params_a_remplacer = array('veg' => 1043, 'bot' => 1083, 'pr' => 1030);
-
 
166
		foreach ($params_a_remplacer as $param => $id_liste) {
-
 
167
			if (isset($parametres[$param])) {
-
 
168
				// Si plusieurs valeurs séparées par des virgules
-
 
169
				$valeurs = explode(',', $parametres[$param]);
-
 
170
				$valeurs_nbre = count($valeurs);
-
 
171
				$liste = Ontologie::getListeTrieeParAbreviation($id_liste); 
-
 
172
				foreach ($valeurs as $valeur) {
-
 
173
					$cle = strtoupper($valeur);
-
 
174
					if (isset($liste[$cle])) {
-
 
175
						if ($valeurs_nbre == 1) {
-
 
176
							$parametres[$param] = $liste[$cle]['id'];
-
 
177
						} else if ($valeurs_nbre > 1) {
-
 
178
							$valeur = preg_quote($valeur, '/');
-
 
179
							$parametres[$param] = preg_replace("/$valeur/", $liste[$cle]['id'], $parametres[$param]);								
-
 
180
						}
-
 
181
					}
-
 
182
				}
-
 
183
			}
-
 
184
		}
-
 
185
	}
-
 
186
}
183
}
187
184