| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- if(!isset($id, $type)) {
- $ids = http::value("ids", "int");
- $type = http::value("type");
- }
- else {
- $ids = [$id];
- }
- $projects = Project::query(["id" => $ids]);
- if(!$projects) throw new Exception("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 Exception("Cannot create export with different templates.");
- $template = Template::get($template_ids[0]);
- if(!$template) throw new Exception("Template cannot be found.");
- }
- $tests = Test::query([
- "project_id" => $ids,
- "status" => (new Constraint("NOT_EQUALS"))->setValues(Test::STATUS_CANCELLED),
- ]);
- switch($type) {
- case "admin":
- $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;
- }
|