Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 1517 Rev 1518
Line 40... Line 40...
40
		switch ($cmd) {
40
		switch ($cmd) {
41
			case 'tout' :
41
			case 'tout' :
42
				// à effectuer manuellement au premier lancement du script
42
				// à effectuer manuellement au premier lancement du script
43
				$this->creerColonne();
43
				$this->creerColonne();
44
				$this->calculerCodeInsee();
44
				$this->calculerCodeInsee();
45
				// modifierCodeInsee semble poser problème sur le serveur après beaucoup de requetes
-
 
46
				//$this->modifierCodeInsee();
45
				//$this->modifierCodeInsee();
47
				break;
46
				break;
48
			case 'sanscorrespondance' :
47
			case 'sanscorrespondance' :
49
				// devrait être être l'option utilisée dans le cron quotidien
48
				// devrait être être l'option utilisée dans le cron quotidien
50
				$this->calculerCodeInseeSansCorrespondance();
49
				$this->calculerCodeInseeSansCorrespondance();
51
				// modifierCodeInsee semble poser problème sur le serveur après beaucoup de requetes
-
 
52
				//$this->modifierCodeInsee();
50
				//$this->modifierCodeInsee();
53
			break;
51
			break;
54
			case 'colonne' :
52
			case 'colonne' :
55
				$this->creerColonne();
53
				$this->creerColonne();
56
				break;
54
				break;
Line 100... Line 98...
100
					}
98
					}
101
				}
99
				}
102
			}
100
			}
103
			$i++;
101
			$i++;
104
			$this->afficherAvancement('  Lignes traitées ', $i);
102
			$this->afficherAvancement('  Lignes traitées ', $i);
-
 
103
			
-
 
104
			// pause toutes les 1000 requêtes
-
 
105
			if($i %1000 == 0) {
-
 
106
				sleep(2);
-
 
107
			}
105
		}
108
		}
106
		echo "\n";
109
		echo "\n";
107
		$fin = microtime(true);
110
		$fin = microtime(true);
108
		echo "-------------------------------------------------------------------\n";
111
		echo "-------------------------------------------------------------------\n";
109
		echo "  Fin du traitement, ".($fin - $debut)." secondes écoulées \n";
112
		echo "  Fin du traitement, ".($fin - $debut)." secondes écoulées \n";
Line 114... Line 117...
114
	private function modifierCodeInsee() {
117
	private function modifierCodeInsee() {
115
		$this->dao->modifierCodeInsee();
118
		$this->dao->modifierCodeInsee();
116
	}
119
	}
Line 117... Line 120...
117
	
120
	
118
	private function chercherCodeCommune($projet, $latitude, $longitude) {
-
 
119
		$code_insee = '';
121
	private function chercherCodeCommune($projet, $latitude, $longitude) {
120
		$url_service = "www.tela-botanica.org/service:eflore:0.1/{$projet}/nom-commune".
122
		$url_service = "www.tela-botanica.org/service:eflore:0.1/{$projet}/nom-commune".
Line 121... Line 123...
121
					"?lat={$latitude}&lon={$longitude}";
123
					"?lat={$latitude}&lon={$longitude}";
122
		
124
		
123
		$url_service = str_replace(',', '.', $url_service);
125
		$url_service = str_replace(',', '.', $url_service);
124
		$ch = curl_init($url_service);
126
		$ch = curl_init($url_service);
-
 
127
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
-
 
128
		$reponse = curl_exec($ch);
-
 
129
		$reponse = $this->traiterReponseServiceCommune($response);
-
 
130
		curl_close($ch);
-
 
131
		
-
 
132
		return $code_insee;
-
 
133
	}
-
 
134
 
125
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
135
	private function traiterReponseServiceCommune($response) {
-
 
136
		$code_insee = '';
-
 
137
		$reponse = json_decode($reponse);
-
 
138
		// cas du service lion 1906 qui peut renvoyer plusieurs communes (on prend la première)
-
 
139
		if(is_array($reponse)) {
126
		$reponse = curl_exec($ch);
140
			$reponse = $reponse[0];
127
		$reponse = json_decode($reponse);
141
		}
128
		if (isset($reponse->codeINSEE)) {
142
		if (isset($reponse->codeINSEE)) {
129
			$code_insee = $reponse->codeINSEE;
-
 
130
		} 
-
 
131
		curl_close($ch);
143
			$code_insee = $reponse->codeINSEE;
132
		
144
		} 
Line 133... Line 145...
133
		return $code_insee;
145
		return $code_insee;
134
	}
146
	}
Line 184... Line 196...
184
			$ligneDecoupe['longitude'] = null;
196
			$ligneDecoupe['longitude'] = null;
185
		}
197
		}
186
		return $ligneDecoupe;
198
		return $ligneDecoupe;
187
	}
199
	}
188
}
200
}
189
?>
201
?>
190
202