Subversion Repositories eFlore/Applications.coel-consultation

Rev

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

Rev 193 Rev 195
1
<?php
1
<?php
2
// declare(encoding='UTF-8');
2
// declare(encoding='UTF-8');
3
/**
3
/**
4
 * Modèle d'accès à la base de données des Collections pour la Recherche
4
 * Modèle d'accès à la base de données des Collections pour la Recherche
5
 *
5
 *
6
 * @package		Collection
6
 * @package		Collection
7
 * @category	php5
7
 * @category	php5
8
 * @author		aurelien <aurelien@tela-botanica.org>
8
 * @author		aurelien <aurelien@tela-botanica.org>
9
 * @author		mathias <mathias@tela-botanica.org>
9
 * @author		mathias <mathias@tela-botanica.org>
10
 * @copyright	2010 Tela-Botanica
10
 * @copyright	2010 Tela-Botanica
11
 * @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
12
 * @license		http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
12
 * @license		http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
13
 * @version		SVN: $Id: RechercheDao.php 193 2014-01-10 16:10:03Z mathias $
13
 * @version		SVN: $Id: RechercheDao.php 195 2014-01-22 13:29:20Z aurelien $
14
 *
14
 *
15
 */
15
 */
16
class RechercheDao extends Dao {
16
class RechercheDao extends Dao {
17
	const SERVICE = 'CoelRecherche';
17
	const SERVICE = 'CoelRecherche';
18
 
18
 
19
	/** @deprecated retro-compatibilité */
19
	/** @deprecated retro-compatibilité */
20
	public function chercherStructureNbre($parametres) {
20
	public function chercherStructureNbre($parametres) {
21
		return $this->chercherCollectionsNbre($parametres);
21
		return $this->chercherCollectionsNbre($parametres);
22
	}
22
	}
23
	/** @deprecated retro-compatibilité */
23
	/** @deprecated retro-compatibilité */
24
	public function chercher($parametres) {
24
	public function chercher($parametres) {
25
   		return $this->chercherCollections($parametres);
25
   		return $this->chercherCollections($parametres);
26
	}
26
	}
27
 
27
 
28
	// recherche du nombre de collections : nouveau
28
	// recherche du nombre de collections : nouveau
29
	public function chercherCollectionsNbre($parametres) {
29
	public function chercherCollectionsNbre($parametres) {
30
		$url = $this->construireUrlRechercheCollections('NombreCollections', $parametres, false);
30
		$url = $this->construireUrlRechercheCollections('NombreCollections', $parametres, false);
31
   		$json = $this->envoyerRequeteConsultation($url);
31
   		$json = $this->envoyerRequeteConsultation($url);
32
   		$donnees = json_decode($json, true);
32
   		$donnees = json_decode($json, true);
33
 
33
 
34
		return $donnees;
34
		return $donnees;
35
	}
35
	}
36
 
36
 
37
	// recherche du nombre de personnes : nouveau
37
	// recherche du nombre de personnes : nouveau
38
	public function chercherPersonnesNbre($parametres) {
38
	public function chercherPersonnesNbre($parametres) {
39
		$url = $this->construireUrlRecherchePersonnes('NombrePersonnes', $parametres, false);
39
		$url = $this->construireUrlRecherchePersonnes('NombrePersonnes', $parametres, false);
40
   		$json = $this->envoyerRequeteConsultation($url);
40
   		$json = $this->envoyerRequeteConsultation($url);
41
   		$donnees = json_decode($json, true);
41
   		$donnees = json_decode($json, true);
42
 
42
 
43
		return $donnees;
43
		return $donnees;
44
	}
44
	}
45
 
45
 
46
	// recherche de collections : nouveau 
46
	// recherche de collections : nouveau 
47
	public function chercherCollections($parametres) {
47
	public function chercherCollections($parametres) {
48
		$url = $this->construireUrlRechercheCollections('Collections', $parametres);
48
		$url = $this->construireUrlRechercheCollections('Collections', $parametres);
49
   		$json = $this->envoyerRequeteConsultation($url);
49
   		$json = $this->envoyerRequeteConsultation($url);
50
   		$donnees = json_decode($json, true);
50
   		$donnees = json_decode($json, true);
51
 
51
 
52
		return $donnees;
52
		return $donnees;
53
	}
53
	}
54
 
54
 
55
	// recherche de personnes : nouveau 
55
	// recherche de personnes : nouveau 
56
	public function chercherPersonnes($parametres) {
56
	public function chercherPersonnes($parametres) {
57
		$url = $this->construireUrlRecherchePersonnes('Personnes', $parametres);
57
		$url = $this->construireUrlRecherchePersonnes('Personnes', $parametres);
58
   		$json = $this->envoyerRequeteConsultation($url);
58
   		$json = $this->envoyerRequeteConsultation($url);
59
   		$donnees = json_decode($json, true);
59
   		$donnees = json_decode($json, true);
60
 
60
 
61
		return $donnees;
61
		return $donnees;
62
	}
62
	}
63
 
63
 
64
	// construit l'URL du service CoelRecherche pour obtenir des collections
64
	// construit l'URL du service CoelRecherche pour obtenir des collections
65
	// Attention au nombre et à l'ordre des paramètres !
65
	// Attention au nombre et à l'ordre des paramètres !
66
	private function construireUrlRechercheCollections($type, $parametres, $limitation = true) {
66
	private function construireUrlRechercheCollections($type, $parametres, $limitation = true) {
67
		return $this->construireUrlRecherche(
67
		return $this->construireUrlRecherche(
68
			$type,
68
			$type,
69
			$parametres,
69
			$parametres,
70
			$limitation,
70
			$limitation,
71
			array('mots', 'sci', 'bot', 'lieu-stockage', 'zg', 'p', 'pr', 'str-d', 'veg', 'projets')
71
			array('mots', 'sci', 'bot', 'lieu-stockage', 'zg', 'p', 'pr', 'str-d', 'veg')
72
		);
72
		);
73
	}
73
	}
74
 
74
 
75
	// construit l'URL du service CoelRecherche pour obtenir des personnes
75
	// construit l'URL du service CoelRecherche pour obtenir des personnes
76
	// Attention au nombre et à l'ordre des paramètres !
76
	// Attention au nombre et à l'ordre des paramètres !
77
	private function construireUrlRecherchePersonnes($type, $parametres, $limitation = true) {
77
	private function construireUrlRecherchePersonnes($type, $parametres, $limitation = true) {
78
		return $this->construireUrlRecherche(
78
		return $this->construireUrlRecherche(
79
			$type,
79
			$type,
80
			$parametres,
80
			$parametres,
81
			$limitation,
81
			$limitation,
82
			array('nom-famille', 'adresse', 'date-vivant')
82
			array('nom-famille', 'adresse', 'date-vivant')
83
		);
83
		);
84
	}
84
	}
85
 
85
 
86
	// fabrique une URL pour le service CoelRecherche en collant les paramètres fournis (sinon "*")
86
	// fabrique une URL pour le service CoelRecherche en collant les paramètres fournis (sinon "*")
87
	// dans l'ordre attendu par le service demandé ($type)
87
	// dans l'ordre attendu par le service demandé ($type)
88
	private function construireUrlRecherche($type, $parametres, $limitation, $paramsAPasser) {
88
	private function construireUrlRecherche($type, $parametres, $limitation, $paramsAPasser) {
89
 
89
 
90
		$url = $this->url_jrest . self::SERVICE . '/' . $type;
90
		$url = $this->url_jrest . self::SERVICE . '/' . $type;
91
 
91
 
92
		foreach ($paramsAPasser as $param_cle) {
92
		foreach ($paramsAPasser as $param_cle) {
93
			if (isset($parametres[$param_cle]) && $parametres[$param_cle] != '') {
93
			if (isset($parametres[$param_cle]) && $parametres[$param_cle] != '') {
94
				$valeur = rawurlencode(trim($parametres[$param_cle]));
94
				$valeur = rawurlencode(trim($parametres[$param_cle]));
95
				$url .= '/'.$valeur;
95
				$url .= '/'.$valeur;
96
			} else {
96
			} else {
97
				$url .= '/*';
97
				$url .= '/*';
98
			}
98
			}
99
		}	
99
		}	
100
		return $url;
100
		return $url;
101
   }
101
   }
102
}
102
}
103
?>
103
?>