| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?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"));
- $projects = Project::load($project_ids);
- $templates = Template::load(array_column($projects, "template_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");
- ?>
|