Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 336 | Rev 340 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 336 Rev 339
Line 136... Line 136...
136
			if ($resultat === false) {
136
			if ($resultat === false) {
137
				throw new Exception("Erreur d'insertion pour le tuple $id");
137
				throw new Exception("Erreur d'insertion pour le tuple $id");
138
			}
138
			}
139
		}
139
		}
140
	}
140
	}
141
	
141
 
142
	private function genererChpFamille() {
142
	private function genererChpFamille() {
143
		$this->initialiserGenerationChamps();
143
		$this->initialiserGenerationChamps();
144
		$this->preparerTablePrChpFamille();
144
		$this->preparerTablePrChpFamille();
145
		$resultats = $this->recupererTuplesPrChpFamille();
145
		$resultats = $this->recupererTuplesPrChpFamille();
146
		$famille = array();
146
		$famille = array();
147
		$noms = array();
147
		$noms = array();
148
		$introuvables = array();
148
		$introuvables = array();
-
 
149
		$introuvablesSyno = array();
149
		foreach ($resultats as $nom) {
150
		foreach ($resultats as $id => $nom) {
150
			$nn = $nom['num_nom'];
151
			$nn = $nom['num_nom'];
-
 
152
			$nnr = $nom['num_nom_retenu'];
151
			$nts = $nom['num_tax_sup'];
153
			$nts = $nom['num_tax_sup'];
152
			$rg = $nom['rang'];
154
			$rg = $nom['rang'];
153
			if ($rg == '180') {
155
			if ($nnr != '') {
154
				$famille[$nn] = $nom['nom_sci'];
-
 
155
			} else {
-
 
156
				if (isset($noms[$nts])) {
156
				if ($rg == '180') {
157
					$noms[$nn] = $noms[$nts];
157
					$famille[$nn] = $nom['nom_sci'];
158
				} else if (isset($famille[$nts])) {
-
 
159
					$noms[$nn] = $famille[$nts];
-
 
160
				} else {
158
				} else {
-
 
159
					if ($nn == $nnr) {// nom retenu
-
 
160
						if (isset($noms[$nts])) {
-
 
161
							$noms[$nn] = $noms[$nts];
-
 
162
						} else if (isset($famille[$nts])) {
-
 
163
							$noms[$nn] = $famille[$nts];
-
 
164
						} else {
161
					$introuvables[] = $nn;
165
							$introuvables[] = $nn;
-
 
166
						}
-
 
167
					} else {// nom synonyme
-
 
168
						if (isset($noms[$nnr])) {
-
 
169
							$noms[$nn] = $noms[$nnr];
-
 
170
						} else {
-
 
171
							$introuvablesSyno[] = $nom;
-
 
172
						}
-
 
173
					}
162
				}
174
				}
163
			}
175
			}
-
 
176
			unset($resultats[$id]);
164
			$this->afficherAvancement("Attribution de leur famille aux noms en cours");
177
			$this->afficherAvancement("Attribution de leur famille aux noms en cours");
165
			if ($this->stopperLaBoucle($this->getParametre('t'))) break;
178
			if ($this->stopperLaBoucle($this->getParametre('t'))) break;
166
		}
179
		}
167
		echo "\n";
180
		echo "\n";
-
 
181
 
-
 
182
		foreach ($introuvablesSyno as $id => $nom) {
-
 
183
			$nn = $nom['num_nom'];
-
 
184
			$nnr = $nom['num_nom_retenu'];
-
 
185
			if (isset($noms[$nnr])) {
-
 
186
				$noms[$nn] = $noms[$nnr];
-
 
187
			} else {
-
 
188
				$introuvables[] = $nn;
-
 
189
			}
-
 
190
			unset($introuvablesSyno[$id]);
-
 
191
			$this->afficherAvancement("Attribution de leur famille aux synonymes en cours");
-
 
192
		}
-
 
193
		echo "\n";
-
 
194
 
168
		if ($introuvables != 0) {
195
		if (count($introuvables) != 0) {
-
 
196
			$introuvablesNbre = count($introuvables);
-
 
197
			echo "Famille introuvable pour $introuvablesNbre noms ! Voir le log.\n";
-
 
198
 
-
 
199
			$logContenu = implode(", \n", $introuvables);
-
 
200
			$logFichier = realpath(dirname(__FILE__)).'/log/famille_introuvable.log';
-
 
201
			echo $logFichier."\n";
-
 
202
			file_put_contents($logFichier, $logContenu);
-
 
203
		}
-
 
204
		if (count($introuvablesSyno) != 0) {
169
			$introuvables = implode(', ', $introuvables);
205
			//$introuvablesSyno = implode(', ', $introuvablesSyno);
-
 
206
			$introuvablesSyno = count($introuvablesSyno);
170
			echo "Parent introuvable pour les noms : $introuvables\n";
207
			echo "Synonyme avec nom retenu introuvable : $introuvablesSyno\n";
171
		}
208
		}
172
		$this->lancerRequeteModificationPrChpFamille($noms);
209
		$this->lancerRequeteModificationPrChpFamille($noms);
173
	}
210
	}
174
	
211
 
175
	private function preparerTablePrChpFamille() {
212
	private function preparerTablePrChpFamille() {
176
		$requete = "SHOW COLUMNS FROM {$this->table} LIKE 'famille' ";
213
		$requete = "SHOW COLUMNS FROM {$this->table} LIKE 'famille' ";
177
		$resultat = $this->getBdd()->recuperer($requete);
214
		$resultat = $this->getBdd()->recuperer($requete);
178
		if ($resultat === false) {
215
		if ($resultat === false) {
179
			$requete = 	"ALTER TABLE {$this->table} ".
216
			$requete = 	"ALTER TABLE {$this->table} ".
180
				'ADD famille VARCHAR(255) '.
217
				'ADD famille VARCHAR(255) '.
181
				'CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ';
218
				'CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ';
182
			$this->getBdd()->requeter($requete);
219
			$this->getBdd()->requeter($requete);
183
		}
220
		}
184
	}
221
	}
185
	
222
 
186
	private function recupererTuplesPrChpFamille() {
223
	private function recupererTuplesPrChpFamille() {
187
		$requete = 'SELECT num_nom, num_tax_sup, rang, nom_sci '.
224
		$requete = 'SELECT num_nom, num_nom_retenu, num_tax_sup, rang, nom_sci '.
188
				"FROM {$this->table} ".
225
				"FROM {$this->table} ".
189
				"WHERE rang >= 180 ".
226
				"WHERE rang >= 180 ".
190
				"	AND num_tax_sup != '' ".
227
				"ORDER BY rang ASC, num_tax_sup ASC , num_nom_retenu DESC ";
191
				"ORDER BY rang ASC,num_tax_sup ASC ";
228
		//echo $requete."\n";
192
		$resultat = $this->getBdd()->recupererTous($requete);
229
		$resultat = $this->getBdd()->recupererTous($requete);
193
		return $resultat;
230
		return $resultat;
194
	}
231
	}
195
	
232
 
196
	private function lancerRequeteModificationPrChpFamille($noms) {
233
	private function lancerRequeteModificationPrChpFamille($noms) {
197
		foreach ($noms as $id => $famille) {
234
		foreach ($noms as $id => $famille) {
198
			$famille = $this->getBdd()->proteger($famille);
235
			$famille = $this->getBdd()->proteger($famille);
199
			$requete = "UPDATE {$this->table} ".
236
			$requete = "UPDATE {$this->table} ".
200
					"SET famille = $famille ".
237
					"SET famille = $famille ".