test_results_test_list.php 1.8 KB

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