diff options
author | Frederic Guillot <fred@kanboard.net> | 2016-05-15 21:20:46 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2016-05-15 21:20:46 -0400 |
commit | 20052c7dd295464c7782350628701675b1f07db7 (patch) | |
tree | 5eb416262114feb864694ae05a3c04667f54f727 /app/Controller | |
parent | 4eaab1f6da1a56376a840231f7b8a10469308f97 (diff) |
User import is now a popover
Diffstat (limited to 'app/Controller')
-rw-r--r-- | app/Controller/Config.php | 2 | ||||
-rw-r--r-- | app/Controller/Export.php | 2 | ||||
-rw-r--r-- | app/Controller/FileViewer.php | 2 | ||||
-rw-r--r-- | app/Controller/TaskImport.php | 2 | ||||
-rw-r--r-- | app/Controller/UserImportController.php (renamed from app/Controller/UserImport.php) | 51 |
5 files changed, 35 insertions, 24 deletions
diff --git a/app/Controller/Config.php b/app/Controller/Config.php index ebb541d2..deafd05b 100644 --- a/app/Controller/Config.php +++ b/app/Controller/Config.php @@ -176,7 +176,7 @@ class Config extends BaseController public function downloadDb() { $this->checkCSRFParam(); - $this->response->withDownload('db.sqlite.gz'); + $this->response->withFileDownload('db.sqlite.gz'); $this->response->binary($this->config->downloadDatabase()); } diff --git a/app/Controller/Export.php b/app/Controller/Export.php index f5783b72..7e1d2fdc 100644 --- a/app/Controller/Export.php +++ b/app/Controller/Export.php @@ -29,7 +29,7 @@ class Export extends BaseController if ($from && $to) { $data = $this->$model->$method($project['id'], $from, $to); - $this->response->withDownload($filename.'.csv'); + $this->response->withFileDownload($filename.'.csv'); $this->response->csv($data); } diff --git a/app/Controller/FileViewer.php b/app/Controller/FileViewer.php index a990e12a..52ff0d0e 100644 --- a/app/Controller/FileViewer.php +++ b/app/Controller/FileViewer.php @@ -123,7 +123,7 @@ class FileViewer extends BaseController { try { $file = $this->getFile(); - $this->response->withDownload($file['name']); + $this->response->withFileDownload($file['name']); $this->objectStorage->output($file['path']); } catch (ObjectStorageException $e) { $this->logger->error($e->getMessage()); diff --git a/app/Controller/TaskImport.php b/app/Controller/TaskImport.php index 5dbf8678..5e37fb2f 100644 --- a/app/Controller/TaskImport.php +++ b/app/Controller/TaskImport.php @@ -69,7 +69,7 @@ class TaskImport extends BaseController */ public function template() { - $this->response->withDownload('tasks.csv'); + $this->response->withFileDownload('tasks.csv'); $this->response->csv(array($this->taskImport->getColumnMapping())); } } diff --git a/app/Controller/UserImport.php b/app/Controller/UserImportController.php index b99e56a0..b3cb52d1 100644 --- a/app/Controller/UserImport.php +++ b/app/Controller/UserImportController.php @@ -7,51 +7,43 @@ use Kanboard\Core\Csv; /** * User Import controller * - * @package controller + * @package Kanboard\Controller * @author Frederic Guillot */ -class UserImport extends BaseController +class UserImportController extends BaseController { /** * Upload the file and ask settings * + * @param array $values + * @param array $errors */ - public function step1(array $values = array(), array $errors = array()) + public function show(array $values = array(), array $errors = array()) { - $this->response->html($this->helper->layout->app('user_import/step1', array( + $this->response->html($this->template->render('user_import/show', array( 'values' => $values, 'errors' => $errors, 'max_size' => ini_get('upload_max_filesize'), 'delimiters' => Csv::getDelimiters(), 'enclosures' => Csv::getEnclosures(), - 'title' => t('Import users from CSV file'), ))); } /** - * Process CSV file - * + * Submit form */ - public function step2() + public function save() { $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')))); - } - - $csv = new Csv($values['delimiter'], $values['enclosure']); - $csv->setColumnMapping($this->userImport->getColumnMapping()); - $csv->read($filename, array($this->userImport, 'import')); - - if ($this->userImport->counter > 0) { - $this->flash->success(t('%d user(s) have been imported successfully.', $this->userImport->counter)); + $this->flash->failure(t('Unable to read your file')); } else { - $this->flash->failure(t('Nothing have been imported!')); + $this->importFile($values, $filename); } - $this->response->redirect($this->helper->url->to('userImport', 'step1')); + $this->response->redirect($this->helper->url->to('user', 'index')); } /** @@ -60,7 +52,26 @@ class UserImport extends BaseController */ public function template() { - $this->response->withDownload('users.csv'); + $this->response->withFileDownload('users.csv'); $this->response->csv(array($this->userImport->getColumnMapping())); } + + /** + * Process file + * + * @param array $values + * @param $filename + */ + private function importFile(array $values, $filename) + { + $csv = new Csv($values['delimiter'], $values['enclosure']); + $csv->setColumnMapping($this->userImport->getColumnMapping()); + $csv->read($filename, array($this->userImport, 'import')); + + if ($this->userImport->counter > 0) { + $this->flash->success(t('%d user(s) have been imported successfully.', $this->userImport->counter)); + } else { + $this->flash->failure(t('Nothing have been imported!')); + } + } } |