Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 352 | Rev 485 | 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>';
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) {
46 jpm 53
			$this->initialiserVariables($infos);
54
 
55
			$nomSciHtml = '';
56
			$nomSciHtml .= $this->ajouterBaliseNomSupraGen();
57
			$nomSciHtml .= $this->verifierHybridite($this->compo_nom['genre'], 'gen');
58
			$nomSciHtml .= $this->ajouterBaliseInfraGen();
59
			$nomSciHtml .= $this->verifierHybridite($this->compo_nom['epithete_sp'], 'sp');
60
			$nomSciHtml .= $this->ajouterBaliseTypeInfraSp();
61
			$nomSciHtml .= $this->verifierHybridite($this->compo_nom['epithete_infra_sp'], 'infra-sp');
62
			$nomSciHtml .= $this->ajouterCultivarGpComm();
63
 
64
			if ($nomSciHtml != '') {
65
				$nomsSciHtml[$this->num] = sprintf($this->nomSciTpl, trim($nomSciHtml));
66
			}
67
		}
68
		return $nomsSciHtml;
69
	}
70
 
71
	private function initialiserVariables($infos) {
72
		$this->num = $infos['num_nom'];
73
		$this->compo_nom = $infos;
74
	}
75
 
76
	private function ajouterBaliseNomSupraGen() {
77
		$html = '';
78
		if ($this->compo_nom['nom_supra_generique'] != '') {
79
			$html = sprintf($this->nomSupraGenTpl, $this->compo_nom['nom_supra_generique']);
80
		}
81
		return $html;
82
	}
83
 
84
	private function ajouterTypeEpithete($type) {
85
		if (!array_key_exists($type, $this->abbr)) {
86
			$this->abbr[$type] = $type;
87
		}
88
	}
89
 
90
	private function ajouterBaliseInfraGen() {
91
		$html = '';
92
		if ($this->verifierTypeInfraGen()) {
93
			$html .= $this->ajouterBaliseTypeInfraGen();
94
		} else {
95
			if ($this->avoirInfo('epithete_infra_generique')) {
96
				$html .= sprintf($this->infraGenTpl, $this->compo_nom['epithete_infra_generique']);
97
			}
98
		}
99
		return $html;
100
	}
101
 
102
	private function verifierTypeInfraGen() {
103
		$ok = false;
104
		if ($this->compo_nom['type_epithete'] != '' && $this->compo_nom['epithete_infra_generique'] != '') {
105
			$this->ajouterTypeEpithete($this->compo_nom['type_epithete']);
106
			$ok = true;
107
		}
108
		return $ok;
109
	}
110
 
111
	private function ajouterBaliseTypeInfraGen() {
112
		$html = '';
113
		$type = $this->compo_nom['type_epithete'];
114
 
115
		if ($type == 'agg.') {
116
			// Ajout de l'infra gen avant le type s'il est égal à agg.
117
			$html .= ' '.$this->ajouterBaliseInfraGen().
118
					' '.sprintf($this->typeEpitheteTpl, $this->abbr[$type], $type);
119
		} else {
120
			$html .= ' '.sprintf($this->typeEpitheteTpl, $this->abbr[$type], $type).
121
					' '.$this->ajouterBaliseInfraGen();
122
		}
123
		return $html;
124
	}
125
 
126
	private function ajouterBaliseTypeInfraSp() {
127
		$html = '';
128
		$type = $this->compo_nom['type_epithete'];
129
		$infraSp = $this->compo_nom['epithete_infra_sp'];
130
 
131
		if ($infraSp != '') {
132
			if ($type != '') {
133
				$this->ajouterTypeEpithete($type);
134
				$html = ' '.sprintf($this->typeEpitheteTpl, $this->abbr[$type], $type);
135
			} else {
136
				$message = "Nom #%s contient un épithète infra-spécifique mais son type n'est pas renseigné.";
137
				$this->traiterErreur($message, array($this->num));
138
			}
139
		}
140
		return $html;
141
	}
142
 
143
	private function ajouterCultivarGpComm() {
144
		$html = '';
145
		if ($this->avoirInfo('cultivar_groupe')) {
146
			$html .= ' '.$this->ajouterCultivarGroupe();
147
		}
148
		if ($this->avoirInfo('nom_commercial')) {
353 jpm 149
			$html .= ' '.sprintf($this->commTpl, $this->compo_nom['nom_commercial']);
46 jpm 150
		}
151
		if ($this->avoirInfo('cultivar')) {
353 jpm 152
			$html .= ' '.sprintf($this->cvarTpl, $this->compo_nom['cultivar']);
46 jpm 153
		}
154
		return $html;
155
	}
156
 
157
	private function avoirInfo($valeur) {
158
		return (isset($this->compo_nom[$valeur]) && $this->compo_nom[$valeur] != '') ? true : false;
159
	}
160
 
161
	/**
162
	 * Permet d'ajouter les groupes de cultivar en fonction de la présence d'un cultivar et de la présence d'un grex
163
	 *
164
	 * L'ensemble des individus obtenu par une fécondation particulière s'appelle un le Grex (que pour les orchidées).
165
	 * Au sein du grex, certains individus peuvent se distinguer par des formes, des coloris ou autres qui font que
166
	 * l'obtenteur du grex va les sélectionner.
167
	 * les noms de groupes de cultivars sont suivis de l'abréviation « Gp » et placés entre parenthèses
168
	 * les noms de grex, s'ils sont utilisés devant une épithète de cultivar, ne se mettent pas entre parenthèses
169
	 *	 ex : Cymbidium Alexanderi gx 'Westonbirt' (cultivar_groupe = Alexanderi gx) ;
170
	 * les noms de groupe se mettent entre parenthèses s'ils sont devant une épithète de cultivar
171
	 *	 ex : Dracaena fragrans (Deremenis Gp) 'Christianne' (cultivar_groupe = Deremenis)
172
	 * Un grex peut contenir des groupes (rédaction d'un exemple de l'ICNCP)
173
	 *	 ex : × Rhyncosophrocattleya Marie Lemon Stick grex Francis Suzuki Group
174
	 *	 ou : × Rhyncosophrocattleya Marie Lemon Stick gx Francis Suzuki Gp
175
	 * @param unknown_type $val
176
	 *
177
	 */
178
	private function ajouterCultivarGroupe() {
179
		$html = '';
353 jpm 180
		// si le champ cultivar_groupe n'est pas vide
46 jpm 181
		if ($this->avoirInfo('cultivar_groupe')) {
353 jpm 182
			$groupe = trim($this->compo_nom['cultivar_groupe']);
183
 
184
			// Sélection des templates
185
			$tplGx = $this->gxTpl;
186
			$tplGpGx = $this->gpGxSansCvarTpl;
187
			$tplGp = $this->gpSansCvarTpl;
188
			// s'il y a un cultivar, on ajoute des parenthèses au groupe (mais pas au grex)
352 jpm 189
			if ($this->avoirInfo('cultivar')) {
353 jpm 190
				$tplGpGx = $this->gpGxAvecCvarTpl;
191
				$tplGp = $this->gpAvecCvarTpl;
46 jpm 192
			}
353 jpm 193
 
194
			// Création du HTML du groupe de cultivar
195
			if (strrpos($groupe, ' gx ') !== false) {//si le grex est composé de groupe
196
				$gpEtGx = explode(' gx ', $groupe);
197
				$html = sprintf($tplGpGx, $gpEtGx[0], $gpEtGx[1]);
198
			} else if (preg_match('/ gx$/', $groupe)) {//s'il y a un grex et pas de groupe
199
				$gx = str_replace(' gx', '', $groupe);
200
				$html = sprintf($tplGx, $gx);
201
			} else { //s'il n'y a pas de grex mais un groupe
202
				$html = sprintf($tplGp, $groupe);
203
			}
46 jpm 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 ') {
353 jpm 218
				$hybride = str_replace('x ', '', $epithete);
219
				$html = ' '.sprintf($this->hybrideTpl, $type, $hybride);
46 jpm 220
			} elseif (substr($epithete, 0, 2) == '+ ') {
353 jpm 221
				$hybride = str_replace('+ ', '', $epithete);
222
				$html = ' '.sprintf($this->chimereTpl, $type, $hybride);
223
			} else if (substr_count($epithete, ' x ') > 1) {// Cas d'une formule d'hybridité comprenant des parents hybrides
46 jpm 224
				$html = ' '.$this->insererBaliseFormuleHyb($epithete);
353 jpm 225
			} elseif (substr_count($epithete, ' x ') == 1) {// Cas d'une formule d'hybridité simple
46 jpm 226
				$html = ' '.$this->ajouterFomuleHybridite($epithete, $type);
353 jpm 227
			} else {// Autre cas...
228
				$html = ' '.sprintf($this->hybriditeTpl, $type, $epithete);
46 jpm 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
?>