| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- Core::addScript("public/js/app-tests-available.js");
- $page_title = "Find Tests";
- Core::addBreadcrumb("/account", "Account");
- Core::addBreadcrumb("/account/tests", "Tests");
- Core::addBreadcrumb("/account/tests/available", $page_title);
- $user = Core::$user;
- if(!$user->can_claim) throw new Exception("You do not have permission to perform this action.");
- $dts = date("Y-m-d H:i:s");
- // Get active projects
- $projects = Project::query([
- "tester_can_claim" => 1,
- "dts_start" => (new Constraint("LESS_THAN_OR_EQUAL"))->setValues($dts),
- ]);
- $project_ids = array_column($projects, "id");
- $tests = Test::query([
- "project_id" => $project_ids,
- "tester_id" => (new Constraint("IS_NULL")),
- "status" => (new Constraint("MORE_THAN_OR_EQUAL"))->setValues(1),
- ]);
- $locations = Location::load(array_column($tests, "location_id"));
- $addresses = $user->getAddresses();
- if(!$addresses) {
- $latitude = 51.509865;
- $longitude = -0.118092;
- }
- else {
- $address = $addresses[0];
- list($latitude, $longitude) = $address->getGeolocation();
- }
- // AJAX
- if(HTTP::isAJAX()) {
- require "tests_available_ajax.php";
- }
- usort($tests, function($a, $b) use ($address) {
- $distance_a = Geolocation::getDistance($a->getLocation()->getGeolocation(), $address->getGeolocation());
- $distance_b = Geolocation::getDistance($b->getLocation()->getGeolocation(), $address->getGeolocation());
- return $distance_a <=> $distance_b;
- });
- View::includeOnce("header", compact("page_title"));
- View::include("tests_available", compact("tests", "address", "latitude", "longitude"));
- View::include("modal_test_claim");
- View::includeOnce("footer");
- ?>
|