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