1
0

project_export.php 1.2 KB

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