From 9ebbe3da56914c408327997cea4eb00db2f88e0c Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Thu, 26 May 2016 21:38:43 -0400 Subject: Rename task controllers --- app/Controller/TaskImportController.php | 75 +++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 app/Controller/TaskImportController.php (limited to 'app/Controller/TaskImportController.php') diff --git a/app/Controller/TaskImportController.php b/app/Controller/TaskImportController.php new file mode 100644 index 00000000..a4c39f84 --- /dev/null +++ b/app/Controller/TaskImportController.php @@ -0,0 +1,75 @@ +getProject(); + + $this->response->html($this->helper->layout->project('task_import/step1', array( + 'project' => $project, + 'values' => $values, + 'errors' => $errors, + 'max_size' => ini_get('upload_max_filesize'), + 'delimiters' => Csv::getDelimiters(), + 'enclosures' => Csv::getEnclosures(), + 'title' => t('Import tasks from CSV file'), + ))); + } + + /** + * Process CSV file + * + */ + public function step2() + { + $project = $this->getProject(); + $values = $this->request->getValues(); + $filename = $this->request->getFilePath('file'); + + if (! file_exists($filename)) { + $this->step1($values, array('file' => array(t('Unable to read your file')))); + } + + $this->taskImport->projectId = $project['id']; + + $csv = new Csv($values['delimiter'], $values['enclosure']); + $csv->setColumnMapping($this->taskImport->getColumnMapping()); + $csv->read($filename, array($this->taskImport, 'import')); + + if ($this->taskImport->counter > 0) { + $this->flash->success(t('%d task(s) have been imported successfully.', $this->taskImport->counter)); + } else { + $this->flash->failure(t('Nothing have been imported!')); + } + + $this->response->redirect($this->helper->url->to('TaskImportController', 'step1', array('project_id' => $project['id']))); + } + + /** + * Generate template + * + */ + public function template() + { + $this->response->withFileDownload('tasks.csv'); + $this->response->csv(array($this->taskImport->getColumnMapping())); + } +} -- cgit v1.2.3