Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 416 | Rev 439 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 416 Rev 433
Line 3... Line 3...
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 {
Line 6... Line 6...
6
	
6
 
-
 
7
	private $table = null;
-
 
8
	private $fichierDonnees = '';
7
	private $table = null;
9
	private $log = '';
8
	private $nb_erreurs; 
10
	private $nb_erreurs;
9
	private $erreurs_ligne;
11
	private $erreurs_ligne;
10
	private $ligne_num;
12
	private $ligne_num;
11
	private $colonne_valeur;
13
	private $colonne_valeur;
12
	private $colonne_num;
14
	private $colonne_num;
13
	private $type_bio = array(
-
 
14
		"A","a","B","b","C","c","Cfru","cfru","Csuf","csuf","Ccou","ccou","H","h","Heri",
-
 
15
		"heri","Hsto","hsto","Hces","hces","Hros","hros","Hrub","hrub","Hbis","hbis","G",
-
 
16
		"g","Gbul","gbul","Gtub","gtub","Grhi","grhi","T","t","Tver","tver","Test","test");
15
	private $type_bio = array();
17
	private $ss_type_bio = array("aqua", "lia", "épi", "hpar", "par", "suc", "semp", "cad", "car");
16
	private $ss_type_bio = array();
18
	//les deux suivants 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 !)
19
	private $signes_seuls = array("?", "x", "x~", "x=","xb","xB","-"); 
18
	private $signes_nn_seuls = array();// basés sur valeurs trouvées (--> pas de légende !)
20
	private $signes_nn_seuls = array("~", "=","b","B");
19
	private $intervalles = array();
21
	//paramètres pour lancement de fonctions sur colonnes
-
 
22
	private $verifierIntervalle = array(23 => array(1,9), 24 => array(1,9), 25 => array(1,9),
-
 
23
		26 => array(1,9), 27 => array(1,12), 28 => array(1,9), 29 => array(1,9), 30 => array(0,9),
-
 
24
		31 => array(1,9), 32 => array(1,9), 33 => array(1,9), 34 => array(1,9), 35 => array(1,9),
-
 
25
		36 => array(1,12), 37 => array(1,9), 38 => array(1,9), 39 => array(0,9),);
-
 
26
	private $verifierColonnesBasiques = array(1 =>"/(^[0-9]*\/)|(inconnu)/", 2 => "/(^[AB]?[0-9]+$)|(^nc$)/",
-
 
27
		3 => "/(^[AB]?[0-9]+$)|(^nc$)/", 4 => "/[^0-9]+/", 5 => "/[^0-9]+/", 6 => "/[^0-9]+/", 7 => "/[^0-9]+/",
-
 
28
		8 => "/[^0-9]+/", 9 => "/[^0-9]+/", 10 => "/[^0-9]+/", 11 => "/[^0-9]+/", 12 => "/[^0-9]+/",
-
 
29
		13 => "/[^0-9]+/", 14 => "/^([1-9]|1[0-2])(\-([1-9]|1[0-2]))*$/", 16 => "/[^0-9]+/", 19 => "/[^0-9]+/", 
-
 
30
		20 => "/[^0-9]+/", 21 => "/[^0-9]+/", 22 => "/[^0-9]+/",  40 => "/[^0-9]+/", 
-
 
31
		41 => "/[^0-9]+/", 42 => "/[^0-9]+/", 43 => "/[^0-9]+/", 44 => "/[^0-9]+/", 45 => "/[^0-9]+/", 
-
 
32
		46 => "/[^0-9]+/", 47 => "/[^0-9]+/", 48 => "/[^0-9]+/", 49 => "/[^0-9]+/", 50 => "/[^0-9]+/", 
-
 
33
		51 => "/[^0-9]+/", 52 => "/[^0-9]+/", 53 => "/[^0-9]+/", 54 => "/[^0-9]+/", 55 => "/[^0-9]+/"
-
 
34
		);
-
 
Line 35... Line 20...
35
 
20
	private $motifs = array();
36
	
-
 
37
	public function executer() {
21
 
38
		// Lancement de l'action demandée
22
	public function executer() {
39
		try {
23
		try {
40
			$this->initialiserProjet('baseflor');
24
			$this->initialiserProjet('baseflor');
41
			$cmd = $this->getParametre('a');
25
			$cmd = $this->getParametre('a');
42
		    switch ($cmd) {
26
			switch ($cmd) {
43
		    	case 'chargerStructureSql' :
27
				case 'chargerStructureSql' :
44
	    			$this->chargerStructureSql();
28
					$this->chargerStructureSql();
45
	    			break;
-
 
46
	    		case 'chargerDonnees' :
-
 
47
	    			$this->verifFichier();
29
					break;
48
	    			if($this->nb_erreurs == 0){
-
 
49
	    				$this->chargerDonnees();
-
 
50
	    				} else {
-
 
51
	    				echo "je ne peux pas charger les données car le fichier comporte des erreurs.
-
 
52
	    				Voir le fichier baseflor_verif.txt\n";
-
 
53
	    			}
-
 
54
	    			break;
-
 
55
				case 'supprimerTous' :
30
				case 'chargerMetadonnees':
56
					$this->supprimerTous();
31
					$this->chargerMetadonnees();
57
					break;
32
					break;
58
				case 'chargerOntologies' :
33
				case 'chargerOntologies' :
59
					$this->chargerOntologies();
34
					$this->chargerOntologies();
60
					break;
35
					break;
61
				case 'verifierDonnees' :
36
				case 'verifierDonnees' :
-
 
37
					$this->verifFichier();
-
 
38
					break;
-
 
39
				case 'chargerDonnees' :
62
					 $this->verifFichier();
40
					$this->chargerDonnees();
63
					 break;
41
					break;
64
				case 'genererChamps' :
-
 
65
					 $this->genererChpsBDNT();
-
 
66
					 $this->genererChpsNumTaxon();
42
				case 'genererChamps' :
67
					 $this->genererChpsNumNomen();
43
					 $this->genererChamps();
-
 
44
					 break;
68
					 break;
45
				case 'chargerTous':
-
 
46
					$this->chargerStructureSql();
-
 
47
					$this->chargerMetadonnees();
-
 
48
					$this->chargerOntologies();
-
 
49
					$this->chargerDonnees();
-
 
50
					$this->genererChamps();
-
 
51
					break;
69
				case 'chargerMetadonnees':
52
				case 'supprimerTous' :
70
					$this->chargerMetadonnees();
53
					$this->supprimerTous();
71
					break;
54
					break;
72
				default :
55
				default :
73
					throw new Exception("Erreur : la commande '$cmd' n'existe pas!");
56
					throw new Exception("Erreur : la commande '$cmd' n'existe pas!");
74
			}
57
			}
75
		} catch (Exception $e) {
58
		} catch (Exception $e) {
76
			$this->traiterErreur($e->getMessage());
59
			$this->traiterErreur($e->getMessage());
Line 77... Line -...
77
		}
-
 
78
    }
-
 
79
    
-
 
80
   
60
		}
81
    
-
 
82
   //-- génération de champs --// 
-
 
83
    private function genererChamps(){  
-
 
84
    	$this->genererChpsBDNT();
-
 
85
    	$this->genererChpsNumTaxon();
-
 
86
    	$this->genererChpsNumNomen();
-
 
87
    }
61
	}
88
    
62
 
89
    private function genererChpsBDNT(){
-
 
90
    	$this->initialiserGenerationChamps();
-
 
91
    	$this->preparerTablePrChpsBDNT();
-
 
92
    	$resultats = $this->recupererTuplesNumsOriginels();
-
 
93
    	$bdnt = array();
-
 
94
    	foreach ($resultats as $chps => $res) {
63
	private function genererChamps(){
95
    		$cle = $res['cle'];
-
 
96
    		$nno = $res['num_nomen_originel'];
-
 
97
    		$nto = $res['num_taxon_originel'];
-
 
98
    		if ( (preg_match("/^([AB])[0-9]+$/", $nno, $retour)) || (preg_match("/^([AB])[0-9]+$/", $nto, $retour)) ){
-
 
99
    			if($retour[1]=='A'){
-
 
100
    				$bdnt[$cle]= "BDAFX";
-
 
101
    			}else{
-
 
102
    				$bdnt[$cle]= "BDBFX";
-
 
103
    			}
-
 
104
    			
-
 
105
    		}elseif(($nno == 'nc') && ($nto == 'nc')){
-
 
106
    			$bdnt[$cle]= "nc";
64
		$this->initialiserGenerationChamps();
Line 107... Line 65...
107
    		}else{
65
		$this->ajouterChamps();
108
    			$bdnt[$cle]= "BDTFX";
66
		$this->analyserChampsExistant();
109
    		}
67
	}
Line 110... Line 68...
110
    		
68
 
111
    	}
69
	private function initialiserGenerationChamps() {
112
    	$this->remplirChamps($bdnt, "BDNT");
70
		$this->table = Config::get('tables.donnees');
113
    }
-
 
114
    
-
 
115
    private function genererChpsNumTaxon(){
-
 
116
    	$this->initialiserGenerationChamps();
-
 
117
    	$this->preparerTablePrChpsNumTaxon();
-
 
118
    	$resultats = $this->recupererTuplesNumsOriginels();
-
 
119
    	$num_taxon= array();
-
 
120
    	foreach ($resultats as $chps => $res) {
-
 
121
    		$cle = $res['cle'];
-
 
122
    	  	$nto = $res['num_taxon_originel'];
-
 
123
    		if  (preg_match("/^[AB]([0-9]+)$/", $nto, $retour)){
-
 
124
    			$num_taxon[$cle]= intval($retour[1]);
-
 
125
    		}elseif($nto == 'nc'){
-
 
126
    			$num_taxon[$cle]= 0;
-
 
127
    		}else{
-
 
128
    			$num_taxon[$cle]= intval($nto);
-
 
129
    		}
-
 
130
    
-
 
131
    	}
-
 
132
    	$this->remplirChamps($num_taxon, "num_taxon");
71
	}
133
    }
-
 
134
    
-
 
135
    private function genererChpsNumNomen(){
-
 
136
    	$this->initialiserGenerationChamps();
-
 
137
    	$this->preparerTablePrChpsNumNomen();
-
 
138
    	$resultats = $this->recupererTuplesNumsOriginels();
-
 
139
    	$num_nomen= array();
-
 
140
    	foreach ($resultats as $chps => $res) {
-
 
141
    		$cle = $res['cle'];
-
 
142
    		$nno = $res['num_nomen_originel'];
-
 
143
    		if  (preg_match("/^[AB]([0-9]+)$/", $nno, $retour)){
-
 
144
				$num_nomen[$cle]= intval($retour[1]);
-
 
145
    		}elseif($nno == 'nc'){
-
 
146
    			$num_nomen[$cle]= 0;
-
 
147
    		}else{
-
 
148
    			$num_nomen[$cle]=intval($nno);
-
 
149
    		}
-
 
150
    	}
-
 
151
    	$this->remplirChamps($num_nomen, "num_nomen");
-
 
152
    }
-
 
153
    
-
 
154
     private function remplirChamps($champs, $nom_colonne) {
-
 
155
    	foreach ($champs as $cle => $val) {
-
 
156
    		$val = $this->getBdd()->proteger($val);
-
 
157
    		$requete = "UPDATE {$this->table} SET $nom_colonne = $val WHERE cle = $cle ";
-
 
158
    		$resultat = $this->getBdd()->requeter($requete);
-
 
159
    		if ($resultat === false) {
-
 
160
    			throw new Exception("Erreur d'insertion pour le tuple clé = ".$cle);
-
 
161
    		}
-
 
162
    		$this->afficherAvancement("Insertion des valeurs pour ".$nom_colonne." dans la base en cours");
-
 
163
    	}
-
 
164
    	echo "\n";
-
 
165
    }
-
 
166
    
-
 
167
    
72
 
Line 168... Line 73...
168
 
73
	private function ajouterChamps() {
169
    
74
		$this->preparerTablePrChpsBDNT();
170
    private function initialiserGenerationChamps() {
75
		$this->preparerTablePrChpsNumTaxon();
Line 202... Line 107...
202
            				'ADD num_nomen INT( 10 ) NOT NULL'.
107
					'ADD num_nomen INT( 10 ) NOT NULL '.
203
            				' AFTER catminat_code';
108
					'AFTER catminat_code';
204
    		$this->getBdd()->requeter($requete);
109
			$this->getBdd()->requeter($requete);
205
    	}
110
		}
206
    }
111
	}
-
 
112
 
-
 
113
	private function analyserChampsExistant() {
-
 
114
		$resultats = $this->recupererTuplesNumsOriginels();
-
 
115
		foreach ($resultats as $chps) {
-
 
116
			$cle = $chps['cle'];
-
 
117
			$nno = $chps['num_nomen_originel'];
-
 
118
			$nto = $chps['num_taxon_originel'];
-
 
119
 
-
 
120
			$valeurs = array();
-
 
121
			$valeurs["BDNT"] = $this->genererChpsBDNT($nno, $nto);
-
 
122
			$valeurs["num_taxon"] = $this->genererChpsNumTaxon($nto);
-
 
123
			$valeurs["num_nomen"] = $this->genererChpsNumNomen($nno);
-
 
124
 
-
 
125
			$this->remplirChamps($cle, $valeurs);
-
 
126
 
-
 
127
			$this->afficherAvancement("Insertion des valeurs dans la base en cours");
-
 
128
		}
-
 
129
		echo "\n";
-
 
130
	}
-
 
131
 
207
    private function recupererTuplesNumsOriginels(){
132
	private function recupererTuplesNumsOriginels(){
208
    	$requete = 'SELECT cle, num_taxon_originel, num_nomen_originel '.
133
		$requete = "SELECT cle, num_taxon_originel, num_nomen_originel FROM {$this->table} ";
209
    					"FROM {$this->table} ";
-
 
210
    	$resultat = $this->getBdd()->recupererTous($requete);
134
		$resultat = $this->getBdd()->recupererTous($requete);
211
    	return $resultat;
135
		return $resultat;
212
    }
136
	}
Line -... Line 137...
-
 
137
 
-
 
138
	private function genererChpsBDNT($nno, $nto) {
-
 
139
		$bdnt = '';
-
 
140
		if (preg_match("/^([AB])[0-9]+$/", $nno, $retour) || preg_match("/^([AB])[0-9]+$/", $nto, $retour)){
-
 
141
			if ($retour[1]=='A') {
-
 
142
				$bdnt = "BDAFX";
-
 
143
			} else {
-
 
144
				$bdnt = "BDBFX";
-
 
145
			}
-
 
146
		} elseif (($nno == 'nc') && ($nto == 'nc')) {
-
 
147
			$bdnt = "nc";
-
 
148
		} else {
-
 
149
			$bdnt = "BDTFX";
-
 
150
		}
-
 
151
		return $bdnt;
-
 
152
	}
-
 
153
 
-
 
154
	private function genererChpsNumTaxon($nto){
-
 
155
		$num_taxon = '';
-
 
156
		if (preg_match("/^[AB]([0-9]+)$/", $nto, $retour)) {
-
 
157
			$num_taxon = intval($retour[1]);
-
 
158
		} elseif($nto == 'nc') {
-
 
159
			$num_taxon = 0;
-
 
160
		} else {
-
 
161
			$num_taxon = intval($nto);
-
 
162
		}
-
 
163
		return $num_taxon;
-
 
164
	}
-
 
165
 
-
 
166
	private function genererChpsNumNomen($nno) {
-
 
167
		$num_nomen = '';
-
 
168
		if (preg_match("/^[AB]([0-9]+)$/", $nno, $retour)) {
-
 
169
			$num_nomen = intval($retour[1]);
-
 
170
		} elseif ($nno == 'nc') {
-
 
171
			$num_nomen = 0;
-
 
172
		} else {
-
 
173
			$num_nomen = intval($nno);
-
 
174
		}
-
 
175
		return $num_nomen;
-
 
176
	}
-
 
177
 
-
 
178
	 private function remplirChamps($cle, $valeurs) {
-
 
179
		foreach ($valeurs as $nomChamp => $valeurChamp) {
-
 
180
			$valeurChamp = $this->getBdd()->proteger($valeurChamp);
-
 
181
			$requete = "UPDATE {$this->table} SET $nomChamp = $valeurChamp WHERE cle = $cle ";
-
 
182
			$resultat = $this->getBdd()->requeter($requete);
-
 
183
			if ($resultat === false) {
-
 
184
				throw new Exception("Erreur d'insertion pour le tuple clé = $cle");
-
 
185
			}
-
 
186
		}
-
 
187
	}
-
 
188
 
213
    
189
	//+------------------------------------------------------------------------------------------------------+
Line 214... Line 190...
214
    //-- chargements, suppression, exécution  --//
190
	// chargements, suppression, exécution
215
    
191
 
216
    protected function chargerMetadonnees() {
192
	protected function chargerMetadonnees() {
217
    	$contenuSql = $this->recupererContenu(Config::get('chemins.metadonnees'));
193
		$contenuSql = $this->recupererContenu(Config::get('chemins.metadonnees'));
Line 233... Line 209...
233
    }
209
	}
Line 234... Line 210...
234
    
210
 
235
    protected function chargerStructureSql() {
211
	protected function chargerStructureSql() {
236
    	$contenuSql = $this->recupererContenu(Config::get('chemins.structureSql'));
212
		$contenuSql = $this->recupererContenu(Config::get('chemins.structureSql'));
237
     	$this->executerScripSql($contenuSql);
-
 
238
    
213
		$this->executerScripSql($contenuSql);
Line 239... Line -...
239
    }
-
 
240
    
214
	}
241
    
215
 
242
    protected function executerScripSql($sql) {
216
	protected function executerScripSql($sql) {
243
    	$requetes = Outils::extraireRequetes($sql);
217
		$requetes = Outils::extraireRequetes($sql);
244
    	foreach ($requetes as $requete) {
218
		foreach ($requetes as $requete) {
245
    		$this->getBdd()->requeter($requete);
219
			$this->getBdd()->requeter($requete);
Line 246... Line 220...
246
    	}
220
		}
-
 
221
	}
-
 
222
 
-
 
223
	private function chargerDonnees() {
-
 
224
		$this->verifFichier();
-
 
225
		if ($this->nb_erreurs > 0) {
-
 
226
			$e = "Je ne peux pas charger les données car le fichier comporte des erreurs.".
-
 
227
					"Voir le fichier baseflor_verif.txt\n";
247
    }
228
			throw new Exception($e);
248
 
229
		}
249
    private function chargerDonnees() {
230
 
250
    	$table = Config::get('tables.donnees');
231
		$table = Config::get('tables.donnees');
251
    	$requete = "LOAD DATA INFILE '".Config::get('chemins.donnees')."' ".
232
		$requete = "LOAD DATA INFILE '".Config::get('chemins.donnees')."' ".
Line 261... Line 242...
261
    private function supprimerTous() {
242
	private function supprimerTous() {
262
    	$requete = "DROP TABLE IF EXISTS baseflor_meta, baseflor_ontologies, baseflor_v2012_03_19";
243
		$requete = "DROP TABLE IF EXISTS baseflor_meta, baseflor_ontologies, baseflor_v2012_03_19";
263
    	$this->getBdd()->requeter($requete);
244
		$this->getBdd()->requeter($requete);
264
    }
245
	}
Line -... Line 246...
-
 
246
 
-
 
247
	//+------------------------------------------------------------------------------------------------------+
Line 265... Line 248...
265
	
248
	// vérifications de données
-
 
249
 
-
 
250
	//verifie la cohérence des valeurs des colonnes
Line 266... Line 251...
266
    
251
	private function verifFichier(){
267
    //-- vérifications de données  --//
252
		$this->initialiserParametresVerif();
-
 
253
 
268
    
254
		$lignes = file($this->fichierDonnees, FILE_IGNORE_NEW_LINES);
269
    private function verifierSiVide(){
255
		if ($lignes != false) {
-
 
256
			$this->ajouterAuLog("!!! REGARDEZ LES COLONNES DANS NUMERO_COLONNES_IMPORTANT.TXT.");
270
    	$bool=false;
257
			foreach ($lignes as $this->ligne_num => $ligne) {
271
    	if ( $this->colonne_valeur  == "" ){
258
				$this->verifierErreursLigne($ligne);
-
 
259
				$this->afficherAvancement("Vérification des lignes");
-
 
260
			}
272
    		$bool=true;
261
			echo "\n";
Line 273... Line -...
273
    	}
-
 
274
    	return $bool;
262
		} else {
275
    }
263
			$this->traiterErreur("Le fichier {$this->fichierDonnees} ne peut pas être ouvert.");
276
    
-
 
277
    
264
		}
-
 
265
 
Line 278... Line -...
278
    private function verifierIntervallesTous($valeur){
-
 
279
    	$intervalle=$this->verifierIntervalle[$this->colonne_num];
-
 
280
      	$this->verifierIntervalleChiffres($intervalle[0], $intervalle[1],$valeur);
-
 
281
    }
-
 
282
    
266
		if ($this->nb_erreurs == 0) {
283
 
267
			$this->ajouterAuLog("Il n'y a pas d'erreurs.");
Line -... Line 268...
-
 
268
		}
-
 
269
		$this->traiterInfo($this->nb_erreurs." erreurs");
-
 
270
 
-
 
271
		$this->ecrireFichierLog();
-
 
272
	}
-
 
273
 
-
 
274
	//vérifie par colonnes les erreurs d'une ligne
-
 
275
	private function verifierErreursLigne($ligne){
-
 
276
		$this->erreurs_ligne = array();
-
 
277
		$colonnes = explode("\t", $ligne);
-
 
278
		if (isset($colonnes)) {
-
 
279
			foreach ($colonnes as $this->colonne_num => $this->colonne_valeur) {
-
 
280
				if (( $this->colonne_num > 0 && $this->colonne_num < 15 )
-
 
281
						|| $this->colonne_num == 16
-
 
282
						|| ($this->colonne_num > 18 && $this->colonne_num < 23)
-
 
283
						|| $this->colonne_num > 39) {
-
 
284
					$this->verifierColonne();
284
    private function verifierIntervalleChiffres($mini, $max, $valeur){
285
				} elseif ($this->colonne_num == 15) {
285
    	 if (( ($valeur < $mini) || ($valeur > $max) ) && ($valeur != "")){
-
 
286
    		$this->erreurs_ligne[$this->colonne_num] = $this->colonne_valeur;
-
 
287
   			$this->nb_erreurs++;
-
 
288
    	}
-
 
289
    	
-
 
290
    }
-
 
291
 
-
 
292
  
-
 
293
    private function verifierValeursIndic(){
286
					$this->verifierTypeBio();
294
    	if (( preg_match("/^([^0-9])*([0-9]+)([^0-9])*$/", $this->colonne_valeur,$retour) == 1  )){
287
				} elseif ($this->colonne_num >= 23 && $this->colonne_num <= 32) {
295
    		$this->verifierIntervallesTous($retour[2]);
288
					$this->verifierIntervalles($this->colonne_valeur);
296
    		if((isset($retour[3]))&&(!(in_array($retour[3], $this->signes_nn_seuls))) ){
289
				} elseif ($this->colonne_num >= 33 && $this->colonne_num < 41) {
297
    			$this->erreurs_ligne[$this->colonne_num] =$this->colonne_valeur;
-
 
298
    			$this->nb_erreurs++;
290
					$this->verifierValeursIndic();
-
 
291
				}
-
 
292
			}
299
    		}	
293
		} else {
-
 
294
			$message = "Ligne {$this->ligne_num} : pas de tabulation";
-
 
295
			$this->ajouterAuLog($message);
-
 
296
		}
300
    		if(($retour[1] != "-")&&($retour[1]!="") ){
297
 
301
    			$this->erreurs_ligne[$this->colonne_num] =$this->colonne_valeur;
298
		$this->controlerErreursLigne();
302
    			$this->nb_erreurs++;
-
 
303
    			if($this->ligne_num==3){
299
	}
304
    			}
300
 
Line -... Line 301...
-
 
301
	private function verifierColonne(){
-
 
302
		$motif = $this->motifs[$this->colonne_num];
-
 
303
		if (preg_match($motif, $this->colonne_valeur) == 0 && $this->verifierSiVide() == false){
-
 
304
			$this->erreurs_ligne[$this->colonne_num] = $this->colonne_valeur;
-
 
305
		}
305
    		}	
306
	}
306
    	}elseif(!(in_array( $this->colonne_valeur, $this->signes_seuls))&& !($this->verifierSiVide())) {
307
 
307
    			$this->erreurs_ligne[$this->colonne_num] = $this->colonne_valeur;
308
	private function verifierSiVide(){
308
    			$this->nb_erreurs++;
309
		$vide = ($this->colonne_valeur  == '') ? true : false;
309
    		}
310
		return $vide;
310
    }
311
	}
311
 
312
 
312
 private function verifierTypeBio(){
313
	private function verifierTypeBio(){
Line 313... Line 314...
313
 	if (( preg_match("/(.+)\((.+)\)$/", $this->colonne_valeur,$retour) == 1  )){
314
		if (preg_match("/(.+)\((.+)\)$/", $this->colonne_valeur, $retour) == 1) {
314
 		$this->verifType_SsType($retour[1]);
-
 
315
 		$this->verifType_SsType($retour[2]);
315
			$this->verifierTypeEtSsType($retour[1]);
316
 	}else{
316
			$this->verifierTypeEtSsType($retour[2]);
317
 		$this->verifType_SsType($this->colonne_valeur);
317
		} else {
-
 
318
			$this->verifierTypeEtSsType($this->colonne_valeur);
318
 	}
319
		}
-
 
320
	}
-
 
321
 
319
 }
322
	private function verifierTypeEtSsType($chaine_a_verif){
-
 
323
		if (preg_match("/^([a-zA-Zé]+)\-(.+)$|^([a-zA-Zé]+[^\-])$/", $chaine_a_verif, $retour) == 1) {
-
 
324
			$type = (isset($retour[3])) ? $retour[3] : $retour[1];
320
 
325
			$this->verifierType($type);
321
    private function verifType_SsType($chaine_a_verif){
326
 
322
    	//verifie type
-
 
323
    	if(( preg_match("/^([a-zA-Zé]+)\-(.+)$|^([a-zA-Zé]+[^\-])$/", $chaine_a_verif, $retour) == 1  )){
327
			$sousType = $retour[2];
324
    		$type=$retour[1];
-
 
325
    		if(isset($retour[3])){
-
 
326
    			$type=$retour[3];
-
 
327
    		}
-
 
328
    		 if(!(in_array($type, $this->type_bio))) {
-
 
329
    			$this->erreurs_ligne[$this->colonne_num] = $this->colonne_valeur;
328
			$this->verifierSousType($sousType);
-
 
329
		}
-
 
330
	}
-
 
331
 
-
 
332
	private function verifierType($type) {
330
    			$this->nb_erreurs++;
333
		if (in_array($type, $this->type_bio) == false) {
331
    		}
334
			$this->erreurs_ligne[$this->colonne_num] = $this->colonne_valeur;
332
    		//verifie sous_type(s)
335
		}
333
    		if ($retour[2]!=""){
-
 
334
    			$ss_type[0]=$retour[2];
-
 
335
    			if (( preg_match("/\-/", $ss_type[0])) == 1 ){
336
	}
336
    				$ss_type = preg_split("/\-/", $retour[2]);
337
 
337
    			}
338
	private function verifierSousType($sousType) {
338
    			foreach($ss_type as $sst){
339
		if ($sousType != ''){
Line 339... Line 340...
339
    				if(!(in_array($sst, $this->ss_type_bio))) {
340
			$ss_type = explode('-', $sousType);
-
 
341
			foreach ($ss_type as $sst) {
340
    					$this->erreurs_ligne[$this->colonne_num] = $this->colonne_valeur;
342
				if (in_array($sst, $this->ss_type_bio) == false) {
-
 
343
					$this->erreurs_ligne[$this->colonne_num] = $this->colonne_valeur;
341
    					$this->nb_erreurs++;
344
				}
342
    				}
345
			}
343
    			}
346
		}
344
    		}
347
	}
Line 345... Line -...
345
    	}
-
 
346
    }
348
 
347
 
-
 
348
    private function verifierColonne($chaine){
-
 
349
    	if ( ( preg_match($chaine, $this->colonne_valeur) == 0 ) && !($this->verifierSiVide()) ){
-
 
350
    		$this->erreurs_ligne[$this->colonne_num]=$this->colonne_valeur;
-
 
351
    		$this->nb_erreurs++;
-
 
352
    	}
349
	private function verifierIntervalles($valeur){
353
    }
-
 
354
    
-
 
355
    //vérifie par colonnes les erreurs d'une ligne 
350
		if ($valeur != '') {
356
   private function verifErreursLignes($colonne_array){
-
 
357
   	$this->erreurs_ligne=array();
-
 
358
     for ($this->colonne_num = 0; $this->colonne_num < count($colonne_array); $this->colonne_num++){
351
			list($min, $max) = explode('-', $this->intervalles[$this->colonne_num]);
359
     	 if ( isset($colonne_array) ){
352
			if ($valeur < $min || $valeur > $max){
360
     	 	$this->colonne_valeur = $colonne_array[$this->colonne_num];
-
 
361
   			if ( (( ($this->colonne_num > 0) && ($this->colonne_num < 15) ) || ( $this->colonne_num == 16 )  
-
 
362
   				|| (($this->colonne_num > 18 ) && ( $this->colonne_num < 23 ) ) 
353
				$this->erreurs_ligne[$this->colonne_num] = $this->colonne_valeur;
363
   				||  ( $this->colonne_num > 39 ))  ){
354
			}
364
   				$motif = $this->verifierColonnesBasiques[$this->colonne_num];
355
		}
365
   			  	$this->verifierColonne($motif);
356
	}
-
 
357
 
-
 
358
	private function verifierValeursIndic(){
366
   			}elseif ( $this->colonne_num == 15 ){
359
		if (preg_match("/^([^0-9])*([0-9]+)([^0-9])*$/", $this->colonne_valeur, $retour) == 1){
367
   				$this->verifierTypeBio();
-
 
368
   			} elseif (($this->colonne_num > 22 ) && ( $this->colonne_num < 33 )){
360
			$this->verifierIntervalles($retour[2]);
Line 369... Line -...
369
   				$this->verifierIntervallesTous($this->colonne_valeur);   				
-
 
370
   			}elseif (( $this->colonne_num > 32) && ( $this->colonne_num < 41)){
361
			if (isset($retour[3]) && in_array($retour[3], $this->signes_nn_seuls) == false){
371
   				  $this->verifierValeursIndic();
-
 
372
   			}
-
 
373
   		} else {
362
				$this->erreurs_ligne[$this->colonne_num] = $this->colonne_valeur;
374
   			echo "ligne ".$this->ligne_num.": pas de tabulation  \n ";
-
 
375
   		}	
-
 
376
   }
-
 
377
   
-
 
378
}
363
			}
379
    
-
 
380
    //verifie la cohérence des valeurs des colonnes 
-
 
381
    private function verifFichier(){
-
 
382
    	$dernier_nb_erreur = 0;
364
			if ($retour[1] != '-' && $retour[1] != ''){
383
    	if (file_exists(Config::get('chemins.donnees_verif'))) {
365
				$this->erreurs_ligne[$this->colonne_num] = $this->colonne_valeur;
384
    		unlink(Config::get('chemins.donnees_verif'));
-
 
385
    	}
366
			}
386
    	$fichier = fopen(Config::get('chemins.donnees'), "r");
-
 
387
    	$fichier2 = fopen(Config::get('chemins.donnees_verif'), "w");
-
 
388
    	$this->valeurs=array();
-
 
389
    	$this->nb_erreurs=0;
-
 
390
    	if ( ($fichier != false) && ($fichier2 != false) ){
-
 
391
    		$this->ligne_num=0;
-
 
392
    		while ( !feof($fichier) ) {
-
 
393
    			if ($this->ligne_num == 0){
-
 
394
    				fputs($fichier2," !!! REGARDEZ LES COLONNES DANS NUMERO_COLONNES_IMPORTANT.TXT.\n");
367
		} elseif (in_array( $this->colonne_valeur, $this->signes_seuls) == false && $this->verifierSiVide() == false) {
395
    			}
368
			$this->erreurs_ligne[$this->colonne_num] = $this->colonne_valeur;
396
    			$this->ligne_num++;
369
		}
-
 
370
	}
397
    			$ligne = fgets($fichier);
371
 
398
    			$col = preg_split("/	/", $ligne);
372
	private function controlerErreursLigne() {
-
 
373
		$nbreErreursLigne = count($this->erreurs_ligne);
-
 
374
		$this->nb_erreurs += $nbreErreursLigne;
-
 
375
		if ($nbreErreursLigne != 0) {
-
 
376
			$this->ajouterAuLog("Erreurs sur la ligne {$this->ligne_num}");
-
 
377
			$ligneLog = '';
-
 
378
			foreach ($this->erreurs_ligne as $cle => $v){
-
 
379
				$ligneLog .= "colonne $cle : $v - ";
-
 
380
			}
-
 
381
			$this->ajouterAuLog($ligneLog);
-
 
382
		}
-
 
383
	}
-
 
384
 
-
 
385
	//+------------------------------------------------------------------------------------------------------+
-
 
386
	// Chargement Paramètres
-
 
387
 
-
 
388
	private function initialiserParametresVerif() {
-
 
389
		$this->nb_erreurs = 0;
-
 
390
		$this->fichierDonnees = Config::get('chemins.donnees');
-
 
391
		$this->type_bio = $this->getParametreTableau('Parametres.typesBio');
-
 
392
		$this->ss_type_bio = $this->getParametreTableau('Parametres.sousTypesBio');
-
 
393
		$this->signes_seuls = $this->getParametreTableau('Parametres.signesSeuls');
-
 
394
		$this->signes_nn_seuls = $this->getParametreTableau('Parametres.signesNonSeuls');
-
 
395
		$this->intervalles = $this->inverserTableau($this->getParametreTableau('Parametres.intervalles'));
-
 
396
		$this->motifs = $this->inverserTableau($this->getParametreTableau('Parametres.motifs'));
-
 
397
	}
-
 
398
 
-
 
399
	private function getParametreTableau($cle) {
399
    			$this->verifErreursLignes($col);
400
		$tableau = array();
400
    			//rédaction du fichier de vérif
401
		$parametre = Config::get($cle);
401
    			if(count($this->nb_erreurs)!= 0){
-
 
402
    				if($dernier_nb_erreur != $this->nb_erreurs){
-
 
403
    					$dernier_nb_erreur = $this->nb_erreurs;
402
		if (empty($parametre) === false) {
404
    					fputs($fichier2," \n erreurs sur la ligne".$this->ligne_num."\n");
-
 
405
    					foreach ($this->erreurs_ligne as $cle => $v){
403
			$tableauPartiel = explode(',', $parametre);
406
    						fputs($fichier2,"colonne ".$cle." : ".$v." - ");
-
 
407
    					}
404
			$tableauPartiel = array_map('trim', $tableauPartiel);
Line -... Line 405...
-
 
405
			foreach ($tableauPartiel as $champ) {
-
 
406
				if (strpos($champ, '=') !== false && strlen($champ) >= 3) {
-
 
407
					list($cle, $val) = explode('=', $champ);
-
 
408
					$tableau[trim($cle)] = trim($val);
-
 
409
				} else {
-
 
410
					$tableau[] = trim($champ);
-
 
411
				}
-
 
412
			}
-
 
413
		}
-
 
414
		return $tableau;
Line -... Line 415...
-
 
415
	}
-
 
416
 
Line -... Line 417...
-
 
417
	private function inverserTableau($tableau) {
-
 
418
		$inverse = array();
408
    				}
419
		foreach ($tableau as $cle => $valeurs) {
Line -... Line 420...
-
 
420
			$valeurs = explode(';', $valeurs);
-
 
421
			foreach ($valeurs as $valeur) {
-
 
422
				$inverse[$valeur] = $cle;
-
 
423
			}
-
 
424
		}
409
    			} 
425
		return $inverse;
410
    		}  
426
	}