Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 439 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 439 Rev 456
1
<?php
1
<?php
2
/** Exemple lancement:
2
/** Exemple lancement:
3
 * /opt/lampp/bin/php -d memory_limit=3500M ~/web/eflore-projets/scripts/cli.php baseflor -a chargerTous
3
 * /opt/lampp/bin/php -d memory_limit=3500M ~/web/eflore-projets/scripts/cli.php baseflor -a chargerTous
4
*/
4
*/
5
class Baseflor extends EfloreScript {
5
class Baseflor extends EfloreScript {
6
 
6
 
7
	private $table = null;
7
	private $table = null;
8
	private $fichierDonnees = '';
8
	private $fichierDonnees = '';
9
	private $log = '';
9
	private $log = '';
10
	private $nb_erreurs;
10
	private $nb_erreurs;
11
	private $erreurs_ligne;
11
	private $erreurs_ligne;
12
	private $ligne_num;
12
	private $ligne_num;
13
	private $colonne_valeur;
13
	private $colonne_valeur;
14
	private $colonne_num;
14
	private $colonne_num;
15
	private $type_bio = array();
15
	private $type_bio = array();
16
	private $ss_type_bio = array();
16
	private $ss_type_bio = array();
17
	private $signes_seuls = array();// basés sur valeurs trouvées (--> pas de légende !)
17
	private $signes_seuls = array();// basés sur valeurs trouvées (--> pas de légende !)
18
	private $signes_nn_seuls = array();// basés sur valeurs trouvées (--> pas de légende !)
18
	private $signes_nn_seuls = array();// basés sur valeurs trouvées (--> pas de légende !)
19
	private $intervalles = array();
19
	private $intervalles = array();
20
	private $motifs = array();
20
	private $motifs = array();
21
 
21
 
22
	public function executer() {
22
	public function executer() {
23
		try {
23
		try {
24
			$this->initialiserProjet('baseflor');
24
			$this->initialiserProjet('baseflor');
25
			$cmd = $this->getParametre('a');
25
			$cmd = $this->getParametre('a');
26
			switch ($cmd) {
26
			switch ($cmd) {
27
				case 'chargerStructureSql' :
27
				case 'chargerStructureSql' :
28
					$this->chargerStructureSql();
28
					$this->chargerStructureSql();
29
					break;
29
					break;
30
				case 'chargerMetadonnees':
30
				case 'chargerMetadonnees':
31
					$this->chargerMetadonnees();
31
					$this->chargerMetadonnees();
32
					break;
32
					break;
33
				case 'chargerOntologies' :
33
				case 'chargerOntologies' :
34
					$this->chargerOntologies();
34
					$this->chargerOntologies();
35
					break;
35
					break;
36
				case 'verifierDonnees' :
36
				case 'verifierDonnees' :
37
					$this->verifFichier();
37
					$this->verifFichier();
38
					break;
38
					break;
39
				case 'chargerDonnees' :
39
				case 'chargerDonnees' :
40
					$this->chargerDonnees();
40
					$this->chargerDonnees();
41
					break;
41
					break;
42
				case 'genererChamps' :
42
				case 'genererChamps' :
43
					 $this->genererChamps();
43
					 $this->genererChamps();
44
					 break;
44
					 break;
45
				case 'chargerTous':
45
				case 'chargerTous':
46
					$this->chargerStructureSql();
46
					$this->chargerStructureSql();
47
					$this->chargerMetadonnees();
47
					$this->chargerMetadonnees();
48
					$this->chargerOntologies();
48
					$this->chargerOntologies();
49
					$this->chargerDonnees();
49
					$this->chargerDonnees();
50
					$this->genererChamps();
50
					$this->genererChamps();
-
 
51
					$this->insererDonneesBaseflorRangSupEcolo();
51
					break;
52
					break;
52
				case 'insererDonneesRangSup' :
53
				case 'insererDonneesRangSup' :
53
					$this->insererDonneesBaseflorRangSupEcolo();
54
					$this->insererDonneesBaseflorRangSupEcolo();
54
					break;
55
					break;
55
				case 'supprimerTous' :
56
				case 'supprimerTous' :
56
					$this->supprimerTous();
57
					$this->supprimerTous();
57
					break;
58
					break;
58
				case 'voirRangSup' :
59
				case 'voirRangSup' :
59
					$this->voirRangSup();
60
					$this->voirRangSup();
60
					break;
61
					break;
61
				case 'voirRangSupEcologie' :
62
				case 'voirRangSupEcologie' :
62
					$this->voirRangSupEcologie();
63
					$this->voirRangSupEcologie();
63
					break;
64
					break;
64
				default :
65
				default :
65
					throw new Exception("Erreur : la commande '$cmd' n'existe pas!");
66
					throw new Exception("Erreur : la commande '$cmd' n'existe pas!");
66
			}
67
			}
67
		} catch (Exception $e) {
68
		} catch (Exception $e) {
68
			$this->traiterErreur($e->getMessage());
69
			$this->traiterErreur($e->getMessage());
69
		}
70
		}
70
	}
71
	}
71
 
72
 
72
	//-- traitement de la table baseflorRangSupInsertion --//
73
	//-- traitement de la table baseflorRangSupInsertion --//
73
	
74
	
74
	private function  getClasseBaseflorRangSupInsertion() {
75
	private function  getClasseBaseflorRangSupInsertion() {
75
		$conteneur = new Conteneur();
76
		$conteneur = new Conteneur();
76
		require_once dirname(__FILE__)."/BaseflorRangSupInsertion.php";
77
		require_once dirname(__FILE__)."/BaseflorRangSupInsertion.php";
77
		$rangSupInsert = new BaseflorRangSupInsertion($conteneur);///?
78
		$rangSupInsert = new BaseflorRangSupInsertion($conteneur);///?
78
		return $rangSupInsert;
79
		return $rangSupInsert;
79
	}
80
	}
80
	
81
	
81
	 
82
	 
82
	private function insererDonneesBaseflorRangSupEcolo(){
83
	private function insererDonneesBaseflorRangSupEcolo(){
83
		$rangSupInsert = $this->getClasseBaseflorRangSupInsertion();
84
		$rangSupInsert = $this->getClasseBaseflorRangSupInsertion();
84
		$rangSupInsert->insererDonnees();
85
		$rangSupInsert->insererDonnees();
85
	}
86
	}
86
	
87
	
87
	private function voirRangSup(){
88
	private function voirRangSup(){
88
		$rangSupInsert = $this->getClasseBaseflorRangSupInsertion();
89
		$rangSupInsert = $this->getClasseBaseflorRangSupInsertion();
89
		$rangSupInsert->testAscendantsDeBaseflor();
90
		$rangSupInsert->testAscendantsDeBaseflor();
90
	}
91
	}
91
	
92
	
92
	private function voirRangSupEcologie(){
93
	private function voirRangSupEcologie(){
93
		$rangSupInsert = $this->getClasseBaseflorRangSupInsertion();
94
		$rangSupInsert = $this->getClasseBaseflorRangSupInsertion();
94
		$rangSupInsert->testEcologieAscendantsDeBaseflor();
95
		$rangSupInsert->testEcologieAscendantsDeBaseflor();
95
	}
96
	}
96
	
97
	
97
	
98
	
98
	//-- traitement de la table generer champs --//
99
	//-- traitement de la table generer champs --//
99
	private function genererChamps(){
100
	private function genererChamps(){
100
		$this->initialiserGenerationChamps();
101
		$this->initialiserGenerationChamps();
101
		$this->ajouterChamps();
102
		$this->ajouterChamps();
102
		$this->analyserChampsExistant();
103
		$this->analyserChampsExistant();
103
	}
104
	}
104
 
105
 
105
	private function initialiserGenerationChamps() {
106
	private function initialiserGenerationChamps() {
106
		$this->table = Config::get('tables.donnees');
107
		$this->table = Config::get('tables.donnees');
107
	}
108
	}
108
 
109
 
109
	private function ajouterChamps() {
110
	private function ajouterChamps() {
110
		$this->preparerTablePrChpsBDNT();
111
		$this->preparerTablePrChpsBDNT();
111
		$this->preparerTablePrChpsNumTaxon();
112
		$this->preparerTablePrChpsNumTaxon();
112
		$this->preparerTablePrChpsNumNomen();
113
		$this->preparerTablePrChpsNumNomen();
113
	}
114
	}
114
 
115
 
115
	private function preparerTablePrChpsBDNT() {
116
	private function preparerTablePrChpsBDNT() {
116
		$requete = "SHOW COLUMNS FROM {$this->table} LIKE 'BDNT' ";
117
		$requete = "SHOW COLUMNS FROM {$this->table} LIKE 'BDNT' ";
117
		$resultat = $this->getBdd()->recuperer($requete);
118
		$resultat = $this->getBdd()->recuperer($requete);
118
		if ($resultat === false) {
119
		if ($resultat === false) {
119
			$requete = 	"ALTER TABLE {$this->table} ".
120
			$requete = 	"ALTER TABLE {$this->table} ".
120
					'ADD BDNT VARCHAR( 6 ) '.
121
					'ADD BDNT VARCHAR( 6 ) '.
121
					'CHARACTER SET utf8 COLLATE utf8_general_ci '.
122
					'CHARACTER SET utf8 COLLATE utf8_general_ci '.
122
					'NOT NULL AFTER catminat_code ';
123
					'NOT NULL AFTER catminat_code ';
123
			$this->getBdd()->requeter($requete);
124
			$this->getBdd()->requeter($requete);
124
		}
125
		}
125
	}
126
	}
126
 
127
 
127
	private function preparerTablePrChpsNumTaxon() {
128
	private function preparerTablePrChpsNumTaxon() {
128
		$requete = "SHOW COLUMNS FROM {$this->table} LIKE 'num_taxon' ";
129
		$requete = "SHOW COLUMNS FROM {$this->table} LIKE 'num_taxon' ";
129
		$resultat = $this->getBdd()->recuperer($requete);
130
		$resultat = $this->getBdd()->recuperer($requete);
130
		if ($resultat === false) {
131
		if ($resultat === false) {
131
			$requete = "ALTER TABLE {$this->table} ".
132
			$requete = "ALTER TABLE {$this->table} ".
132
					'ADD num_taxon INT( 10 ) NOT NULL '.
133
					'ADD num_taxon INT( 10 ) NOT NULL '.
133
					'AFTER catminat_code';
134
					'AFTER catminat_code';
134
			$this->getBdd()->requeter($requete);
135
			$this->getBdd()->requeter($requete);
135
		}
136
		}
136
	}
137
	}
137
 
138
 
138
	private function preparerTablePrChpsNumNomen() {
139
	private function preparerTablePrChpsNumNomen() {
139
		$requete = "SHOW COLUMNS FROM {$this->table} LIKE 'num_nomen' ";
140
		$requete = "SHOW COLUMNS FROM {$this->table} LIKE 'num_nomen' ";
140
		$resultat = $this->getBdd()->recuperer($requete);
141
		$resultat = $this->getBdd()->recuperer($requete);
141
		if ($resultat === false) {
142
		if ($resultat === false) {
142
			$requete = "ALTER TABLE {$this->table} ".
143
			$requete = "ALTER TABLE {$this->table} ".
143
					'ADD num_nomen INT( 10 ) NOT NULL '.
144
					'ADD num_nomen INT( 10 ) NOT NULL '.
144
					'AFTER catminat_code';
145
					'AFTER catminat_code';
145
			$this->getBdd()->requeter($requete);
146
			$this->getBdd()->requeter($requete);
146
		}
147
		}
147
	}
148
	}
148
 
149
 
149
	private function analyserChampsExistant() {
150
	private function analyserChampsExistant() {
150
		$resultats = $this->recupererTuplesNumsOriginels();
151
		$resultats = $this->recupererTuplesNumsOriginels();
151
		foreach ($resultats as $chps) {
152
		foreach ($resultats as $chps) {
152
			$cle = $chps['cle'];
153
			$cle = $chps['cle'];
153
			$nno = $chps['num_nomen_originel'];
154
			$nno = $chps['num_nomen_originel'];
154
			$nto = $chps['num_taxon_originel'];
155
			$nto = $chps['num_taxon_originel'];
155
 
156
 
156
			$valeurs = array();
157
			$valeurs = array();
157
			$valeurs["BDNT"] = $this->genererChpsBDNT($nno, $nto);
158
			$valeurs["BDNT"] = $this->genererChpsBDNT($nno, $nto);
158
			$valeurs["num_taxon"] = $this->genererChpsNumTaxon($nto);
159
			$valeurs["num_taxon"] = $this->genererChpsNumTaxon($nto);
159
			$valeurs["num_nomen"] = $this->genererChpsNumNomen($nno);
160
			$valeurs["num_nomen"] = $this->genererChpsNumNomen($nno);
160
 
161
 
161
			$this->remplirChamps($cle, $valeurs);
162
			$this->remplirChamps($cle, $valeurs);
162
 
163
 
163
			$this->afficherAvancement("Insertion des valeurs dans la base en cours");
164
			$this->afficherAvancement("Insertion des valeurs dans la base en cours");
164
		}
165
		}
165
		echo "\n";
166
		echo "\n";
166
	}
167
	}
167
 
168
 
168
	private function recupererTuplesNumsOriginels(){
169
	private function recupererTuplesNumsOriginels(){
169
		$requete = "SELECT cle, num_taxon_originel, num_nomen_originel FROM {$this->table} ";
170
		$requete = "SELECT cle, num_taxon_originel, num_nomen_originel FROM {$this->table} ";
170
		$resultat = $this->getBdd()->recupererTous($requete);
171
		$resultat = $this->getBdd()->recupererTous($requete);
171
		return $resultat;
172
		return $resultat;
172
	}
173
	}
173
 
174
 
174
	private function genererChpsBDNT($nno, $nto) {
175
	private function genererChpsBDNT($nno, $nto) {
175
		$bdnt = '';
176
		$bdnt = '';
176
		if (preg_match("/^([AB])[0-9]+$/", $nno, $retour) || preg_match("/^([AB])[0-9]+$/", $nto, $retour)){
177
		if (preg_match("/^([AB])[0-9]+$/", $nno, $retour) || preg_match("/^([AB])[0-9]+$/", $nto, $retour)){
177
			if ($retour[1]=='A') {
178
			if ($retour[1]=='A') {
178
				$bdnt = "BDAFX";
179
				$bdnt = "BDAFX";
179
			} else {
180
			} else {
180
				$bdnt = "BDBFX";
181
				$bdnt = "BDBFX";
181
			}
182
			}
182
		} elseif (($nno == 'nc') && ($nto == 'nc')) {
183
		} elseif (($nno == 'nc') && ($nto == 'nc')) {
183
			$bdnt = "nc";
184
			$bdnt = "nc";
184
		} else {
185
		} else {
185
			$bdnt = "BDTFX";
186
			$bdnt = "BDTFX";
186
		}
187
		}
187
		return $bdnt;
188
		return $bdnt;
188
	}
189
	}
189
 
190
 
190
	private function genererChpsNumTaxon($nto){
191
	private function genererChpsNumTaxon($nto){
191
		$num_taxon = '';
192
		$num_taxon = '';
192
		if (preg_match("/^[AB]([0-9]+)$/", $nto, $retour)) {
193
		if (preg_match("/^[AB]([0-9]+)$/", $nto, $retour)) {
193
			$num_taxon = intval($retour[1]);
194
			$num_taxon = intval($retour[1]);
194
		} elseif($nto == 'nc') {
195
		} elseif($nto == 'nc') {
195
			$num_taxon = 0;
196
			$num_taxon = 0;
196
		} else {
197
		} else {
197
			$num_taxon = intval($nto);
198
			$num_taxon = intval($nto);
198
		}
199
		}
199
		return $num_taxon;
200
		return $num_taxon;
200
	}
201
	}
201
 
202
 
202
	private function genererChpsNumNomen($nno) {
203
	private function genererChpsNumNomen($nno) {
203
		$num_nomen = '';
204
		$num_nomen = '';
204
		if (preg_match("/^[AB]([0-9]+)$/", $nno, $retour)) {
205
		if (preg_match("/^[AB]([0-9]+)$/", $nno, $retour)) {
205
			$num_nomen = intval($retour[1]);
206
			$num_nomen = intval($retour[1]);
206
		} elseif ($nno == 'nc') {
207
		} elseif ($nno == 'nc') {
207
			$num_nomen = 0;
208
			$num_nomen = 0;
208
		} else {
209
		} else {
209
			$num_nomen = intval($nno);
210
			$num_nomen = intval($nno);
210
		}
211
		}
211
		return $num_nomen;
212
		return $num_nomen;
212
	}
213
	}
213
 
214
 
214
	 private function remplirChamps($cle, $valeurs) {
215
	 private function remplirChamps($cle, $valeurs) {
215
		foreach ($valeurs as $nomChamp => $valeurChamp) {
216
		foreach ($valeurs as $nomChamp => $valeurChamp) {
216
			$valeurChamp = $this->getBdd()->proteger($valeurChamp);
217
			$valeurChamp = $this->getBdd()->proteger($valeurChamp);
217
			$requete = "UPDATE {$this->table} SET $nomChamp = $valeurChamp WHERE cle = $cle ";
218
			$requete = "UPDATE {$this->table} SET $nomChamp = $valeurChamp WHERE cle = $cle ";
218
			$resultat = $this->getBdd()->requeter($requete);
219
			$resultat = $this->getBdd()->requeter($requete);
219
			if ($resultat === false) {
220
			if ($resultat === false) {
220
				throw new Exception("Erreur d'insertion pour le tuple clé = $cle");
221
				throw new Exception("Erreur d'insertion pour le tuple clé = $cle");
221
			}
222
			}
222
		}
223
		}
223
	}
224
	}
224
 
225
 
225
	//+------------------------------------------------------------------------------------------------------+
226
	//+------------------------------------------------------------------------------------------------------+
226
	// chargements, suppression, exécution
227
	// chargements, suppression, exécution
227
 
228
 
228
	protected function chargerMetadonnees() {
229
	protected function chargerMetadonnees() {
229
		$contenuSql = $this->recupererContenu(Config::get('chemins.metadonnees'));
230
		$contenuSql = $this->recupererContenu(Config::get('chemins.metadonnees'));
230
		$this->executerScripSql($contenuSql);
231
		$this->executerScripSql($contenuSql);
231
	}
232
	}
232
 
233
 
233
	private function chargerOntologies() {
234
	private function chargerOntologies() {
234
		$chemin = Config::get('chemins.ontologies');
235
		$chemin = Config::get('chemins.ontologies');
235
		$table = Config::get('tables.ontologies');
236
		$table = Config::get('tables.ontologies');
236
		$requete = "LOAD DATA INFILE '$chemin' ".
237
		$requete = "LOAD DATA INFILE '$chemin' ".
237
			"REPLACE INTO TABLE $table ".
238
			"REPLACE INTO TABLE $table ".
238
			'CHARACTER SET utf8 '.
239
			'CHARACTER SET utf8 '.
239
			'FIELDS '.
240
			'FIELDS '.
240
			"	TERMINATED BY '\t' ".
241
			"	TERMINATED BY '\t' ".
241
			"	ENCLOSED BY '' ".
242
			"	ENCLOSED BY '' ".
242
			"	ESCAPED BY '\\\' "
243
			"	ESCAPED BY '\\\' "
243
			;
244
			;
244
		$this->getBdd()->requeter($requete);
245
		$this->getBdd()->requeter($requete);
245
	}
246
	}
246
 
247
 
247
	protected function chargerStructureSql() {
248
	protected function chargerStructureSql() {
248
		$contenuSql = $this->recupererContenu(Config::get('chemins.structureSql'));
249
		$contenuSql = $this->recupererContenu(Config::get('chemins.structureSql'));
249
		$this->executerScripSql($contenuSql);
250
		$this->executerScripSql($contenuSql);
250
	}
251
	}
251
 
252
 
252
	protected function executerScripSql($sql) {
253
	protected function executerScripSql($sql) {
253
		$requetes = Outils::extraireRequetes($sql);
254
		$requetes = Outils::extraireRequetes($sql);
254
		foreach ($requetes as $requete) {
255
		foreach ($requetes as $requete) {
255
			$this->getBdd()->requeter($requete);
256
			$this->getBdd()->requeter($requete);
256
		}
257
		}
257
	}
258
	}
258
 
259
 
259
	private function chargerDonnees() {
260
	private function chargerDonnees() {
260
		$this->verifFichier();
261
		$this->verifFichier();
261
		if ($this->nb_erreurs > 0) {
262
		if ($this->nb_erreurs > 0) {
262
			$e = "Je ne peux pas charger les données car le fichier comporte des erreurs.".
263
			$e = "Je ne peux pas charger les données car le fichier comporte des erreurs.".
263
					"Voir le fichier baseflor_verif.txt\n";
264
					"Voir le fichier baseflor_verif.txt\n";
264
			throw new Exception($e);
265
			throw new Exception($e);
265
		}
266
		}
266
 
267
 
267
		$table = Config::get('tables.donnees');
268
		$table = Config::get('tables.donnees');
268
		$requete = "LOAD DATA INFILE '".Config::get('chemins.donnees')."' ".
269
		$requete = "LOAD DATA INFILE '".Config::get('chemins.donnees')."' ".
269
			"REPLACE INTO TABLE $table ".
270
			"REPLACE INTO TABLE $table ".
270
			'CHARACTER SET utf8 '.
271
			'CHARACTER SET utf8 '.
271
			'FIELDS '.
272
			'FIELDS '.
272
			"	TERMINATED BY '\t' ".
273
			"	TERMINATED BY '\t' ".
273
			"	ENCLOSED BY '' ".
274
			"	ENCLOSED BY '' ".
274
			"	ESCAPED BY '\\\'";
275
			"	ESCAPED BY '\\\'";
275
		$this->getBdd()->requeter($requete);
276
		$this->getBdd()->requeter($requete);
276
	}
277
	}
277
 
278
 
278
	private function supprimerTous() {
279
	private function supprimerTous() {
279
		$requete = "DROP TABLE IF EXISTS baseflor_meta, baseflor_ontologies, baseflor_v2012_03_19";
280
		$requete = "DROP TABLE IF EXISTS baseflor_meta, baseflor_ontologies, baseflor_v2012_03_19";
280
		$this->getBdd()->requeter($requete);
281
		$this->getBdd()->requeter($requete);
281
	}
282
	}
282
 
283
 
283
	//+------------------------------------------------------------------------------------------------------+
284
	//+------------------------------------------------------------------------------------------------------+
284
	// vérifications de données
285
	// vérifications de données
285
 
286
 
286
	//verifie la cohérence des valeurs des colonnes
287
	//verifie la cohérence des valeurs des colonnes
287
	private function verifFichier(){
288
	private function verifFichier(){
288
		$this->initialiserParametresVerif();
289
		$this->initialiserParametresVerif();
289
 
290
 
290
		$lignes = file($this->fichierDonnees, FILE_IGNORE_NEW_LINES);
291
		$lignes = file($this->fichierDonnees, FILE_IGNORE_NEW_LINES);
291
		if ($lignes != false) {
292
		if ($lignes != false) {
292
			$this->ajouterAuLog("!!! REGARDEZ LES COLONNES DANS NUMERO_COLONNES_IMPORTANT.TXT.");
293
			$this->ajouterAuLog("!!! REGARDEZ LES COLONNES DANS NUMERO_COLONNES_IMPORTANT.TXT.");
293
			foreach ($lignes as $this->ligne_num => $ligne) {
294
			foreach ($lignes as $this->ligne_num => $ligne) {
294
				$this->verifierErreursLigne($ligne);
295
				$this->verifierErreursLigne($ligne);
295
				$this->afficherAvancement("Vérification des lignes");
296
				$this->afficherAvancement("Vérification des lignes");
296
			}
297
			}
297
			echo "\n";
298
			echo "\n";
298
		} else {
299
		} else {
299
			$this->traiterErreur("Le fichier {$this->fichierDonnees} ne peut pas être ouvert.");
300
			$this->traiterErreur("Le fichier {$this->fichierDonnees} ne peut pas être ouvert.");
300
		}
301
		}
301
 
302
 
302
		if ($this->nb_erreurs == 0) {
303
		if ($this->nb_erreurs == 0) {
303
			$this->ajouterAuLog("Il n'y a pas d'erreurs.");
304
			$this->ajouterAuLog("Il n'y a pas d'erreurs.");
304
		}
305
		}
305
		$this->traiterInfo($this->nb_erreurs." erreurs");
306
		$this->traiterInfo($this->nb_erreurs." erreurs");
306
 
307
 
307
		$this->ecrireFichierLog();
308
		$this->ecrireFichierLog();
308
	}
309
	}
309
 
310
 
310
	//vérifie par colonnes les erreurs d'une ligne
311
	//vérifie par colonnes les erreurs d'une ligne
311
	private function verifierErreursLigne($ligne){
312
	private function verifierErreursLigne($ligne){
312
		$this->erreurs_ligne = array();
313
		$this->erreurs_ligne = array();
313
		$colonnes = explode("\t", $ligne);
314
		$colonnes = explode("\t", $ligne);
314
		if (isset($colonnes)) {
315
		if (isset($colonnes)) {
315
			foreach ($colonnes as $this->colonne_num => $this->colonne_valeur) {
316
			foreach ($colonnes as $this->colonne_num => $this->colonne_valeur) {
316
				if (( $this->colonne_num > 0 && $this->colonne_num < 15 )
317
				if (( $this->colonne_num > 0 && $this->colonne_num < 15 )
317
						|| $this->colonne_num == 16
318
						|| $this->colonne_num == 16
318
						|| ($this->colonne_num > 18 && $this->colonne_num < 23)
319
						|| ($this->colonne_num > 18 && $this->colonne_num < 23)
319
						|| $this->colonne_num > 39) {
320
						|| $this->colonne_num > 39) {
320
					$this->verifierColonne();
321
					$this->verifierColonne();
321
				} elseif ($this->colonne_num == 15) {
322
				} elseif ($this->colonne_num == 15) {
322
					$this->verifierTypeBio();
323
					$this->verifierTypeBio();
323
				} elseif ($this->colonne_num >= 23 && $this->colonne_num <= 32) {
324
				} elseif ($this->colonne_num >= 23 && $this->colonne_num <= 32) {
324
					$this->verifierIntervalles($this->colonne_valeur);
325
					$this->verifierIntervalles($this->colonne_valeur);
325
				} elseif ($this->colonne_num >= 33 && $this->colonne_num < 41) {
326
				} elseif ($this->colonne_num >= 33 && $this->colonne_num < 41) {
326
					$this->verifierValeursIndic();
327
					$this->verifierValeursIndic();
327
				}
328
				}
328
			}
329
			}
329
		} else {
330
		} else {
330
			$message = "Ligne {$this->ligne_num} : pas de tabulation";
331
			$message = "Ligne {$this->ligne_num} : pas de tabulation";
331
			$this->ajouterAuLog($message);
332
			$this->ajouterAuLog($message);
332
		}
333
		}
333
 
334
 
334
		$this->controlerErreursLigne();
335
		$this->controlerErreursLigne();
335
	}
336
	}
336
 
337
 
337
	private function verifierColonne(){
338
	private function verifierColonne(){
338
		$motif = $this->motifs[$this->colonne_num];
339
		$motif = $this->motifs[$this->colonne_num];
339
		if (preg_match($motif, $this->colonne_valeur) == 0 && $this->verifierSiVide() == false){
340
		if (preg_match($motif, $this->colonne_valeur) == 0 && $this->verifierSiVide() == false){
340
			$this->erreurs_ligne[$this->colonne_num] = $this->colonne_valeur;
341
			$this->erreurs_ligne[$this->colonne_num] = $this->colonne_valeur;
341
		}
342
		}
342
	}
343
	}
343
 
344
 
344
	private function verifierSiVide(){
345
	private function verifierSiVide(){
345
		$vide = ($this->colonne_valeur  == '') ? true : false;
346
		$vide = ($this->colonne_valeur  == '') ? true : false;
346
		return $vide;
347
		return $vide;
347
	}
348
	}
348
 
349
 
349
	private function verifierTypeBio(){
350
	private function verifierTypeBio(){
350
		if (preg_match("/(.+)\((.+)\)$/", $this->colonne_valeur, $retour) == 1) {
351
		if (preg_match("/(.+)\((.+)\)$/", $this->colonne_valeur, $retour) == 1) {
351
			$this->verifierTypeEtSsType($retour[1]);
352
			$this->verifierTypeEtSsType($retour[1]);
352
			$this->verifierTypeEtSsType($retour[2]);
353
			$this->verifierTypeEtSsType($retour[2]);
353
		} else {
354
		} else {
354
			$this->verifierTypeEtSsType($this->colonne_valeur);
355
			$this->verifierTypeEtSsType($this->colonne_valeur);
355
		}
356
		}
356
	}
357
	}
357
 
358
 
358
	private function verifierTypeEtSsType($chaine_a_verif){
359
	private function verifierTypeEtSsType($chaine_a_verif){
359
		if (preg_match("/^([a-zA-Zé]+)\-(.+)$|^([a-zA-Zé]+[^\-])$/", $chaine_a_verif, $retour) == 1) {
360
		if (preg_match("/^([a-zA-Zé]+)\-(.+)$|^([a-zA-Zé]+[^\-])$/", $chaine_a_verif, $retour) == 1) {
360
			$type = (isset($retour[3])) ? $retour[3] : $retour[1];
361
			$type = (isset($retour[3])) ? $retour[3] : $retour[1];
361
			$this->verifierType($type);
362
			$this->verifierType($type);
362
 
363
 
363
			$sousType = $retour[2];
364
			$sousType = $retour[2];
364
			$this->verifierSousType($sousType);
365
			$this->verifierSousType($sousType);
365
		}
366
		}
366
	}
367
	}
367
 
368
 
368
	private function verifierType($type) {
369
	private function verifierType($type) {
369
		if (in_array($type, $this->type_bio) == false) {
370
		if (in_array($type, $this->type_bio) == false) {
370
			$this->erreurs_ligne[$this->colonne_num] = $this->colonne_valeur;
371
			$this->erreurs_ligne[$this->colonne_num] = $this->colonne_valeur;
371
		}
372
		}
372
	}
373
	}
373
 
374
 
374
	private function verifierSousType($sousType) {
375
	private function verifierSousType($sousType) {
375
		if ($sousType != ''){
376
		if ($sousType != ''){
376
			$ss_type = explode('-', $sousType);
377
			$ss_type = explode('-', $sousType);
377
			foreach ($ss_type as $sst) {
378
			foreach ($ss_type as $sst) {
378
				if (in_array($sst, $this->ss_type_bio) == false) {
379
				if (in_array($sst, $this->ss_type_bio) == false) {
379
					$this->erreurs_ligne[$this->colonne_num] = $this->colonne_valeur;
380
					$this->erreurs_ligne[$this->colonne_num] = $this->colonne_valeur;
380
				}
381
				}
381
			}
382
			}
382
		}
383
		}
383
	}
384
	}
384
 
385
 
385
	private function verifierIntervalles($valeur){
386
	private function verifierIntervalles($valeur){
386
		if ($valeur != '') {
387
		if ($valeur != '') {
387
			list($min, $max) = explode('-', $this->intervalles[$this->colonne_num]);
388
			list($min, $max) = explode('-', $this->intervalles[$this->colonne_num]);
388
			if ($valeur < $min || $valeur > $max){
389
			if ($valeur < $min || $valeur > $max){
389
				$this->erreurs_ligne[$this->colonne_num] = $this->colonne_valeur;
390
				$this->erreurs_ligne[$this->colonne_num] = $this->colonne_valeur;
390
			}
391
			}
391
		}
392
		}
392
	}
393
	}
393
 
394
 
394
	private function verifierValeursIndic(){
395
	private function verifierValeursIndic(){
395
		if (preg_match("/^([^0-9])*([0-9]+)([^0-9])*$/", $this->colonne_valeur, $retour) == 1){
396
		if (preg_match("/^([^0-9])*([0-9]+)([^0-9])*$/", $this->colonne_valeur, $retour) == 1){
396
			$this->verifierIntervalles($retour[2]);
397
			$this->verifierIntervalles($retour[2]);
397
			if (isset($retour[3]) && in_array($retour[3], $this->signes_nn_seuls) == false){
398
			if (isset($retour[3]) && in_array($retour[3], $this->signes_nn_seuls) == false){
398
				$this->erreurs_ligne[$this->colonne_num] = $this->colonne_valeur;
399
				$this->erreurs_ligne[$this->colonne_num] = $this->colonne_valeur;
399
			}
400
			}
400
			if ($retour[1] != '-' && $retour[1] != ''){
401
			if ($retour[1] != '-' && $retour[1] != ''){
401
				$this->erreurs_ligne[$this->colonne_num] = $this->colonne_valeur;
402
				$this->erreurs_ligne[$this->colonne_num] = $this->colonne_valeur;
402
			}
403
			}
403
		} elseif (in_array( $this->colonne_valeur, $this->signes_seuls) == false && $this->verifierSiVide() == false) {
404
		} elseif (in_array( $this->colonne_valeur, $this->signes_seuls) == false && $this->verifierSiVide() == false) {
404
			$this->erreurs_ligne[$this->colonne_num] = $this->colonne_valeur;
405
			$this->erreurs_ligne[$this->colonne_num] = $this->colonne_valeur;
405
		}
406
		}
406
	}
407
	}
407
 
408
 
408
	private function controlerErreursLigne() {
409
	private function controlerErreursLigne() {
409
		$nbreErreursLigne = count($this->erreurs_ligne);
410
		$nbreErreursLigne = count($this->erreurs_ligne);
410
		$this->nb_erreurs += $nbreErreursLigne;
411
		$this->nb_erreurs += $nbreErreursLigne;
411
		if ($nbreErreursLigne != 0) {
412
		if ($nbreErreursLigne != 0) {
412
			$this->ajouterAuLog("Erreurs sur la ligne {$this->ligne_num}");
413
			$this->ajouterAuLog("Erreurs sur la ligne {$this->ligne_num}");
413
			$ligneLog = '';
414
			$ligneLog = '';
414
			foreach ($this->erreurs_ligne as $cle => $v){
415
			foreach ($this->erreurs_ligne as $cle => $v){
415
				$ligneLog .= "colonne $cle : $v - ";
416
				$ligneLog .= "colonne $cle : $v - ";
416
			}
417
			}
417
			$this->ajouterAuLog($ligneLog);
418
			$this->ajouterAuLog($ligneLog);
418
		}
419
		}
419
	}
420
	}
420
 
421
 
421
	//+------------------------------------------------------------------------------------------------------+
422
	//+------------------------------------------------------------------------------------------------------+
422
	// Chargement Paramètres
423
	// Chargement Paramètres
423
 
424
 
424
	private function initialiserParametresVerif() {
425
	private function initialiserParametresVerif() {
425
		$this->nb_erreurs = 0;
426
		$this->nb_erreurs = 0;
426
		$this->fichierDonnees = Config::get('chemins.donnees');
427
		$this->fichierDonnees = Config::get('chemins.donnees');
427
		$this->type_bio = $this->getParametreTableau('Parametres.typesBio');
428
		$this->type_bio = $this->getParametreTableau('Parametres.typesBio');
428
		$this->ss_type_bio = $this->getParametreTableau('Parametres.sousTypesBio');
429
		$this->ss_type_bio = $this->getParametreTableau('Parametres.sousTypesBio');
429
		$this->signes_seuls = $this->getParametreTableau('Parametres.signesSeuls');
430
		$this->signes_seuls = $this->getParametreTableau('Parametres.signesSeuls');
430
		$this->signes_nn_seuls = $this->getParametreTableau('Parametres.signesNonSeuls');
431
		$this->signes_nn_seuls = $this->getParametreTableau('Parametres.signesNonSeuls');
431
		$this->intervalles = $this->inverserTableau($this->getParametreTableau('Parametres.intervalles'));
432
		$this->intervalles = $this->inverserTableau($this->getParametreTableau('Parametres.intervalles'));
432
		$this->motifs = $this->inverserTableau($this->getParametreTableau('Parametres.motifs'));
433
		$this->motifs = $this->inverserTableau($this->getParametreTableau('Parametres.motifs'));
433
		
434
		
434
	}
435
	}
435
 
436
 
436
	private function getParametreTableau($cle) {
437
	private function getParametreTableau($cle) {
437
		$tableau = array();
438
		$tableau = array();
438
		$parametre = Config::get($cle);
439
		$parametre = Config::get($cle);
439
		if (empty($parametre) === false) {
440
		if (empty($parametre) === false) {
440
			$tableauPartiel = explode(',', $parametre);
441
			$tableauPartiel = explode(',', $parametre);
441
			$tableauPartiel = array_map('trim', $tableauPartiel);
442
			$tableauPartiel = array_map('trim', $tableauPartiel);
442
			foreach ($tableauPartiel as $champ) {
443
			foreach ($tableauPartiel as $champ) {
443
				if (strpos($champ, '=') !== false && strlen($champ) >= 3) {
444
				if (strpos($champ, '=') !== false && strlen($champ) >= 3) {
444
					list($cle, $val) = explode('=', $champ);
445
					list($cle, $val) = explode('=', $champ);
445
					$tableau[trim($cle)] = trim($val);
446
					$tableau[trim($cle)] = trim($val);
446
				} else {
447
				} else {
447
					$tableau[] = trim($champ);
448
					$tableau[] = trim($champ);
448
				}
449
				}
449
			}
450
			}
450
		}
451
		}
451
		return $tableau;
452
		return $tableau;
452
	}
453
	}
453
 
454
 
454
	private function inverserTableau($tableau) {
455
	private function inverserTableau($tableau) {
455
		$inverse = array();
456
		$inverse = array();
456
		foreach ($tableau as $cle => $valeurs) {
457
		foreach ($tableau as $cle => $valeurs) {
457
			$valeurs = explode(';', $valeurs);
458
			$valeurs = explode(';', $valeurs);
458
			foreach ($valeurs as $valeur) {
459
			foreach ($valeurs as $valeur) {
459
				$inverse[$valeur] = $cle;
460
				$inverse[$valeur] = $cle;
460
			}
461
			}
461
		}
462
		}
462
		return $inverse;
463
		return $inverse;
463
	}
464
	}
464
 
465
 
465
	//+------------------------------------------------------------------------------------------------------+
466
	//+------------------------------------------------------------------------------------------------------+
466
	// Gestion du Log
467
	// Gestion du Log
467
 
468
 
468
	private function ajouterAuLog($txt) {
469
	private function ajouterAuLog($txt) {
469
		$this->log .= "$txt\n";
470
		$this->log .= "$txt\n";
470
	}
471
	}
471
 
472
 
472
	private function ecrireFichierLog() {
473
	private function ecrireFichierLog() {
473
		$fichierLog = dirname(__FILE__).'/log/verification.log';
474
		$fichierLog = dirname(__FILE__).'/log/verification.log';
474
		file_put_contents($fichierLog, $this->log);
475
		file_put_contents($fichierLog, $this->log);
475
	}
476
	}
476
}
477
}
477
?>
478
?>