|
|
@@ -111,14 +111,14 @@ if($submit) {
|
|
|
$status_constraint = new Constraint("MORE_THAN_OR_EQUAL");
|
|
|
$status_constraint->setValues(Test::STATUS_UNASSIGNED);
|
|
|
|
|
|
- $nvp = [
|
|
|
+ $test = Test::queryOne([
|
|
|
"location_id" => $location_id,
|
|
|
"project_id" => $project->id,
|
|
|
"status" => $status_constraint,
|
|
|
- ];
|
|
|
-
|
|
|
- $test = Test::queryOne($nvp);
|
|
|
- if(!$test) throw new Exception("A test does not exist for this project.");
|
|
|
+ ]);
|
|
|
+ if(!$test) {
|
|
|
+ throw new RuntimeException("A test does not exist for this project.");
|
|
|
+ }
|
|
|
|
|
|
/*
|
|
|
$max_distance = http::value("max_distance", "int");
|
|
|
@@ -140,12 +140,10 @@ if($submit) {
|
|
|
$lng_constraint = new Constraint("BETWEEN");
|
|
|
$lng_constraint->setValues($bounds->southWest[1], $bounds->northEast[1]);
|
|
|
|
|
|
- $nvp = [
|
|
|
+ $addresses = UserAddress::query([
|
|
|
"latitude" => $lat_constraint,
|
|
|
"longitude" => $lng_constraint
|
|
|
- ];
|
|
|
-
|
|
|
- $addresses = UserAddress::query($nvp);
|
|
|
+ ]);
|
|
|
|
|
|
$users = User::load(array_column($addresses, "user_id"));
|
|
|
$user_last_tests = Test::query([
|
|
|
@@ -157,7 +155,9 @@ if($submit) {
|
|
|
foreach($user_last_tests as $user_last_test) {
|
|
|
$unix_start = strtotime($user_last_test->dts_start . " UTC");
|
|
|
$current_start = $user_last_test_times[$user_last_test->tester_id] ?? 0;
|
|
|
- if($unix_start > $current_start) $user_last_test_times[$user_last_test->tester_id] = $unix_start;
|
|
|
+ if($unix_start > $current_start) {
|
|
|
+ $user_last_test_times[$user_last_test->tester_id] = $unix_start;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
$pending_tests = Test::query([
|
|
|
@@ -165,7 +165,8 @@ if($submit) {
|
|
|
"status" => Test::STATUS_ASSIGNED,
|
|
|
]);
|
|
|
|
|
|
- usort($addresses, function($a, $b) use ($location) {
|
|
|
+ // Sort by distance to location
|
|
|
+ usort($addresses, static function($a, $b) use ($location) {
|
|
|
$lat_lng = $location->getGeolocation();
|
|
|
return Geolocation::getDistance($lat_lng, $a->getGeolocation()) <=> Geolocation::getDistance($lat_lng, $b->getGeolocation());
|
|
|
});
|
|
|
@@ -176,21 +177,33 @@ if($submit) {
|
|
|
$user = $address->getUser();
|
|
|
|
|
|
$is_current_tester = $user->id == $test->tester_id;
|
|
|
- $is_deactivated = $user->level == User::LEVEL_DEACTIVATED;
|
|
|
- $is_registered = $user->level == User::LEVEL_REGISTERED;
|
|
|
$is_unverified = $user->level <= User::LEVEL_UNVERIFIED;
|
|
|
- $is_tester = $user->isTester();
|
|
|
|
|
|
- if($is_deactivated) continue;
|
|
|
- if(!$include_unverified && $is_unverified) continue;
|
|
|
- if(!$is_tester) continue;
|
|
|
- if($user->score < $minimum_score) continue;
|
|
|
+ if($user->isArchived()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if($user->isDeactivated()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!$include_unverified && $user->isUnverified()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!$user->isTester()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if($user->score < $minimum_score) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
$distance_miles = Geolocation::getDistance($location->getGeolocation(), $address->getGeolocation());
|
|
|
$distance_kilometers = $distance_miles * Geolocation::KMS_IN_MILE;
|
|
|
|
|
|
- $user_pending_tests = array_filter($pending_tests, function($test) use ($user) {
|
|
|
- return ($user->id == $test->tester_id);
|
|
|
+ $user_pending_tests = array_filter($pending_tests, static function($test) use ($user) {
|
|
|
+ return ((int) $user->id === (int) $test->tester_id);
|
|
|
});
|
|
|
$pending_test_count = count($user_pending_tests);
|
|
|
|
|
|
@@ -227,7 +240,7 @@ if($submit) {
|
|
|
"longitude" => (float) $address->longitude,
|
|
|
"pendingTestCount" => $pending_test_count,
|
|
|
"isCurrentTester" => $is_current_tester,
|
|
|
- "isRegistered" => $is_registered,
|
|
|
+ "isRegistered" => $user->isRegistered(),
|
|
|
"isUnverified" => $is_unverified,
|
|
|
"levelText" => $user->getLevelText(),
|
|
|
"levelClass" => $user->getLevelClass(),
|