|
|
@@ -5,12 +5,16 @@
|
|
|
* @var string $action
|
|
|
*/
|
|
|
|
|
|
+use Carbon\CarbonImmutable;
|
|
|
+
|
|
|
JSON::header();
|
|
|
|
|
|
$project = Project::get($id);
|
|
|
if(!$project) throw new Exception("Project cannot be found.");
|
|
|
if(!Core::$user->hasPermission($project)) throw new Exception("You do not have permission to access this resource.");
|
|
|
|
|
|
+$dt_now = CarbonImmutable::now(TIMEZONE);
|
|
|
+
|
|
|
$submit = http::value("submit");
|
|
|
|
|
|
if($submit) {
|
|
|
@@ -105,16 +109,17 @@ if($submit) {
|
|
|
$location_id = http::value("location_id", "int");
|
|
|
$include_unverified = http::value("include_unverified", "int");
|
|
|
$minimum_score = http::value("minimum_score", "int");
|
|
|
- $location = Location::get($location_id);
|
|
|
- if(!$location) throw new Exception("Location not found.");
|
|
|
+ $days_since_last_test = http::value("days_since_last_test", "int");
|
|
|
|
|
|
- $status_constraint = new Constraint("MORE_THAN_OR_EQUAL");
|
|
|
- $status_constraint->setValues(Test::STATUS_UNASSIGNED);
|
|
|
+ $location = Location::get($location_id);
|
|
|
+ if(!$location) {
|
|
|
+ throw new RuntimeException("Location not found.");
|
|
|
+ }
|
|
|
|
|
|
$test = Test::queryOne([
|
|
|
"location_id" => $location_id,
|
|
|
"project_id" => $project->id,
|
|
|
- "status" => $status_constraint,
|
|
|
+ "status" => Constraint::moreThanOrEquals(Test::STATUS_UNASSIGNED),
|
|
|
]);
|
|
|
if(!$test) {
|
|
|
throw new RuntimeException("A test does not exist for this project.");
|
|
|
@@ -134,26 +139,21 @@ if($submit) {
|
|
|
|
|
|
$bounds = Geolocation::getBounds($location->getGeolocation(), $max_distance);
|
|
|
|
|
|
- $lat_constraint = new Constraint("BETWEEN");
|
|
|
- $lat_constraint->setValues($bounds->southWest[0], $bounds->northEast[0]);
|
|
|
-
|
|
|
- $lng_constraint = new Constraint("BETWEEN");
|
|
|
- $lng_constraint->setValues($bounds->southWest[1], $bounds->northEast[1]);
|
|
|
-
|
|
|
$addresses = UserAddress::query([
|
|
|
- "latitude" => $lat_constraint,
|
|
|
- "longitude" => $lng_constraint
|
|
|
+ "latitude" => Constraint::between($bounds->southWest[0], $bounds->northEast[0]),
|
|
|
+ "longitude" => Constraint::between($bounds->southWest[1], $bounds->northEast[1])
|
|
|
]);
|
|
|
|
|
|
$users = User::load(array_column($addresses, "user_id"));
|
|
|
$user_last_tests = Test::query([
|
|
|
"tester_id" => array_column($users, "id"),
|
|
|
- "dts_start" => new Constraint("IS_NOT_NULL"),
|
|
|
+ "dts_start" => Constraint::isNotNull(),
|
|
|
]);
|
|
|
|
|
|
$user_last_test_times = [];
|
|
|
foreach($user_last_tests as $user_last_test) {
|
|
|
- $unix_start = strtotime($user_last_test->dts_start . " UTC");
|
|
|
+ $dt_start = $user_last_test->getDateTimeStart();
|
|
|
+ $unix_start = $dt_start->getTimestamp();
|
|
|
$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;
|
|
|
@@ -210,13 +210,7 @@ if($submit) {
|
|
|
$age = $user->getAge();
|
|
|
|
|
|
// Age check
|
|
|
- if($project->min_age && $project->max_age && ($age < $project->min_age || $age > $project->max_age)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- else if($project->min_age && $age < $project->min_age) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- else if($project->max_age && $age > $project->max_age) {
|
|
|
+ if(!$project->isAgeValid($age)) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
@@ -224,6 +218,14 @@ if($submit) {
|
|
|
|
|
|
$time_last_test = $user_last_test_times[$user->id] ?? false;
|
|
|
|
|
|
+ if($time_last_test && $days_since_last_test) {
|
|
|
+ $dt_last_test = CarbonImmutable::createFromTimestamp($time_last_test, TIMEZONE);
|
|
|
+ $days = $dt_last_test->diffInDays($dt_now);
|
|
|
+ if($days < $days_since_last_test) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
$output[] = [
|
|
|
"id" => (int) $user->id,
|
|
|
"addressId" => (int) $address->id,
|
|
|
@@ -244,7 +246,7 @@ if($submit) {
|
|
|
"isUnverified" => $is_unverified,
|
|
|
"levelText" => $user->getLevelText(),
|
|
|
"levelClass" => $user->getLevelClass(),
|
|
|
- "termsAccepted" => boolval($user->terms_accepted),
|
|
|
+ "termsAccepted" => (bool) $user->terms_accepted,
|
|
|
"reported" => (int) $user->reported,
|
|
|
"reportedComment" => $user->reported_comment,
|
|
|
"timeRegistered" => strtotime($user->dts_registered . " UTC"),
|