Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 872 | 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>';
353 jpm 29
 
46 jpm 30
	private $nomSupraGenTpl = '<span class="supra_gen">%s</span>';
31
	private $genTpl = '<span class="gen">%s</span>';
32
	private $infraGenTpl = '<span class="infra-gen">%s</span>';
33
	private $spFHTpl = '<span class="gen">%s</span> <span class="sp">%s</span>';
34
	private $typeEpitheteTpl = '<abbr class="type_epithete" title="%s">%s</abbr>';
35
	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>';
353 jpm 36
 
37
	private $hybrideTpl = '<span class="hyb">× <span class="%s">%s</span></span>';
38
	private $chimereTpl = '<span class="chimere">+ <span class="%s">%s</span></span>';
46 jpm 39
	private $formuleHybTpl = '<span class="formule-hyb">%s</span>';
353 jpm 40
	private $hybriditeTpl = '<span class="%s">%s</span>';
46 jpm 41
 
353 jpm 42
	private $gpGxAvecCvarTpl = '<span class="gp">%s <abbr title="grex">gx</abbr>(%s <abbr title="groupe">Gp</abbr>)</span>';
43
	private $gpGxSansCvarTpl = '<span class="gp">%s <abbr title="grex">gx</abbr>%s <abbr title="groupe">Gp</abbr></span>';
44
	private $gxTpl = '<span class="gp">%s <abbr title="grex">gx</abbr></span>';
45
	private $gpAvecCvarTpl = '<span class="gp">(%s <abbr title="groupe">Gp</abbr>)</span>';
46
	private $gpSansCvarTpl = '<span class="gp">%s <abbr title="groupe">Gp</abbr></span>';
47
	private $commTpl = '<span class="commercial">%s</span>';
48
	private $cvarTpl = '<span class="cultivar">\'%s\'</span>';
49
 
46 jpm 50
	public function generer(Array $nomsDecomposes) {
51
		$nomsSciHtml = array();
334 jpm 52
		foreach ($nomsDecomposes as $infos) {
485 jpm 53
			$nom = $this->genererNomSciHtml($infos);
54
			if ($nom != '') {
55
				$nomsSciHtml[$this->num] = $nom;
46 jpm 56
			}
57
		}
58
		return $nomsSciHtml;
59
	}
60
 
485 jpm 61
	public function genererNomSciHtml(Array $nomDecomposes) {
62
		$this->initialiserVariables($nomDecomposes);
63
 
64
		$nomSciHtml = '';
65
		$nomSciHtml .= $this->ajouterBaliseNomSupraGen();
66
		$nomSciHtml .= $this->verifierHybridite($this->compo_nom['genre'], 'gen');
67
		$nomSciHtml .= $this->ajouterBaliseInfraGen();
68
		$nomSciHtml .= $this->verifierHybridite($this->compo_nom['epithete_sp'], 'sp');
69
		$nomSciHtml .= $this->ajouterBaliseTypeInfraSp();
70
		$nomSciHtml .= $this->verifierHybridite($this->compo_nom['epithete_infra_sp'], 'infra-sp');
71
		$nomSciHtml .= $this->ajouterCultivarGpComm();
72
 
73
		if ($nomSciHtml != '') {
74
			$nomSciHtml = sprintf($this->nomSciTpl, trim($nomSciHtml));
872 delphine 75
		} else {
76
			$nomSciHtml = $this->verifierHybridite($this->compo_nom['nom_sci'], 'infra-sp');
485 jpm 77
		}
78
		return $nomSciHtml;
79
	}
80
 
46 jpm 81
	private function initialiserVariables($infos) {
82
		$this->num = $infos['num_nom'];
83
		$this->compo_nom = $infos;
84
	}
85
 
86
	private function ajouterBaliseNomSupraGen() {
87
		$html = '';
88
		if ($this->compo_nom['nom_supra_generique'] != '') {
89
			$html = sprintf($this->nomSupraGenTpl, $this->compo_nom['nom_supra_generique']);
90
		}
91
		return $html;
92
	}
93
 
94
	private function ajouterTypeEpithete($type) {
95
		if (!array_key_exists($type, $this->abbr)) {
96
			$this->abbr[$type] = $type;
97
		}
98
	}
99
 
100
	private function ajouterBaliseInfraGen() {
101
		$html = '';
102
		if ($this->verifierTypeInfraGen()) {
485 jpm 103
			$html = $this->ajouterBaliseTypeInfraGen();
46 jpm 104
		} else {
105
			if ($this->avoirInfo('epithete_infra_generique')) {
485 jpm 106
				$html = sprintf($this->infraGenTpl, $this->compo_nom['epithete_infra_generique']);
46 jpm 107
			}
108
		}
109
		return $html;
110
	}
111
 
112
	private function verifierTypeInfraGen() {
113
		$ok = false;
114
		if ($this->compo_nom['type_epithete'] != '' && $this->compo_nom['epithete_infra_generique'] != '') {
115
			$this->ajouterTypeEpithete($this->compo_nom['type_epithete']);
116
			$ok = true;
117
		}
118
		return $ok;
119
	}
120
 
121
	private function ajouterBaliseTypeInfraGen() {
122
		$html = '';
123
		$type = $this->compo_nom['type_epithete'];
124
 
125
		if ($type == 'agg.') {
126
			// Ajout de l'infra gen avant le type s'il est égal à agg.
1160 delphine 127
			$html = ' '.$this->compo_nom['epithete_infra_generique'].
46 jpm 128
					' '.sprintf($this->typeEpitheteTpl, $this->abbr[$type], $type);
129
		} else {
485 jpm 130
			$html = ' '.sprintf($this->typeEpitheteTpl, $this->abbr[$type], $type).
1160 delphine 131
					' '.$this->compo_nom['epithete_infra_generique'];
46 jpm 132
		}
133
		return $html;
134
	}
135
 
136
	private function ajouterBaliseTypeInfraSp() {
137
		$html = '';
138
		$type = $this->compo_nom['type_epithete'];
139
		$infraSp = $this->compo_nom['epithete_infra_sp'];
140
 
141
		if ($infraSp != '') {
142
			if ($type != '') {
143
				$this->ajouterTypeEpithete($type);
144
				$html = ' '.sprintf($this->typeEpitheteTpl, $this->abbr[$type], $type);
145
			} else {
661 jpm 146
				$message = "Nom #{$this->num} contient un épithète infra-spécifique mais son type n'est pas renseigné.";
147
				throw new Exception($message);
46 jpm 148
			}
149
		}
150
		return $html;
151
	}
152
 
153
	private function ajouterCultivarGpComm() {
154
		$html = '';
155
		if ($this->avoirInfo('cultivar_groupe')) {
156
			$html .= ' '.$this->ajouterCultivarGroupe();
157
		}
158
		if ($this->avoirInfo('nom_commercial')) {
353 jpm 159
			$html .= ' '.sprintf($this->commTpl, $this->compo_nom['nom_commercial']);
46 jpm 160
		}
161
		if ($this->avoirInfo('cultivar')) {
353 jpm 162
			$html .= ' '.sprintf($this->cvarTpl, $this->compo_nom['cultivar']);
46 jpm 163
		}
164
		return $html;
165
	}
166
 
167
	private function avoirInfo($valeur) {
168
		return (isset($this->compo_nom[$valeur]) && $this->compo_nom[$valeur] != '') ? true : false;
169
	}
170
 
171
	/**
172
	 * Permet d'ajouter les groupes de cultivar en fonction de la présence d'un cultivar et de la présence d'un grex
173
	 *
174
	 * L'ensemble des individus obtenu par une fécondation particulière s'appelle un le Grex (que pour les orchidées).
175
	 * Au sein du grex, certains individus peuvent se distinguer par des formes, des coloris ou autres qui font que
176
	 * l'obtenteur du grex va les sélectionner.
177
	 * les noms de groupes de cultivars sont suivis de l'abréviation « Gp » et placés entre parenthèses
178
	 * les noms de grex, s'ils sont utilisés devant une épithète de cultivar, ne se mettent pas entre parenthèses
179
	 *	 ex : Cymbidium Alexanderi gx 'Westonbirt' (cultivar_groupe = Alexanderi gx) ;
180
	 * les noms de groupe se mettent entre parenthèses s'ils sont devant une épithète de cultivar
181
	 *	 ex : Dracaena fragrans (Deremenis Gp) 'Christianne' (cultivar_groupe = Deremenis)
182
	 * Un grex peut contenir des groupes (rédaction d'un exemple de l'ICNCP)
183
	 *	 ex : × Rhyncosophrocattleya Marie Lemon Stick grex Francis Suzuki Group
184
	 *	 ou : × Rhyncosophrocattleya Marie Lemon Stick gx Francis Suzuki Gp
185
	 * @param unknown_type $val
186
	 *
187
	 */
188
	private function ajouterCultivarGroupe() {
189
		$html = '';
353 jpm 190
		// si le champ cultivar_groupe n'est pas vide
46 jpm 191
		if ($this->avoirInfo('cultivar_groupe')) {
353 jpm 192
			$groupe = trim($this->compo_nom['cultivar_groupe']);
193
 
194
			// Sélection des templates
195
			$tplGx = $this->gxTpl;
196
			$tplGpGx = $this->gpGxSansCvarTpl;
197
			$tplGp = $this->gpSansCvarTpl;
198
			// s'il y a un cultivar, on ajoute des parenthèses au groupe (mais pas au grex)
352 jpm 199
			if ($this->avoirInfo('cultivar')) {
353 jpm 200
				$tplGpGx = $this->gpGxAvecCvarTpl;
201
				$tplGp = $this->gpAvecCvarTpl;
46 jpm 202
			}
353 jpm 203
 
204
			// Création du HTML du groupe de cultivar
205
			if (strrpos($groupe, ' gx ') !== false) {//si le grex est composé de groupe
206
				$gpEtGx = explode(' gx ', $groupe);
207
				$html = sprintf($tplGpGx, $gpEtGx[0], $gpEtGx[1]);
208
			} else if (preg_match('/ gx$/', $groupe)) {//s'il y a un grex et pas de groupe
209
				$gx = str_replace(' gx', '', $groupe);
210
				$html = sprintf($tplGx, $gx);
211
			} else { //s'il n'y a pas de grex mais un groupe
212
				$html = sprintf($tplGp, $groupe);
213
			}
46 jpm 214
		}
215
		return $html;
216
	}
217
 
218
	/**
219
	 *
220
	 * Permet de repérer s'il s'agit d'un hybride (infra-sp, genre, sp) ou d'une chimère.
221
	 * @param unknown_type $val
222
	 * @param unknown_type $type
223
	 */
224
	private function verifierHybridite($epithete, $type) {
225
		$html = '';
226
		if ($epithete != '') {
227
			if (substr($epithete, 0, 2) == 'x ') {
353 jpm 228
				$hybride = str_replace('x ', '', $epithete);
229
				$html = ' '.sprintf($this->hybrideTpl, $type, $hybride);
46 jpm 230
			} elseif (substr($epithete, 0, 2) == '+ ') {
353 jpm 231
				$hybride = str_replace('+ ', '', $epithete);
232
				$html = ' '.sprintf($this->chimereTpl, $type, $hybride);
233
			} else if (substr_count($epithete, ' x ') > 1) {// Cas d'une formule d'hybridité comprenant des parents hybrides
46 jpm 234
				$html = ' '.$this->insererBaliseFormuleHyb($epithete);
353 jpm 235
			} elseif (substr_count($epithete, ' x ') == 1) {// Cas d'une formule d'hybridité simple
46 jpm 236
				$html = ' '.$this->ajouterFomuleHybridite($epithete, $type);
353 jpm 237
			} else {// Autre cas...
238
				$html = ' '.sprintf($this->hybriditeTpl, $type, $epithete);
46 jpm 239
			}
240
		}
241
		return $html;
242
	}
243
 
244
	private function ajouterFomuleHybridite($formule, $type) {
245
		$tab_x = explode(' x ', $formule);
246
		$formule_hyb = array();
247
		switch ($type) {
248
			case 'gen' 		:
249
				foreach ($tab_x as $hyb) {
250
					$formule_hyb[] = sprintf($this->genTpl, $hyb);
251
				}
252
				break;
253
			case 'sp'		:
254
				foreach ($tab_x as $hyb) {
255
					if (substr_count($hyb, ' ') >= 1) {
256
						list($gen, $sp) = explode(' ', $hyb);
257
						$formule_hyb[] = sprintf($this->spFHTpl, $gen, $sp);
185 jpm 258
					} else if (preg_match('/^[A-Z]/', $hyb)) {
259
						$gen = $hyb;
260
						$formule_hyb[] = sprintf($this->genTpl, $gen);
46 jpm 261
					}
262
				}
263
				break;
264
			case 'infra-sp' :
265
				foreach ($tab_x as $hyb) {
266
					list($gen, $sp, $typeEpithete, $infraSp) = explode (' ', $hyb);
872 delphine 267
					if (isset($infraSp)) {
268
						$formule_hyb[] = sprintf($this->infraSpFHTpl, $gen, $sp, $this->abbr[$typeEpithete], $typeEpithete, $infraSp);
269
					} else {
270
						$formule_hyb[] = sprintf($this->spFHTpl, $gen, $sp);
271
					}
46 jpm 272
				}
273
				break;
274
			default : break;
275
		}
276
		return $this->insererBaliseFormuleHyb(implode(' x ', $formule_hyb));
277
	}
278
 
279
	private function insererBaliseFormuleHyb($formule) {
280
		return sprintf($this->formuleHybTpl, $formule);
281
	}
282
}
283
?>