project.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. $min_lat = $min_lng = 180;
  24. $max_lat = $max_lng = -180;
  25. foreach($locations as $location) {
  26. if($location->latitude < $min_lat) $min_lat = $location->latitude;
  27. if($location->latitude > $max_lat) $max_lat = $location->latitude;
  28. if($location->longitude < $min_lng) $min_lng = $location->longitude;
  29. if($location->longitude > $max_lng) $max_lng = $location->longitude;
  30. }
  31. $latitude = ($min_lat + $max_lat) / 2;
  32. $longitude = ($min_lng + $max_lng) / 2;
  33. $deadline_date = explode(" ", $project->dts_deadline)[0];
  34. View::includeOnce("header", compact("page_title"));
  35. View::include("project", compact("project", "tests", "latitude", "longitude", "completed_percentage", "customer", "locations", "deadline_date", "created_test_count", "completed_test_count"));
  36. View::include("modal_assign_tester");
  37. View::includeOnce("footer");
  38. ?>