tests_tester_list.php 1.5 KB

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