project_export.php 842 B

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