Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 1042 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1042 Rev 1078
1
<?php
1
<?php
2
// declare(encoding='UTF-8');
2
// declare(encoding='UTF-8');
3
/**
3
/**
4
 * Service de recherche dans eflore, permettant d'intégrer le moteur dans une page donnée
4
 * Service de recherche dans eflore, permettant d'intégrer le moteur dans une page donnée
5
 * Encodage en entrée : utf8
5
 * Encodage en entrée : utf8
6
 * Encodage en sortie : utf8
6
 * Encodage en sortie : utf8
7
 *
7
 *
8
 * Cas d'utilisation et documentation :
8
 * Cas d'utilisation et documentation :
9
 * @link http://www.tela-botanica.org/wikini/eflore/wakka.php?wiki=AideEfloreWidgetRecherche
9
 * @link http://www.tela-botanica.org/wikini/eflore/wakka.php?wiki=AideEfloreWidgetRecherche
10
 *
10
 *
11
 *
11
 *
12
 * @author		Aurélien PERONNET <aurelien@tela-botanica.org>
12
 * @author		Aurélien PERONNET <aurelien@tela-botanica.org>
13
 * @license	GPL v3 <http://www.gnu.org/licenses/gpl.txt>
13
 * @license	GPL v3 <http://www.gnu.org/licenses/gpl.txt>
14
 * @license	CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
14
 * @license	CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
15
 * @version	$Id$
15
 * @version	$Id$
16
 * @copyright	Copyright (c) 2013, Tela Botanica (accueil@tela-botanica.org)
16
 * @copyright	Copyright (c) 2013, Tela Botanica (accueil@tela-botanica.org)
17
 */
17
 */
18
class Recherche extends WidgetCommun {
18
class Recherche extends WidgetCommun {
19
	const DS = DIRECTORY_SEPARATOR;
19
	const DS = DIRECTORY_SEPARATOR;
20
	/**
20
	/**
21
	* Méthode appelée par défaut pour charger ce widget.
21
	* Méthode appelée par défaut pour charger ce widget.
22
	*/
22
	*/
23
	public function executer() {
23
	public function executer() {
24
		$retour = null;
24
		$retour = null;
25
		$this->extraireParametres();
25
		$this->extraireParametres();
26
		$methode = $this->traiterNomMethodeExecuter("recherche");
26
		$methode = $this->traiterNomMethodeExecuter("recherche");
27
		if (method_exists($this, $methode)) {
27
		if (method_exists($this, $methode)) {
28
			$retour = $this->$methode();
28
			$retour = $this->$methode();
29
		} else {
29
		} else {
30
			$this->messages[] = "Ce type de service '$methode' n'est pas disponible.";
30
			$this->messages[] = "Ce type de service '$methode' n'est pas disponible.";
31
		}
31
		}
32
		if (is_null($retour)) {
32
		if (is_null($retour)) {
33
			$info = 'Un problème est survenu : '.print_r($this->messages, true);
33
			$info = 'Un problème est survenu : '.print_r($this->messages, true);
34
			$this->envoyer($info);
34
			$this->envoyer($info);
35
		} else {
35
		} else {
36
			$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.$retour['squelette'].'.tpl.html';
36
			$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.$retour['squelette'].'.tpl.html';
37
			$contenu = $this->traiterSquelettePhp($squelette, $retour['donnees']);
37
			$contenu = $this->traiterSquelettePhp($squelette, $retour['donnees']);
38
			if (isset($_GET['callback'])) {
38
			if (isset($_GET['callback'])) {
39
				$this->envoyerJsonp(array('contenu' => $contenu));
39
				$this->envoyerJsonp(array('contenu' => $contenu));
40
			} else {
40
			} else {
41
				$this->envoyer($contenu);
41
				$this->envoyer($contenu);
42
			}
42
			}
43
		}
43
		}
44
	}
44
	}
45
	
45
	
46
	public function extraireParametres() {
46
	public function extraireParametres() {
47
		extract($this->parametres);
47
		extract($this->parametres);
48
	}
48
	}
49
	
49
	
50
	public function executerRecherche() {
50
	public function executerRecherche() {
51
		$widget['donnees'] = array();
51
		$widget['donnees'] = array();
52
		$widget['donnees']['efloreScriptUrl'] = $this->config['url']['efloreScriptUrl'];
52
		$widget['donnees']['efloreScriptUrl'] = $this->config['url']['efloreScriptUrl'];
53
		$widget['donnees']['efloreConsultationUrl'] = $this->config['url']['efloreConsultationUrl'];
53
		$widget['donnees']['efloreConsultationUrl'] = $this->config['url']['efloreConsultationUrl'];
54
		$widget['donnees']['efloreRechercheSciUrlTpl'] = $this->config['url']['efloreRechercheSciUrlTpl'];
54
		$widget['donnees']['efloreRechercheSciUrlTpl'] = $this->config['url']['efloreRechercheSciUrlTpl'];
55
		$widget['donnees']['efloreRechercheVernaUrlTpl'] = $this->config['url']['efloreRechercheVernaUrlTpl'];
55
		$widget['donnees']['efloreRechercheVernaUrlTpl'] = $this->config['url']['efloreRechercheVernaUrlTpl'];
56
		$widget['donnees']['ficheTaxonUrlTpl'] = $this->config['url']['ficheTaxonUrlTpl'];
56
		$widget['donnees']['ficheTaxonUrlTpl'] = $this->config['url']['ficheTaxonUrlTpl'];
57
		
57
		
58
		$widget['donnees']['referentielsSciDispos'] = $this->traiterReferentielSciDispos();
58
		$widget['donnees']['referentielsSciDispos'] = $this->traiterReferentielSciDispos();
-
 
59
		$widget['donnees']['referentielsConsultationUrls'] = $this->traiterUrlsConsultationReferentiels($widget['donnees']['referentielsSciDispos']);
59
		$widget['donnees']['referentielsVernasDispos'] = $this->traiterReferentielsSciVernasDispos();
60
		$widget['donnees']['referentielsVernasDispos'] = $this->traiterReferentielsSciVernasDispos();
60
		$ref_sci_defaut = array_shift(array_keys($widget['donnees']['referentielsSciDispos']));
61
		$ref_sci_defaut = array_shift(array_keys($widget['donnees']['referentielsSciDispos']));
61
		$ref_verna_defaut = $widget['donnees']['referentielsVernasDispos'][$ref_sci_defaut];
62
		$ref_verna_defaut = $widget['donnees']['referentielsVernasDispos'][$ref_sci_defaut];
62
		$widget['donnees']['efloreRechercheSciUrlDefaut'] = str_replace('{referentiel}', $ref_sci_defaut, $this->config['url']['efloreRechercheSciUrlTpl']);
63
		$widget['donnees']['efloreRechercheSciUrlDefaut'] = str_replace('{referentiel}', $ref_sci_defaut, $this->config['url']['efloreRechercheSciUrlTpl']);
63
		$widget['donnees']['efloreRechercheVernaUrlDefaut'] = str_replace('{referentiel}',$ref_verna_defaut, $this->config['url']['efloreRechercheVernaUrlTpl']);
64
		$widget['donnees']['efloreRechercheVernaUrlDefaut'] = str_replace('{referentiel}',$ref_verna_defaut, $this->config['url']['efloreRechercheVernaUrlTpl']);
64
		$widget['donnees']['ficheTaxonUrlTplDefaut'] = str_replace('{referentiel}', $ref_sci_defaut, $this->config['url']['ficheTaxonUrlTpl']);
65
		$widget['donnees']['ficheTaxonUrlTplDefaut'] = str_replace('{referentiel}', $ref_sci_defaut, $this->config['url']['ficheTaxonUrlTpl']);
65
		$widget['squelette'] = 'recherche';
66
		$widget['squelette'] = 'recherche';
66
		return $widget;
67
		return $widget;
67
	}
68
	}
68
	
69
	
69
	private function traiterReferentielSciDispos() {
70
	private function traiterReferentielSciDispos() {
70
		$refs_sci_fmt = array();
71
		$refs_sci_fmt = array();
71
		$refs_sci = $this->config['referentiel']['referentielsSciDispos'];
72
		$refs_sci = $this->config['referentiel']['referentielsSciDispos'];
72
		$refs_sci = explode(',', $refs_sci);
73
		$refs_sci = explode(',', $refs_sci);
73
		foreach($refs_sci as $ref) {
74
		foreach($refs_sci as $ref) {
74
			$ref_code_desc = explode('#', $ref);
75
			$ref_code_desc = explode('#', $ref);
75
			$refs_sci_fmt[$ref_code_desc[0]] = $ref_code_desc[1];
76
			$refs_sci_fmt[$ref_code_desc[0]] = $ref_code_desc[1];
76
		}
77
		}
77
		return $refs_sci_fmt;
78
		return $refs_sci_fmt;
78
	}
79
	}
79
	
80
	
80
	private function traiterReferentielsSciVernasDispos() {
81
	private function traiterReferentielsSciVernasDispos() {
81
		$refs_verna = $this->config['referentiel']['referentielsVernaDispos'];
82
		$refs_verna = $this->config['referentiel']['referentielsVernaDispos'];
82
		$refs_verna = explode(',', $refs_verna);
83
		$refs_verna = explode(',', $refs_verna);
83
		$tab_refs_verna = array();
84
		$tab_refs_verna = array();
84
		foreach($refs_verna as $ref_verna) {
85
		foreach($refs_verna as $ref_verna) {
85
			$ref_sci_a_verna = explode(":", $ref_verna);
86
			$ref_sci_a_verna = explode(":", $ref_verna);
86
			$tab_refs_verna[$ref_sci_a_verna[0]] = $ref_sci_a_verna[1];
87
			$tab_refs_verna[$ref_sci_a_verna[0]] = $ref_sci_a_verna[1];
87
		}
88
		}
88
		return $tab_refs_verna;
89
		return $tab_refs_verna;
89
	}
90
	}
-
 
91
	
-
 
92
	private function traiterUrlsConsultationReferentiels($referentiels) {
-
 
93
		$urls = array();
-
 
94
		foreach($referentiels as $code_ref => $nom) {
-
 
95
			$config_url_ref = 'efloreConsultation'.ucwords($code_ref).'Url';
-
 
96
			if(isset($this->config['url'][$config_url_ref])) {
-
 
97
				$urls[$code_ref] = $this->config['url'][$config_url_ref];
-
 
98
			} else {
-
 
99
				$urls[$code_ref] = $this->config['url']['efloreConsultationUrl'];
-
 
100
			}
-
 
101
		}
-
 
102
		return $urls;
-
 
103
	}
90
}
104
}
91
?>
105
?>