Subversion Repositories eFlore/Projets.eflore-projets

Compare Revisions

Ignore whitespace Rev 45 → Rev 46

/trunk/scripts/modules/bdtfx/GenerateurNomSciHtml.php
New file
0,0 → 1,264
<?php
class GenerateurNomSciHtml {
protected $bdd = null;
protected $table = null;
 
protected $num = null;
protected $compo_nom = array();
 
protected $abbr = array (
'infra-gen.' => 'Infra-Genre',
'sect.' => 'Section',
'subsect.' => 'Sous-Section',
'ser.' => 'Série',
'subser.' => 'Sous-Série',
'gr.' => 'Groupe',
'agg.' => 'Agrégat',
'sp.' => 'Espèce',
'subsp.' => 'Sous-Espèce',
'infra-sp.' => 'Infra-Espèce',
'var.' => 'Variété',
'subvar.' => 'Sous-Variété',
'fa' => 'Forme',
'subf.' => 'Sous-Forme',
'f. sp.' => 'Forma species',
'proles' => 'Race prole'
);
 
private $nomSciTpl = '<span class=sci>%s</span>';
private $nomSupraGenTpl = '<span class="supra_gen">%s</span>';
private $genTpl = '<span class="gen">%s</span>';
private $infraGenTpl = '<span class="infra-gen">%s</span>';
private $spFHTpl = '<span class="gen">%s</span> <span class="sp">%s</span>';
private $typeEpitheteTpl = '<abbr class="type_epithete" title="%s">%s</abbr>';
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>';
private $formuleHybTpl = '<span class="formule-hyb">%s</span>';
 
public function generer(Array $nomsDecomposes) {
$nomsSciHtml = array();
foreach ($nomsDecomposes as $noms => $infos) {
$this->initialiserVariables($infos);
 
$nomSciHtml = '';
$nomSciHtml .= $this->ajouterBaliseNomSupraGen();
$nomSciHtml .= $this->verifierHybridite($this->compo_nom['genre'], 'gen');
$nomSciHtml .= $this->ajouterBaliseInfraGen();
$nomSciHtml .= $this->verifierHybridite($this->compo_nom['epithete_sp'], 'sp');
$nomSciHtml .= $this->ajouterBaliseTypeInfraSp();
$nomSciHtml .= $this->verifierHybridite($this->compo_nom['epithete_infra_sp'], 'infra-sp');
$nomSciHtml .= $this->ajouterCultivarGpComm();
 
if ($nomSciHtml != '') {
$nomsSciHtml[$this->num] = sprintf($this->nomSciTpl, trim($nomSciHtml));
}
}
return $nomsSciHtml;
}
 
private function initialiserVariables($infos) {
$this->num = $infos['num_nom'];
$this->compo_nom = $infos;
}
 
private function ajouterBaliseNomSupraGen() {
$html = '';
if ($this->compo_nom['nom_supra_generique'] != '') {
$html = sprintf($this->nomSupraGenTpl, $this->compo_nom['nom_supra_generique']);
}
return $html;
}
 
private function ajouterTypeEpithete($type) {
if (!array_key_exists($type, $this->abbr)) {
$this->abbr[$type] = $type;
}
}
 
private function ajouterBaliseInfraGen() {
$html = '';
if ($this->verifierTypeInfraGen()) {
$html .= $this->ajouterBaliseTypeInfraGen();
} else {
if ($this->avoirInfo('epithete_infra_generique')) {
$html .= sprintf($this->infraGenTpl, $this->compo_nom['epithete_infra_generique']);
}
}
return $html;
}
 
private function verifierTypeInfraGen() {
$ok = false;
if ($this->compo_nom['type_epithete'] != '' && $this->compo_nom['epithete_infra_generique'] != '') {
$this->ajouterTypeEpithete($this->compo_nom['type_epithete']);
$ok = true;
}
return $ok;
}
 
private function ajouterBaliseTypeInfraGen() {
$html = '';
$type = $this->compo_nom['type_epithete'];
 
if ($type == 'agg.') {
// Ajout de l'infra gen avant le type s'il est égal à agg.
$html .= ' '.$this->ajouterBaliseInfraGen().
' '.sprintf($this->typeEpitheteTpl, $this->abbr[$type], $type);
} else {
$html .= ' '.sprintf($this->typeEpitheteTpl, $this->abbr[$type], $type).
' '.$this->ajouterBaliseInfraGen();
}
return $html;
}
 
private function ajouterBaliseTypeInfraSp() {
$html = '';
$type = $this->compo_nom['type_epithete'];
$infraSp = $this->compo_nom['epithete_infra_sp'];
 
if ($infraSp != '') {
if ($type != '') {
$this->ajouterTypeEpithete($type);
$html = ' '.sprintf($this->typeEpitheteTpl, $this->abbr[$type], $type);
} else {
$message = "Nom #%s contient un épithète infra-spécifique mais son type n'est pas renseigné.";
$this->traiterErreur($message, array($this->num));
}
}
return $html;
}
 
private function ajouterCultivarGpComm() {
$html = '';
if ($this->avoirInfo('cultivar_groupe')) {
$html .= ' '.$this->ajouterCultivarGroupe();
}
if ($this->avoirInfo('nom_commercial')) {
$html .= ' <span class="commercial">'.$this->compo_nom['nom_commercial'].'</span>';
}
if ($this->avoirInfo('cultivar')) {
$html .= ' <span class="cultivar">\''.$this->compo_nom['cultivar'].'\'</span>';
}
return $html;
}
 
private function avoirInfo($valeur) {
return (isset($this->compo_nom[$valeur]) && $this->compo_nom[$valeur] != '') ? true : false;
}
 
/**
* Permet d'ajouter les groupes de cultivar en fonction de la présence d'un cultivar et de la présence d'un grex
*
* L'ensemble des individus obtenu par une fécondation particulière s'appelle un le Grex (que pour les orchidées).
* Au sein du grex, certains individus peuvent se distinguer par des formes, des coloris ou autres qui font que
* l'obtenteur du grex va les sélectionner.
* les noms de groupes de cultivars sont suivis de l'abréviation « Gp » et placés entre parenthèses
* les noms de grex, s'ils sont utilisés devant une épithète de cultivar, ne se mettent pas entre parenthèses
* ex : Cymbidium Alexanderi gx 'Westonbirt' (cultivar_groupe = Alexanderi gx) ;
* les noms de groupe se mettent entre parenthèses s'ils sont devant une épithète de cultivar
* ex : Dracaena fragrans (Deremenis Gp) 'Christianne' (cultivar_groupe = Deremenis)
* Un grex peut contenir des groupes (rédaction d'un exemple de l'ICNCP)
* ex : × Rhyncosophrocattleya Marie Lemon Stick grex Francis Suzuki Group
* ou : × Rhyncosophrocattleya Marie Lemon Stick gx Francis Suzuki Gp
* @param unknown_type $val
*
*/
private function ajouterCultivarGroupe() {
$html = '';
if ($this->avoirInfo('cultivar_groupe')) {
//si le champ cultivar_groupe n'est pas vide
if ($this->compo_nom['cultivar']) {
//si il y a un cultivar, on ajoute des parenthèses au group (mais pas au grex)
if (strrpos($this->compo_nom['cultivar_groupe'], ' gx ') !== false) {
//si le grex est composé de groupe
$tab_gp = explode(' gx ', $this->compo_nom['cultivar_groupe']);
$html = ' <span class="gp">'.$tab_gp[0].
' <abbr title="grex">gx </abbr>('.$tab_gp[1].
' <abbr title="groupe">Gp</abbr>)</span>';
} elseif (strrpos($this->compo_nom['cultivar_groupe'], ' gx') !== false) {
//si il y a un grex et pas de groupe
$tab_gp = explode(' gx', $this->compo_nom['cultivar_groupe']);
$html = ' <span class="gp">'.$tab_gp[0].' <abbr title="grex">gx</abbr></span>';
} else { //si il n'y a pas de grex mais un groupe
$html = ' <span class="gp">'.$this->compo_nom['cultivar_groupe'].' <abbr title="groupe">Gp</abbr>)</span>';
}
} else { //s'il n'y a pas de cultivar
if (strrpos($this->compo_nom['cultivar_groupe'], ' gx ') !== false) {
//si le grex est composé de groupe
$tab_gp = explode(' gx ', $this->compo_nom['cultivar_groupe']);
$html = ' <span class="gp">'.$tab_gp[0].
' <abbr title="grex">gx</abbr>'.$tab_gp[1].
' <abbr title="groupe">Gp</abbr></span>';
} elseif (strrpos($this->compo_nom['cultivar_groupe'], ' gx') !== false) {
//si il y a un grex et pas de groupe
$tab_gp = explode(' gx', $this->compo_nom['cultivar_groupe']);
$html = ' <span class="gp">'.$tab_gp[0].' <abbr title="grex">gx</abbr></span>';
} else { //si il n'y a pas de grex mais un groupe
$html = ' <span class="gp">'.$this->compo_nom['cultivar_groupe'].' <abbr title="groupe">Gp</abbr></span>';
}
}
}
return $html;
}
 
/**
*
* Permet de repérer s'il s'agit d'un hybride (infra-sp, genre, sp) ou d'une chimère.
* @param unknown_type $val
* @param unknown_type $type
*/
private function verifierHybridite($epithete, $type) {
$html = '';
if ($epithete != '') {
if (substr($epithete, 0, 2) == 'x ') {
$html = ' <span class=hyb>x <span class="'.$type.'">'.str_replace('x ', '', $epithete).'</span></span>';
} elseif (substr($epithete, 0, 2) == '+ ') {
$html = ' <span class=chimere>+ <span class="'.$type.'">'.str_replace('+ ', '', $epithete).'</span></span>';
} else if (substr_count($epithete, ' x ') > 1) {
// Cas d'une formule d'hybridité comprenant des parents hybrides
$html = ' '.$this->insererBaliseFormuleHyb($epithete);
} elseif (substr_count($epithete, ' x ') == 1) {
// Cas d'une formule d'hybridité simple
$html = ' '.$this->ajouterFomuleHybridite($epithete, $type);
} else {
$html = ' <span class="'.$type.'">'.$epithete.'</span>';
}
}
return $html;
}
 
private function ajouterFomuleHybridite($formule, $type) {
$tab_x = explode(' x ', $formule);
$formule_hyb = array();
switch ($type) {
case 'gen' :
foreach ($tab_x as $hyb) {
$formule_hyb[] = sprintf($this->genTpl, $hyb);
}
break;
case 'sp' :
foreach ($tab_x as $hyb) {
if (substr_count($hyb, ' ') >= 1) {
list($gen, $sp) = explode(' ', $hyb);
$formule_hyb[] = sprintf($this->spFHTpl, $gen, $sp);
} else {
$avertissement = "Nom #%s : la valeur d'hybride '%s' ne contenait pas d'espace .";
$this->traiterAvertissement($avertissement, array($this->num, $hyb));
}
}
break;
case 'infra-sp' :
foreach ($tab_x as $hyb) {
list($gen, $sp, $typeEpithete, $infraSp) = explode (' ', $hyb);
$formule_hyb[] = sprintf($this->infraSpFHTpl, $gen, $sp, $this->abbr[$typeEpithete], $typeEpithete, $infraSp);
}
break;
default : break;
}
return $this->insererBaliseFormuleHyb(implode(' x ', $formule_hyb));
}
 
private function insererBaliseFormuleHyb($formule) {
return sprintf($this->formuleHybTpl, $formule);
}
}
?>