Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 334 | Rev 353 | 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();
334 jpm 39
		foreach ($nomsDecomposes as $infos) {
46 jpm 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')) {
352 jpm 168
			$groupe = $this->compo_nom['cultivar_groupe'];
46 jpm 169
			//si le champ cultivar_groupe n'est pas vide
352 jpm 170
			if ($this->avoirInfo('cultivar')) {
46 jpm 171
				//si il y a un cultivar, on ajoute des parenthèses au group (mais pas au grex)
352 jpm 172
				if (strrpos($groupe, ' gx ') !== false) {
46 jpm 173
					//si le grex est composé de groupe
352 jpm 174
					$gpEtGx = explode(' gx ', $groupe);
175
					$html = ' <span class="gp">'.
176
								$gpEtGx[0].' '.'<abbr title="grex">gx</abbr>'.
177
								' '.
178
								'('.$gpEtGx[1].' <abbr title="groupe">Gp</abbr>)'.
179
							'</span>';
180
				} elseif (strrpos($groupe, ' gx') !== false) {
46 jpm 181
					//si il y a un grex et pas de groupe
352 jpm 182
					$gx = str_replace(' gx', '', $groupe);
183
					$html = ' <span class="gp">'.$gx.' <abbr title="grex">gx</abbr></span>';
46 jpm 184
				} else { //si il n'y a pas de grex mais un groupe
352 jpm 185
					$html = ' <span class="gp">('.$groupe.' <abbr title="groupe">Gp</abbr>)</span>';
46 jpm 186
				}
187
			} else { //s'il n'y a pas de cultivar
352 jpm 188
				if (strrpos($groupe, ' gx ') !== false) {
46 jpm 189
					//si le grex est composé de groupe
352 jpm 190
					$gpEtGx = explode(' gx ', $groupe);
191
					$html = ' <span class="gp">'.
192
								$gpEtGx[0].' <abbr title="grex">gx</abbr>'.
193
								' '.
194
								$gpEtGx[1].' <abbr title="groupe">Gp</abbr>'.
195
							'</span>';
196
				} elseif (strrpos($groupe, ' gx') !== false) {
46 jpm 197
					//si il y a un grex et pas de groupe
352 jpm 198
					$gx = str_replace(' gx', '', $groupe);
199
					$html = ' <span class="gp">'.$gx.' <abbr title="grex">gx</abbr></span>';
46 jpm 200
				} else { //si il n'y a pas de grex mais un groupe
352 jpm 201
					$html = ' <span class="gp">'.$groupe.' <abbr title="groupe">Gp</abbr></span>';
46 jpm 202
				}
203
			}
204
		}
205
		return $html;
206
	}
207
 
208
	/**
209
	 *
210
	 * Permet de repérer s'il s'agit d'un hybride (infra-sp, genre, sp) ou d'une chimère.
211
	 * @param unknown_type $val
212
	 * @param unknown_type $type
213
	 */
214
	private function verifierHybridite($epithete, $type) {
215
		$html = '';
216
		if ($epithete != '') {
217
			if (substr($epithete, 0, 2) == 'x ') {
129 jpm 218
				$html = ' <span class="hyb">x <span class="'.$type.'">'.str_replace('x ', '', $epithete).'</span></span>';
46 jpm 219
			} elseif (substr($epithete, 0, 2) == '+ ') {
129 jpm 220
				$html = ' <span class="chimere">+ <span class="'.$type.'">'.str_replace('+ ', '', $epithete).'</span></span>';
46 jpm 221
			} else if (substr_count($epithete, ' x ') > 1) {
222
				// Cas d'une formule d'hybridité comprenant des parents hybrides
223
				$html = ' '.$this->insererBaliseFormuleHyb($epithete);
224
			} elseif (substr_count($epithete, ' x ') == 1) {
225
				// Cas d'une formule d'hybridité simple
226
				$html = ' '.$this->ajouterFomuleHybridite($epithete, $type);
227
			} else {
228
				$html = ' <span class="'.$type.'">'.$epithete.'</span>';
229
			}
230
		}
231
		return $html;
232
	}
233
 
234
	private function ajouterFomuleHybridite($formule, $type) {
235
		$tab_x = explode(' x ', $formule);
236
		$formule_hyb = array();
237
		switch ($type) {
238
			case 'gen' 		:
239
				foreach ($tab_x as $hyb) {
240
					$formule_hyb[] = sprintf($this->genTpl, $hyb);
241
				}
242
				break;
243
			case 'sp'		:
244
				foreach ($tab_x as $hyb) {
245
					if (substr_count($hyb, ' ') >= 1) {
246
						list($gen, $sp) = explode(' ', $hyb);
247
						$formule_hyb[] = sprintf($this->spFHTpl, $gen, $sp);
185 jpm 248
					} else if (preg_match('/^[A-Z]/', $hyb)) {
249
						$gen = $hyb;
250
						$formule_hyb[] = sprintf($this->genTpl, $gen);
46 jpm 251
					}
252
				}
253
				break;
254
			case 'infra-sp' :
255
				foreach ($tab_x as $hyb) {
256
					list($gen, $sp, $typeEpithete, $infraSp) = explode (' ', $hyb);
257
					$formule_hyb[] = sprintf($this->infraSpFHTpl, $gen, $sp, $this->abbr[$typeEpithete], $typeEpithete, $infraSp);
258
				}
259
				break;
260
			default : break;
261
		}
262
		return $this->insererBaliseFormuleHyb(implode(' x ', $formule_hyb));
263
	}
264
 
265
	private function insererBaliseFormuleHyb($formule) {
266
		return sprintf($this->formuleHybTpl, $formule);
267
	}
268
}
269
?>