$ids]); if(!$projects) { throw new RuntimeException("No projects to export."); } $template_processing = false; switch($type) { case "admin": case "customer": $template_processing = true; break; } if($template_processing) { $template_ids = array_column($projects, "template_id"); $template_ids = array_unique($template_ids); if(count($template_ids) !== 1) { throw new RuntimeException("Cannot create export with different templates."); } $template = Template::get($template_ids[0]); if(!$template) { throw new RuntimeException("Template cannot be found."); } } $tests = Test::query([ "project_id" => $ids, "status" => (new Constraint("NOT_EQUALS"))->setValues(Test::STATUS_CANCELLED), ]); switch($type) { case "admin": if(!$user->canExportProjectCsv()) { throw new RuntimeException("You do not have permission to perform this action."); } $template->exportTestsCSV("project_csv.php", $tests); break; case "customer": $template->exportTestsCSV("project_customer_csv.php", $tests); break; case "quickbooks-customer": Project::exportCSV("project_quickbooks_customer_csv.php", $projects); break; case "quickbooks-tester": Test::exportCSV("project_quickbooks_tester_csv.php", $tests); break; case "kml": // TODO break; }