Subversion Repositories Applications.referentiel

Rev

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