Просмотр исходного кода

Show test status for current year

Alan Lam 7 лет назад
Родитель
Сommit
ed51f75001
2 измененных файлов с 16 добавлено и 4 удалено
  1. 12 3
      controllers/user_ajax.php
  2. 4 1
      views/user.php

+ 12 - 3
controllers/user_ajax.php

@@ -70,6 +70,18 @@ switch($action) {
 			"location_id" => array_column($locations, "id")
 		]);
 
+		// Get projects
+		$projects = Project::load(array_column($tests, "project_id"));
+
+		// Filter tests to current year only
+		$tests = array_filter($tests, function($test) {
+			$project = $test->getProject();
+			$project_unix_start = strtotime($project->dts_start);
+			$project_year = date("Y", $project_unix_start);
+			$current_year = date("Y");
+			return $current_year == $project_year;
+		});
+
 		$location_test_array = [];
 		foreach($tests as $test) {
 			$exists = isset($location_test_array[$test->location_id]);
@@ -88,9 +100,6 @@ switch($action) {
 			}
 		}
 
-		// Get projects
-		$projects = Project::load(array_column($location_test_array, "project_id"));
-
 		// Start output
 		foreach($locations as $location) {
 

+ 4 - 1
views/user.php

@@ -271,7 +271,9 @@ var userId = <?=$user->id?>;
 			?>
 		</div>
 		<div class="tab-pane fade" id="nearby-locations" role="tabpanel" aria-labelledby="nearby-locations-tab">
-			<h3>Nearby Locations</h3>
+			<h3>
+				Nearby Locations
+			</h3>
 
 			<?php
 			if(empty($addresses)) {
@@ -334,6 +336,7 @@ var userId = <?=$user->id?>;
 
 					</div>
 					<div class="col-lg-6 mb-4">
+						<h3><?=date("Y")?> Tests</h3>
 						<div id="nearby-locations-map" style="height: 480px;" data-maps data-lat="<?=$address->latitude?>" data-lng="<?=$address->longitude?>" data-zoom="10">
 					</div>
 					</div>