tests_tester_list.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php /** @noinspection PhpUnhandledExceptionInspection */
  2. /**
  3. * @var User $user
  4. * @var string $page_title
  5. */
  6. Core::addScript("public/js/app-tests-tester-list.js");
  7. $tests = $user->getPendingTests();
  8. $locations = Location::load(array_column($tests, "location_id"));
  9. $bounds = new GeolocationBounds;
  10. foreach($tests as $test) {
  11. $location = $test->getLocation();
  12. $bounds->extend($location->latitude, $location->longitude);
  13. }
  14. $latitude = 51.3555177;
  15. $longitude = -1.1743197;
  16. if(HTTP::isAJAX()) {
  17. JSON::header();
  18. $action = http::value("action");
  19. switch($action) {
  20. case "get-tests":
  21. $output = [];
  22. foreach($tests as $test) {
  23. $location = $test->getLocation();
  24. $icon = null;
  25. switch($test->getStatus()) {
  26. case Test::STATUS_ASSIGNED:
  27. $icon = "building-orange";
  28. break;
  29. case Test::STATUS_CONFIRMED:
  30. $icon = "building-green";
  31. break;
  32. case Test::STATUS_STARTED:
  33. $icon = "building-pink";
  34. break;
  35. case Test::STATUS_PENDING_VERIFICATION:
  36. $icon = "building-grey";
  37. break;
  38. }
  39. $output[] = (object) [
  40. "id" => $test->id,
  41. "status" => $test->getStatusText(),
  42. "statusClass" => $test->getStatusClass(),
  43. "name" => $location->name,
  44. "address" => $location->getDisplayAddress(["address_1", "address_2", "city", "county", "postal_code", "state"]),
  45. "icon" => $icon,
  46. "geolocation" => $location->getGeolocation(),
  47. ];
  48. }
  49. JSON::success([
  50. "tests" => $output,
  51. "southWest" => $bounds->getSouthWest(),
  52. "northEast" => $bounds->getNorthEast(),
  53. ]);
  54. break;
  55. default:
  56. JSON::fail("Invalid action");
  57. }
  58. }
  59. View::includeOnce("header", compact("page_title"));
  60. View::include("test_list_assigned", compact("tests", "latitude", "longitude"));