project_export.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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":
  37. Test::exportCSV("project_quickbooks_csv.php", $tests);
  38. case "kml":
  39. // TODO
  40. break;
  41. }