Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

Rev Author Line No. Line
46 jpm 1
<?php
2
class GenerateurNomSciHtml {
3
	protected $bdd = null;
4
	protected $table = null;
5
 
6
	protected $num = null;
7
	protected $compo_nom = array();
8
 
9
	protected $abbr = array (
10
			'infra-gen.' 	=>	'Infra-Genre',
11
			'sect.'			=> 'Section',
12
			'subsect.'		=> 'Sous-Section',
13
			'ser.'			=> 'Série',
14
			'subser.'		=> 'Sous-Série',
15
			'gr.'			=> 'Groupe',
16
			'agg.' 			=> 'Agrégat',
17
			'sp.' 			=> 'Espèce',
18
			'subsp.'		=> 'Sous-Espèce',
19
			'infra-sp.'		=> 'Infra-Espèce',
20
			'var.'			=> 'Variété',
21
			'subvar.'		=> 'Sous-Variété',
22
			'fa'			=> 'Forme',
23
			'subf.'			=> 'Sous-Forme',
24
			'f. sp.'		=> 'Forma species',
25
			'proles' 		=> 'Race prole'
26
	);
27
 
129 jpm 28
	private $nomSciTpl = '<span class="sci">%s</span>';
46 jpm 29
	private $nomSupraGenTpl = '<span class="supra_gen">%s</span>';
30
	private $genTpl = '<span class="gen">%s</span>';
31
	private $infraGenTpl = '<span class="infra-gen">%s</span>';
32
	private $spFHTpl = '<span class="gen">%s</span> <span class="sp">%s</span>';
33
	private $typeEpitheteTpl = '<abbr class="type_epithete" title="%s">%s</abbr>';
34
	private $infraSpFHTpl = '<span class="gen">%s</span> <span class="sp">%s</span> <abbr class="type-epithete" title="%s">%s</abbr> <span class="infra-sp">%s</span>';
35
	private $formuleHybTpl = '<span class="formule-hyb">%s</span>';
36
 
37
	public function generer(Array $nomsDecomposes) {
38
		$nomsSciHtml = array();
39
		foreach ($nomsDecomposes as $noms => $infos) {
40
			$this->initialiserVariables($infos);
41
 
42
			$nomSciHtml = '';
43
			$nomSciHtml .= $this->ajouterBaliseNomSupraGen();
44
			$nomSciHtml .= $this->verifierHybridite($this->compo_nom['genre'], 'gen');
45
			$nomSciHtml .= $this->ajouterBaliseInfraGen();
46
			$nomSciHtml .= $this->verifierHybridite($this->compo_nom['epithete_sp'], 'sp');
47
			$nomSciHtml .= $this->ajouterBaliseTypeInfraSp();
48
			$nomSciHtml .= $this->verifierHybridite($this->compo_nom['epithete_infra_sp'], 'infra-sp');
49
			$nomSciHtml .= $this->ajouterCultivarGpComm();
50
 
51
			if ($nomSciHtml != '') {
52
				$nomsSciHtml[$this->num] = sprintf($this->nomSciTpl, trim($nomSciHtml));
53
			}
54
		}
55
		return $nomsSciHtml;
56
	}
57
 
58
	private function initialiserVariables($infos) {
59
		$this->num = $infos['num_nom'];
60
		$this->compo_nom = $infos;
61
	}
62
 
63
	private function ajouterBaliseNomSupraGen() {
64
		$html = '';
65
		if ($this->compo_nom['nom_supra_generique'] != '') {
66
			$html = sprintf($this->nomSupraGenTpl, $this->compo_nom['nom_supra_generique']);
67
		}
68
		return $html;
69
	}
70
 
71
	private function ajouterTypeEpithete($type) {
72
		if (!array_key_exists($type, $this->abbr)) {
73
			$this->abbr[$type] = $type;
74
		}
75
	}
76
 
77
	private function ajouterBaliseInfraGen() {
78
		$html = '';
79
		if ($this->verifierTypeInfraGen()) {
80
			$html .= $this->ajouterBaliseTypeInfraGen();
81
		} else {
82
			if ($this->avoirInfo('epithete_infra_generique')) {
83
				$html .= sprintf($this->infraGenTpl, $this->compo_nom['epithete_infra_generique']);
84
			}
85
		}
86
		return $html;
87
	}
88
 
89
	private function verifierTypeInfraGen() {
90
		$ok = false;
91
		if ($this->compo_nom['type_epithete'] != '' && $this->compo_nom['epithete_infra_generique'] != '') {
92
			$this->ajouterTypeEpithete($this->compo_nom['type_epithete']);
93
			$ok = true;
94
		}
95
		return $ok;
96
	}
97
 
98
	private function ajouterBaliseTypeInfraGen() {
99
		$html = '';
100
		$type = $this->compo_nom['type_epithete'];
101
 
102
		if ($type == 'agg.') {
103
			// Ajout de l'infra gen avant le type s'il est égal à agg.
104
			$html .= ' '.$this->ajouterBaliseInfraGen().
105
					' '.sprintf($this->typeEpitheteTpl, $this->abbr[$type], $type);
106
		} else {
107
			$html .= ' '.sprintf($this->typeEpitheteTpl, $this->abbr[$type], $type).
108
					' '.$this->ajouterBaliseInfraGen();
109
		}
110
		return $html;
111
	}
112
 
113
	private function ajouterBaliseTypeInfraSp() {
114
		$html = '';
115
		$type = $this->compo_nom['type_epithete'];
116
		$infraSp = $this->compo_nom['epithete_infra_sp'];
117
 
118
		if ($infraSp != '') {
119
			if ($type != '') {
120
				$this->ajouterTypeEpithete($type);
121
				$html = ' '.sprintf($this->typeEpitheteTpl, $this->abbr[$type], $type);
122
			} else {
123
				$message = "Nom #%s contient un épithète infra-spécifique mais son type n'est pas renseigné.";
124
				$this->traiterErreur($message, array($this->num));
125
			}
126
		}
127
		return $html;
128
	}
129
 
130
	private function ajouterCultivarGpComm() {
131
		$html = '';
132
		if ($this->avoirInfo('cultivar_groupe')) {
133
			$html .= ' '.$this->ajouterCultivarGroupe();
134
		}
135
		if ($this->avoirInfo('nom_commercial')) {
136
			$html .= ' <span class="commercial">'.$this->compo_nom['nom_commercial'].'</span>';
137
		}
138
		if ($this->avoirInfo('cultivar')) {
139
			$html .= ' <span class="cultivar">\''.$this->compo_nom['cultivar'].'\'</span>';
140
		}
141
		return $html;
142
	}
143
 
144
	private function avoirInfo($valeur) {
145
		return (isset($this->compo_nom[$valeur]) && $this->compo_nom[$valeur] != '') ? true : false;
146
	}
147
 
148
	/**
149
	 * Permet d'ajouter les groupes de cultivar en fonction de la présence d'un cultivar et de la présence d'un grex
150
	 *
151
	 * L'ensemble des individus obtenu par une fécondation particulière s'appelle un le Grex (que pour les orchidées).
152
	 * Au sein du grex, certains individus peuvent se distinguer par des formes, des coloris ou autres qui font que
153
	 * l'obtenteur du grex va les sélectionner.
154
	 * les noms de groupes de cultivars sont suivis de l'abréviation « Gp » et placés entre parenthèses
155
	 * les noms de grex, s'ils sont utilisés devant une épithète de cultivar, ne se mettent pas entre parenthèses
156
	 *	 ex : Cymbidium Alexanderi gx 'Westonbirt' (cultivar_groupe = Alexanderi gx) ;
157
	 * les noms de groupe se mettent entre parenthèses s'ils sont devant une épithète de cultivar
158
	 *	 ex : Dracaena fragrans (Deremenis Gp) 'Christianne' (cultivar_groupe = Deremenis)
159
	 * Un grex peut contenir des groupes (rédaction d'un exemple de l'ICNCP)
160
	 *	 ex : × Rhyncosophrocattleya Marie Lemon Stick grex Francis Suzuki Group
161
	 *	 ou : × Rhyncosophrocattleya Marie Lemon Stick gx Francis Suzuki Gp
162
	 * @param unknown_type $val
163
	 *
164
	 */
165
	private function ajouterCultivarGroupe() {
166
		$html = '';
167
		if ($this->avoirInfo('cultivar_groupe')) {
168
			//si le champ cultivar_groupe n'est pas vide
169
			if ($this->compo_nom['cultivar']) {
170
				//si il y a un cultivar, on ajoute des parenthèses au group (mais pas au grex)
171
				if (strrpos($this->compo_nom['cultivar_groupe'], ' gx ') !== false) {
172
					//si le grex est composé de groupe
173
					$tab_gp = explode(' gx ', $this->compo_nom['cultivar_groupe']);
174
					$html = ' <span class="gp">'.$tab_gp[0].
175
								' <abbr title="grex">gx </abbr>('.$tab_gp[1].
176
								' <abbr title="groupe">Gp</abbr>)</span>';
177
				} elseif (strrpos($this->compo_nom['cultivar_groupe'], ' gx') !== false) {
178
					//si il y a un grex et pas de groupe
179
					$tab_gp = explode(' gx', $this->compo_nom['cultivar_groupe']);
180
					$html = ' <span class="gp">'.$tab_gp[0].' <abbr title="grex">gx</abbr></span>';
181
				} else { //si il n'y a pas de grex mais un groupe
182
					$html = ' <span class="gp">'.$this->compo_nom['cultivar_groupe'].' <abbr title="groupe">Gp</abbr>)</span>';
183
				}
184
			} else { //s'il n'y a pas de cultivar
185
				if (strrpos($this->compo_nom['cultivar_groupe'], ' gx ') !== false) {
186
					//si le grex est composé de groupe
187
					$tab_gp = explode(' gx ', $this->compo_nom['cultivar_groupe']);
188
					$html = ' <span class="gp">'.$tab_gp[0].
189
								' <abbr title="grex">gx</abbr>'.$tab_gp[1].
190
								' <abbr title="groupe">Gp</abbr></span>';
191
				} elseif (strrpos($this->compo_nom['cultivar_groupe'], ' gx') !== false) {
192
					//si il y a un grex et pas de groupe
193
					$tab_gp = explode(' gx', $this->compo_nom['cultivar_groupe']);
194
					$html = ' <span class="gp">'.$tab_gp[0].' <abbr title="grex">gx</abbr></span>';
195
				} else { //si il n'y a pas de grex mais un groupe
196
					$html = ' <span class="gp">'.$this->compo_nom['cultivar_groupe'].' <abbr title="groupe">Gp</abbr></span>';
197
				}
198
			}
199
		}
200
		return $html;
201
	}
202
 
203
	/**
204
	 *
205
	 * Permet de repérer s'il s'agit d'un hybride (infra-sp, genre, sp) ou d'une chimère.
206
	 * @param unknown_type $val
207
	 * @param unknown_type $type
208
	 */
209
	private function verifierHybridite($epithete, $type) {
210
		$html = '';
211
		if ($epithete != '') {
212
			if (substr($epithete, 0, 2) == 'x ') {
129 jpm 213
				$html = ' <span class="hyb">x <span class="'.$type.'">'.str_replace('x ', '', $epithete).'</span></span>';
46 jpm 214
			} elseif (substr($epithete, 0, 2) == '+ ') {
129 jpm 215
				$html = ' <span class="chimere">+ <span class="'.$type.'">'.str_replace('+ ', '', $epithete).'</span></span>';
46 jpm 216
			} else if (substr_count($epithete, ' x ') > 1) {
217
				// Cas d'une formule d'hybridité comprenant des parents hybrides
218
				$html = ' '.$this->insererBaliseFormuleHyb($epithete);
219
			} elseif (substr_count($epithete, ' x ') == 1) {
220
				// Cas d'une formule d'hybridité simple
221
				$html = ' '.$this->ajouterFomuleHybridite($epithete, $type);
222
			} else {
223
				$html = ' <span class="'.$type.'">'.$epithete.'</span>';
224
			}
225
		}
226
		return $html;
227
	}
228
 
229
	private function ajouterFomuleHybridite($formule, $type) {
230
		$tab_x = explode(' x ', $formule);
231
		$formule_hyb = array();
232
		switch ($type) {
233
			case 'gen' 		:
234
				foreach ($tab_x as $hyb) {
235
					$formule_hyb[] = sprintf($this->genTpl, $hyb);
236
				}
237
				break;
238
			case 'sp'		:
239
				foreach ($tab_x as $hyb) {
240
					if (substr_count($hyb, ' ') >= 1) {
241
						list($gen, $sp) = explode(' ', $hyb);
242
						$formule_hyb[] = sprintf($this->spFHTpl, $gen, $sp);
243
					} else {
244
						$avertissement = "Nom #%s : la valeur d'hybride '%s' ne contenait pas d'espace .";
245
						$this->traiterAvertissement($avertissement, array($this->num, $hyb));
246
					}
247
				}
248
				break;
249
			case 'infra-sp' :
250
				foreach ($tab_x as $hyb) {
251
					list($gen, $sp, $typeEpithete, $infraSp) = explode (' ', $hyb);
252
					$formule_hyb[] = sprintf($this->infraSpFHTpl, $gen, $sp, $this->abbr[$typeEpithete], $typeEpithete, $infraSp);
253
				}
254
				break;
255
			default : break;
256
		}
257
		return $this->insererBaliseFormuleHyb(implode(' x ', $formule_hyb));
258
	}
259
 
260
	private function insererBaliseFormuleHyb($formule) {
261
		return sprintf($this->formuleHybTpl, $formule);
262
	}
263
}
264
?>