project_export.php 904 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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_ids = array_column($projects, "template_id");
  12. $template_ids = array_unique($template_ids);
  13. if(count($template_ids) != 1) throw new Exception("Cannot create export with different templates.");
  14. $template = Template::get($template_ids[0]);
  15. if(!$template) throw new Exception("Template cannot be found.");
  16. $tests = Test::query([
  17. "project_id" => $ids,
  18. "status" => (new Constraint("NOT_EQUALS"))->setValues(Test::STATUS_CANCELLED),
  19. ]);
  20. switch($type) {
  21. case "admin":
  22. $template->exportTestsCSV("project_csv.php", $tests);
  23. break;
  24. case "customer":
  25. $template->exportTestsCSV("project_customer_csv.php", $tests);
  26. break;
  27. case "kml":
  28. // TODO
  29. break;
  30. }