1
0

project_export.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php /** @noinspection PhpUnhandledExceptionInspection */
  2. $user = Core::$user;
  3. if(!isset($id, $type)) {
  4. $ids = http::value("ids", "int");
  5. $type = http::value("type");
  6. }
  7. else {
  8. $ids = [$id];
  9. }
  10. $projects = Project::query(["id" => $ids]);
  11. if(!$projects) throw new Exception("No projects to export.");
  12. $template_processing = false;
  13. switch($type) {
  14. case "admin":
  15. case "customer":
  16. $template_processing = true;
  17. break;
  18. }
  19. if($template_processing) {
  20. $template_ids = array_column($projects, "template_id");
  21. $template_ids = array_unique($template_ids);
  22. if(count($template_ids) != 1) throw new Exception("Cannot create export with different templates.");
  23. $template = Template::get($template_ids[0]);
  24. if(!$template) throw new Exception("Template cannot be found.");
  25. }
  26. $tests = Test::query([
  27. "project_id" => $ids,
  28. "status" => (new Constraint("NOT_EQUALS"))->setValues(Test::STATUS_CANCELLED),
  29. ]);
  30. switch($type) {
  31. case "admin":
  32. if(!$user->canExportProjectCsv()) throw new Exception("You do not have permission to perform this action.");
  33. $template->exportTestsCSV("project_csv.php", $tests);
  34. break;
  35. case "customer":
  36. $template->exportTestsCSV("project_customer_csv.php", $tests);
  37. break;
  38. case "quickbooks-customer":
  39. Project::exportCSV("project_quickbooks_customer_csv.php", $projects);
  40. break;
  41. case "quickbooks-tester":
  42. Test::exportCSV("project_quickbooks_tester_csv.php", $tests);
  43. break;
  44. case "kml":
  45. // TODO
  46. break;
  47. }