1
0

project.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. $completed_percentage = $project->getCompletedPercentage();
  13. $locations = $customer->getLocations();
  14. $tests = $project->getTests();
  15. usort($tests, function($a, $b) {
  16. return $a->status <=> $b->status;
  17. });
  18. $created_test_count = count($tests);
  19. $pending_verification_tests = array_filter($tests, function($test) { return $test->status == Test::STATUS_PENDING_VERIFICATION; });
  20. $pending_verification_test_count = count($pending_verification_tests);
  21. $completed_tests = array_filter($tests, function($test) { return $test->status == Test::STATUS_COMPLETED; });
  22. $completed_test_count = count($completed_tests);
  23. $pass_count = count(array_filter($tests, function($test) { return $test->pass === "1"; }));
  24. $fail_count = count(array_filter($tests, function($test) { return $test->pass === "0"; }));
  25. $pass_fail_count = $pass_count + $fail_count;
  26. $pass_percentage = 0;
  27. $fail_percentage = 0;
  28. if($pass_fail_count) {
  29. $pass_percentage = number_format(($pass_count / $fail_count) * 100, 1);
  30. $fail_percentage = 100 - $pass_percentage;
  31. }
  32. $min_lat = $min_lng = 180;
  33. $max_lat = $max_lng = -180;
  34. foreach($locations as $location) {
  35. if($location->latitude < $min_lat) $min_lat = $location->latitude;
  36. if($location->latitude > $max_lat) $max_lat = $location->latitude;
  37. if($location->longitude < $min_lng) $min_lng = $location->longitude;
  38. if($location->longitude > $max_lng) $max_lng = $location->longitude;
  39. }
  40. $latitude = ($min_lat + $max_lat) / 2;
  41. $longitude = ($min_lng + $max_lng) / 2;
  42. $latitude = 51.3555177;
  43. $longitude = -1.1743197;
  44. $deadline_date = explode(" ", $project->dts_deadline)[0];
  45. View::includeOnce("header", compact("page_title"));
  46. 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"));
  47. View::include("modal_assign_tester");
  48. View::includeOnce("footer");
  49. ?>