From 833bd3f8a90b604f4ab289dab9366c0032ce5216 Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Sat, 19 Jul 2014 22:08:07 -0230 Subject: Add Task CSV export and Kanboard CLI --- app/Controller/Base.php | 21 ++++++++++++ app/Controller/Category.php | 19 ---------- app/Controller/Project.php | 84 +++++++++++++++++++++++---------------------- 3 files changed, 64 insertions(+), 60 deletions(-) (limited to 'app/Controller') diff --git a/app/Controller/Base.php b/app/Controller/Base.php index 8890db4c..462529b1 100644 --- a/app/Controller/Base.php +++ b/app/Controller/Base.php @@ -246,4 +246,25 @@ abstract class Base return $task; } + + /** + * Common method to get a project + * + * @access protected + * @return array + */ + protected function getProject() + { + $project_id = $this->request->getIntegerParam('project_id'); + $project = $this->project->getById($project_id); + + if (! $project) { + $this->session->flashError(t('Project not found.')); + $this->response->redirect('?controller=project'); + } + + $this->checkProjectPermissions($project['id']); + + return $project; + } } diff --git a/app/Controller/Category.php b/app/Controller/Category.php index 9e2bcdbb..5fd59c0a 100644 --- a/app/Controller/Category.php +++ b/app/Controller/Category.php @@ -10,25 +10,6 @@ namespace Controller; */ class Category extends Base { - /** - * Get the current project (common method between actions) - * - * @access private - * @return array - */ - private function getProject() - { - $project_id = $this->request->getIntegerParam('project_id'); - $project = $this->project->getById($project_id); - - if (! $project) { - $this->session->flashError(t('Project not found.')); - $this->response->redirect('?controller=project'); - } - - return $project; - } - /** * Get the category (common method between actions) * diff --git a/app/Controller/Project.php b/app/Controller/Project.php index 0de67691..8c21801b 100644 --- a/app/Controller/Project.php +++ b/app/Controller/Project.php @@ -3,6 +3,7 @@ namespace Controller; use Model\Task as TaskModel; +use Core\Translator; /** * Project controller @@ -12,6 +13,39 @@ use Model\Task as TaskModel; */ class Project extends Base { + /** + * Task export + * + * @access public + */ + public function export() + { + $project = $this->getProject(); + $from = $this->request->getStringParam('from'); + $to = $this->request->getStringParam('to'); + + if ($from && $to) { + Translator::disableEscaping(); + $data = $this->task->export($project['id'], $from, $to); + $this->response->forceDownload('Export_'.date('Y_m_d_H_i_S').'.csv'); + $this->response->csv($data); + } + + $this->response->html($this->template->layout('project_export', array( + 'values' => array( + 'controller' => 'project', + 'action' => 'export', + 'project_id' => $project['id'], + 'from' => $from, + 'to' => $to, + ), + 'errors' => array(), + 'menu' => 'projects', + 'project' => $project, + 'title' => t('Tasks Export') + ))); + } + /** * Task search for a given project * @@ -19,24 +53,15 @@ class Project extends Base */ public function search() { - $project_id = $this->request->getIntegerParam('project_id'); + $project = $this->getProject(); $search = $this->request->getStringParam('search'); - - $project = $this->project->getById($project_id); $tasks = array(); $nb_tasks = 0; - if (! $project) { - $this->session->flashError(t('Project not found.')); - $this->response->redirect('?controller=project'); - } - - $this->checkProjectPermissions($project['id']); - if ($search !== '') { $filters = array( - array('column' => 'project_id', 'operator' => 'eq', 'value' => $project_id), + array('column' => 'project_id', 'operator' => 'eq', 'value' => $project['id']), 'or' => array( array('column' => 'title', 'operator' => 'like', 'value' => '%'.$search.'%'), //array('column' => 'description', 'operator' => 'like', 'value' => '%'.$search.'%'), @@ -58,7 +83,7 @@ class Project extends Base ), 'menu' => 'projects', 'project' => $project, - 'columns' => $this->board->getColumnsList($project_id), + 'columns' => $this->board->getColumnsList($project['id']), 'categories' => $this->category->getList($project['id'], false), 'title' => $project['name'].($nb_tasks > 0 ? ' ('.$nb_tasks.')' : '') ))); @@ -71,18 +96,10 @@ class Project extends Base */ public function tasks() { - $project_id = $this->request->getIntegerParam('project_id'); - $project = $this->project->getById($project_id); - - if (! $project) { - $this->session->flashError(t('Project not found.')); - $this->response->redirect('?controller=project'); - } - - $this->checkProjectPermissions($project['id']); + $project = $this->getProject(); $filters = array( - array('column' => 'project_id', 'operator' => 'eq', 'value' => $project_id), + array('column' => 'project_id', 'operator' => 'eq', 'value' => $project['id']), array('column' => 'is_active', 'operator' => 'eq', 'value' => TaskModel::STATUS_CLOSED), ); @@ -92,7 +109,7 @@ class Project extends Base $this->response->html($this->template->layout('project_tasks', array( 'menu' => 'projects', 'project' => $project, - 'columns' => $this->board->getColumnsList($project_id), + 'columns' => $this->board->getColumnsList($project['id']), 'categories' => $this->category->getList($project['id'], false), 'tasks' => $tasks, 'nb_tasks' => $nb_tasks, @@ -169,12 +186,7 @@ class Project extends Base */ public function edit() { - $project = $this->project->getById($this->request->getIntegerParam('project_id')); - - if (! $project) { - $this->session->flashError(t('Project not found.')); - $this->response->redirect('?controller=project'); - } + $project = $this->getProject(); $this->response->html($this->template->layout('project_edit', array( 'errors' => array(), @@ -220,12 +232,7 @@ class Project extends Base */ public function confirm() { - $project = $this->project->getById($this->request->getIntegerParam('project_id')); - - if (! $project) { - $this->session->flashError(t('Project not found.')); - $this->response->redirect('?controller=project'); - } + $project = $this->getProject(); $this->response->html($this->template->layout('project_remove', array( 'project' => $project, @@ -298,12 +305,7 @@ class Project extends Base */ public function users() { - $project = $this->project->getById($this->request->getIntegerParam('project_id')); - - if (! $project) { - $this->session->flashError(t('Project not found.')); - $this->response->redirect('?controller=project'); - } + $project = $this->getProject(); $this->response->html($this->template->layout('project_users', array( 'project' => $project, -- cgit v1.2.3