project_csv.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. $processing_file_path = $template->getProcessingFilePath("project_csv.php");
  11. $object = json_decode($template->getJSON());
  12. $fields_1 = $object->beforeTest;
  13. $fields_2 = $object->duringTest;
  14. $fields = array_merge($fields_1, $fields_2);
  15. $fields = array_filter($fields, function($field) {
  16. if(!isset($field->name)) return false;
  17. if($field->type == "file") return false;
  18. return true;
  19. });
  20. $tests = Test::query([
  21. "project_id" => $id,
  22. "status" => (new Constraint("NOT_EQUALS"))->setValues(Test::STATUS_CANCELLED),
  23. ]);
  24. $locations = Location::load(array_column($tests, "location_id"));
  25. $testers = User::load(array_column($tests, "tester_id"));
  26. $handle = fopen("php://output", "w");
  27. require $processing_file_path;
  28. fclose($handle);
  29. ?>