test_results_test_list.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php /** @noinspection PhpUnhandledExceptionInspection */
  2. /**
  3. * @var int $project_id
  4. */
  5. $customers = Core::$user->getCustomers();
  6. if(!$customers) {
  7. throw new RuntimeException(__("An unexpected error has occurred. Please try again later."));
  8. }
  9. $project = Project::get($project_id);
  10. if(!$project) {
  11. throw new RuntimeException(__("Project not found."));
  12. }
  13. $template = $project->getTemplate();
  14. $has_pass_fail = $template->hasPassFail();
  15. $customer_ids = array_column($customers, "id");
  16. if(!in_array($project->customer_id, $customer_ids)) {
  17. throw new RuntimeException(__("You do not have permission to access this page."));
  18. }
  19. $customer = $project->getCustomer();
  20. $tests = $project->getTests();
  21. $location_ids = array_column($tests, "location_id");
  22. Location::load($location_ids);
  23. usort($tests, static function(Test $a, Test $b) {
  24. $a_location = $a->getLocation();
  25. $b_location = $b->getLocation();
  26. return strnatcasecmp($a_location->name, $b_location->name);
  27. });
  28. $test_count = $project->getTestCount();
  29. $pass_count = $project->getPassCount();
  30. $fail_count = $project->getFailCount();
  31. $pass_percentage = 0;
  32. $fail_percentage = 0;
  33. $pass_fail_count = $pass_count + $fail_count;
  34. if($pass_fail_count > 0) {
  35. $pass_percentage = number_format($pass_count / $pass_fail_count, 4) * 100;
  36. $fail_percentage = 100 - $pass_percentage;
  37. }
  38. $project_list_url = $customer->getTestResultsUrl();
  39. $test_list_url = $project->getTestResultsUrl();
  40. $page_title = __("Test Results %s Test List", $project->name);
  41. Core::addBreadcrumb("/account", __("Account"));
  42. Core::addBreadcrumb("/account/test-results", __("Test Results"));
  43. Core::addBreadcrumb($project_list_url, $customer->name);
  44. Core::addBreadcrumb($test_list_url, $project->name);
  45. View::includeOnce("header", compact("page_title"));
  46. View::include("test_results_test_list", compact("project", "has_pass_fail", "tests", "test_count", "pass_count", "fail_count", "pass_percentage", "fail_percentage"));
  47. View::includeOnce("footer");