Subversion Repositories eFlore/Applications.cel

Rev

Rev 3122 | Rev 3164 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3122 delphine 1
<?php
2
// declare(encoding='UTF-8');
3
/**
4
 * Service affichant les dernières photo publiques du CEL ouvrable sous forme de diaporama.
5
 * Encodage en entrée : utf8
6
 * Encodage en sortie : utf8
7
 *
8
 * Cas d'utilisation et documentation :
9
 * @link http://www.tela-botanica.org/wikini/eflore/wakka.php?wiki=AideCELWidgetPhoto
10
 *
11
 * Paramètres :
12
 * ===> extra = booléen (1 ou 0)  [par défaut : 1]
13
 * Affiche / Cache la vignette en taille plus importante au bas du widget.
14
 * ===> vignette = [0-9]+,[0-9]+  [par défaut : 4,3]
15
 * Indique le nombre de vignette par ligne et le nombre de ligne.
16
 *
17
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
18
 * @license	GPL v3 <http://www.gnu.org/licenses/gpl.txt>
19
 * @license	CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
20
 * @version	$Id$
21
 * @copyright	Copyright (c) 2010, Tela Botanica (accueil@tela-botanica.org)
22
 */
23
class Manager extends WidgetCommun {
24
 
25
	const DS = DIRECTORY_SEPARATOR;
26
	const SERVICE_DEFAUT = 'manager';
27
	private $cel_url_tpl = null;
28
	/** Si spécifié, on ajoute une barre de navigation inter-applications */
29
	private $bar;
30
	//private $parametres_autorises = array('projet', 'type', 'langue', 'order');
31
	private $parametres_autorises = array(
32
			'projet' => 'projet',
33
			'type' => 'type',
34
			'langue' => 'langue',
35
			'order' => 'order'
36
	);
37
	/**
38
	 * Méthode appelée par défaut pour charger ce widget.
39
	 */
40
	public function executer() {
41
		$retour = null;
42
		// Pour la création de l'id du cache nous ne tenons pas compte du paramètre de l'url callback
43
		unset($this->parametres['callback']);
44
		extract($this->parametres);
45
		$this->bar = (isset($bar)) ? $bar : false;
46
 
47
		if (!isset($mode)) {
48
			$mode = self::SERVICE_DEFAUT;
49
		}
50
 
51
		$this->cel_url_tpl = $this->config['manager']['celUrlTpl'];
52
 
53
		if ($_POST != array()) {
54
			$this->parametres['projet'] = $_POST['projet'];
55
			$this->parametres['langue'] = $_POST['langue'];
56
			if ($mode == 'modification') {
57
				$parametres = $this->traiterParametresModif();
58
				$json = $this->getDao()->modifier($this->cel_url_tpl, $parametres);
59
			} else {
60
				$json = $this->getDao()->ajouter($this->cel_url_tpl, $_POST);
61
				$this->parametres['mode'] = $mode = 'modification';
62
			}
63
		}
64
 
65
 
66
 
67
 
68
		$methode = $this->traiterNomMethodeExecuter($mode);
69
		if (method_exists($this, $methode)) {
70
			$retour = $this->$methode();
71
		} else {
72
			$this->messages[] = "Ce type de service '$methode' n'est pas disponible.";
73
		}
74
 
75
		$contenu = '';
76
		if (is_null($retour)) {
77
			$this->messages[] = 'La ressource demandée a retourné une valeur nulle.';
78
		} else {
79
			if (isset($retour['donnees'])) {
80
				$retour['donnees']['prod'] = ($this->config['parametres']['modeServeur'] == "prod");
81
				$retour['donnees']['bar'] = $this->bar;
82
				$retour['donnees']['url_base'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], '');
83
				$retour['donnees']['mode'] = $mode;
84
				$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.$retour['squelette'].'.tpl.html';
85
				$contenu = $this->traiterSquelettePhp($squelette, $retour['donnees']);
86
			} else {
87
				$this->messages[] = 'Les données à transmettre au squelette sont nulles.';
88
			}
89
		}
90
		$this->envoyer($contenu);
91
	}
92
 
93
	private function executerManager() {
94
		$params = array();
95
		$retour['squelette'] = 'manager';
96
		foreach ($this->parametres_autorises as $id=>$pa) {
97
			if (isset($this->parametres[$pa])) {
98
				$params[] = $pa."=".$this->parametres[$pa];
99
			}
100
		}
101
		$param = implode($params, '&');
102
		$url = $this->cel_url_tpl;
103
		if ($param != "") $url .= '?'.$param;
104
		$json = $this->getDao()->consulter($url);
105
		$retour['donnees']['widget'] = (array) json_decode($json, true);
3125 mathias 106
		$retour['donnees']['widgetUrlTpl'] = $this->config['manager']['widgetUrlTpl'];
3122 delphine 107
		return $retour;
108
	}
109
 
110
	private function executerCreation() {
111
		//https://api.tela-botanica.org/service:cel:NomsChampsEtendus/cle
112
		$retour['squelette'] ='creation';
113
		$jsonlangue = $this->getDao()->consulter($this->config['manager']['languesUrl']);
114
		$tableaulangue= (array) json_decode($jsonlangue, true);
115
		$retour['donnees']['langues'] = $tableaulangue['resultat'] ;
116
		$retour['donnees']['widget'] = array();
117
		if (isset($this->parametres['projet'])) {
118
			$url = $this->cel_url_tpl.'?projet='.$this->parametres['projet'];
119
			$json = $this->getDao()->consulter($url);
120
			$tableau = (array) json_decode($json, true);
121
			$retour['donnees']['widget'] = $tableau[0];
122
			$urltype = $this->cel_url_tpl.'?esttype=1';
123
			$jsontype = $this->getDao()->consulter($urltype);
124
			$tableautype= (array) json_decode($jsontype, true);
125
			$retour['donnees']['type'] = $tableautype;
126
		}
127
		return $retour;
128
	}
129
 
130
	private function executerSaisie() {
131
		$retour = '';
132
		if (isset($this->parametres['projet'])) {
133
			$retour['squelette'] = 'saisie';
134
			$url = $this->cel_url_tpl.'?projet='.$this->parametres['projet'];
135
			$json = $this->getDao()->consulter($url);
136
			$tableau = (array) json_decode($json, true);
137
			$retour['donnees']['widget'] = $tableau[0];
138
		}
139
		return $retour;
140
	}
141
 
142
	private function executerModification() {
143
		$retour = '';
144
		if (isset($this->parametres['projet'])) {
145
			$retour['squelette'] = 'creation';
146
			$url = $this->cel_url_tpl.'?projet='.$this->parametres['projet'].'&langue='.$this->parametres['langue'];
147
			$json = $this->getDao()->consulter($url);
148
			$tableau = (array) json_decode($json, true);
149
			$retour['donnees']['widget'] = $tableau[0];
150
			$urltype = $this->cel_url_tpl.'?esttype=1';
151
			$jsontype = $this->getDao()->consulter($urltype);
152
			$tableautype= (array) json_decode($jsontype, true);
153
			$retour['donnees']['type'] = $tableautype;
154
		}
155
		return $retour;
156
	}
157
	private function traiterParametres() {
158
		$parametres_flux = '?';
159
		$criteres = array('utilisateur', 'commune', 'dept', 'taxon', 'commentaire', 'date', 'tag', 'motcle', 'projet', 'num_taxon', 'num_nom', 'referentiel', 'groupe_zones_geo');
160
		foreach($this->parametres as $nom_critere => $valeur_critere) {
161
			if (in_array($nom_critere, $criteres)) {
162
				$valeur_critere = str_replace(' ', '%20', $valeur_critere);
163
				$parametres_flux .= $nom_critere.'='.$valeur_critere.'&';
164
			}
165
		}
166
 
167
		if ($parametres_flux == '?') {
168
			$parametres_flux = '';
169
		} else {
170
			$parametres_flux = rtrim($parametres_flux, '&');
171
		}
172
		return $parametres_flux;
173
	}
174
 
175
	private function traiterParametresModif() {
176
		$parametres_modif = array();
177
		foreach ($_POST as $id => $parametres) {
178
			if ($parametres != "") {
179
				$parametres_modif[$id] = $parametres;
180
			}
181
		}
182
		return $parametres_modif;
183
	}
184
}
185
?>