Completed
Push — openstreetmap ( 989c11...97b8ee )
by Greg
11:56
created
app/Module/OpenStreetMapModule.php 3 patches
Braces   +6 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1067,9 +1067,11 @@  discard block
 block discarded – undo
1067 1067
 		$delimiter   = '';
1068 1068
 		$field_names = ['pl_level', 'pl_long', 'pl_lati', 'pl_zoom', 'pl_icon', 'fqpn'];
1069 1069
 
1070
-		if ($serverfile !== '') {  // first choice is file on server
1070
+		if ($serverfile !== '') {
1071
+// first choice is file on server
1071 1072
 			$filename = WT_MODULES_DIR . $this->getName() . '/extra/' . $serverfile;
1072
-		} elseif ($_FILES['localfile']['error'] === UPLOAD_ERR_OK) { // 2nd choice is local file
1073
+		} elseif ($_FILES['localfile']['error'] === UPLOAD_ERR_OK) {
1074
+// 2nd choice is local file
1073 1075
 			$filename = $_FILES['localfile']['tmp_name'];
1074 1076
 		}
1075 1077
 
@@ -1090,7 +1092,8 @@  discard block
 block discarded – undo
1090 1092
 					$delimiter = ',';
1091 1093
 				}
1092 1094
 				if ($delimiter !== '') {
1093
-					if (!is_numeric($record[0])) { // lose the header
1095
+					if (!is_numeric($record[0])) {
1096
+// lose the header
1094 1097
 						array_shift($input_array);
1095 1098
 					}
1096 1099
 
Please login to merge, or discard this patch.
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -529,8 +529,8 @@  discard block
 block discarded – undo
529 529
 			case 'BaseData':
530 530
 				$varName = (self::$map_selections['style'] === '') ? '' : self::$map_providers[self::$map_selections['provider']]['styles'][self::$map_selections['style']];
531 531
 				$payload = ['selectedProvIndex' => self::$map_selections['provider'],
532
-				            'selectedProvName'  => self::$map_providers[self::$map_selections['provider']]['name'],
533
-				            'selectedStyleName' => $varName,
532
+										'selectedProvName'  => self::$map_providers[self::$map_selections['provider']]['name'],
533
+										'selectedStyleName' => $varName,
534 534
 				];
535 535
 				break;
536 536
 			case 'ProviderStyles':
@@ -543,9 +543,9 @@  discard block
 block discarded – undo
543 543
 					$providers[$key] = $provider['name'];
544 544
 				}
545 545
 				$payload = ['providers'     => $providers,
546
-				            'selectedProv'  => self::$map_selections['provider'],
547
-				            'styles'        => self::$map_providers[self::$map_selections['provider']]['styles'],
548
-				            'selectedStyle' => self::$map_selections['style'],
546
+										'selectedProv'  => self::$map_selections['provider'],
547
+										'styles'        => self::$map_providers[self::$map_selections['provider']]['styles'],
548
+										'selectedStyle' => self::$map_selections['style'],
549 549
 				];
550 550
 				break;
551 551
 			default:
@@ -1105,8 +1105,8 @@  discard block
 block discarded – undo
1105 1105
 					$row    = explode($delimiter, $input_array[0]);
1106 1106
 					$fields = count($row);
1107 1107
 					if ($fields >= 6 &&
1108
-					    (bool)preg_match("/[SN][0-9]*\.?[0-9]*/", $row[$fields - 3]) &&
1109
-					    (bool)preg_match("/[EW][0-9]*\.?[0-9]*/", $row[$fields - 4])) {
1108
+							(bool)preg_match("/[SN][0-9]*\.?[0-9]*/", $row[$fields - 3]) &&
1109
+							(bool)preg_match("/[EW][0-9]*\.?[0-9]*/", $row[$fields - 4])) {
1110 1110
 						$filetype = 'csv';
1111 1111
 					}
1112 1112
 				}
Please login to merge, or discard this patch.
Spacing   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
 						$color            = self::LINE_COLORS[log($id, 2) % $color_count];
298 298
 						$icon['color']    = $color; //make icon color the same as the line
299 299
 						$sosa_points[$id] = $event->getLatLonJSArray();
300
-						$sosa_parent      = (int)floor($id / 2);
300
+						$sosa_parent      = (int) floor($id / 2);
301 301
 						if (array_key_exists($sosa_parent, $sosa_points)) {
302 302
 							// Would like to use a GeometryCollection to hold LineStrings
303 303
 							// rather than generate polylines but the MarkerCluster library
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
 								'modules/openstreetmap/event-sidebar',
330 330
 								$event->shortSummary($mapType, $id)
331 331
 							),
332
-							'zoom'     => (int)$event->getZoom(),
332
+							'zoom'     => (int) $event->getZoom(),
333 333
 						],
334 334
 					];
335 335
 				}
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
 							'stats'    => $placeStats,
400 400
 						]
401 401
 					),
402
-					'zoom'    => (int)($location->getZoom() ?? 2),
402
+					'zoom'    => (int) ($location->getZoom() ?? 2),
403 403
 				],
404 404
 			];
405 405
 		}
@@ -451,7 +451,7 @@  discard block
 block discarded – undo
451 451
 		$xref        = $request->get('reference');
452 452
 		$tree        = $request->attributes->get('tree');
453 453
 		$individual  = Individual::getInstance($xref, $tree);
454
-		$generations = (int)$request->get(
454
+		$generations = (int) $request->get(
455 455
 			'generations',
456 456
 			$tree->getPreference('DEFAULT_PEDIGREE_GENERATIONS')
457 457
 		);
@@ -500,14 +500,14 @@  discard block
 block discarded – undo
500 500
 						function ($item) {
501 501
 							return preg_replace('/[^a-z\d]/i', '', strtolower($item));
502 502
 						},
503
-						(array)$provider->styles
503
+						(array) $provider->styles
504 504
 					);
505 505
 
506
-					$key = preg_replace('/[^a-z\d]/i', '', strtolower((string)$provider->name));
506
+					$key = preg_replace('/[^a-z\d]/i', '', strtolower((string) $provider->name));
507 507
 
508 508
 					self::$map_providers[$key] = [
509
-						'name'   => (string)$provider->name,
510
-						'styles' => array_combine($style_keys, (array)$provider->styles),
509
+						'name'   => (string) $provider->name,
510
+						'styles' => array_combine($style_keys, (array) $provider->styles),
511 511
 					];
512 512
 				}
513 513
 			} catch (\Exception $ex) {
@@ -516,7 +516,7 @@  discard block
 block discarded – undo
516 516
 					'provider' => 'openstreetmap',
517 517
 					'style'    => 'mapnik',
518 518
 				];
519
-				self::$map_providers  = [
519
+				self::$map_providers = [
520 520
 					'openstreetmap' => [
521 521
 						'name'   => 'OpenStreetMap',
522 522
 						'styles' => ['mapnik' => 'Mapnik'],
@@ -569,7 +569,7 @@  discard block
 block discarded – undo
569 569
 		$maxgenerations = $tree->getPreference('MAX_PEDIGREE_GENERATIONS');
570 570
 		$generations    = $request->get('generations', $tree->getPreference('DEFAULT_PEDIGREE_GENERATIONS'));
571 571
 
572
-		return (object)[
572
+		return (object) [
573 573
 			'name' => 'modules/openstreetmap/pedigreemap',
574 574
 			'data' => [
575 575
 				'assets'         => $this->assets(),
@@ -632,7 +632,7 @@  discard block
 block discarded – undo
632 632
 	 * @return object
633 633
 	 */
634 634
 	public function getAdminConfigAction(Request $request) {
635
-		return (object)[
635
+		return (object) [
636 636
 			'name' => 'modules/openstreetmap/admin-config',
637 637
 			'data' => [
638 638
 				'title'        => I18N::translate('Open Street Maps (Configuration)'),
@@ -688,8 +688,8 @@  discard block
 block discarded – undo
688 688
 	 * @throws \Exception
689 689
 	 */
690 690
 	public function getAdminPlacesAction(Request $request) {
691
-		$parent_id   = (int)$request->get('parent_id', 0);
692
-		$inactive    = (bool)$request->get('inactive');
691
+		$parent_id   = (int) $request->get('parent_id', 0);
692
+		$inactive    = (bool) $request->get('inactive');
693 693
 		$hierarchy   = $this->gethierarchy($parent_id);
694 694
 		$title       = I18N::translate('Open Street Maps (Geographic data)');
695 695
 		$breadcrumbs = [
@@ -712,7 +712,7 @@  discard block
 block discarded – undo
712 712
 		}
713 713
 		$breadcrumbs[] = array_pop($breadcrumbs);
714 714
 
715
-		return (object)[
715
+		return (object) [
716 716
 			'name' => 'modules/openstreetmap/admin-places',
717 717
 			'data' => [
718 718
 				'title'       => $title,
@@ -733,9 +733,9 @@  discard block
 block discarded – undo
733 733
 	 * @throws \Exception
734 734
 	 */
735 735
 	public function getAdminPlaceEditAction(Request $request) {
736
-		$parent_id = (int)$request->get('parent_id', 0);
737
-		$place_id  = (int)$request->get('place_id');
738
-		$inactive  = (int)$request->get('inactive');
736
+		$parent_id = (int) $request->get('parent_id', 0);
737
+		$place_id  = (int) $request->get('place_id');
738
+		$inactive  = (int) $request->get('inactive');
739 739
 		$hierarchy = $this->gethierarchy($place_id);
740 740
 		$fqpn      = empty($hierarchy) ? '' : $hierarchy[0]->fqpn;
741 741
 		$location  = new Location($fqpn);
@@ -771,7 +771,7 @@  discard block
 block discarded – undo
771 771
 		}
772 772
 		$breadcrumbs[] = $place_id === 0 ? I18N::translate('Add') : I18N::translate('Edit');
773 773
 
774
-		return (object)[
774
+		return (object) [
775 775
 			'name' => 'modules/openstreetmap/admin-place-edit',
776 776
 			'data' => [
777 777
 				'module'      => $this->getName(),
@@ -797,9 +797,9 @@  discard block
 block discarded – undo
797 797
 	 */
798 798
 	public function postAdminSaveAction(Request $request): RedirectResponse {
799 799
 		if (Filter::checkCsrf()) {
800
-			$parent_id = (int)$request->get('parent_id');
801
-			$place_id  = (int)$request->get('place_id');
802
-			$inactive  = (int)$request->get('inactive');
800
+			$parent_id = (int) $request->get('parent_id');
801
+			$place_id  = (int) $request->get('place_id');
802
+			$inactive  = (int) $request->get('inactive');
803 803
 			$lat       = round($request->get('new_place_lati'), 5); // 5 decimal places (locate to within about 1 metre)
804 804
 			$lat       = ($lat < 0 ? 'S' : 'N') . abs($lat);
805 805
 			$lng       = round($request->get('new_place_long'), 5);
@@ -818,7 +818,7 @@  discard block
 block discarded – undo
818 818
 						  VALUES (:id, :parent, :level, :place, :lng, :lat, :zoom, :icon)"
819 819
 				)->execute(
820 820
 					[
821
-						'id'     => (int)Database::prepare("SELECT MAX(pl_id)+1 FROM `##placelocation`")->fetchOne(),
821
+						'id'     => (int) Database::prepare("SELECT MAX(pl_id)+1 FROM `##placelocation`")->fetchOne(),
822 822
 						'parent' => $parent_id,
823 823
 						'level'  => $level,
824 824
 						'place'  => $request->get('new_place_name'),
@@ -837,7 +837,7 @@  discard block
 block discarded – undo
837 837
 						'place' => $request->get('new_place_name'),
838 838
 						'lat'   => $request->get('lati_control') . $lat,
839 839
 						'lng'   => $request->get('long_control') . $lng,
840
-						'zoom'  => (int)$request->get('new_zoom_factor'),
840
+						'zoom'  => (int) $request->get('new_zoom_factor'),
841 841
 						'icon'  => $icon,
842 842
 					]
843 843
 				);
@@ -870,9 +870,9 @@  discard block
 block discarded – undo
870 870
 	 */
871 871
 	public function postAdminDeleteRecordAction(Request $request): RedirectResponse {
872 872
 		if (Filter::checkCsrf()) {
873
-			$place_id  = (int)$request->get('place_id');
874
-			$parent_id = (int)$request->get('parent_id');
875
-			$inactive  = (int)$request->get('inactive');
873
+			$place_id  = (int) $request->get('place_id');
874
+			$parent_id = (int) $request->get('parent_id');
875
+			$inactive  = (int) $request->get('inactive');
876 876
 
877 877
 			try {
878 878
 				Database::prepare(
@@ -891,7 +891,7 @@  discard block
 block discarded – undo
891 891
 				);
892 892
 			}
893 893
 			// If after deleting there are no more places at this level then go up a level
894
-			$children = (int)Database::prepare(
894
+			$children = (int) Database::prepare(
895 895
 				"SELECT COUNT(pl_id) FROM `##placelocation` WHERE pl_parent_id = :parent_id"
896 896
 			)
897 897
 				->execute(['parent_id' => $parent_id])
@@ -924,9 +924,9 @@  discard block
 block discarded – undo
924 924
 	 * @throws \Exception
925 925
 	 */
926 926
 	public function getAdminExportAction(Request $request): RedirectResponse {
927
-		$parent_id = (int)$request->get('parent_id');
927
+		$parent_id = (int) $request->get('parent_id');
928 928
 		$format    = $request->get('format', 'csv');
929
-		$maxlevel  = (int)Database::prepare("SELECT max(pl_level) FROM `##placelocation`")->execute()->fetchOne();
929
+		$maxlevel  = (int) Database::prepare("SELECT max(pl_level) FROM `##placelocation`")->execute()->fetchOne();
930 930
 		$startfqpn = [];
931 931
 		$hierarchy = $this->gethierarchy($parent_id);
932 932
 		$geojson   = [];
@@ -978,8 +978,8 @@  discard block
 block discarded – undo
978 978
 							)
979 979
 						)
980 980
 					);
981
-					$long = (float)strtr($place['pl_long'], ['E' => '', 'W' => '-', ',' => '.']);
982
-					$lati = (float)strtr($place['pl_lati'], ['N' => '', 'S' => '-', ',' => '.']);
981
+					$long = (float) strtr($place['pl_long'], ['E' => '', 'W' => '-', ',' => '.']);
982
+					$lati = (float) strtr($place['pl_lati'], ['N' => '', 'S' => '-', ',' => '.']);
983 983
 
984 984
 					$geojson['features'][] = [
985 985
 						'type'       => 'Feature',
@@ -1015,8 +1015,8 @@  discard block
 block discarded – undo
1015 1015
 	 * @return object
1016 1016
 	 */
1017 1017
 	public function getAdminImportFormAction(Request $request) {
1018
-		$parent_id   = (int)$request->get('parent_id');
1019
-		$inactive    = (int)$request->get('inactive');
1018
+		$parent_id   = (int) $request->get('parent_id');
1019
+		$inactive    = (int) $request->get('inactive');
1020 1020
 		$breadcrumbs = [
1021 1021
 			route('admin-control-panel') => I18N::translate('Control panel'),
1022 1022
 			route('admin-modules')       => I18N::translate('Module administration'),
@@ -1031,7 +1031,7 @@  discard block
 block discarded – undo
1031 1031
 			)                            => $this->getTitle() . ' (' . I18N::translate('Geographic data') . ')',
1032 1032
 			I18N::translate('Import file'),
1033 1033
 		];
1034
-		$files       = $this->findFiles(WT_MODULES_DIR . $this->getName() . '/extra', ['csv', 'geojson', 'json']);
1034
+		$files = $this->findFiles(WT_MODULES_DIR . $this->getName() . '/extra', ['csv', 'geojson', 'json']);
1035 1035
 		uasort(
1036 1036
 			$files,
1037 1037
 			function ($a, $b) {
@@ -1042,7 +1042,7 @@  discard block
 block discarded – undo
1042 1042
 			}
1043 1043
 		);
1044 1044
 
1045
-		return (object)[
1045
+		return (object) [
1046 1046
 			'name' => 'modules/openstreetmap/admin-import-form',
1047 1047
 			'data' => [
1048 1048
 				'title'       => I18N::translate('Import geographic data'),
@@ -1106,8 +1106,8 @@  discard block
 block discarded – undo
1106 1106
 					$row    = explode($delimiter, $input_array[0]);
1107 1107
 					$fields = count($row);
1108 1108
 					if ($fields >= 6 &&
1109
-					    (bool)preg_match("/[SN][0-9]*\.?[0-9]*/", $row[$fields - 3]) &&
1110
-					    (bool)preg_match("/[EW][0-9]*\.?[0-9]*/", $row[$fields - 4])) {
1109
+					    (bool) preg_match("/[SN][0-9]*\.?[0-9]*/", $row[$fields - 3]) &&
1110
+					    (bool) preg_match("/[EW][0-9]*\.?[0-9]*/", $row[$fields - 4])) {
1111 1111
 						$filetype = 'csv';
1112 1112
 					}
1113 1113
 				}
@@ -1147,7 +1147,7 @@  discard block
 block discarded – undo
1147 1147
 							}
1148 1148
 						);
1149 1149
 						// convert separate place fields into a comma separated placename
1150
-						$row[]    = implode(
1150
+						$row[] = implode(
1151 1151
 							Place::GEDCOM_SEPARATOR,
1152 1152
 							array_filter(
1153 1153
 								array_reverse(
@@ -1163,7 +1163,7 @@  discard block
 block discarded – undo
1163 1163
 			}
1164 1164
 
1165 1165
 			if ($filetype !== '?') {
1166
-				if ((bool)$request->get('cleardatabase')) {
1166
+				if ((bool) $request->get('cleardatabase')) {
1167 1167
 					Database::exec("TRUNCATE TABLE `##placelocation`");
1168 1168
 				}
1169 1169
 				//process places
@@ -1174,10 +1174,10 @@  discard block
 block discarded – undo
1174 1174
 				usort(
1175 1175
 					$places,
1176 1176
 					function (array $a, array $b) {
1177
-						if ((int)$a['pl_level'] === (int)$b['pl_level']) {
1177
+						if ((int) $a['pl_level'] === (int) $b['pl_level']) {
1178 1178
 							return I18N::strcasecmp($a['fqpn'], $b['fqpn']);
1179 1179
 						} else {
1180
-							return (int)$a['pl_level'] - (int)$b['pl_level'];
1180
+							return (int) $a['pl_level'] - (int) $b['pl_level'];
1181 1181
 						}
1182 1182
 					}
1183 1183
 				);
@@ -1197,7 +1197,7 @@  discard block
 block discarded – undo
1197 1197
 						)) {
1198 1198
 
1199 1199
 						// overwrite
1200
-						$location->update((object)$place);
1200
+						$location->update((object) $place);
1201 1201
 						$updated++;
1202 1202
 					} elseif (!$valid && $options !== 'update') {
1203 1203
 						//add
@@ -1267,7 +1267,7 @@  discard block
 block discarded – undo
1267 1267
 	 */
1268 1268
 	public function postAdminImportPlacesAction(Request $request): RedirectResponse {
1269 1269
 		$gedcomName = $request->get('ged');
1270
-		$inactive   = (int)$request->get('inactive');
1270
+		$inactive   = (int) $request->get('inactive');
1271 1271
 		$tree       = Tree::findByName($gedcomName);
1272 1272
 
1273 1273
 		// Get all the places from the places table ...
@@ -1323,7 +1323,7 @@  discard block
 block discarded – undo
1323 1323
 				"INSERT INTO `##placelocation` (pl_id, pl_parent_id, pl_level, pl_place)" .
1324 1324
 				" VALUES (:id, :parent, :level, :place)"
1325 1325
 			);
1326
-			$checkRecordQry  = Database::prepare(
1326
+			$checkRecordQry = Database::prepare(
1327 1327
 				"SELECT pl1.pl_id" .
1328 1328
 				" FROM	  `##placelocation` AS pl1" .
1329 1329
 				" LEFT JOIN `##placelocation` AS pl2 ON (pl1.pl_parent_id = pl2.pl_id)" .
@@ -1486,18 +1486,18 @@  discard block
 block discarded – undo
1486 1486
 
1487 1487
 			if ($row['inactive']) {
1488 1488
 				$badge = 'danger';
1489
-			} elseif ((int)$children->no_coord > 0) {
1489
+			} elseif ((int) $children->no_coord > 0) {
1490 1490
 				$badge = 'warning';
1491
-			} elseif ((int)$children->child_count > 0) {
1491
+			} elseif ((int) $children->child_count > 0) {
1492 1492
 				$badge = 'info';
1493 1493
 			} else {
1494 1494
 				$badge = 'secondary';
1495 1495
 			}
1496 1496
 
1497
-			$list[] = (object)array_merge(
1497
+			$list[] = (object) array_merge(
1498 1498
 				$row,
1499 1499
 				[
1500
-					'child_count' => (int)$children->child_count,
1500
+					'child_count' => (int) $children->child_count,
1501 1501
 					'badge'       => $badge,
1502 1502
 				]
1503 1503
 			);
@@ -1519,7 +1519,7 @@  discard block
 block discarded – undo
1519 1519
 			$row       = $statement->execute(['id' => $id])->fetchOneRow();
1520 1520
 			$fqpn[]    = $row->pl_place;
1521 1521
 			$row->fqpn = implode(Place::GEDCOM_SEPARATOR, $fqpn);
1522
-			$id        = (int)$row->pl_parent_id;
1522
+			$id        = (int) $row->pl_parent_id;
1523 1523
 			$arr[]     = $row;
1524 1524
 		}
1525 1525
 
@@ -1534,7 +1534,7 @@  discard block
 block discarded – undo
1534 1534
 	 */
1535 1535
 	private function buildLevel($parent_id, $placename, &$places) {
1536 1536
 		$level = array_search('', $placename);
1537
-		$rows  = (array)Database::prepare(
1537
+		$rows  = (array) Database::prepare(
1538 1538
 			"SELECT pl_level, pl_id, pl_place, pl_long, pl_lati, pl_zoom, pl_icon FROM `##placelocation` WHERE pl_parent_id=? ORDER BY pl_place"
1539 1539
 		)
1540 1540
 			->execute([$parent_id])
Please login to merge, or discard this patch.