New file |
0,0 → 1,273 |
<?php |
// declare(encoding='UTF-8'); |
/** |
* Classe Controleur du module Versionnage. |
* Permet de publier une nouvelle version d'un référentiel de travail. |
* |
* @package Referentiel |
* @category Php5.2 |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org> |
* @copyright 2010 Tela-Botanica |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL |
* @license http://www.gnu.org/licenses/gpl.html Licence GNU-GPL |
* @version SVN: $Id$ |
*/ |
class Versionnage extends AppliControleur { |
|
const SCRIPT_A_LANCER = 'versionnage'; |
|
private $version = array('titre', 'acronyme', 'version', 'date_prod', |
'auteur_principal', 'coordinateur', 'editeur', 'contact', |
'contributeur', |
'classification', 'dom_tax', 'dom_geo', 'dom_code', |
'source', 'copyright', 'licence', 'referencement', |
'errata', 'notes'); |
private $referentiel = null; |
private $referentielDao = null; |
private $traitementDao = null; |
|
public function __construct() { |
parent::__construct(); |
|
// Récupération de paramêtres |
if (isset($_GET['ref'])) { // code du projet courrant |
$this->referentiel = strtolower($_GET['ref']); |
} |
|
// Chargement des DAO nécessaires |
$this->referentielDao = new ReferentielDao(); |
$this->traitementDao = new TraitementDao(); |
} |
|
//+----------------------------------------------------------------------------------------------------------------+ |
// Méthodes |
/** |
* Fonction d'affichage par défaut |
*/ |
public function executerActionParDefaut() { |
return $this->afficherInterface(); |
} |
|
/** |
* Affiche le formulaire de demande de versionnage |
*/ |
public function afficherInterface() { |
if ($this->authentifierCoordinateur()) { |
$donnees = array(); |
$this->definirCommeModulePrincipal(get_class($this)); |
|
// Paramêtres pour l'url du formulaire |
$this->url->unsetVariablesRequete(array('module', 'action', 'ref')); |
$donnees['url_form'] = $this->obtenirUrlDemandeVersionnage($this->referentiel); |
$donnees['url_module'] = 'Versionnage'; |
$donnees['url_action_rafraichir'] = 'afficherInterface'; |
|
$donnees['version'] = $this->instancierChampsVersionnage(); |
$donnees['version'] = $this->traiterCasesACocher($donnees['version']); |
|
// Récupération des paramètres de configuration du manuel des référentiels |
$donnees['domaine_geo'] = explode(';', $this->manuel['domaine_geo']); |
$donnees['domaine_taxo'] = explode(';', $this->manuel['domaine_taxo']); |
$donnees['domaine_code'] = explode(';', $this->manuel['domaine_code']); |
|
// Traitement de l'info sur le code du référentiel |
if (isset($this->referentiel)) { |
// Récupération du nom du référentiel courrant |
$donnees['nom_referentiel'] = $this->referentielDao->getNom($this->referentiel); |
|
// Récupération du référentiel courrant |
$donnees['ref'] = $this->referentiel; |
|
// Recherche des traitements en attente |
$donnees['traitements_en_attente'] = $this->traitementDao->getTraitementsEnAttente($this->referentiel, self::SCRIPT_A_LANCER); |
|
// Recherche des traitements en cours d'éxecution |
$donnees['traitements_en_cours'] = $this->traitementDao->getTraitementsEnCours($this->referentiel, self::SCRIPT_A_LANCER); |
|
// Recherche des traitements déjà effectué |
$resultat = $this->traitementDao->getTraitementsTermines($this->referentiel, self::SCRIPT_A_LANCER); |
if (is_array($resultat)) { |
// Ajout de l'url vers la fiche du traitement |
foreach ($resultat as &$traitement) { |
$traitement['url'] = $this->obtenirUrlFicheTraitement($this->referentiel, $traitement['id_traitement']); |
} |
$donnees['traitements_termines'] = $resultat; |
} |
} else { |
$this->addMessage("Aucun code de projet de référentiel n'est indiqué (Ex. bdtfx)."); |
} |
|
$donnees['messages'] = $this->getMessages(); |
$this->traiterEsperluette($donnees); |
$this->setSortie(self::RENDU_CORPS, $this->getVue('form_version', $donnees), false); |
$this->construireMenu($this->referentiel); |
$this->construireFilAriane($this->referentiel); |
} |
} |
|
public function instancierChampsVersionnage() { |
$version = array(); |
foreach ($this->version as $champ) { |
if (isset($_POST[$champ])) { |
$version[$champ] = $this->supprimerSlash($_POST[$champ]); |
} else { |
$version[$champ] = $this->getValeurParDefaut($champ); |
|
} |
} |
return $version; |
} |
|
public function getValeurParDefaut($champ) { |
$valeur = ''; |
if ('date_prod' == $champ) { |
$valeur = date('Y-m-d'); |
} |
return $valeur; |
} |
|
private function traiterCasesACocher(Array $donnees) { |
foreach ($donnees as $cle => $valeur) { |
if (is_array($valeur)) { |
$this->traiterEsperluette($valeur); |
$donnees[$cle] = array_flip($valeur); |
} |
} |
return $donnees; |
} |
|
/** |
* Lance l'ajout d'un traitement |
*/ |
public function demanderTraitement() { |
if ($this->verifierMetadonnees()) { |
$parametres = $this->instancierChampsVersionnage(); |
$parametres_serialises = serialize($parametres); |
$this->ajouterTraitementParametre($this->referentiel, $parametres_serialises, self::SCRIPT_A_LANCER); |
} |
$this->afficherInterface(); |
} |
|
/** |
* Vérifie les données du formulaire |
*/ |
public function verifierMetadonnees() { |
$ok = true; |
if (! $this->verifierChampsObligatoires()) { |
$ok = false; |
} |
if (! $this->verifierChampsMajuscule()) { |
$ok = false; |
} |
if (! $this->verifierChampsContact()) { |
$ok = false; |
} |
if (! $this->verifierChampsCourriel()) { |
$ok = false; |
} |
return $ok; |
} |
|
public function verifierChampsObligatoires() { |
$ok = true; |
$champs_obligatoires = array('titre' => 'Titre', |
'acronyme' => 'Acronyme', |
'version' => 'Version', |
'auteur_principal' => 'Auteur Principal', |
'coordinateur' => 'coordinateur', |
'contact' => 'Courriel de contact', |
'classification' => 'Classification par défaut', |
'dom_tax' => 'Domaine taxonomique', |
'dom_geo' => 'Domaine géographique', |
'dom_code' => 'Codes botaniques utilisés', |
'referencement' => 'Comment citer ce référentiel?', |
'errata' => 'Errata (URL)'); |
foreach ($champs_obligatoires as $champ_id => $champ_nom) { |
if (!isset($_POST[$champ_id]) || empty($_POST[$champ_id])) { |
$this->addMessage("Le champ '$champ_nom' doit être obligatoirement rempli."); |
$ok = false; |
} |
} |
return $ok; |
} |
|
public function verifierChampsMajuscule() { |
$ok = true; |
$champs_en_majuscule = array('acronyme' => 'Acronyme'); |
foreach ($champs_en_majuscule as $champ_id => $champ_nom) { |
if (isset($_POST[$champ_id]) && ! $this->verifierMajusculeSansAccent($_POST[$champ_id])) { |
$this->addMessage("Le champ '$champ_nom' doit être obligatoirement composé de majuscules non accentuées."); |
$ok = false; |
} |
} |
return $ok; |
} |
|
/** |
* Vérifie la mise en majuscule |
*/ |
public function verifierMajusculeSansAccent($txt) { |
$ok = (preg_match('/^[A-Z]+$/', $txt)) ? true : false; |
return $ok; |
} |
|
public function verifierChampsContact() { |
$ok = true; |
$champs_contact = array('auteur_principal' => 'Auteur Principal', |
'coordinateur' => 'coordinateur', |
'contributeur' => 'Auteurs/Contributeurs'); |
foreach ($champs_contact as $champ_id => $champ_nom) { |
if (isset($_POST[$champ_id]) && ! $this->verifierContact($_POST[$champ_id])) { |
$this->addMessage("Le champ '$champ_nom' n'est pas au format : Prénom1 NOM1 (Organisation1) [courriel1], Prénom2 NOM2 (Organisation2) [courriel2]."); |
$ok = false; |
} |
} |
return $ok; |
} |
|
/** |
* Vérifie que le texte est au format : |
* Prénom1 NOM1 (Organisation1) <courriel1>, |
* Prénom2 NOM2 (Organisation2) <courriel2>. |
*/ |
public function verifierContact($txt) { |
$ok = true; |
if ($txt != '') { |
$pp = Pattern::PRENOM; |
$pn = Pattern::NOM; |
$po = "\([^\)]+\)";// Pattern organisation |
$pc = Pattern::COURRIEL; |
|
$contacts = explode(',', $txt); |
foreach ($contacts as $contact) { |
$contact = trim($contact); |
if (! preg_match("/^$pp $pn $po \[$pc\](?:|.)$/u", $contact)) { |
$ok = false; |
} |
} |
} |
return $ok; |
} |
|
public function verifierChampsCourriel() { |
$ok = true; |
$champs_courriel = array('contact' => 'Courriel de contact'); |
foreach ($champs_courriel as $champ_id => $champ_nom) { |
if (isset($_POST[$champ_id]) && ! $this->verifierCourriel($_POST[$champ_id])) { |
$this->addMessage("Le champ '$champ_nom' ne comptient pas une adresse de courriel valide."); |
$ok = false; |
} |
} |
return $ok; |
} |
|
/** |
* Vérifie que le texte est une adresse de courriel valide. |
*/ |
public function verifierCourriel($txt) { |
$pattern_courriel = Pattern::COURRIEL; |
$ok = (preg_match('/^'.$pattern_courriel.'+$/', $txt)) ? true : false; |
return $ok; |
} |
} |
?> |