1
0

project_csv.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. $project = Project::get($id);
  3. if(!$project) throw new Exception("Project cannot be found.");
  4. if(!Core::$user->hasPermission($project)) throw new Exception("You do not have permission to access this resource.");
  5. header("Content-Type: text/csv");
  6. header("Content-Disposition: attachment; filename=\"export.csv\"");
  7. header("Cache-Control: private, max-age=0, must-revalidate");
  8. header("Pragma: public");
  9. $template = $project->getTemplate();
  10. $object = json_decode($template->json);
  11. $fields_1 = $object->beforeTest;
  12. $fields_2 = $object->duringTest;
  13. $fields = array_merge($fields_1, $fields_2);
  14. $fields = array_filter($fields, function($field) {
  15. if(!isset($field->name)) return false;
  16. if($field->type == "file") return false;
  17. return true;
  18. });
  19. $tests = Test::query([
  20. "project_id" => $id,
  21. "status" => (new Constraint("NOT_EQUALS"))->setValues(Test::STATUS_CANCELLED),
  22. ]);
  23. $locations = Location::load(array_column($tests, "location_id"));
  24. $testers = User::load(array_column($tests, "tester_id"));
  25. $handle = fopen("php://output", "w");
  26. fclose($handle);
  27. ?>