1
0
Эх сурвалжийг харах

Show user addresses on verification page.

Alan Lam 8 жил өмнө
parent
commit
536719aa6d

+ 20 - 1
controllers/user_verify.php

@@ -4,6 +4,25 @@ $user = User::get($id);
 if(!$user) throw new Exception("User not found.");
 if(!$user) throw new Exception("User not found.");
 if($user->level != User::LEVEL_UNVERIFIED) throw new Exception("User level is not unverified.");
 if($user->level != User::LEVEL_UNVERIFIED) throw new Exception("User level is not unverified.");
 
 
+$addresses = $user->getAddresses();
+$markers = [];
+$total_lat = $total_lng = 0;
+$lat = $lng = 0;
+
+foreach($addresses as $address) {
+	$markers[] = [
+		"latitude" => $address->latitude,
+		"longitude" => $address->longitude,
+	];
+	$total_lat += $address->latitude;
+	$total_lng += $address->longitude;
+}
+
+if($addresses) {
+	$lat = $total_lat / count($addresses);
+	$lng = $total_lng / count($addresses);
+}
+
 $page_title = "Verify User";
 $page_title = "Verify User";
 
 
 Core::addBreadcrumb("/account", "Account");
 Core::addBreadcrumb("/account", "Account");
@@ -60,7 +79,7 @@ if($submit) {
 }
 }
 
 
 View::includeOnce("header", compact("page_title"));
 View::includeOnce("header", compact("page_title"));
-View::include("user_verify", compact("user"));
+View::include("user_verify", compact("user", "addresses", "markers", "lat", "lng"));
 View::includeOnce("footer");
 View::includeOnce("footer");
 
 
 ?>
 ?>

+ 23 - 0
public/js/app.js

@@ -70,6 +70,7 @@ function initialiseMaps() {
 			maps[this.id] = map;
 			maps[this.id] = map;
 		}
 		}
 
 
+		// Plot marker
 		let marker = $(this).data("marker");
 		let marker = $(this).data("marker");
 		if(marker) {
 		if(marker) {
 			let options = {};
 			let options = {};
@@ -89,6 +90,28 @@ function initialiseMaps() {
 			}
 			}
 		}
 		}
 
 
+		// Plot basic markers
+		let markers = $(this).data("markers");
+		if(markers) {
+
+			let bounds = new google.maps.LatLngBounds;
+
+			for(let i in markers) {
+				let options = {};
+				options.position = {
+					"lat": markers[i].latitude * 1,
+					"lng": markers[i].longitude * 1
+				};
+				options.map = map;
+
+				let marker = new google.maps.Marker(options);
+				bounds.extend(options.position);
+			}
+			if(markers.length > 1) {
+				maps[this.id].fitBounds(bounds, 32);
+			}
+		}
+
 		let callback = $(this).data("callback");
 		let callback = $(this).data("callback");
 		if(callback) {
 		if(callback) {
 			try {
 			try {

+ 36 - 3
views/user_verify.php

@@ -15,11 +15,10 @@
 			<h3>Contact Number</h3>
 			<h3>Contact Number</h3>
 			<p><?=htmlspecialchars($user->phone)?></p>
 			<p><?=htmlspecialchars($user->phone)?></p>
 		</div>
 		</div>
-		<div class="col-md">
-		</div>
-
 	</div>
 	</div>
 
 
+	<hr />
+
 	<div class="row">
 	<div class="row">
 		<div class="col-md mb-4">
 		<div class="col-md mb-4">
 			<h3>ID Document</h3>
 			<h3>ID Document</h3>
@@ -37,6 +36,40 @@
 			</a>
 			</a>
 
 
 		</div>
 		</div>
+		<div class="col-md mb-4">
+			<h3>Addresses</h3>
+
+			<?php
+			if(empty($addresses)) {
+				?>
+				<div class="alert alert-info">
+					This user does not have any addresses.
+				</div>
+				<?php
+			}
+			else {
+				?>
+				<div class="list-group mb-3">
+					<?php
+					foreach($addresses as $address) {
+						?>
+						<div class="list-group-item">
+							<strong><?=htmlspecialchars($address->name)?></strong><br />
+							<?=htmlspecialchars($address->getDisplayAddress())?>
+						</div>
+						<?php
+					}
+					?>
+				</div>
+
+				<div id="map" data-maps data-lat="<?=$lat?>" data-lng="<?=$lng?>" data-zoom="17" data-markers="<?=htmlspecialchars(json_encode($markers))?>" style="height: 10rem;">
+				</div>
+
+				<?php
+			}
+			?>
+
+		</div>
 	</div>
 	</div>
 
 
 	<hr />
 	<hr />