project.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. $project = Project::get($id);
  3. if(!$project) throw new Exception("Project not found.");
  4. if(!Core::$user->hasPermission($project)) throw new Exception("You do not have permission to access this page.");
  5. $page_title = $project->name;
  6. $customer = $project->getCustomer();
  7. Core::addBreadcrumb("/account", "Account");
  8. Core::addBreadcrumb("/account/projects", "Projects");
  9. Core::addBreadcrumb("/account/projects?customer_id=$customer->id", "$customer->name Projects");
  10. Core::addBreadcrumb("/account/projects/$project->id", $page_title);
  11. Core::addScript("public/js/app-project.js");
  12. Core::addScript("public/js/markerclusterer.js");
  13. $completed_percentage = $project->getCompletedPercentage();
  14. $locations = $customer->getLocations();
  15. $tests = $project->getTests();
  16. usort($tests, function($a, $b) {
  17. return $a->status <=> $b->status;
  18. });
  19. $created_test_count = count($tests);
  20. $pending_verification_tests = array_filter($tests, function($test) { return $test->status == Test::STATUS_PENDING_VERIFICATION; });
  21. $pending_verification_test_count = count($pending_verification_tests);
  22. $completed_tests = array_filter($tests, function($test) { return $test->status == Test::STATUS_COMPLETED; });
  23. $completed_test_count = count($completed_tests);
  24. $pass_count = count(array_filter($tests, function($test) { return $test->pass === "1"; }));
  25. $fail_count = count(array_filter($tests, function($test) { return $test->pass === "0"; }));
  26. $pass_fail_count = $pass_count + $fail_count;
  27. $pass_percentage = 0;
  28. $fail_percentage = 0;
  29. if($pass_fail_count) {
  30. $pass_percentage = number_format(($pass_count / $pass_fail_count) * 100, 1);
  31. $fail_percentage = 100 - $pass_percentage;
  32. }
  33. $min_lat = $min_lng = 180;
  34. $max_lat = $max_lng = -180;
  35. foreach($locations as $location) {
  36. if($location->latitude < $min_lat) $min_lat = $location->latitude;
  37. if($location->latitude > $max_lat) $max_lat = $location->latitude;
  38. if($location->longitude < $min_lng) $min_lng = $location->longitude;
  39. if($location->longitude > $max_lng) $max_lng = $location->longitude;
  40. }
  41. $latitude = ($min_lat + $max_lat) / 2;
  42. $longitude = ($min_lng + $max_lng) / 2;
  43. $latitude = 51.3555177;
  44. $longitude = -1.1743197;
  45. $deadline_date = explode(" ", $project->dts_deadline)[0];
  46. View::includeOnce("header", compact("page_title"));
  47. View::include("project", compact("project", "tests", "latitude", "longitude", "completed_percentage", "pass_count", "fail_count", "pass_fail_count", "pass_percentage", "fail_percentage", "customer", "locations", "deadline_date", "created_test_count", "completed_test_count"));
  48. View::include("modal_assign_tester");
  49. View::includeOnce("footer");
  50. ?>