Subversion Repositories Applications.referentiel

Rev

Rev 51 | Rev 58 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
37 jpm 1
<?php
2
// declare(encoding='UTF-8');
3
/**
4
 * Classe Controleur du module Versionnage.
5
 * Permet de publier une nouvelle version d'un référentiel de travail.
6
 *
7
 * @package		Referentiel
8
 * @category	Php5.2
9
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
10
 * @copyright	2010 Tela-Botanica
11
 * @license		http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
12
 * @license		http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
13
 * @version		SVN: $Id$
14
 */
15
class Versionnage extends AppliControleur {
16
 
39 jpm 17
	const SCRIPT_A_LANCER = 'versionnage';
18
 
48 jpm 19
	private $version = array('titre', 'acronyme', 'version', 'date_prod',
20
		'auteur_principal', 'coordinateur', 'editeur', 'contact',
21
		'contributeur',
49 jpm 22
		'classification', 'dom_tax', 'dom_geo', 'dom_code',
48 jpm 23
		'source', 'copyright', 'licence', 'referencement');
37 jpm 24
	private $referentiel = null;
39 jpm 25
	private $traitementDao = null;
37 jpm 26
 
27
	public function __construct()  {
28
		parent::__construct();
29
 
30
		// Récupération de paramêtres
31
		if (isset($_GET['ref'])) { // code du projet courrant
32
			$this->referentiel = strtolower($_GET['ref']);
33
		}
38 jpm 34
 
39 jpm 35
		// Chargement des DAO nécessaires
36
		$this->traitementDao = new TraitementDao();
37 jpm 37
	}
38
 
39
	//+----------------------------------------------------------------------------------------------------------------+
40
	// Méthodes
41
	/**
42
	 * Fonction d'affichage par défaut
43
	 */
44
	public function executerActionParDefaut() {
38 jpm 45
		return $this->afficherInterface();
46
	}
47
 
48
	/**
49
	 * Affiche le formulaire de demande de versionnage
50
	 */
51
	public function afficherInterface() {
52
		$donnees = array();
45 jpm 53
		$this->definirCommeModulePrincipal(get_class($this));
39 jpm 54
 
38 jpm 55
		// Paramêtres pour l'url du formulaire
56
		$this->url->unsetVariablesRequete(array('module', 'action', 'ref'));
46 jpm 57
		$donnees['url_form'] = $this->obtenirUrlDemandeVersionnage($this->referentiel);
38 jpm 58
		$donnees['url_module'] = 'Versionnage';
59
		$donnees['url_action_rafraichir'] = 'afficherInterface';
60
 
48 jpm 61
		$donnees['version'] = $this->instancierChampsVersionnage();
62
 
38 jpm 63
		// Récupération des paramètres de configuration du manuel des référentiels
64
		$donnees['domaine_geo'] = explode(';', $this->manuel['domaine_geo']);
65
		$donnees['domaine_taxo'] = explode(';', $this->manuel['domaine_taxo']);
66
		$donnees['domaine_code'] = explode(';', $this->manuel['domaine_code']);
67
 
39 jpm 68
		// Traitement de l'info sur le code du référentiel
69
		if (isset($this->referentiel)) {
70
			// Récupération du référentiel courrant
71
			$donnees['ref'] = $this->referentiel;
72
 
73
			// Recherche des traitements en attente
74
			$donnees['traitements_en_attente'] = $this->traitementDao->getTraitementsEnAttente($this->referentiel, self::SCRIPT_A_LANCER);
75
 
76
			// Recherche des traitements en cours d'éxecution
77
			$donnees['traitements_en_cours'] = $this->traitementDao->getTraitementsEnCours($this->referentiel, self::SCRIPT_A_LANCER);
78
 
79
			// Recherche des traitements déjà effectué
80
			$resultat = $this->traitementDao->getTraitementsTermines($this->referentiel, self::SCRIPT_A_LANCER);
81
			if (is_array($resultat)) {
82
				// Ajout de l'url vers la fiche du traitement
83
				foreach ($resultat as &$traitement) {
84
					$traitement['url'] = $this->obtenirUrlFicheTraitement($this->referentiel, $traitement['id_traitement']);
85
				}
86
				$donnees['traitements_termines'] = $resultat;
87
			}
88
		} else {
89
			$this->addMessage("Aucun code de projet de référentiel n'est indiqué (Ex. bdnff).");
90
		}
91
 
46 jpm 92
		$donnees['messages'] = $this->getMessages();
57 jpm 93
		$this->traiterEsperluette($donnees);
38 jpm 94
		$this->setSortie(self::RENDU_CORPS, $this->getVue('form_version', $donnees), false);
37 jpm 95
		$this->construireMenu($this->referentiel);
96
		$this->construireFilAriane($this->referentiel);
38 jpm 97
	}
39 jpm 98
 
48 jpm 99
	public function instancierChampsVersionnage() {
100
		$version = array();
101
		foreach ($this->version as $champ) {
102
			if (isset($_POST[$champ])) {
57 jpm 103
				$version[$champ] = $this->supprimerSlash($_POST[$champ]);
104
				$version[$champ] = $this->traiterCasesACocher($version[$champ]);
48 jpm 105
			} else {
106
				$version[$champ] = $this->getValeurParDefaut($champ);
107
 
108
			}
109
		}
110
		return $version;
111
	}
112
 
57 jpm 113
	private function traiterCasesACocher($valeur_post) {
114
		if (is_array($valeur_post)) {
115
			$valeur_post = array_flip($valeur_post);
116
		}
117
		return $valeur_post;
118
	}
119
 
48 jpm 120
	public function getValeurParDefaut($champ) {
121
		$valeur = '';
122
		if ('date_prod' == $champ) {
123
			$valeur = date('Y-m-d');
124
		}
125
		return $valeur;
126
	}
127
 
39 jpm 128
	/**
129
	 * Lance l'ajout d'un traitement
130
	 */
131
	public function demanderTraitement() {
48 jpm 132
		if ($this->verifierMetadonnees()) {
49 jpm 133
			$parametres = $this->instancierChampsVersionnage();
134
			$parametres_serialises = serialize($parametres);
135
			$this->ajouterTraitementParametre($this->referentiel, $parametres_serialises, self::SCRIPT_A_LANCER);
48 jpm 136
		}
39 jpm 137
		$this->afficherInterface();
138
	}
48 jpm 139
 
140
	/**
141
	 * Vérifie les données du formulaire
142
	 */
143
	public function verifierMetadonnees() {
144
		$ok = true;
49 jpm 145
		if (! $this->verifierChampsObligatoires()) {
146
			$ok = false;
147
		}
148
		if (! $this->verifierChampsMajuscule()) {
149
			$ok = false;
150
		}
151
		if (! $this->verifierChampsContact()) {
152
			$ok = false;
153
		}
154
		if (! $this->verifierChampsCourriel()) {
155
			$ok = false;
156
		}
48 jpm 157
		return $ok;
158
	}
159
 
160
	public function verifierChampsObligatoires() {
161
		$ok = true;
162
		$champs_obligatoires = array('titre' => 'Titre',
163
			'acronyme' => 'Acronyme',
164
			'version' => 'Version',
165
			'auteur_principal' => 'Auteur Principal',
166
			'coordinateur' => 'coordinateur',
167
			'contact' => 'Courriel de contact',
49 jpm 168
			'classification' => 'Classification par défaut',
48 jpm 169
			'dom_tax' => 'Domaine taxonomique',
170
			'dom_geo' => 'Domaine géographique',
171
			'dom_code' => 'Codes botaniques utilisés',
172
			'referencement' => 'Comment citer ce référentiel?');
173
		foreach ($champs_obligatoires as $champ_id => $champ_nom) {
174
			if (!isset($_POST[$champ_id]) || empty($_POST[$champ_id])) {
175
				$this->addMessage("Le champ '$champ_nom' doit être obligatoirement rempli.");
176
				$ok = false;
177
			}
178
		}
179
		return $ok;
180
	}
49 jpm 181
 
182
	public function verifierChampsMajuscule() {
183
		$ok = true;
184
		$champs_en_majuscule = array('acronyme' => 'Acronyme');
185
		foreach ($champs_en_majuscule as $champ_id => $champ_nom) {
186
			if (isset($_POST[$champ_id]) && ! $this->verifierMajusculeSansAccent($_POST[$champ_id])) {
187
				$this->addMessage("Le champ '$champ_nom' doit être obligatoirement composé de majuscules non accentuées.");
188
				$ok = false;
189
			}
190
		}
191
		return $ok;
192
	}
193
 
194
	/**
195
	 * Vérifie la mise en majuscule
196
	 */
197
	public function verifierMajusculeSansAccent($txt) {
198
		$ok = (preg_match('/^[A-Z]+$/', $txt)) ? true : false;
199
		return $ok;
200
	}
201
 
202
	public function verifierChampsContact() {
203
		$ok = true;
204
		$champs_contact = array('auteur_principal' => 'Auteur Principal',
205
			'coordinateur' => 'coordinateur',
206
			'contributeur' => 'Auteurs/Contributeurs');
207
		foreach ($champs_contact as $champ_id => $champ_nom) {
208
			if (isset($_POST[$champ_id]) && ! $this->verifierContact($_POST[$champ_id])) {
51 jpm 209
				$this->addMessage("Le champ '$champ_nom' n'est pas au format : Prénom1 NOM1 (Organisation1) [courriel1], Prénom2 NOM2 (Organisation2) [courriel2].");
49 jpm 210
				$ok = false;
211
			}
212
		}
213
		return $ok;
214
	}
215
 
216
	/**
217
	 * Vérifie que le texte est au format :
218
	 * Prénom1 NOM1 (Organisation1) <courriel1>,
219
	 * Prénom2 NOM2 (Organisation2) <courriel2>.
220
	 */
221
	public function verifierContact($txt) {
222
		$ok = true;
223
		if ($txt != '') {
224
			$pp = Pattern::PRENOM;
225
			$pn = Pattern::NOM;
226
			$po = "\([^\)]+\)";// Pattern organisation
227
			$pc = Pattern::COURRIEL;
228
 
229
			$contacts = explode(',', $txt);
230
			foreach ($contacts as $contact) {
231
				$contact = trim($contact);
51 jpm 232
				if (! preg_match("/^$pp $pn $po \[$pc\](?:|.)$/u", $contact)) {
49 jpm 233
					$ok = false;
234
				}
235
			}
236
		}
237
		return $ok;
238
	}
239
 
240
	public function verifierChampsCourriel() {
241
		$ok = true;
242
		$champs_courriel = array('contact' => 'Courriel de contact');
243
		foreach ($champs_courriel as $champ_id => $champ_nom) {
244
			if (isset($_POST[$champ_id]) && ! $this->verifierCourriel($_POST[$champ_id])) {
245
				$this->addMessage("Le champ '$champ_nom' ne comptient pas une adresse de courriel valide.");
246
				$ok = false;
247
			}
248
		}
249
		return $ok;
250
	}
251
 
252
	/**
253
	 * Vérifie que le texte est une adresse de courriel valide.
254
	 */
255
	public function verifierCourriel($txt) {
256
		$pattern_courriel =  Pattern::COURRIEL;
257
		$ok = (preg_match('/^'.$pattern_courriel.'+$/', $txt)) ? true : false;
258
		return $ok;
259
	}
37 jpm 260
}
261
?>