Completed
Push — master ( 3a53f6...03fc29 )
by Yannick
07:50 queued 02:22
created
require/class.Accident.php 1 patch
Braces   +69 added lines, -25 removed lines patch added patch discarded remove patch
@@ -85,8 +85,11 @@  discard block
 block discarded – undo
85 85
 			$data = array();
86 86
 			if ($row['registration'] != '') {
87 87
 				$image_array = $Image->getSpotterImage($row['registration']);
88
-				if (count($image_array) > 0) $data = array_merge($data,array('image' => $image_array[0]['image'],'image_thumbnail' => $image_array[0]['image_thumbnail'],'image_copyright' => $image_array[0]['image_copyright'],'image_source' => $image_array[0]['image_source'],'image_source_website' => $image_array[0]['image_source_website']));
89
-				else $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
88
+				if (count($image_array) > 0) {
89
+					$data = array_merge($data,array('image' => $image_array[0]['image'],'image_thumbnail' => $image_array[0]['image_thumbnail'],'image_copyright' => $image_array[0]['image_copyright'],'image_source' => $image_array[0]['image_source'],'image_source_website' => $image_array[0]['image_source_website']));
90
+				} else {
91
+					$data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
92
+				}
90 93
 				$aircraft_type = $Spotter->getAllAircraftTypeByRegistration($row['registration']);
91 94
 				$aircraft_info = $Spotter->getAllAircraftInfo($aircraft_type);
92 95
 				if (!empty($aircraft_info)) {
@@ -102,32 +105,50 @@  discard block
 block discarded – undo
102 105
 					$data['aircraft_base'] = $owner_data['base'];
103 106
 					$data['aircraft_date_first_reg'] = $owner_data['date_first_reg'];
104 107
 				}
105
-			} else $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
106
-			if ($row['registration'] == '') $row['registration'] = 'NA';
107
-			if ($row['ident'] == '') $row['ident'] = 'NA';
108
+			} else {
109
+				$data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
110
+			}
111
+			if ($row['registration'] == '') {
112
+				$row['registration'] = 'NA';
113
+			}
114
+			if ($row['ident'] == '') {
115
+				$row['ident'] = 'NA';
116
+			}
108 117
 			$identicao = $Spotter->getAllAirlineInfo(substr($row['ident'],0,2));
109 118
 			if (isset($identicao[0])) {
110 119
 				if (substr($row['ident'],0,2) == 'AF') {
111
-					if (filter_var(substr($row['ident'],2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) $icao = $row['ident'];
112
-					else $icao = 'AFR'.ltrim(substr($row['ident'],2),'0');
113
-				} else $icao = $identicao[0]['icao'].ltrim(substr($row['ident'],2),'0');
120
+					if (filter_var(substr($row['ident'],2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) {
121
+						$icao = $row['ident'];
122
+					} else {
123
+						$icao = 'AFR'.ltrim(substr($row['ident'],2),'0');
124
+					}
125
+				} else {
126
+					$icao = $identicao[0]['icao'].ltrim(substr($row['ident'],2),'0');
127
+				}
114 128
 				$data = array_merge($data,array('airline_icao' => $identicao[0]['icao'],'airline_name' => $identicao[0]['name']));
115
-			} else $icao = $row['ident'];
129
+			} else {
130
+				$icao = $row['ident'];
131
+			}
116 132
 			$icao = $Translation->checkTranslation($icao,false);
117 133
 			//$data = array_merge($data,array('registration' => $row['registration'], 'date' => $row['date'], 'ident' => $icao,'url' => $row['url']));
118 134
 			$data = array_merge($row,$data);
119
-			if ($data['ident'] == null) $data['ident'] = $icao;
135
+			if ($data['ident'] == null) {
136
+				$data['ident'] = $icao;
137
+			}
120 138
 			if ($data['title'] == null) {
121 139
 				$data['message'] = $row['type'].' of '.$row['registration'].' at '.$row['place'].','.$row['country'];
122
-			} else $data['message'] = strtolower($data['title']);
140
+			} else {
141
+				$data['message'] = strtolower($data['title']);
142
+			}
123 143
 			$result[] = $data;
124 144
 			$i++;
125 145
 		}
126 146
 		if (isset($result)) {
127 147
 			$result[0]['query_number_rows'] = $i;
128 148
 			return $result;
149
+		} else {
150
+			return array();
129 151
 		}
130
-		else return array();
131 152
 	}
132 153
 	
133 154
 	
@@ -137,7 +158,9 @@  discard block
 block discarded – undo
137 158
 	*/
138 159
 	public function import($file) {
139 160
 		global $globalTransaction, $globalDebug;
140
-		if ($globalDebug) echo 'Import '.$file."\n";
161
+		if ($globalDebug) {
162
+			echo 'Import '.$file."\n";
163
+		}
141 164
 		$result = array();
142 165
 		if (file_exists($file)) {
143 166
 			if (($handle = fopen($file,'r')) !== FALSE) {
@@ -148,8 +171,11 @@  discard block
 block discarded – undo
148 171
 				}
149 172
 				fclose($handle);
150 173
 			}
151
-			if (!empty($result)) $this->add($result,true);
152
-			elseif ($globalDebug) echo 'Nothing to import';
174
+			if (!empty($result)) {
175
+				$this->add($result,true);
176
+			} elseif ($globalDebug) {
177
+				echo 'Nothing to import';
178
+			}
153 179
 		}
154 180
 	}
155 181
 
@@ -183,13 +209,20 @@  discard block
 block discarded – undo
183 209
 				}
184 210
 				fclose($handle);
185 211
 			}
186
-		} elseif ($globalDebug) echo 'Download cr-all.md5 failed. '.dirname(__FILE__).'/../install/tmp/cr-all.md5 not here.';
212
+		} elseif ($globalDebug) {
213
+			echo 'Download cr-all.md5 failed. '.dirname(__FILE__).'/../install/tmp/cr-all.md5 not here.';
214
+		}
187 215
 		$result = $Common->arr_diff($all_md5_new,$all_md5);
188
-		if (empty($result) && $globalDebug) echo 'Nothing to update';
216
+		if (empty($result) && $globalDebug) {
217
+			echo 'Nothing to update';
218
+		}
189 219
 		foreach ($result as $file => $md5) {
190 220
 			$Common->download('https://data.flightairmap.fr/data/cr/'.$file,dirname(__FILE__).'/../install/tmp/'.$file);
191
-			if (file_exists(dirname(__FILE__).'/../install/tmp/'.$file)) $this->import(dirname(__FILE__).'/../install/tmp/'.$file);
192
-			elseif ($globalDebug) echo 'Download '.$file.' failed';
221
+			if (file_exists(dirname(__FILE__).'/../install/tmp/'.$file)) {
222
+				$this->import(dirname(__FILE__).'/../install/tmp/'.$file);
223
+			} elseif ($globalDebug) {
224
+				echo 'Download '.$file.' failed';
225
+			}
193 226
 		}
194 227
 	}
195 228
 
@@ -200,13 +233,17 @@  discard block
 block discarded – undo
200 233
 		$Connection = new Connection();
201 234
 		$Image = new Image();
202 235
 
203
-		if (empty($crash)) return false;
236
+		if (empty($crash)) {
237
+			return false;
238
+		}
204 239
 		if (!$new) {
205 240
 			$query_delete = 'DELETE FROM accidents WHERE source = :source';
206 241
 			$sthd = $Connection->db->prepare($query_delete);
207 242
 			$sthd->execute(array(':source' => $crash[0]['source']));
208 243
 		}
209
-		if ($globalTransaction) $Connection->db->beginTransaction();
244
+		if ($globalTransaction) {
245
+			$Connection->db->beginTransaction();
246
+		}
210 247
 		$initial_array = array('ident' => null,'type' => 'accident','url' => null,'registration' => null, 'date' => null, 'place' => null,'country' => null, 'latitude' => null, 'longitude' => null, 'fatalities' => null, 'title' => '','source' => '','aircraft_manufacturer' => null,'aircraft_name' => null);
211 248
 		$query_check = 'SELECT COUNT(*) as nb FROM accidents WHERE registration = :registration AND date = :date AND type = :type AND source = :source';
212 249
 		$sth_check = $Connection->db->prepare($query_check);
@@ -241,9 +278,13 @@  discard block
 block discarded – undo
241 278
 					$Connection->db->beginTransaction();
242 279
 				}
243 280
 			}
244
-			if ($globalTransaction) $Connection->db->commit();
281
+			if ($globalTransaction) {
282
+				$Connection->db->commit();
283
+			}
245 284
 		} catch(PDOException $e) {
246
-			if ($globalTransaction) $Connection->db->rollBack();
285
+			if ($globalTransaction) {
286
+				$Connection->db->rollBack();
287
+			}
247 288
 			echo $e->getMessage();
248 289
 		}
249 290
 		$sth_check->closeCursor();
@@ -278,8 +319,11 @@  discard block
 block discarded – undo
278 319
 			return "error : ".$e->getMessage();
279 320
 		}
280 321
 		$row = $sth->fetch(PDO::FETCH_ASSOC);
281
-		if ($row['nb'] > 0) return false;
282
-		else return true;
322
+		if ($row['nb'] > 0) {
323
+			return false;
324
+		} else {
325
+			return true;
326
+		}
283 327
 	}
284 328
 
285 329
 	public static function insert_last_accidents_update() {
Please login to merge, or discard this patch.