Subversion Repositories eFlore/Applications.coel-consultation

Compare Revisions

Ignore whitespace Rev 14 → Rev 15

/trunk/bibliotheque/noyau/ColControleur.php
16,6 → 16,12
const RENDU_TETE = 'tete';
const RENDU_CORPS = 'corps';
const RENDU_PIED = 'pied';
const TYPE_AUTRE = 'AUTRE';
const TYPE_TOTAL = 'TOTAL';
const SEPARATEUR_TYPE_VALEUR = '##';
const SEPARATEUR_VALEURS = ';;';
const SEPARATEUR_DONNEES = '||';
const VALEUR_NULL = 'NC';
private $sortie = array();
private $parametres = array();
83,4 → 89,175
$this->sortie = array_merge($this->sortie, $sortie);
}
protected function construireTxtTruckSansMajuscule($chaine_a_analyser) {
return $this->construireTxtTruck($chaine_a_analyser, false);
}
protected function construireTxtTruck($chaine_a_analyser, $majuscule = true) {
$termes = array();
if ((!is_null($chaine_a_analyser)) && (trim($chaine_a_analyser) != '')) {
$valeurs = explode(self::SEPARATEUR_VALEURS, $chaine_a_analyser);
$nbre_valeurs = count($valeurs);
if ($nbre_valeurs > 0) {
for ($i = 0; $i < $nbre_valeurs; $i++) {
$valeur = trim($valeurs[$i]);
if ($valeur != '') {
$valeur_formatee = $this->formaterValeurTruck($valeur);
$termes[] = $valeur_formatee;
}
}
}
}
$chaine_a_retourner = $this->formaterTableauDeTxt($termes, $majuscule);
return $chaine_a_retourner;
}
private function formaterValeurTruck($valeur) {
$chaine_a_retourner = '';
if (preg_match('/^[^#]+##[^$]+$/', $valeur)) {
$cle_valeur = explode(self::SEPARATEUR_TYPE_VALEUR, $valeur);
$chaine_a_retourner = (($cle_valeur[1] == '' || $cle_valeur[1] == 'null') ? self::VALEUR_NULL : $cle_valeur[1]);
$chaine_a_retourner .= ' '.$this->formaterParenthese($cle_valeur[0]);
} else if ($valeur != '') {
$chaine_a_retourner = $valeur;
} else {
trigger_error("Valeur truck posant problème :$valeur", E_USER_NOTICE);
}
return $chaine_a_retourner;
}
protected function formaterParenthese($chaine_a_afficher) {
if ($chaine_a_afficher != '') {
$chaine_a_afficher = '('.$chaine_a_afficher.')';
}
return $chaine_a_afficher;
}
protected function formaterSautDeLigne($chaine_a_formater) {
$txt_a_retourner = preg_replace('/\n/', '<br />', $chaine_a_formater);
return $txt_a_retourner;
}
protected function formaterTableauDeTxt($tableau_de_txt, $majuscule = true) {
$chaine_a_afficher = '';
$taille_du_tableau = count($tableau_de_txt);
if ($taille_du_tableau > 0) {
$index_avt_dernier = $taille_du_tableau - 1;
for ($i = 0; $i < $taille_du_tableau; $i++) {
$mot = $tableau_de_txt[$i];
if ($i != $index_avt_dernier) {
$chaine_a_afficher .= $mot.', ';
} else {
$chaine_a_afficher .= $this->nettoyerPointFinal($mot).'.';
}
}
}
if ($majuscule) {
$chaine_a_afficher = ucfirst($chaine_a_afficher);
}
return $chaine_a_afficher;
}
protected function formaterAutre($chaine_a_afficher) {
if ($chaine_a_afficher != '') {
$chaine_a_afficher = ' [Autre : '.$chaine_a_afficher.']';
}
return $chaine_a_afficher;
}
protected function formaterOuiNon($chaine_a_formater) {
$txt_a_retourner = '';
if ($chaine_a_formater == '0') {
$txt_a_retourner = 'non';
} else if ($chaine_a_formater == '1') {
$txt_a_retourner = 'oui';
}
return $txt_a_retourner;
}
protected function nettoyerPointFinal($mot) {
$mot = preg_replace('/[.]$/', '', $mot);
return $mot;
}
public function construireTxtListeOntologie($chaineAAnalyser, $valeurEstOntologie = true, $typeEstOntologie = true, $donneeEstOntologie = false) {
$termes = array();
$autres = array();
$chaineAAnalyser = trim($chaineAAnalyser);
if ($chaineAAnalyser != '') {
$valeurs = explode(self::SEPARATEUR_VALEURS, $chaineAAnalyser);
$nbreValeurs = count($valeurs);
if ($nbreValeurs > 0) {
for ($i = 0; $i < $nbreValeurs; $i++) {
$valeur = $valeurs[$i];
// VALEUR SANS TYPE
// La valeur sans type est une entrée de l'ontologie
if ($valeurEstOntologie && preg_match('/^[0-9]+$/', $valeur)) {
if ($valeur == '0') {
$valeur = '';
} else {
$valeurOntologie = Ontologie::getValeur($valeur);
if ($valeurOntologie != '') {
$valeur = $valeurOntologie['nom'];
}
}
}
// VALEUR AVEC TYPE
// Type : AUTRE
$valeurTypeAutre = self::TYPE_AUTRE.self::SEPARATEUR_TYPE_VALEUR;
if (preg_match('/^'.$valeurTypeAutre.'.+$/', $valeur)) {
$txtAutre = preg_replace('/^'.$valeurTypeAutre.'/', '', $valeur);
if ($txtAutre != '') {
$autres[] = $txtAutre;
}
$valeur = '';
}
// Type correspondant à une entrée de l'ontologie
if ($typeEstOntologie) {
$valeurTypeOntologie = '[0-9]+'.self::SEPARATEUR_TYPE_VALEUR;
if (preg_match('/^'.$valeurTypeOntologie.'.+$/', $valeur)) {
$type = substr($valeur, 0, strripos($valeur, self::SEPARATEUR_TYPE_VALEUR));
$valeurOntologie = Ontologie::getValeur($type);
if ($valeurOntologie != '') {
$valeurOntologieNom = $valeurOntologie['nom'];
$valeur = preg_replace('/^'.$type.'/', $valeurOntologieNom.': ', $valeur);
}
}
}
// Donnée correspondant à une entrée de l'ontologie
if ($donneeEstOntologie) {
$donneeOntologie = self::SEPARATEUR_TYPE_VALEUR.'([0-9]+)';
if (preg_match('/^.+'.$donneeOntologie.'$/', $valeur, $match)) {
$donnee = $match[1];
$donnee = str_replace(self::SEPARATEUR_TYPE_VALEUR, '', $donnee);
$valeurOntologie = Ontologie::getValeur($donnee);
if ($valeurOntologie != '') {
$valeurOntologieNom = $valeurOntologie['nom'];
$valeur = preg_replace('/'.$donnee.'$/', $valeurOntologieNom, $valeur);
}
}
}
// Nettoyage final
$valeur = preg_replace('/'.self::SEPARATEUR_TYPE_VALEUR.'/', '', $valeur);
if ($valeur != '') {
$termes[] = $valeur;
}
}
}
}
$chaineTermes = $this->formaterTableauDeTxt($termes);
$chaineAutres = $this->formaterTableauDeTxt($autres);
$chaineARetourner = $chaineTermes.$this->formaterAutre($chaineAutres);
return $chaineARetourner;
}
}