New file |
0,0 → 1,153 |
<?php |
// declare(encoding='UTF-8'); |
/** |
* Service de recherche dans eflore, permettant d'intégrer le moteur dans une page donnée |
* Encodage en entrée : utf8 |
* Encodage en sortie : utf8 |
* |
* Cas d'utilisation et documentation : |
* @link http://www.tela-botanica.org/wikini/eflore/wakka.php?wiki=AideEfloreWidgetRecherche |
* |
* |
* @author Aurélien PERONNET <aurelien@tela-botanica.org> |
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt> |
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt> |
* @version $Id$ |
* @copyright Copyright (c) 2013, Tela Botanica (accueil@tela-botanica.org) |
*/ |
class Chorodep extends WidgetCommun { |
const DS = DIRECTORY_SEPARATOR; |
/** |
* Méthode appelée par défaut pour charger ce widget. |
*/ |
public function executer() { |
$retour = null; |
$methode = $this->traiterNomMethodeExecuter($this->ressources[0]); |
if (method_exists($this, $methode)) { |
$retour = $this->$methode(); |
} else { |
$this->messages[] = "Ce type de service '$methode' n'est pas disponible."; |
} |
if (is_null($retour)) { |
$info = 'Un problème est survenu : '.print_r($this->messages, true); |
$this->envoyer($info); |
} else { |
$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.$retour['squelette'].'.tpl.html'; |
$contenu = $this->traiterSquelettePhp($squelette, $retour['donnees']); |
if (isset($_GET['callback'])) { |
$this->envoyerJsonp(array('contenu' => $contenu)); |
} else { |
$this->envoyer($contenu); |
} |
} |
} |
/* |
* dans validation |
* reflechir comment gérer prop refusee |
* quand prop validée/refusée changée dans chorodep_prop et chorodep_version |
*/ |
|
|
|
public function executerFormulaire() { |
$widget['donnees'] = array(); |
if ($this->parametres != array()) { |
$widget['donnees'] = $this->parametres; |
$this->ajouterProposition(); |
} |
|
$l = json_decode(file_get_contents("http://api.tela-botanica.org/service:eflore:0.1/insee-d/zone-geo?retour.format=liste"), true); |
$widget['donnees']['liste_dept'] = $l["resultat"]; |
|
$widget['donnees']['efloreScriptUrl'] = $this->config['url']['efloreScriptUrl']; |
|
$widget['squelette'] = 'formulaire'; |
return $widget; |
} |
|
private function ajouterProposition() { |
$params_obli = array("dept",/*"num_nom",*/"statut","nom_sci","sources","notes"); |
$donnees[] = "provenance=form"; |
$donnees[] = "num_nom=24545"; // à modifier avec javascript |
$url_propo = "http://localhost/service:eflore:0.1/chorodep/propositions/"; |
foreach ($params_obli as $param) { |
if (isset($this->parametres[$param])) { |
$donnees[] = $param."=".$this->parametres[$param]; |
} else { |
$donnees[] = $param."="; |
} |
} |
$contexte = stream_context_create(array( |
'http' => array( |
'method' => 'PUT', |
'header' => "Content-type: application/x-www-form-urlencoded\r\n", |
'content' => implode("&", $donnees)))); |
$flux = fopen($url_propo, 'r', false, $contexte); |
if (!$flux) { |
$this->reponse_entetes = $http_response_header; |
$e = "Echec requête 'PUT' : {$url_propo}\n". |
"Paramètres requête : implode("&", $donnees) \n". |
"Entêtes réponse : \n"; |
trigger_error($e, E_USER_WARNING); |
} else { |
// Informations sur les en-têtes et métadonnées du flux |
$this->reponse_entetes = stream_get_meta_data($flux); |
|
// Contenu actuel de $url |
$contenu = stream_get_contents($flux); |
|
fclose($flux); |
} |
} |
|
public function executerValidation() { |
$widget['donnees'] = array(); |
if ($this->parametres != array()) { |
$this->modifierProposition(); |
} |
$widget['donnees']['liste_prop'] = json_decode(file_get_contents("http://localhost/service:eflore:0.1/chorodep/propositions/"), true); |
|
$widget['squelette'] = 'tableau_validation'; |
return $widget; |
} |
|
private function modifierProposition() { |
$url_propo = "http://localhost/service:eflore:0.1/chorodep/propositions/"; |
foreach ($this->parametres as $id => $prop) { |
$donnees[] = $id."=".$prop; |
} |
$contexte = stream_context_create(array( |
'http' => array( |
'method' => 'POST', |
'header' => "Content-type: application/x-www-form-urlencoded\r\n", |
'content' => implode("&", $donnees)))); |
$flux = fopen($url_propo, 'r', false, $contexte); |
if (!$flux) { |
$this->reponse_entetes = $http_response_header; |
$e = "Echec requête 'POST' : {$url_propo}\n". |
"Paramètres requête : implode("&", $donnees) \n". |
"Entêtes réponse : \n"; |
trigger_error($e, E_USER_WARNING); |
} else { |
// Informations sur les en-têtes et métadonnées du flux |
$this->reponse_entetes = stream_get_meta_data($flux); |
|
// Contenu actuel de $url |
$contenu = stream_get_contents($flux); |
|
fclose($flux); |
} |
} |
|
/*"1","0","presenceChorologie","Tableau des présences pour le projet de chorologie départementale","presenceChorologie", |
"2","1","non renseignée","Zone géographique non renseignée.",,"legende=#808080" |
"3","1","présence",,"1","legende=#A0FF7D,priorite=6" |
"4","1","présence à confimer",,"1?","legende=#FFFF32,priorite=5" |
"5","1","douteux",,"?","legende=#FFCB30,priorite=4" |
"6","1","disparu",,"-|-","legende=#F88017,priorite=3" |
"7","1","erreur",,"#","legende=#FF2850,priorite=2" |
"8","1","erreur à confirmer",,"#?","legende=#9F0016,priorite=1"*/ |
|
|
} |
?> |