Subversion Repositories eFlore/Applications.coel-consultation

Rev

Rev 11 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 11 Rev 15
Line 7... Line 7...
7
 * @package		Collection
7
 * @package		Collection
8
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
8
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
9
 * @copyright	2010 Tela-Botanica
9
 * @copyright	2010 Tela-Botanica
10
 * @license		http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
10
 * @license		http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
11
 * @license		http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
11
 * @license		http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
12
 * @version		SVN: $Id: ColControleur.php 11 2010-03-05 16:04:01Z jpm $
12
 * @version		SVN: $Id: ColControleur.php 15 2010-03-19 17:55:16Z jpm $
13
 */
13
 */
14
abstract class ColControleur extends Controleur {
14
abstract class ColControleur extends Controleur {
Line 15... Line 15...
15
 
15
 
16
	const RENDU_TETE = 'tete';
16
	const RENDU_TETE = 'tete';
17
	const RENDU_CORPS = 'corps';
17
	const RENDU_CORPS = 'corps';
-
 
18
	const RENDU_PIED = 'pied';
-
 
19
	const TYPE_AUTRE = 'AUTRE';
-
 
20
	const TYPE_TOTAL = 'TOTAL';
-
 
21
	const SEPARATEUR_TYPE_VALEUR = '##';
-
 
22
	const SEPARATEUR_VALEURS = ';;';
-
 
23
	const SEPARATEUR_DONNEES = '||';
Line 18... Line 24...
18
	const RENDU_PIED = 'pied';
24
	const VALEUR_NULL = 'NC';
19
	
25
	
20
	private $sortie = array();
26
	private $sortie = array();
21
	private $parametres = array();
27
	private $parametres = array();
Line 81... Line 87...
81
	 */
87
	 */
82
	private function fusionnerSortie($sortie) {
88
	private function fusionnerSortie($sortie) {
83
		$this->sortie = array_merge($this->sortie, $sortie);
89
		$this->sortie = array_merge($this->sortie, $sortie);
84
	}
90
	}
Line -... Line 91...
-
 
91
	
-
 
92
	protected function construireTxtTruckSansMajuscule($chaine_a_analyser) {
-
 
93
		return $this->construireTxtTruck($chaine_a_analyser, false);
-
 
94
	}
-
 
95
	
-
 
96
	protected function construireTxtTruck($chaine_a_analyser, $majuscule = true) {
-
 
97
		$termes = array();
-
 
98
		if ((!is_null($chaine_a_analyser)) && (trim($chaine_a_analyser) != ''))	{
-
 
99
			$valeurs = explode(self::SEPARATEUR_VALEURS, $chaine_a_analyser);
-
 
100
			$nbre_valeurs = count($valeurs);
-
 
101
			if ($nbre_valeurs > 0) {
-
 
102
				for ($i = 0; $i < $nbre_valeurs; $i++)	{
-
 
103
					$valeur = trim($valeurs[$i]);
-
 
104
					if ($valeur != '') {
-
 
105
						$valeur_formatee = $this->formaterValeurTruck($valeur);
-
 
106
						$termes[] = $valeur_formatee;
-
 
107
					}
-
 
108
				}
-
 
109
			}
-
 
110
		}
-
 
111
		
-
 
112
		$chaine_a_retourner = $this->formaterTableauDeTxt($termes, $majuscule);
-
 
113
		return $chaine_a_retourner;
-
 
114
	}
-
 
115
	
-
 
116
	private function formaterValeurTruck($valeur) {
-
 
117
		$chaine_a_retourner = '';
-
 
118
		
-
 
119
		if (preg_match('/^[^#]+##[^$]+$/', $valeur))	{
-
 
120
			$cle_valeur = explode(self::SEPARATEUR_TYPE_VALEUR, $valeur);
-
 
121
			$chaine_a_retourner = (($cle_valeur[1] == '' || $cle_valeur[1] == 'null') ? self::VALEUR_NULL : $cle_valeur[1]);
-
 
122
			$chaine_a_retourner .= ' '.$this->formaterParenthese($cle_valeur[0]);
-
 
123
		} else if ($valeur != '')	{
-
 
124
			$chaine_a_retourner = $valeur;
-
 
125
		} else {
-
 
126
			trigger_error("Valeur truck posant problème :$valeur", E_USER_NOTICE);
-
 
127
		}
-
 
128
		
-
 
129
		return $chaine_a_retourner;
-
 
130
	}
-
 
131
	
-
 
132
	protected function formaterParenthese($chaine_a_afficher) {
-
 
133
		if ($chaine_a_afficher != '') {
-
 
134
			$chaine_a_afficher = '('.$chaine_a_afficher.')';
-
 
135
		}
-
 
136
		return $chaine_a_afficher;
-
 
137
	}
-
 
138
	
-
 
139
	protected function formaterSautDeLigne($chaine_a_formater) {
-
 
140
		$txt_a_retourner = preg_replace('/\n/', '<br />', $chaine_a_formater);
-
 
141
		return $txt_a_retourner;
-
 
142
	}
-
 
143
	
-
 
144
	protected function formaterTableauDeTxt($tableau_de_txt, $majuscule = true) {
-
 
145
		$chaine_a_afficher = '';
-
 
146
		$taille_du_tableau = count($tableau_de_txt);
-
 
147
		if ($taille_du_tableau > 0) {
-
 
148
			$index_avt_dernier = $taille_du_tableau - 1;
-
 
149
			for ($i = 0; $i < $taille_du_tableau; $i++)	{
-
 
150
				$mot = $tableau_de_txt[$i];
-
 
151
				if ($i != $index_avt_dernier) {
-
 
152
					$chaine_a_afficher .= $mot.', ';
-
 
153
				} else {
-
 
154
					$chaine_a_afficher .= $this->nettoyerPointFinal($mot).'.';
-
 
155
				}
-
 
156
			}
-
 
157
		}
-
 
158
		if ($majuscule) {
-
 
159
			$chaine_a_afficher = ucfirst($chaine_a_afficher);
-
 
160
		}
-
 
161
		return $chaine_a_afficher;
-
 
162
	}
-
 
163
	
-
 
164
	protected function formaterAutre($chaine_a_afficher) {
-
 
165
		if ($chaine_a_afficher != '') {
-
 
166
			$chaine_a_afficher = ' [Autre : '.$chaine_a_afficher.']';
-
 
167
		}
-
 
168
		return $chaine_a_afficher;
-
 
169
	}
-
 
170
	
-
 
171
	protected function formaterOuiNon($chaine_a_formater) {
-
 
172
		$txt_a_retourner = '';
-
 
173
		if ($chaine_a_formater == '0') {
-
 
174
			$txt_a_retourner = 'non';
-
 
175
		} else if ($chaine_a_formater == '1') {
-
 
176
			$txt_a_retourner = 'oui';
-
 
177
		}
-
 
178
		return $txt_a_retourner;
-
 
179
	}
-
 
180
	
-
 
181
	protected function nettoyerPointFinal($mot) {
-
 
182
		$mot = preg_replace('/[.]$/', '', $mot);
-
 
183
		return $mot;
-
 
184
	}
-
 
185
	
-
 
186
	public function construireTxtListeOntologie($chaineAAnalyser, $valeurEstOntologie = true, $typeEstOntologie = true, $donneeEstOntologie = false) {
-
 
187
		$termes = array();
-
 
188
		$autres = array();
-
 
189
		$chaineAAnalyser = trim($chaineAAnalyser);
-
 
190
		if ($chaineAAnalyser != '') {
-
 
191
			$valeurs = explode(self::SEPARATEUR_VALEURS, $chaineAAnalyser);
-
 
192
			$nbreValeurs = count($valeurs);
-
 
193
			if ($nbreValeurs > 0)	{
-
 
194
				for ($i = 0; $i < $nbreValeurs; $i++)	{
-
 
195
					$valeur = $valeurs[$i];
-
 
196
					
-
 
197
					// VALEUR SANS TYPE 
-
 
198
					// La valeur sans type est une entrée de l'ontologie
-
 
199
					if ($valeurEstOntologie && preg_match('/^[0-9]+$/', $valeur)) {
-
 
200
						if ($valeur == '0') {
-
 
201
							$valeur = '';
-
 
202
						} else {
-
 
203
							$valeurOntologie = Ontologie::getValeur($valeur);
-
 
204
							if ($valeurOntologie != '') {
-
 
205
								$valeur = $valeurOntologie['nom'];
-
 
206
							}
-
 
207
						}
-
 
208
					}
-
 
209
					
-
 
210
					// VALEUR AVEC TYPE
-
 
211
					// Type : AUTRE
-
 
212
					$valeurTypeAutre = self::TYPE_AUTRE.self::SEPARATEUR_TYPE_VALEUR;
-
 
213
					if (preg_match('/^'.$valeurTypeAutre.'.+$/', $valeur)) {
-
 
214
						$txtAutre = preg_replace('/^'.$valeurTypeAutre.'/', '', $valeur);
-
 
215
						if ($txtAutre != '') {
-
 
216
							$autres[] = $txtAutre;
-
 
217
						}
-
 
218
						$valeur = '';
-
 
219
					}
-
 
220
					// Type correspondant à une entrée de l'ontologie
-
 
221
					if ($typeEstOntologie) {
-
 
222
						$valeurTypeOntologie = '[0-9]+'.self::SEPARATEUR_TYPE_VALEUR;
-
 
223
						if (preg_match('/^'.$valeurTypeOntologie.'.+$/', $valeur)) {
-
 
224
							$type = substr($valeur, 0, strripos($valeur, self::SEPARATEUR_TYPE_VALEUR));
-
 
225
							$valeurOntologie = Ontologie::getValeur($type);
-
 
226
							if ($valeurOntologie != '') {
-
 
227
								$valeurOntologieNom = $valeurOntologie['nom'];
-
 
228
								$valeur = preg_replace('/^'.$type.'/', $valeurOntologieNom.': ', $valeur);
-
 
229
							}
-
 
230
						}
-
 
231
					}
-
 
232
					// Donnée correspondant à une entrée de l'ontologie
-
 
233
					if ($donneeEstOntologie) {
-
 
234
						$donneeOntologie = self::SEPARATEUR_TYPE_VALEUR.'([0-9]+)';
-
 
235
						if (preg_match('/^.+'.$donneeOntologie.'$/', $valeur, $match)) {
-
 
236
							$donnee = $match[1];
-
 
237
							$donnee = str_replace(self::SEPARATEUR_TYPE_VALEUR, '', $donnee);
-
 
238
							$valeurOntologie = Ontologie::getValeur($donnee);
-
 
239
							if ($valeurOntologie != '') {
-
 
240
								$valeurOntologieNom = $valeurOntologie['nom'];
-
 
241
								$valeur = preg_replace('/'.$donnee.'$/', $valeurOntologieNom, $valeur);
-
 
242
							}
-
 
243
						}
-
 
244
					}
-
 
245
					
-
 
246
					// Nettoyage final
-
 
247
					$valeur = preg_replace('/'.self::SEPARATEUR_TYPE_VALEUR.'/', '', $valeur);
-
 
248
					
-
 
249
					if ($valeur != '') {
-
 
250
						$termes[] = $valeur;
-
 
251
					}
-
 
252
				}
-
 
253
			}
-
 
254
		}
-
 
255
		
-
 
256
		$chaineTermes = $this->formaterTableauDeTxt($termes);
-
 
257
		$chaineAutres = $this->formaterTableauDeTxt($autres);
-
 
258
		$chaineARetourner = $chaineTermes.$this->formaterAutre($chaineAutres);
-
 
259
		
-
 
260
		return $chaineARetourner;
-
 
261
	}
85
	
262
	
86
}
263
}