Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

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