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

Add registered time and last test time to tester table

Alan Lam 7 лет назад
Родитель
Сommit
9a12fd544c
3 измененных файлов с 32 добавлено и 8 удалено
  1. 19 1
      controllers/project_ajax.php
  2. 10 5
      public/js/app-project.js
  3. 3 2
      views/project.php

+ 19 - 1
controllers/project_ajax.php

@@ -141,7 +141,21 @@ if($submit) {
 
 				$addresses = UserAddress::query($nvp);
 
+
+
 				$users = User::load(array_column($addresses, "user_id"));
+				$tests = Test::query([
+					"tester_id" => array_column($users, "id"),
+					"dts_start" => new Constraint("IS_NOT_NULL"),
+				]);
+
+				$user_last_test_times = [];
+				foreach($tests as $test) {
+					$unix_start = strtotime($test->dts_start . " UTC");
+					$current_start = $user_last_test_times[$test->tester_id] ?? 0;
+					if($unix_start > $current_start) $user_last_test_times[$test->tester_id] = $unix_start;
+				}
+
 
 				$pending_tests = Test::query([
 					"tester_id" => array_column($users, "id"),
@@ -189,6 +203,8 @@ if($submit) {
 
 					$max_radius_exceeded = ($distance_miles > $address->max_radius_miles);
 
+					$time_last_test = $user_last_test_times[$user->id] ?? false;
+
 					$output[] = [
 						"id" => (int) $user->id,
 						"addressId" => (int) $address->id,
@@ -211,7 +227,9 @@ if($submit) {
 						"levelClass" => $user->getLevelClass(),
 						"termsAccepted" => boolval($user->terms_accepted),
 						"reported" => (int) $user->reported,
-						"reportedComment" => $user->reported_comment
+						"reportedComment" => $user->reported_comment,
+						"timeRegistered" => strtotime($user->dts_registered . " UTC"),
+						"timeLastTest" => $time_last_test,
 					];
 
 				}

+ 10 - 5
public/js/app-project.js

@@ -159,12 +159,12 @@ function initialiseLocations() {
 			td.append("<br />");
 
 			if(location.internalId) {
-				var small = $("<small class=\"text-info\">").text("Internal ID: " + location.internalId);
+				var small = $("<span class=\"text-info\">").text("Internal ID: " + location.internalId);
 				td.append(small);
 				td.append("<br />");
 			}
 
-			var address = $("<small>").text(location.address1);
+			var address = $("<span>").text(location.address1);
 
 			td.append(address);
 			tr.append(td);
@@ -363,16 +363,21 @@ function initialiseTesters() {
 			trHtml += "<td class=\"text-right\">" + tester.id + "</td>";
 			trHtml += "<td><a href=\"/account/users/" + tester.id + "\" target=\"_blank\">" + tester.name + "</a> <span class=\"badge badge-pill badge-" + scoreClass + "\" title=\"Score\">" +  tester.score + "</span><br />";
 
-			trHtml += "<small class=\"" + distanceClass + "\">";
+			trHtml += "<span class=\"" + distanceClass + "\">";
 			trHtml += tester.distanceMiles + " / " + tester.maxRadiusMiles + " miles";
 
 			if(tester.maxRadiusExceeded) {
 				trHtml += " <i class=\"fas fa-exclamation-circle\"></i>";
 			}
 
-			trHtml += "</small>";
+			trHtml += "</span>";
 			trHtml += "</td>";
 
+			var registeredText = moment.unix(tester.timeRegistered).format("D/M/YYYY");
+			var lastTestText = tester.timeLastTest ? moment.unix(tester.timeLastTest).format("D/M/YYYY") : "N/A";
+
+
+			trHtml += "<td class=\"text-right align-middle\"><span class=\"text-danger\">" + registeredText + "</span><br /><span class=\"text-info\">" + lastTestText + "</span></td>";
 			trHtml += "<td class=\"text-right align-middle\">" + tester.age + "</td>";
 			trHtml += "<td class=\"text-right align-middle\">";
 
@@ -385,7 +390,7 @@ function initialiseTesters() {
 			}
 
 			trHtml += "<span class=\"badge badge-" + tester.levelClass + "\">" + tester.levelText + "</span><br />";
-			trHtml += "<small>" + tester.phone + "</small>";
+			trHtml += "<span>" + tester.phone + "</span>";
 
 			trHtml += "<td class=\"text-right align-middle\">";
 

+ 3 - 2
views/project.php

@@ -163,7 +163,7 @@ var projectID = <?=$project->id?>;
 			</div>
 
 			<div class="limit-height-2">
-				<table class="table table-hover table-sm">
+				<table class="table table-hover table-sm table-sm-text">
 					<thead>
 						<tr>
 							<th class="text-right">ID</th>
@@ -228,11 +228,12 @@ var projectID = <?=$project->id?>;
 
 
 			<div class="limit-height-2">
-				<table id="testers-table" class="table table-hover table-sm">
+				<table id="testers-table" class="table table-hover table-sm table-sm-text">
 					<thead>
 						<tr>
 							<th class="text-right">ID</th>
 							<th>Name / Score / Dist.</th>
+							<th>Reg / Last</th>
 							<th>Age</th>
 							<th class="text-right">Level / Phone</th>
 							<th></th>