From 1353929a7dbd3f2e897fa7d3ab88e959ca573f9f Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sat, 28 May 2016 13:41:54 -0400 Subject: Rename controllers --- app/Controller/Action.php | 77 ----- app/Controller/ActionController.php | 77 +++++ app/Controller/ActionCreation.php | 122 -------- app/Controller/ActionCreationController.php | 122 ++++++++ app/Controller/ActionProject.php | 38 --- app/Controller/Activity.php | 45 --- app/Controller/ActivityController.php | 45 +++ app/Controller/Analytic.php | 178 ------------ app/Controller/AnalyticController.php | 178 ++++++++++++ app/Controller/AppController.php | 1 + app/Controller/Auth.php | 83 ------ app/Controller/AuthController.php | 83 ++++++ app/Controller/BoardPopover.php | 47 --- app/Controller/BoardPopoverController.php | 47 +++ app/Controller/BoardTooltip.php | 127 --------- app/Controller/BoardTooltipController.php | 127 +++++++++ app/Controller/Calendar.php | 107 ------- app/Controller/CalendarController.php | 107 +++++++ app/Controller/Category.php | 159 ----------- app/Controller/CategoryController.php | 159 +++++++++++ app/Controller/Column.php | 178 ------------ app/Controller/ColumnController.php | 178 ++++++++++++ app/Controller/Comment.php | 191 ------------- app/Controller/CommentController.php | 191 +++++++++++++ app/Controller/CustomFilterController.php | 165 +++++++++++ app/Controller/Customfilter.php | 164 ----------- app/Controller/Export.php | 91 ------ app/Controller/ExportController.php | 91 ++++++ app/Controller/FileViewer.php | 136 --------- app/Controller/FileViewerController.php | 136 +++++++++ app/Controller/Link.php | 150 ---------- app/Controller/LinkController.php | 150 ++++++++++ app/Controller/Listing.php | 45 --- app/Controller/OAuthController.php | 130 +++++++++ app/Controller/Oauth.php | 130 --------- app/Controller/PasswordReset.php | 122 -------- app/Controller/PasswordResetController.php | 122 ++++++++ .../ProjectActionDuplicationController.php | 38 +++ app/Controller/ProjectCreation.php | 129 --------- app/Controller/ProjectCreationController.php | 129 +++++++++ app/Controller/ProjectEditController.php | 4 +- app/Controller/ProjectFile.php | 79 ------ app/Controller/ProjectFileController.php | 79 ++++++ app/Controller/ProjectOverview.php | 32 --- app/Controller/ProjectOverviewController.php | 32 +++ app/Controller/ProjectUserOverviewController.php | 130 +++++++++ app/Controller/Projectuser.php | 130 --------- app/Controller/Swimlane.php | 314 --------------------- app/Controller/SwimlaneController.php | 314 +++++++++++++++++++++ app/Controller/TaskBulkController.php | 1 + app/Controller/TaskDuplicationController.php | 141 +++++++++ app/Controller/TaskExternalLink.php | 178 ------------ app/Controller/TaskExternalLinkController.php | 178 ++++++++++++ app/Controller/TaskFile.php | 98 ------- app/Controller/TaskFileController.php | 98 +++++++ app/Controller/TaskListController.php | 45 +++ app/Controller/Taskduplication.php | 141 --------- 57 files changed, 3296 insertions(+), 3293 deletions(-) delete mode 100644 app/Controller/Action.php create mode 100644 app/Controller/ActionController.php delete mode 100644 app/Controller/ActionCreation.php create mode 100644 app/Controller/ActionCreationController.php delete mode 100644 app/Controller/ActionProject.php delete mode 100644 app/Controller/Activity.php create mode 100644 app/Controller/ActivityController.php delete mode 100644 app/Controller/Analytic.php create mode 100644 app/Controller/AnalyticController.php delete mode 100644 app/Controller/Auth.php create mode 100644 app/Controller/AuthController.php delete mode 100644 app/Controller/BoardPopover.php create mode 100644 app/Controller/BoardPopoverController.php delete mode 100644 app/Controller/BoardTooltip.php create mode 100644 app/Controller/BoardTooltipController.php delete mode 100644 app/Controller/Calendar.php create mode 100644 app/Controller/CalendarController.php delete mode 100644 app/Controller/Category.php create mode 100644 app/Controller/CategoryController.php delete mode 100644 app/Controller/Column.php create mode 100644 app/Controller/ColumnController.php delete mode 100644 app/Controller/Comment.php create mode 100644 app/Controller/CommentController.php create mode 100644 app/Controller/CustomFilterController.php delete mode 100644 app/Controller/Customfilter.php delete mode 100644 app/Controller/Export.php create mode 100644 app/Controller/ExportController.php delete mode 100644 app/Controller/FileViewer.php create mode 100644 app/Controller/FileViewerController.php delete mode 100644 app/Controller/Link.php create mode 100644 app/Controller/LinkController.php delete mode 100644 app/Controller/Listing.php create mode 100644 app/Controller/OAuthController.php delete mode 100644 app/Controller/Oauth.php delete mode 100644 app/Controller/PasswordReset.php create mode 100644 app/Controller/PasswordResetController.php create mode 100644 app/Controller/ProjectActionDuplicationController.php delete mode 100644 app/Controller/ProjectCreation.php create mode 100644 app/Controller/ProjectCreationController.php delete mode 100644 app/Controller/ProjectFile.php create mode 100644 app/Controller/ProjectFileController.php delete mode 100644 app/Controller/ProjectOverview.php create mode 100644 app/Controller/ProjectOverviewController.php create mode 100644 app/Controller/ProjectUserOverviewController.php delete mode 100644 app/Controller/Projectuser.php delete mode 100644 app/Controller/Swimlane.php create mode 100644 app/Controller/SwimlaneController.php create mode 100644 app/Controller/TaskDuplicationController.php delete mode 100644 app/Controller/TaskExternalLink.php create mode 100644 app/Controller/TaskExternalLinkController.php delete mode 100644 app/Controller/TaskFile.php create mode 100644 app/Controller/TaskFileController.php create mode 100644 app/Controller/TaskListController.php delete mode 100644 app/Controller/Taskduplication.php (limited to 'app/Controller') diff --git a/app/Controller/Action.php b/app/Controller/Action.php deleted file mode 100644 index 40497a62..00000000 --- a/app/Controller/Action.php +++ /dev/null @@ -1,77 +0,0 @@ -getProject(); - $actions = $this->action->getAllByProject($project['id']); - - $this->response->html($this->helper->layout->project('action/index', array( - 'values' => array('project_id' => $project['id']), - 'project' => $project, - 'actions' => $actions, - 'available_actions' => $this->actionManager->getAvailableActions(), - 'available_events' => $this->eventManager->getAll(), - 'available_params' => $this->actionManager->getAvailableParameters($actions), - 'columns_list' => $this->column->getList($project['id']), - 'users_list' => $this->projectUserRole->getAssignableUsersList($project['id']), - 'projects_list' => $this->projectUserRole->getProjectsByUser($this->userSession->getId()), - 'colors_list' => $this->color->getList(), - 'categories_list' => $this->category->getList($project['id']), - 'links_list' => $this->link->getList(0, false), - 'title' => t('Automatic actions') - ))); - } - - /** - * Confirmation dialog before removing an action - * - * @access public - */ - public function confirm() - { - $project = $this->getProject(); - - $this->response->html($this->helper->layout->project('action/remove', array( - 'action' => $this->action->getById($this->request->getIntegerParam('action_id')), - 'available_events' => $this->eventManager->getAll(), - 'available_actions' => $this->actionManager->getAvailableActions(), - 'project' => $project, - 'title' => t('Remove an action') - ))); - } - - /** - * Remove an action - * - * @access public - */ - public function remove() - { - $this->checkCSRFParam(); - $project = $this->getProject(); - $action = $this->action->getById($this->request->getIntegerParam('action_id')); - - if (! empty($action) && $this->action->remove($action['id'])) { - $this->flash->success(t('Action removed successfully.')); - } else { - $this->flash->failure(t('Unable to remove this action.')); - } - - $this->response->redirect($this->helper->url->to('action', 'index', array('project_id' => $project['id']))); - } -} diff --git a/app/Controller/ActionController.php b/app/Controller/ActionController.php new file mode 100644 index 00000000..51090d22 --- /dev/null +++ b/app/Controller/ActionController.php @@ -0,0 +1,77 @@ +getProject(); + $actions = $this->action->getAllByProject($project['id']); + + $this->response->html($this->helper->layout->project('action/index', array( + 'values' => array('project_id' => $project['id']), + 'project' => $project, + 'actions' => $actions, + 'available_actions' => $this->actionManager->getAvailableActions(), + 'available_events' => $this->eventManager->getAll(), + 'available_params' => $this->actionManager->getAvailableParameters($actions), + 'columns_list' => $this->column->getList($project['id']), + 'users_list' => $this->projectUserRole->getAssignableUsersList($project['id']), + 'projects_list' => $this->projectUserRole->getProjectsByUser($this->userSession->getId()), + 'colors_list' => $this->color->getList(), + 'categories_list' => $this->category->getList($project['id']), + 'links_list' => $this->link->getList(0, false), + 'title' => t('Automatic actions') + ))); + } + + /** + * Confirmation dialog before removing an action + * + * @access public + */ + public function confirm() + { + $project = $this->getProject(); + + $this->response->html($this->helper->layout->project('action/remove', array( + 'action' => $this->action->getById($this->request->getIntegerParam('action_id')), + 'available_events' => $this->eventManager->getAll(), + 'available_actions' => $this->actionManager->getAvailableActions(), + 'project' => $project, + 'title' => t('Remove an action') + ))); + } + + /** + * Remove an action + * + * @access public + */ + public function remove() + { + $this->checkCSRFParam(); + $project = $this->getProject(); + $action = $this->action->getById($this->request->getIntegerParam('action_id')); + + if (! empty($action) && $this->action->remove($action['id'])) { + $this->flash->success(t('Action removed successfully.')); + } else { + $this->flash->failure(t('Unable to remove this action.')); + } + + $this->response->redirect($this->helper->url->to('ActionController', 'index', array('project_id' => $project['id']))); + } +} diff --git a/app/Controller/ActionCreation.php b/app/Controller/ActionCreation.php deleted file mode 100644 index 388b30e2..00000000 --- a/app/Controller/ActionCreation.php +++ /dev/null @@ -1,122 +0,0 @@ -getProject(); - - $this->response->html($this->template->render('action_creation/create', array( - 'project' => $project, - 'values' => array('project_id' => $project['id']), - 'available_actions' => $this->actionManager->getAvailableActions(), - ))); - } - - /** - * Choose the event according to the action (step 2) - * - * @access public - */ - public function event() - { - $project = $this->getProject(); - $values = $this->request->getValues(); - - if (empty($values['action_name']) || empty($values['project_id'])) { - return $this->create(); - } - - $this->response->html($this->template->render('action_creation/event', array( - 'values' => $values, - 'project' => $project, - 'available_actions' => $this->actionManager->getAvailableActions(), - 'events' => $this->actionManager->getCompatibleEvents($values['action_name']), - ))); - } - - /** - * Define action parameters (step 3) - * - * @access public - */ - public function params() - { - $project = $this->getProject(); - $values = $this->request->getValues(); - - if (empty($values['action_name']) || empty($values['project_id']) || empty($values['event_name'])) { - return $this->create(); - } - - $action = $this->actionManager->getAction($values['action_name']); - $action_params = $action->getActionRequiredParameters(); - - if (empty($action_params)) { - $this->doCreation($project, $values + array('params' => array())); - } - - $projects_list = $this->projectUserRole->getActiveProjectsByUser($this->userSession->getId()); - unset($projects_list[$project['id']]); - - $this->response->html($this->template->render('action_creation/params', array( - 'values' => $values, - 'action_params' => $action_params, - 'columns_list' => $this->column->getList($project['id']), - 'users_list' => $this->projectUserRole->getAssignableUsersList($project['id']), - 'projects_list' => $projects_list, - 'colors_list' => $this->color->getList(), - 'categories_list' => $this->category->getList($project['id']), - 'links_list' => $this->link->getList(0, false), - 'priorities_list' => $this->project->getPriorities($project), - 'project' => $project, - 'available_actions' => $this->actionManager->getAvailableActions(), - 'events' => $this->actionManager->getCompatibleEvents($values['action_name']), - ))); - } - - /** - * Save the action (last step) - * - * @access public - */ - public function save() - { - $this->doCreation($this->getProject(), $this->request->getValues()); - } - - /** - * Common method to save the action - * - * @access private - * @param array $project Project properties - * @param array $values Form values - */ - private function doCreation(array $project, array $values) - { - list($valid, ) = $this->actionValidator->validateCreation($values); - - if ($valid) { - if ($this->action->create($values) !== false) { - $this->flash->success(t('Your automatic action have been created successfully.')); - } else { - $this->flash->failure(t('Unable to create your automatic action.')); - } - } - - $this->response->redirect($this->helper->url->to('action', 'index', array('project_id' => $project['id']))); - } -} diff --git a/app/Controller/ActionCreationController.php b/app/Controller/ActionCreationController.php new file mode 100644 index 00000000..e055f11b --- /dev/null +++ b/app/Controller/ActionCreationController.php @@ -0,0 +1,122 @@ +getProject(); + + $this->response->html($this->template->render('action_creation/create', array( + 'project' => $project, + 'values' => array('project_id' => $project['id']), + 'available_actions' => $this->actionManager->getAvailableActions(), + ))); + } + + /** + * Choose the event according to the action (step 2) + * + * @access public + */ + public function event() + { + $project = $this->getProject(); + $values = $this->request->getValues(); + + if (empty($values['action_name']) || empty($values['project_id'])) { + return $this->create(); + } + + $this->response->html($this->template->render('action_creation/event', array( + 'values' => $values, + 'project' => $project, + 'available_actions' => $this->actionManager->getAvailableActions(), + 'events' => $this->actionManager->getCompatibleEvents($values['action_name']), + ))); + } + + /** + * Define action parameters (step 3) + * + * @access public + */ + public function params() + { + $project = $this->getProject(); + $values = $this->request->getValues(); + + if (empty($values['action_name']) || empty($values['project_id']) || empty($values['event_name'])) { + return $this->create(); + } + + $action = $this->actionManager->getAction($values['action_name']); + $action_params = $action->getActionRequiredParameters(); + + if (empty($action_params)) { + $this->doCreation($project, $values + array('params' => array())); + } + + $projects_list = $this->projectUserRole->getActiveProjectsByUser($this->userSession->getId()); + unset($projects_list[$project['id']]); + + $this->response->html($this->template->render('action_creation/params', array( + 'values' => $values, + 'action_params' => $action_params, + 'columns_list' => $this->column->getList($project['id']), + 'users_list' => $this->projectUserRole->getAssignableUsersList($project['id']), + 'projects_list' => $projects_list, + 'colors_list' => $this->color->getList(), + 'categories_list' => $this->category->getList($project['id']), + 'links_list' => $this->link->getList(0, false), + 'priorities_list' => $this->project->getPriorities($project), + 'project' => $project, + 'available_actions' => $this->actionManager->getAvailableActions(), + 'events' => $this->actionManager->getCompatibleEvents($values['action_name']), + ))); + } + + /** + * Save the action (last step) + * + * @access public + */ + public function save() + { + $this->doCreation($this->getProject(), $this->request->getValues()); + } + + /** + * Common method to save the action + * + * @access private + * @param array $project Project properties + * @param array $values Form values + */ + private function doCreation(array $project, array $values) + { + list($valid, ) = $this->actionValidator->validateCreation($values); + + if ($valid) { + if ($this->action->create($values) !== false) { + $this->flash->success(t('Your automatic action have been created successfully.')); + } else { + $this->flash->failure(t('Unable to create your automatic action.')); + } + } + + $this->response->redirect($this->helper->url->to('ActionController', 'index', array('project_id' => $project['id']))); + } +} diff --git a/app/Controller/ActionProject.php b/app/Controller/ActionProject.php deleted file mode 100644 index 10b3c9d4..00000000 --- a/app/Controller/ActionProject.php +++ /dev/null @@ -1,38 +0,0 @@ -getProject(); - $projects = $this->projectUserRole->getProjectsByUser($this->userSession->getId()); - unset($projects[$project['id']]); - - $this->response->html($this->template->render('action_project/project', array( - 'project' => $project, - 'projects_list' => $projects, - ))); - } - - public function save() - { - $project = $this->getProject(); - $src_project_id = $this->request->getValue('src_project_id'); - - if ($this->action->duplicate($src_project_id, $project['id'])) { - $this->flash->success(t('Actions duplicated successfully.')); - } else { - $this->flash->failure(t('Unable to duplicate actions.')); - } - - $this->response->redirect($this->helper->url->to('action', 'index', array('project_id' => $project['id']))); - } -} diff --git a/app/Controller/Activity.php b/app/Controller/Activity.php deleted file mode 100644 index 0c6aa3f3..00000000 --- a/app/Controller/Activity.php +++ /dev/null @@ -1,45 +0,0 @@ -getProject(); - - $this->response->html($this->helper->layout->app('activity/project', array( - 'events' => $this->helper->projectActivity->getProjectEvents($project['id']), - 'project' => $project, - 'title' => t('%s\'s activity', $project['name']) - ))); - } - - /** - * Display task activities - * - * @access public - */ - public function task() - { - $task = $this->getTask(); - - $this->response->html($this->helper->layout->task('activity/task', array( - 'title' => $task['title'], - 'task' => $task, - 'project' => $this->project->getById($task['project_id']), - 'events' => $this->helper->projectActivity->getTaskEvents($task['id']), - ))); - } -} diff --git a/app/Controller/ActivityController.php b/app/Controller/ActivityController.php new file mode 100644 index 00000000..a8fc1b39 --- /dev/null +++ b/app/Controller/ActivityController.php @@ -0,0 +1,45 @@ +getProject(); + + $this->response->html($this->helper->layout->app('activity/project', array( + 'events' => $this->helper->projectActivity->getProjectEvents($project['id']), + 'project' => $project, + 'title' => t('%s\'s activity', $project['name']) + ))); + } + + /** + * Display task activities + * + * @access public + */ + public function task() + { + $task = $this->getTask(); + + $this->response->html($this->helper->layout->task('activity/task', array( + 'title' => $task['title'], + 'task' => $task, + 'project' => $this->project->getById($task['project_id']), + 'events' => $this->helper->projectActivity->getTaskEvents($task['id']), + ))); + } +} diff --git a/app/Controller/Analytic.php b/app/Controller/Analytic.php deleted file mode 100644 index ba73c15c..00000000 --- a/app/Controller/Analytic.php +++ /dev/null @@ -1,178 +0,0 @@ -getProject(); - list($from, $to) = $this->getDates(); - - $this->response->html($this->helper->layout->analytic('analytic/lead_cycle_time', array( - 'values' => array( - 'from' => $from, - 'to' => $to, - ), - 'project' => $project, - 'average' => $this->averageLeadCycleTimeAnalytic->build($project['id']), - 'metrics' => $this->projectDailyStats->getRawMetrics($project['id'], $from, $to), - 'date_format' => $this->config->get('application_date_format'), - 'date_formats' => $this->dateParser->getAvailableFormats($this->dateParser->getDateFormats()), - 'title' => t('Lead and Cycle time for "%s"', $project['name']), - ))); - } - - /** - * Show comparison between actual and estimated hours chart - * - * @access public - */ - public function compareHours() - { - $project = $this->getProject(); - - $paginator = $this->paginator - ->setUrl('analytic', 'compareHours', array('project_id' => $project['id'])) - ->setMax(30) - ->setOrder(TaskModel::TABLE.'.id') - ->setQuery($this->taskQuery - ->withFilter(new TaskProjectFilter($project['id'])) - ->getQuery() - ) - ->calculate(); - - $this->response->html($this->helper->layout->analytic('analytic/compare_hours', array( - 'project' => $project, - 'paginator' => $paginator, - 'metrics' => $this->estimatedTimeComparisonAnalytic->build($project['id']), - 'title' => t('Compare hours for "%s"', $project['name']), - ))); - } - - /** - * Show average time spent by column - * - * @access public - */ - public function averageTimeByColumn() - { - $project = $this->getProject(); - - $this->response->html($this->helper->layout->analytic('analytic/avg_time_columns', array( - 'project' => $project, - 'metrics' => $this->averageTimeSpentColumnAnalytic->build($project['id']), - 'title' => t('Average time spent into each column for "%s"', $project['name']), - ))); - } - - /** - * Show tasks distribution graph - * - * @access public - */ - public function tasks() - { - $project = $this->getProject(); - - $this->response->html($this->helper->layout->analytic('analytic/tasks', array( - 'project' => $project, - 'metrics' => $this->taskDistributionAnalytic->build($project['id']), - 'title' => t('Task repartition for "%s"', $project['name']), - ))); - } - - /** - * Show users repartition - * - * @access public - */ - public function users() - { - $project = $this->getProject(); - - $this->response->html($this->helper->layout->analytic('analytic/users', array( - 'project' => $project, - 'metrics' => $this->userDistributionAnalytic->build($project['id']), - 'title' => t('User repartition for "%s"', $project['name']), - ))); - } - - /** - * Show cumulative flow diagram - * - * @access public - */ - public function cfd() - { - $this->commonAggregateMetrics('analytic/cfd', 'total', 'Cumulative flow diagram for "%s"'); - } - - /** - * Show burndown chart - * - * @access public - */ - public function burndown() - { - $this->commonAggregateMetrics('analytic/burndown', 'score', 'Burndown chart for "%s"'); - } - - /** - * Common method for CFD and Burdown chart - * - * @access private - * @param string $template - * @param string $column - * @param string $title - */ - private function commonAggregateMetrics($template, $column, $title) - { - $project = $this->getProject(); - list($from, $to) = $this->getDates(); - - $display_graph = $this->projectDailyColumnStats->countDays($project['id'], $from, $to) >= 2; - - $this->response->html($this->helper->layout->analytic($template, array( - 'values' => array( - 'from' => $from, - 'to' => $to, - ), - 'display_graph' => $display_graph, - 'metrics' => $display_graph ? $this->projectDailyColumnStats->getAggregatedMetrics($project['id'], $from, $to, $column) : array(), - 'project' => $project, - 'date_format' => $this->config->get('application_date_format'), - 'date_formats' => $this->dateParser->getAvailableFormats($this->dateParser->getDateFormats()), - 'title' => t($title, $project['name']), - ))); - } - - private function getDates() - { - $values = $this->request->getValues(); - - $from = $this->request->getStringParam('from', date('Y-m-d', strtotime('-1week'))); - $to = $this->request->getStringParam('to', date('Y-m-d')); - - if (! empty($values)) { - $from = $values['from']; - $to = $values['to']; - } - - return array($from, $to); - } -} diff --git a/app/Controller/AnalyticController.php b/app/Controller/AnalyticController.php new file mode 100644 index 00000000..99d34c66 --- /dev/null +++ b/app/Controller/AnalyticController.php @@ -0,0 +1,178 @@ +getProject(); + list($from, $to) = $this->getDates(); + + $this->response->html($this->helper->layout->analytic('analytic/lead_cycle_time', array( + 'values' => array( + 'from' => $from, + 'to' => $to, + ), + 'project' => $project, + 'average' => $this->averageLeadCycleTimeAnalytic->build($project['id']), + 'metrics' => $this->projectDailyStats->getRawMetrics($project['id'], $from, $to), + 'date_format' => $this->config->get('application_date_format'), + 'date_formats' => $this->dateParser->getAvailableFormats($this->dateParser->getDateFormats()), + 'title' => t('Lead and Cycle time for "%s"', $project['name']), + ))); + } + + /** + * Show comparison between actual and estimated hours chart + * + * @access public + */ + public function compareHours() + { + $project = $this->getProject(); + + $paginator = $this->paginator + ->setUrl('AnalyticController', 'compareHours', array('project_id' => $project['id'])) + ->setMax(30) + ->setOrder(TaskModel::TABLE.'.id') + ->setQuery($this->taskQuery + ->withFilter(new TaskProjectFilter($project['id'])) + ->getQuery() + ) + ->calculate(); + + $this->response->html($this->helper->layout->analytic('analytic/compare_hours', array( + 'project' => $project, + 'paginator' => $paginator, + 'metrics' => $this->estimatedTimeComparisonAnalytic->build($project['id']), + 'title' => t('Compare hours for "%s"', $project['name']), + ))); + } + + /** + * Show average time spent by column + * + * @access public + */ + public function averageTimeByColumn() + { + $project = $this->getProject(); + + $this->response->html($this->helper->layout->analytic('analytic/avg_time_columns', array( + 'project' => $project, + 'metrics' => $this->averageTimeSpentColumnAnalytic->build($project['id']), + 'title' => t('Average time spent into each column for "%s"', $project['name']), + ))); + } + + /** + * Show tasks distribution graph + * + * @access public + */ + public function tasks() + { + $project = $this->getProject(); + + $this->response->html($this->helper->layout->analytic('analytic/tasks', array( + 'project' => $project, + 'metrics' => $this->taskDistributionAnalytic->build($project['id']), + 'title' => t('Task repartition for "%s"', $project['name']), + ))); + } + + /** + * Show users repartition + * + * @access public + */ + public function users() + { + $project = $this->getProject(); + + $this->response->html($this->helper->layout->analytic('analytic/users', array( + 'project' => $project, + 'metrics' => $this->userDistributionAnalytic->build($project['id']), + 'title' => t('User repartition for "%s"', $project['name']), + ))); + } + + /** + * Show cumulative flow diagram + * + * @access public + */ + public function cfd() + { + $this->commonAggregateMetrics('analytic/cfd', 'total', 'Cumulative flow diagram for "%s"'); + } + + /** + * Show burndown chart + * + * @access public + */ + public function burndown() + { + $this->commonAggregateMetrics('analytic/burndown', 'score', 'Burndown chart for "%s"'); + } + + /** + * Common method for CFD and Burdown chart + * + * @access private + * @param string $template + * @param string $column + * @param string $title + */ + private function commonAggregateMetrics($template, $column, $title) + { + $project = $this->getProject(); + list($from, $to) = $this->getDates(); + + $display_graph = $this->projectDailyColumnStats->countDays($project['id'], $from, $to) >= 2; + + $this->response->html($this->helper->layout->analytic($template, array( + 'values' => array( + 'from' => $from, + 'to' => $to, + ), + 'display_graph' => $display_graph, + 'metrics' => $display_graph ? $this->projectDailyColumnStats->getAggregatedMetrics($project['id'], $from, $to, $column) : array(), + 'project' => $project, + 'date_format' => $this->config->get('application_date_format'), + 'date_formats' => $this->dateParser->getAvailableFormats($this->dateParser->getDateFormats()), + 'title' => t($title, $project['name']), + ))); + } + + private function getDates() + { + $values = $this->request->getValues(); + + $from = $this->request->getStringParam('from', date('Y-m-d', strtotime('-1week'))); + $to = $this->request->getStringParam('to', date('Y-m-d')); + + if (! empty($values)) { + $from = $values['from']; + $to = $values['to']; + } + + return array($from, $to); + } +} diff --git a/app/Controller/AppController.php b/app/Controller/AppController.php index 60bc154a..45cf39a5 100644 --- a/app/Controller/AppController.php +++ b/app/Controller/AppController.php @@ -8,6 +8,7 @@ use Kanboard\Core\Base; * Class AppController * * @package Kanboard\Controller + * @author Frederic Guillot */ class AppController extends Base { diff --git a/app/Controller/Auth.php b/app/Controller/Auth.php deleted file mode 100644 index cad44a34..00000000 --- a/app/Controller/Auth.php +++ /dev/null @@ -1,83 +0,0 @@ -userSession->isLogged()) { - $this->response->redirect($this->helper->url->to('DashboardController', 'show')); - } else { - $this->response->html($this->helper->layout->app('auth/index', array( - 'captcha' => ! empty($values['username']) && $this->userLocking->hasCaptcha($values['username']), - 'errors' => $errors, - 'values' => $values, - 'no_layout' => true, - 'title' => t('Login') - ))); - } - } - - /** - * Check credentials - * - * @access public - */ - public function check() - { - $values = $this->request->getValues(); - $this->sessionStorage->hasRememberMe = ! empty($values['remember_me']); - list($valid, $errors) = $this->authValidator->validateForm($values); - - if ($valid) { - $this->redirectAfterLogin(); - } else { - $this->login($values, $errors); - } - } - - /** - * Logout and destroy session - * - * @access public - */ - public function logout() - { - if (! DISABLE_LOGOUT) { - $this->sessionManager->close(); - $this->response->redirect($this->helper->url->to('auth', 'login')); - } else { - $this->response->redirect($this->helper->url->to('auth', 'index')); - } - } - - /** - * Redirect the user after the authentication - * - * @access private - */ - private function redirectAfterLogin() - { - if (isset($this->sessionStorage->redirectAfterLogin) && ! empty($this->sessionStorage->redirectAfterLogin) && ! filter_var($this->sessionStorage->redirectAfterLogin, FILTER_VALIDATE_URL)) { - $redirect = $this->sessionStorage->redirectAfterLogin; - unset($this->sessionStorage->redirectAfterLogin); - $this->response->redirect($redirect); - } else { - $this->response->redirect($this->helper->url->to('DashboardController', 'show')); - } - } -} diff --git a/app/Controller/AuthController.php b/app/Controller/AuthController.php new file mode 100644 index 00000000..598b3ff8 --- /dev/null +++ b/app/Controller/AuthController.php @@ -0,0 +1,83 @@ +userSession->isLogged()) { + $this->response->redirect($this->helper->url->to('DashboardController', 'show')); + } else { + $this->response->html($this->helper->layout->app('auth/index', array( + 'captcha' => ! empty($values['username']) && $this->userLocking->hasCaptcha($values['username']), + 'errors' => $errors, + 'values' => $values, + 'no_layout' => true, + 'title' => t('Login') + ))); + } + } + + /** + * Check credentials + * + * @access public + */ + public function check() + { + $values = $this->request->getValues(); + $this->sessionStorage->hasRememberMe = ! empty($values['remember_me']); + list($valid, $errors) = $this->authValidator->validateForm($values); + + if ($valid) { + $this->redirectAfterLogin(); + } else { + $this->login($values, $errors); + } + } + + /** + * Logout and destroy session + * + * @access public + */ + public function logout() + { + if (! DISABLE_LOGOUT) { + $this->sessionManager->close(); + $this->response->redirect($this->helper->url->to('AuthController', 'login')); + } else { + $this->response->redirect($this->helper->url->to('AuthController', 'index')); + } + } + + /** + * Redirect the user after the authentication + * + * @access private + */ + private function redirectAfterLogin() + { + if (isset($this->sessionStorage->redirectAfterLogin) && ! empty($this->sessionStorage->redirectAfterLogin) && ! filter_var($this->sessionStorage->redirectAfterLogin, FILTER_VALIDATE_URL)) { + $redirect = $this->sessionStorage->redirectAfterLogin; + unset($this->sessionStorage->redirectAfterLogin); + $this->response->redirect($redirect); + } else { + $this->response->redirect($this->helper->url->to('DashboardController', 'show')); + } + } +} diff --git a/app/Controller/BoardPopover.php b/app/Controller/BoardPopover.php deleted file mode 100644 index d3117f78..00000000 --- a/app/Controller/BoardPopover.php +++ /dev/null @@ -1,47 +0,0 @@ -getProject(); - $column_id = $this->request->getIntegerParam('column_id'); - $swimlane_id = $this->request->getIntegerParam('swimlane_id'); - - $this->response->html($this->template->render('board_popover/close_all_tasks_column', array( - 'project' => $project, - 'nb_tasks' => $this->taskFinder->countByColumnAndSwimlaneId($project['id'], $column_id, $swimlane_id), - 'column' => $this->column->getColumnTitleById($column_id), - 'swimlane' => $this->swimlane->getNameById($swimlane_id) ?: t($project['default_swimlane']), - 'values' => array('column_id' => $column_id, 'swimlane_id' => $swimlane_id), - ))); - } - - /** - * Close all column tasks - * - * @access public - */ - public function closeColumnTasks() - { - $project = $this->getProject(); - $values = $this->request->getValues(); - - $this->taskStatus->closeTasksBySwimlaneAndColumn($values['swimlane_id'], $values['column_id']); - $this->flash->success(t('All tasks of the column "%s" and the swimlane "%s" have been closed successfully.', $this->column->getColumnTitleById($values['column_id']), $this->swimlane->getNameById($values['swimlane_id']) ?: t($project['default_swimlane']))); - $this->response->redirect($this->helper->url->to('board', 'show', array('project_id' => $project['id']))); - } -} diff --git a/app/Controller/BoardPopoverController.php b/app/Controller/BoardPopoverController.php new file mode 100644 index 00000000..b204af39 --- /dev/null +++ b/app/Controller/BoardPopoverController.php @@ -0,0 +1,47 @@ +getProject(); + $column_id = $this->request->getIntegerParam('column_id'); + $swimlane_id = $this->request->getIntegerParam('swimlane_id'); + + $this->response->html($this->template->render('board_popover/close_all_tasks_column', array( + 'project' => $project, + 'nb_tasks' => $this->taskFinder->countByColumnAndSwimlaneId($project['id'], $column_id, $swimlane_id), + 'column' => $this->column->getColumnTitleById($column_id), + 'swimlane' => $this->swimlane->getNameById($swimlane_id) ?: t($project['default_swimlane']), + 'values' => array('column_id' => $column_id, 'swimlane_id' => $swimlane_id), + ))); + } + + /** + * Close all column tasks + * + * @access public + */ + public function closeColumnTasks() + { + $project = $this->getProject(); + $values = $this->request->getValues(); + + $this->taskStatus->closeTasksBySwimlaneAndColumn($values['swimlane_id'], $values['column_id']); + $this->flash->success(t('All tasks of the column "%s" and the swimlane "%s" have been closed successfully.', $this->column->getColumnTitleById($values['column_id']), $this->swimlane->getNameById($values['swimlane_id']) ?: t($project['default_swimlane']))); + $this->response->redirect($this->helper->url->to('board', 'show', array('project_id' => $project['id']))); + } +} diff --git a/app/Controller/BoardTooltip.php b/app/Controller/BoardTooltip.php deleted file mode 100644 index 49d02ced..00000000 --- a/app/Controller/BoardTooltip.php +++ /dev/null @@ -1,127 +0,0 @@ -getTask(); - $this->response->html($this->template->render('board/tooltip_tasklinks', array( - 'links' => $this->taskLink->getAllGroupedByLabel($task['id']), - 'task' => $task, - ))); - } - - /** - * Get links on mouseover - * - * @access public - */ - public function externallinks() - { - $task = $this->getTask(); - $this->response->html($this->template->render('board/tooltip_external_links', array( - 'links' => $this->taskExternalLink->getAll($task['id']), - 'task' => $task, - ))); - } - - /** - * Get subtasks on mouseover - * - * @access public - */ - public function subtasks() - { - $task = $this->getTask(); - $this->response->html($this->template->render('board/tooltip_subtasks', array( - 'subtasks' => $this->subtask->getAll($task['id']), - 'task' => $task, - ))); - } - - /** - * Display all attachments during the task mouseover - * - * @access public - */ - public function attachments() - { - $task = $this->getTask(); - - $this->response->html($this->template->render('board/tooltip_files', array( - 'files' => $this->taskFile->getAll($task['id']), - 'task' => $task, - ))); - } - - /** - * Display comments during a task mouseover - * - * @access public - */ - public function comments() - { - $task = $this->getTask(); - - $this->response->html($this->template->render('board/tooltip_comments', array( - 'task' => $task, - 'comments' => $this->comment->getAll($task['id'], $this->userSession->getCommentSorting()) - ))); - } - - /** - * Display task description - * - * @access public - */ - public function description() - { - $task = $this->getTask(); - - $this->response->html($this->template->render('board/tooltip_description', array( - 'task' => $task - ))); - } - - /** - * Get recurrence information on mouseover - * - * @access public - */ - public function recurrence() - { - $task = $this->getTask(); - - $this->response->html($this->template->render('task_recurrence/info', array( - 'task' => $task, - 'recurrence_trigger_list' => $this->task->getRecurrenceTriggerList(), - 'recurrence_timeframe_list' => $this->task->getRecurrenceTimeframeList(), - 'recurrence_basedate_list' => $this->task->getRecurrenceBasedateList(), - ))); - } - - /** - * Display swimlane description in tooltip - * - * @access public - */ - public function swimlane() - { - $this->getProject(); - $swimlane = $this->swimlane->getById($this->request->getIntegerParam('swimlane_id')); - $this->response->html($this->template->render('board/tooltip_description', array('task' => $swimlane))); - } -} diff --git a/app/Controller/BoardTooltipController.php b/app/Controller/BoardTooltipController.php new file mode 100644 index 00000000..2f1d949e --- /dev/null +++ b/app/Controller/BoardTooltipController.php @@ -0,0 +1,127 @@ +getTask(); + $this->response->html($this->template->render('board/tooltip_tasklinks', array( + 'links' => $this->taskLink->getAllGroupedByLabel($task['id']), + 'task' => $task, + ))); + } + + /** + * Get links on mouseover + * + * @access public + */ + public function externallinks() + { + $task = $this->getTask(); + $this->response->html($this->template->render('board/tooltip_external_links', array( + 'links' => $this->taskExternalLink->getAll($task['id']), + 'task' => $task, + ))); + } + + /** + * Get subtasks on mouseover + * + * @access public + */ + public function subtasks() + { + $task = $this->getTask(); + $this->response->html($this->template->render('board/tooltip_subtasks', array( + 'subtasks' => $this->subtask->getAll($task['id']), + 'task' => $task, + ))); + } + + /** + * Display all attachments during the task mouseover + * + * @access public + */ + public function attachments() + { + $task = $this->getTask(); + + $this->response->html($this->template->render('board/tooltip_files', array( + 'files' => $this->taskFile->getAll($task['id']), + 'task' => $task, + ))); + } + + /** + * Display comments during a task mouseover + * + * @access public + */ + public function comments() + { + $task = $this->getTask(); + + $this->response->html($this->template->render('board/tooltip_comments', array( + 'task' => $task, + 'comments' => $this->comment->getAll($task['id'], $this->userSession->getCommentSorting()) + ))); + } + + /** + * Display task description + * + * @access public + */ + public function description() + { + $task = $this->getTask(); + + $this->response->html($this->template->render('board/tooltip_description', array( + 'task' => $task + ))); + } + + /** + * Get recurrence information on mouseover + * + * @access public + */ + public function recurrence() + { + $task = $this->getTask(); + + $this->response->html($this->template->render('task_recurrence/info', array( + 'task' => $task, + 'recurrence_trigger_list' => $this->task->getRecurrenceTriggerList(), + 'recurrence_timeframe_list' => $this->task->getRecurrenceTimeframeList(), + 'recurrence_basedate_list' => $this->task->getRecurrenceBasedateList(), + ))); + } + + /** + * Display swimlane description in tooltip + * + * @access public + */ + public function swimlane() + { + $this->getProject(); + $swimlane = $this->swimlane->getById($this->request->getIntegerParam('swimlane_id')); + $this->response->html($this->template->render('board/tooltip_description', array('task' => $swimlane))); + } +} diff --git a/app/Controller/Calendar.php b/app/Controller/Calendar.php deleted file mode 100644 index 706c1d3b..00000000 --- a/app/Controller/Calendar.php +++ /dev/null @@ -1,107 +0,0 @@ -getProject(); - - $this->response->html($this->helper->layout->app('calendar/show', array( - 'project' => $project, - 'title' => $project['name'], - 'description' => $this->helper->projectHeader->getDescription($project), - 'check_interval' => $this->config->get('board_private_refresh_interval'), - ))); - } - - /** - * Get tasks to display on the calendar (project view) - * - * @access public - */ - public function project() - { - $project_id = $this->request->getIntegerParam('project_id'); - $start = $this->request->getStringParam('start'); - $end = $this->request->getStringParam('end'); - $search = $this->userSession->getFilters($project_id); - $queryBuilder = $this->taskLexer->build($search)->withFilter(new TaskProjectFilter($project_id)); - - $events = $this->helper->calendar->getTaskDateDueEvents(clone($queryBuilder), $start, $end); - $events = array_merge($events, $this->helper->calendar->getTaskEvents(clone($queryBuilder), $start, $end)); - - $events = $this->hook->merge('controller:calendar:project:events', $events, array( - 'project_id' => $project_id, - 'start' => $start, - 'end' => $end, - )); - - $this->response->json($events); - } - - /** - * Get tasks to display on the calendar (user view) - * - * @access public - */ - public function user() - { - $user_id = $this->request->getIntegerParam('user_id'); - $start = $this->request->getStringParam('start'); - $end = $this->request->getStringParam('end'); - $queryBuilder = $this->taskQuery - ->withFilter(new TaskAssigneeFilter($user_id)) - ->withFilter(new TaskStatusFilter(TaskModel::STATUS_OPEN)); - - $events = $this->helper->calendar->getTaskDateDueEvents(clone($queryBuilder), $start, $end); - $events = array_merge($events, $this->helper->calendar->getTaskEvents(clone($queryBuilder), $start, $end)); - - if ($this->config->get('calendar_user_subtasks_time_tracking') == 1) { - $events = array_merge($events, $this->helper->calendar->getSubtaskTimeTrackingEvents($user_id, $start, $end)); - } - - $events = $this->hook->merge('controller:calendar:user:events', $events, array( - 'user_id' => $user_id, - 'start' => $start, - 'end' => $end, - )); - - $this->response->json($events); - } - - /** - * Update task due date - * - * @access public - */ - public function save() - { - if ($this->request->isAjax() && $this->request->isPost()) { - $values = $this->request->getJson(); - - $this->taskModification->update(array( - 'id' => $values['task_id'], - 'date_due' => substr($values['date_due'], 0, 10), - )); - } - } -} diff --git a/app/Controller/CalendarController.php b/app/Controller/CalendarController.php new file mode 100644 index 00000000..c875a18c --- /dev/null +++ b/app/Controller/CalendarController.php @@ -0,0 +1,107 @@ +getProject(); + + $this->response->html($this->helper->layout->app('calendar/show', array( + 'project' => $project, + 'title' => $project['name'], + 'description' => $this->helper->projectHeader->getDescription($project), + 'check_interval' => $this->config->get('board_private_refresh_interval'), + ))); + } + + /** + * Get tasks to display on the calendar (project view) + * + * @access public + */ + public function project() + { + $project_id = $this->request->getIntegerParam('project_id'); + $start = $this->request->getStringParam('start'); + $end = $this->request->getStringParam('end'); + $search = $this->userSession->getFilters($project_id); + $queryBuilder = $this->taskLexer->build($search)->withFilter(new TaskProjectFilter($project_id)); + + $events = $this->helper->calendar->getTaskDateDueEvents(clone($queryBuilder), $start, $end); + $events = array_merge($events, $this->helper->calendar->getTaskEvents(clone($queryBuilder), $start, $end)); + + $events = $this->hook->merge('controller:calendar:project:events', $events, array( + 'project_id' => $project_id, + 'start' => $start, + 'end' => $end, + )); + + $this->response->json($events); + } + + /** + * Get tasks to display on the calendar (user view) + * + * @access public + */ + public function user() + { + $user_id = $this->request->getIntegerParam('user_id'); + $start = $this->request->getStringParam('start'); + $end = $this->request->getStringParam('end'); + $queryBuilder = $this->taskQuery + ->withFilter(new TaskAssigneeFilter($user_id)) + ->withFilter(new TaskStatusFilter(TaskModel::STATUS_OPEN)); + + $events = $this->helper->calendar->getTaskDateDueEvents(clone($queryBuilder), $start, $end); + $events = array_merge($events, $this->helper->calendar->getTaskEvents(clone($queryBuilder), $start, $end)); + + if ($this->config->get('calendar_user_subtasks_time_tracking') == 1) { + $events = array_merge($events, $this->helper->calendar->getSubtaskTimeTrackingEvents($user_id, $start, $end)); + } + + $events = $this->hook->merge('controller:calendar:user:events', $events, array( + 'user_id' => $user_id, + 'start' => $start, + 'end' => $end, + )); + + $this->response->json($events); + } + + /** + * Update task due date + * + * @access public + */ + public function save() + { + if ($this->request->isAjax() && $this->request->isPost()) { + $values = $this->request->getJson(); + + $this->taskModification->update(array( + 'id' => $values['task_id'], + 'date_due' => substr($values['date_due'], 0, 10), + )); + } + } +} diff --git a/app/Controller/Category.php b/app/Controller/Category.php deleted file mode 100644 index 954d92cc..00000000 --- a/app/Controller/Category.php +++ /dev/null @@ -1,159 +0,0 @@ -category->getById($this->request->getIntegerParam('category_id')); - - if (empty($category)) { - throw new PageNotFoundException(); - } - - return $category; - } - - /** - * List of categories for a given project - * - * @access public - * @param array $values - * @param array $errors - * @throws PageNotFoundException - */ - public function index(array $values = array(), array $errors = array()) - { - $project = $this->getProject(); - - $this->response->html($this->helper->layout->project('category/index', array( - 'categories' => $this->category->getList($project['id'], false), - 'values' => $values + array('project_id' => $project['id']), - 'errors' => $errors, - 'project' => $project, - 'title' => t('Categories') - ))); - } - - /** - * Validate and save a new category - * - * @access public - */ - public function save() - { - $project = $this->getProject(); - - $values = $this->request->getValues(); - list($valid, $errors) = $this->categoryValidator->validateCreation($values); - - if ($valid) { - if ($this->category->create($values)) { - $this->flash->success(t('Your category have been created successfully.')); - return $this->response->redirect($this->helper->url->to('category', 'index', array('project_id' => $project['id']))); - } else { - $this->flash->failure(t('Unable to create your category.')); - } - } - - return $this->index($values, $errors); - } - - /** - * Edit a category (display the form) - * - * @access public - * @param array $values - * @param array $errors - * @throws PageNotFoundException - */ - public function edit(array $values = array(), array $errors = array()) - { - $project = $this->getProject(); - $category = $this->getCategory(); - - $this->response->html($this->helper->layout->project('category/edit', array( - 'values' => empty($values) ? $category : $values, - 'errors' => $errors, - 'project' => $project, - 'title' => t('Categories') - ))); - } - - /** - * Edit a category (validate the form and update the database) - * - * @access public - */ - public function update() - { - $project = $this->getProject(); - - $values = $this->request->getValues(); - list($valid, $errors) = $this->categoryValidator->validateModification($values); - - if ($valid) { - if ($this->category->update($values)) { - $this->flash->success(t('Your category have been updated successfully.')); - return $this->response->redirect($this->helper->url->to('category', 'index', array('project_id' => $project['id']))); - } else { - $this->flash->failure(t('Unable to update your category.')); - } - } - - return $this->edit($values, $errors); - } - - /** - * Confirmation dialog before removing a category - * - * @access public - */ - public function confirm() - { - $project = $this->getProject(); - $category = $this->getCategory(); - - $this->response->html($this->helper->layout->project('category/remove', array( - 'project' => $project, - 'category' => $category, - 'title' => t('Remove a category') - ))); - } - - /** - * Remove a category - * - * @access public - */ - public function remove() - { - $this->checkCSRFParam(); - $project = $this->getProject(); - $category = $this->getCategory(); - - if ($this->category->remove($category['id'])) { - $this->flash->success(t('Category removed successfully.')); - } else { - $this->flash->failure(t('Unable to remove this category.')); - } - - $this->response->redirect($this->helper->url->to('category', 'index', array('project_id' => $project['id']))); - } -} diff --git a/app/Controller/CategoryController.php b/app/Controller/CategoryController.php new file mode 100644 index 00000000..e7c8db54 --- /dev/null +++ b/app/Controller/CategoryController.php @@ -0,0 +1,159 @@ +category->getById($this->request->getIntegerParam('category_id')); + + if (empty($category)) { + throw new PageNotFoundException(); + } + + return $category; + } + + /** + * List of categories for a given project + * + * @access public + * @param array $values + * @param array $errors + * @throws PageNotFoundException + */ + public function index(array $values = array(), array $errors = array()) + { + $project = $this->getProject(); + + $this->response->html($this->helper->layout->project('category/index', array( + 'categories' => $this->category->getList($project['id'], false), + 'values' => $values + array('project_id' => $project['id']), + 'errors' => $errors, + 'project' => $project, + 'title' => t('Categories') + ))); + } + + /** + * Validate and save a new category + * + * @access public + */ + public function save() + { + $project = $this->getProject(); + + $values = $this->request->getValues(); + list($valid, $errors) = $this->categoryValidator->validateCreation($values); + + if ($valid) { + if ($this->category->create($values)) { + $this->flash->success(t('Your category have been created successfully.')); + return $this->response->redirect($this->helper->url->to('CategoryController', 'index', array('project_id' => $project['id']))); + } else { + $this->flash->failure(t('Unable to create your category.')); + } + } + + return $this->index($values, $errors); + } + + /** + * Edit a category (display the form) + * + * @access public + * @param array $values + * @param array $errors + * @throws PageNotFoundException + */ + public function edit(array $values = array(), array $errors = array()) + { + $project = $this->getProject(); + $category = $this->getCategory(); + + $this->response->html($this->helper->layout->project('category/edit', array( + 'values' => empty($values) ? $category : $values, + 'errors' => $errors, + 'project' => $project, + 'title' => t('Categories') + ))); + } + + /** + * Edit a category (validate the form and update the database) + * + * @access public + */ + public function update() + { + $project = $this->getProject(); + + $values = $this->request->getValues(); + list($valid, $errors) = $this->categoryValidator->validateModification($values); + + if ($valid) { + if ($this->category->update($values)) { + $this->flash->success(t('Your category have been updated successfully.')); + return $this->response->redirect($this->helper->url->to('CategoryController', 'index', array('project_id' => $project['id']))); + } else { + $this->flash->failure(t('Unable to update your category.')); + } + } + + return $this->edit($values, $errors); + } + + /** + * Confirmation dialog before removing a category + * + * @access public + */ + public function confirm() + { + $project = $this->getProject(); + $category = $this->getCategory(); + + $this->response->html($this->helper->layout->project('category/remove', array( + 'project' => $project, + 'category' => $category, + 'title' => t('Remove a category') + ))); + } + + /** + * Remove a category + * + * @access public + */ + public function remove() + { + $this->checkCSRFParam(); + $project = $this->getProject(); + $category = $this->getCategory(); + + if ($this->category->remove($category['id'])) { + $this->flash->success(t('Category removed successfully.')); + } else { + $this->flash->failure(t('Unable to remove this category.')); + } + + $this->response->redirect($this->helper->url->to('CategoryController', 'index', array('project_id' => $project['id']))); + } +} diff --git a/app/Controller/Column.php b/app/Controller/Column.php deleted file mode 100644 index 294c31d8..00000000 --- a/app/Controller/Column.php +++ /dev/null @@ -1,178 +0,0 @@ -getProject(); - $columns = $this->column->getAll($project['id']); - - $this->response->html($this->helper->layout->project('column/index', array( - 'columns' => $columns, - 'project' => $project, - 'title' => t('Edit board') - ))); - } - - /** - * Show form to create a new column - * - * @access public - * @param array $values - * @param array $errors - * @throws \Kanboard\Core\Controller\PageNotFoundException - */ - public function create(array $values = array(), array $errors = array()) - { - $project = $this->getProject(); - - if (empty($values)) { - $values = array('project_id' => $project['id']); - } - - $this->response->html($this->template->render('column/create', array( - 'values' => $values, - 'errors' => $errors, - 'project' => $project, - 'title' => t('Add a new column') - ))); - } - - /** - * Validate and add a new column - * - * @access public - */ - public function save() - { - $project = $this->getProject(); - $values = $this->request->getValues(); - - list($valid, $errors) = $this->columnValidator->validateCreation($values); - - if ($valid) { - if ($this->column->create($project['id'], $values['title'], $values['task_limit'], $values['description'])) { - $this->flash->success(t('Column created successfully.')); - return $this->response->redirect($this->helper->url->to('column', 'index', array('project_id' => $project['id'])), true); - } else { - $errors['title'] = array(t('Another column with the same name exists in the project')); - } - } - - return $this->create($values, $errors); - } - - /** - * Display a form to edit a column - * - * @access public - * @param array $values - * @param array $errors - */ - public function edit(array $values = array(), array $errors = array()) - { - $project = $this->getProject(); - $column = $this->column->getById($this->request->getIntegerParam('column_id')); - - $this->response->html($this->helper->layout->project('column/edit', array( - 'errors' => $errors, - 'values' => $values ?: $column, - 'project' => $project, - 'column' => $column, - 'title' => t('Edit column "%s"', $column['title']) - ))); - } - - /** - * Validate and update a column - * - * @access public - */ - public function update() - { - $project = $this->getProject(); - $values = $this->request->getValues(); - - list($valid, $errors) = $this->columnValidator->validateModification($values); - - if ($valid) { - if ($this->column->update($values['id'], $values['title'], $values['task_limit'], $values['description'])) { - $this->flash->success(t('Board updated successfully.')); - return $this->response->redirect($this->helper->url->to('column', 'index', array('project_id' => $project['id']))); - } else { - $this->flash->failure(t('Unable to update this board.')); - } - } - - return $this->edit($values, $errors); - } - - /** - * Move column position - * - * @access public - */ - public function move() - { - $project = $this->getProject(); - $values = $this->request->getJson(); - - if (! empty($values) && isset($values['column_id']) && isset($values['position'])) { - $result = $this->column->changePosition($project['id'], $values['column_id'], $values['position']); - $this->response->json(array('result' => $result)); - } else { - throw new AccessForbiddenException(); - } - } - - /** - * Confirm column suppression - * - * @access public - */ - public function confirm() - { - $project = $this->getProject(); - - $this->response->html($this->helper->layout->project('column/remove', array( - 'column' => $this->column->getById($this->request->getIntegerParam('column_id')), - 'project' => $project, - 'title' => t('Remove a column from a board') - ))); - } - - /** - * Remove a column - * - * @access public - */ - public function remove() - { - $project = $this->getProject(); - $this->checkCSRFParam(); - $column_id = $this->request->getIntegerParam('column_id'); - - if ($this->column->remove($column_id)) { - $this->flash->success(t('Column removed successfully.')); - } else { - $this->flash->failure(t('Unable to remove this column.')); - } - - $this->response->redirect($this->helper->url->to('column', 'index', array('project_id' => $project['id']))); - } -} diff --git a/app/Controller/ColumnController.php b/app/Controller/ColumnController.php new file mode 100644 index 00000000..5f04f426 --- /dev/null +++ b/app/Controller/ColumnController.php @@ -0,0 +1,178 @@ +getProject(); + $columns = $this->column->getAll($project['id']); + + $this->response->html($this->helper->layout->project('column/index', array( + 'columns' => $columns, + 'project' => $project, + 'title' => t('Edit board') + ))); + } + + /** + * Show form to create a new column + * + * @access public + * @param array $values + * @param array $errors + * @throws \Kanboard\Core\Controller\PageNotFoundException + */ + public function create(array $values = array(), array $errors = array()) + { + $project = $this->getProject(); + + if (empty($values)) { + $values = array('project_id' => $project['id']); + } + + $this->response->html($this->template->render('column/create', array( + 'values' => $values, + 'errors' => $errors, + 'project' => $project, + 'title' => t('Add a new column') + ))); + } + + /** + * Validate and add a new column + * + * @access public + */ + public function save() + { + $project = $this->getProject(); + $values = $this->request->getValues(); + + list($valid, $errors) = $this->columnValidator->validateCreation($values); + + if ($valid) { + if ($this->column->create($project['id'], $values['title'], $values['task_limit'], $values['description'])) { + $this->flash->success(t('Column created successfully.')); + return $this->response->redirect($this->helper->url->to('ColumnController', 'index', array('project_id' => $project['id'])), true); + } else { + $errors['title'] = array(t('Another column with the same name exists in the project')); + } + } + + return $this->create($values, $errors); + } + + /** + * Display a form to edit a column + * + * @access public + * @param array $values + * @param array $errors + */ + public function edit(array $values = array(), array $errors = array()) + { + $project = $this->getProject(); + $column = $this->column->getById($this->request->getIntegerParam('column_id')); + + $this->response->html($this->helper->layout->project('column/edit', array( + 'errors' => $errors, + 'values' => $values ?: $column, + 'project' => $project, + 'column' => $column, + 'title' => t('Edit column "%s"', $column['title']) + ))); + } + + /** + * Validate and update a column + * + * @access public + */ + public function update() + { + $project = $this->getProject(); + $values = $this->request->getValues(); + + list($valid, $errors) = $this->columnValidator->validateModification($values); + + if ($valid) { + if ($this->column->update($values['id'], $values['title'], $values['task_limit'], $values['description'])) { + $this->flash->success(t('Board updated successfully.')); + return $this->response->redirect($this->helper->url->to('ColumnController', 'index', array('project_id' => $project['id']))); + } else { + $this->flash->failure(t('Unable to update this board.')); + } + } + + return $this->edit($values, $errors); + } + + /** + * Move column position + * + * @access public + */ + public function move() + { + $project = $this->getProject(); + $values = $this->request->getJson(); + + if (! empty($values) && isset($values['column_id']) && isset($values['position'])) { + $result = $this->column->changePosition($project['id'], $values['column_id'], $values['position']); + $this->response->json(array('result' => $result)); + } else { + throw new AccessForbiddenException(); + } + } + + /** + * Confirm column suppression + * + * @access public + */ + public function confirm() + { + $project = $this->getProject(); + + $this->response->html($this->helper->layout->project('column/remove', array( + 'column' => $this->column->getById($this->request->getIntegerParam('column_id')), + 'project' => $project, + 'title' => t('Remove a column from a board') + ))); + } + + /** + * Remove a column + * + * @access public + */ + public function remove() + { + $project = $this->getProject(); + $this->checkCSRFParam(); + $column_id = $this->request->getIntegerParam('column_id'); + + if ($this->column->remove($column_id)) { + $this->flash->success(t('Column removed successfully.')); + } else { + $this->flash->failure(t('Unable to remove this column.')); + } + + $this->response->redirect($this->helper->url->to('ColumnController', 'index', array('project_id' => $project['id']))); + } +} diff --git a/app/Controller/Comment.php b/app/Controller/Comment.php deleted file mode 100644 index 8d3b7862..00000000 --- a/app/Controller/Comment.php +++ /dev/null @@ -1,191 +0,0 @@ -comment->getById($this->request->getIntegerParam('comment_id')); - - if (empty($comment)) { - throw new PageNotFoundException(); - } - - if (! $this->userSession->isAdmin() && $comment['user_id'] != $this->userSession->getId()) { - throw new AccessForbiddenException(); - } - - return $comment; - } - - /** - * Add comment form - * - * @access public - * @param array $values - * @param array $errors - * @throws AccessForbiddenException - * @throws PageNotFoundException - */ - public function create(array $values = array(), array $errors = array()) - { - $task = $this->getTask(); - - if (empty($values)) { - $values = array( - 'user_id' => $this->userSession->getId(), - 'task_id' => $task['id'], - ); - } - - $this->response->html($this->template->render('comment/create', array( - 'values' => $values, - 'errors' => $errors, - 'task' => $task, - ))); - } - - /** - * Add a comment - * - * @access public - */ - public function save() - { - $task = $this->getTask(); - $values = $this->request->getValues(); - - list($valid, $errors) = $this->commentValidator->validateCreation($values); - - if ($valid) { - if ($this->comment->create($values)) { - $this->flash->success(t('Comment added successfully.')); - } else { - $this->flash->failure(t('Unable to create your comment.')); - } - - return $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), 'comments'), true); - } - - return $this->create($values, $errors); - } - - /** - * Edit a comment - * - * @access public - * @param array $values - * @param array $errors - * @throws AccessForbiddenException - * @throws PageNotFoundException - */ - public function edit(array $values = array(), array $errors = array()) - { - $task = $this->getTask(); - $comment = $this->getComment(); - - $this->response->html($this->template->render('comment/edit', array( - 'values' => empty($values) ? $comment : $values, - 'errors' => $errors, - 'comment' => $comment, - 'task' => $task, - 'title' => t('Edit a comment') - ))); - } - - /** - * Update and validate a comment - * - * @access public - */ - public function update() - { - $task = $this->getTask(); - $this->getComment(); - - $values = $this->request->getValues(); - list($valid, $errors) = $this->commentValidator->validateModification($values); - - if ($valid) { - if ($this->comment->update($values)) { - $this->flash->success(t('Comment updated successfully.')); - } else { - $this->flash->failure(t('Unable to update your comment.')); - } - - return $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])), false); - } - - return $this->edit($values, $errors); - } - - /** - * Confirmation dialog before removing a comment - * - * @access public - */ - public function confirm() - { - $task = $this->getTask(); - $comment = $this->getComment(); - - $this->response->html($this->template->render('comment/remove', array( - 'comment' => $comment, - 'task' => $task, - 'title' => t('Remove a comment') - ))); - } - - /** - * Remove a comment - * - * @access public - */ - public function remove() - { - $this->checkCSRFParam(); - $task = $this->getTask(); - $comment = $this->getComment(); - - if ($this->comment->remove($comment['id'])) { - $this->flash->success(t('Comment removed successfully.')); - } else { - $this->flash->failure(t('Unable to remove this comment.')); - } - - $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), 'comments')); - } - - /** - * Toggle comment sorting - * - * @access public - */ - public function toggleSorting() - { - $task = $this->getTask(); - - $order = $this->userSession->getCommentSorting() === 'ASC' ? 'DESC' : 'ASC'; - $this->userSession->setCommentSorting($order); - - $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), 'comments')); - } -} diff --git a/app/Controller/CommentController.php b/app/Controller/CommentController.php new file mode 100644 index 00000000..8d1132ae --- /dev/null +++ b/app/Controller/CommentController.php @@ -0,0 +1,191 @@ +comment->getById($this->request->getIntegerParam('comment_id')); + + if (empty($comment)) { + throw new PageNotFoundException(); + } + + if (! $this->userSession->isAdmin() && $comment['user_id'] != $this->userSession->getId()) { + throw new AccessForbiddenException(); + } + + return $comment; + } + + /** + * Add comment form + * + * @access public + * @param array $values + * @param array $errors + * @throws AccessForbiddenException + * @throws PageNotFoundException + */ + public function create(array $values = array(), array $errors = array()) + { + $task = $this->getTask(); + + if (empty($values)) { + $values = array( + 'user_id' => $this->userSession->getId(), + 'task_id' => $task['id'], + ); + } + + $this->response->html($this->template->render('comment/create', array( + 'values' => $values, + 'errors' => $errors, + 'task' => $task, + ))); + } + + /** + * Add a comment + * + * @access public + */ + public function save() + { + $task = $this->getTask(); + $values = $this->request->getValues(); + + list($valid, $errors) = $this->commentValidator->validateCreation($values); + + if ($valid) { + if ($this->comment->create($values)) { + $this->flash->success(t('Comment added successfully.')); + } else { + $this->flash->failure(t('Unable to create your comment.')); + } + + return $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), 'comments'), true); + } + + return $this->create($values, $errors); + } + + /** + * Edit a comment + * + * @access public + * @param array $values + * @param array $errors + * @throws AccessForbiddenException + * @throws PageNotFoundException + */ + public function edit(array $values = array(), array $errors = array()) + { + $task = $this->getTask(); + $comment = $this->getComment(); + + $this->response->html($this->template->render('comment/edit', array( + 'values' => empty($values) ? $comment : $values, + 'errors' => $errors, + 'comment' => $comment, + 'task' => $task, + 'title' => t('Edit a comment') + ))); + } + + /** + * Update and validate a comment + * + * @access public + */ + public function update() + { + $task = $this->getTask(); + $this->getComment(); + + $values = $this->request->getValues(); + list($valid, $errors) = $this->commentValidator->validateModification($values); + + if ($valid) { + if ($this->comment->update($values)) { + $this->flash->success(t('Comment updated successfully.')); + } else { + $this->flash->failure(t('Unable to update your comment.')); + } + + return $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])), false); + } + + return $this->edit($values, $errors); + } + + /** + * Confirmation dialog before removing a comment + * + * @access public + */ + public function confirm() + { + $task = $this->getTask(); + $comment = $this->getComment(); + + $this->response->html($this->template->render('comment/remove', array( + 'comment' => $comment, + 'task' => $task, + 'title' => t('Remove a comment') + ))); + } + + /** + * Remove a comment + * + * @access public + */ + public function remove() + { + $this->checkCSRFParam(); + $task = $this->getTask(); + $comment = $this->getComment(); + + if ($this->comment->remove($comment['id'])) { + $this->flash->success(t('Comment removed successfully.')); + } else { + $this->flash->failure(t('Unable to remove this comment.')); + } + + $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), 'comments')); + } + + /** + * Toggle comment sorting + * + * @access public + */ + public function toggleSorting() + { + $task = $this->getTask(); + + $order = $this->userSession->getCommentSorting() === 'ASC' ? 'DESC' : 'ASC'; + $this->userSession->setCommentSorting($order); + + $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), 'comments')); + } +} diff --git a/app/Controller/CustomFilterController.php b/app/Controller/CustomFilterController.php new file mode 100644 index 00000000..8dd98764 --- /dev/null +++ b/app/Controller/CustomFilterController.php @@ -0,0 +1,165 @@ +getProject(); + + $this->response->html($this->helper->layout->project('custom_filter/index', array( + 'values' => $values + array('project_id' => $project['id']), + 'errors' => $errors, + 'project' => $project, + 'custom_filters' => $this->customFilter->getAll($project['id'], $this->userSession->getId()), + 'title' => t('Custom filters'), + ))); + } + + /** + * Save a new custom filter + * + * @access public + */ + public function save() + { + $project = $this->getProject(); + + $values = $this->request->getValues(); + $values['user_id'] = $this->userSession->getId(); + + list($valid, $errors) = $this->customFilterValidator->validateCreation($values); + + if ($valid) { + if ($this->customFilter->create($values)) { + $this->flash->success(t('Your custom filter have been created successfully.')); + return $this->response->redirect($this->helper->url->to('CustomFilterController', 'index', array('project_id' => $project['id']))); + } else { + $this->flash->failure(t('Unable to create your custom filter.')); + } + } + + return $this->index($values, $errors); + } + + /** + * Confirmation dialog before removing a custom filter + * + * @access public + */ + public function confirm() + { + $project = $this->getProject(); + $filter = $this->customFilter->getById($this->request->getIntegerParam('filter_id')); + + $this->response->html($this->helper->layout->project('custom_filter/remove', array( + 'project' => $project, + 'filter' => $filter, + 'title' => t('Remove a custom filter') + ))); + } + + /** + * Remove a custom filter + * + * @access public + */ + public function remove() + { + $this->checkCSRFParam(); + $project = $this->getProject(); + $filter = $this->customFilter->getById($this->request->getIntegerParam('filter_id')); + + $this->checkPermission($project, $filter); + + if ($this->customFilter->remove($filter['id'])) { + $this->flash->success(t('Custom filter removed successfully.')); + } else { + $this->flash->failure(t('Unable to remove this custom filter.')); + } + + $this->response->redirect($this->helper->url->to('CustomFilterController', 'index', array('project_id' => $project['id']))); + } + + /** + * Edit a custom filter (display the form) + * + * @access public + */ + public function edit(array $values = array(), array $errors = array()) + { + $project = $this->getProject(); + $filter = $this->customFilter->getById($this->request->getIntegerParam('filter_id')); + + $this->checkPermission($project, $filter); + + $this->response->html($this->helper->layout->project('custom_filter/edit', array( + 'values' => empty($values) ? $filter : $values, + 'errors' => $errors, + 'project' => $project, + 'filter' => $filter, + 'title' => t('Edit custom filter') + ))); + } + + /** + * Edit a custom filter (validate the form and update the database) + * + * @access public + */ + public function update() + { + $project = $this->getProject(); + $filter = $this->customFilter->getById($this->request->getIntegerParam('filter_id')); + + $this->checkPermission($project, $filter); + + $values = $this->request->getValues(); + + if (! isset($values['is_shared'])) { + $values += array('is_shared' => 0); + } + + if (! isset($values['append'])) { + $values += array('append' => 0); + } + + list($valid, $errors) = $this->customFilterValidator->validateModification($values); + + if ($valid) { + if ($this->customFilter->update($values)) { + $this->flash->success(t('Your custom filter have been updated successfully.')); + return $this->response->redirect($this->helper->url->to('CustomFilterController', 'index', array('project_id' => $project['id']))); + } else { + $this->flash->failure(t('Unable to update custom filter.')); + } + } + + return $this->edit($values, $errors); + } + + private function checkPermission(array $project, array $filter) + { + $user_id = $this->userSession->getId(); + + if ($filter['user_id'] != $user_id && ($this->projectUserRole->getUserRole($project['id'], $user_id) === Role::PROJECT_MANAGER || ! $this->userSession->isAdmin())) { + throw new AccessForbiddenException(); + } + } +} diff --git a/app/Controller/Customfilter.php b/app/Controller/Customfilter.php deleted file mode 100644 index d0794366..00000000 --- a/app/Controller/Customfilter.php +++ /dev/null @@ -1,164 +0,0 @@ -getProject(); - - $this->response->html($this->helper->layout->project('custom_filter/index', array( - 'values' => $values + array('project_id' => $project['id']), - 'errors' => $errors, - 'project' => $project, - 'custom_filters' => $this->customFilter->getAll($project['id'], $this->userSession->getId()), - 'title' => t('Custom filters'), - ))); - } - - /** - * Save a new custom filter - * - * @access public - */ - public function save() - { - $project = $this->getProject(); - - $values = $this->request->getValues(); - $values['user_id'] = $this->userSession->getId(); - - list($valid, $errors) = $this->customFilterValidator->validateCreation($values); - - if ($valid) { - if ($this->customFilter->create($values)) { - $this->flash->success(t('Your custom filter have been created successfully.')); - return $this->response->redirect($this->helper->url->to('customfilter', 'index', array('project_id' => $project['id']))); - } else { - $this->flash->failure(t('Unable to create your custom filter.')); - } - } - - return $this->index($values, $errors); - } - - /** - * Confirmation dialog before removing a custom filter - * - * @access public - */ - public function confirm() - { - $project = $this->getProject(); - $filter = $this->customFilter->getById($this->request->getIntegerParam('filter_id')); - - $this->response->html($this->helper->layout->project('custom_filter/remove', array( - 'project' => $project, - 'filter' => $filter, - 'title' => t('Remove a custom filter') - ))); - } - - /** - * Remove a custom filter - * - * @access public - */ - public function remove() - { - $this->checkCSRFParam(); - $project = $this->getProject(); - $filter = $this->customFilter->getById($this->request->getIntegerParam('filter_id')); - - $this->checkPermission($project, $filter); - - if ($this->customFilter->remove($filter['id'])) { - $this->flash->success(t('Custom filter removed successfully.')); - } else { - $this->flash->failure(t('Unable to remove this custom filter.')); - } - - $this->response->redirect($this->helper->url->to('customfilter', 'index', array('project_id' => $project['id']))); - } - - /** - * Edit a custom filter (display the form) - * - * @access public - */ - public function edit(array $values = array(), array $errors = array()) - { - $project = $this->getProject(); - $filter = $this->customFilter->getById($this->request->getIntegerParam('filter_id')); - - $this->checkPermission($project, $filter); - - $this->response->html($this->helper->layout->project('custom_filter/edit', array( - 'values' => empty($values) ? $filter : $values, - 'errors' => $errors, - 'project' => $project, - 'filter' => $filter, - 'title' => t('Edit custom filter') - ))); - } - - /** - * Edit a custom filter (validate the form and update the database) - * - * @access public - */ - public function update() - { - $project = $this->getProject(); - $filter = $this->customFilter->getById($this->request->getIntegerParam('filter_id')); - - $this->checkPermission($project, $filter); - - $values = $this->request->getValues(); - - if (! isset($values['is_shared'])) { - $values += array('is_shared' => 0); - } - - if (! isset($values['append'])) { - $values += array('append' => 0); - } - - list($valid, $errors) = $this->customFilterValidator->validateModification($values); - - if ($valid) { - if ($this->customFilter->update($values)) { - $this->flash->success(t('Your custom filter have been updated successfully.')); - return $this->response->redirect($this->helper->url->to('customfilter', 'index', array('project_id' => $project['id']))); - } else { - $this->flash->failure(t('Unable to update custom filter.')); - } - } - - return $this->edit($values, $errors); - } - - private function checkPermission(array $project, array $filter) - { - $user_id = $this->userSession->getId(); - - if ($filter['user_id'] != $user_id && ($this->projectUserRole->getUserRole($project['id'], $user_id) === Role::PROJECT_MANAGER || ! $this->userSession->isAdmin())) { - throw new AccessForbiddenException(); - } - } -} diff --git a/app/Controller/Export.php b/app/Controller/Export.php deleted file mode 100644 index 7e1d2fdc..00000000 --- a/app/Controller/Export.php +++ /dev/null @@ -1,91 +0,0 @@ -getProject(); - $from = $this->request->getStringParam('from'); - $to = $this->request->getStringParam('to'); - - if ($from && $to) { - $data = $this->$model->$method($project['id'], $from, $to); - $this->response->withFileDownload($filename.'.csv'); - $this->response->csv($data); - } - - $this->response->html($this->helper->layout->project('export/'.$action, array( - 'values' => array( - 'controller' => 'export', - 'action' => $action, - 'project_id' => $project['id'], - 'from' => $from, - 'to' => $to, - ), - 'errors' => array(), - 'date_format' => $this->config->get('application_date_format'), - 'date_formats' => $this->dateParser->getAvailableFormats($this->dateParser->getDateFormats()), - 'project' => $project, - 'title' => $page_title, - ), 'export/sidebar')); - } - - /** - * Task export - * - * @access public - */ - public function tasks() - { - $this->common('taskExport', 'export', t('Tasks'), 'tasks', t('Tasks Export')); - } - - /** - * Subtask export - * - * @access public - */ - public function subtasks() - { - $this->common('subtaskExport', 'export', t('Subtasks'), 'subtasks', t('Subtasks Export')); - } - - /** - * Daily project summary export - * - * @access public - */ - public function summary() - { - $this->common('projectDailyColumnStats', 'getAggregatedMetrics', t('Summary'), 'summary', t('Daily project summary export')); - } - - /** - * Transition export - * - * @access public - */ - public function transitions() - { - $this->common('transitionExport', 'export', t('Transitions'), 'transitions', t('Task transitions export')); - } -} diff --git a/app/Controller/ExportController.php b/app/Controller/ExportController.php new file mode 100644 index 00000000..4ed9ee08 --- /dev/null +++ b/app/Controller/ExportController.php @@ -0,0 +1,91 @@ +getProject(); + $from = $this->request->getStringParam('from'); + $to = $this->request->getStringParam('to'); + + if ($from && $to) { + $data = $this->$model->$method($project['id'], $from, $to); + $this->response->withFileDownload($filename.'.csv'); + $this->response->csv($data); + } + + $this->response->html($this->helper->layout->project('export/'.$action, array( + 'values' => array( + 'controller' => 'ExportController', + 'action' => $action, + 'project_id' => $project['id'], + 'from' => $from, + 'to' => $to, + ), + 'errors' => array(), + 'date_format' => $this->config->get('application_date_format'), + 'date_formats' => $this->dateParser->getAvailableFormats($this->dateParser->getDateFormats()), + 'project' => $project, + 'title' => $page_title, + ), 'export/sidebar')); + } + + /** + * Task export + * + * @access public + */ + public function tasks() + { + $this->common('taskExport', 'export', t('Tasks'), 'tasks', t('Tasks Export')); + } + + /** + * Subtask export + * + * @access public + */ + public function subtasks() + { + $this->common('subtaskExport', 'export', t('Subtasks'), 'subtasks', t('Subtasks Export')); + } + + /** + * Daily project summary export + * + * @access public + */ + public function summary() + { + $this->common('projectDailyColumnStats', 'getAggregatedMetrics', t('Summary'), 'summary', t('Daily project summary export')); + } + + /** + * Transition export + * + * @access public + */ + public function transitions() + { + $this->common('transitionExport', 'export', t('Transitions'), 'transitions', t('Task transitions export')); + } +} diff --git a/app/Controller/FileViewer.php b/app/Controller/FileViewer.php deleted file mode 100644 index a49b0fb2..00000000 --- a/app/Controller/FileViewer.php +++ /dev/null @@ -1,136 +0,0 @@ -objectStorage->get($file['path']); - } - } catch (ObjectStorageException $e) { - $this->logger->error($e->getMessage()); - } - - return $content; - } - - /** - * Show file content in a popover - * - * @access public - */ - public function show() - { - $file = $this->getFile(); - $type = $this->helper->file->getPreviewType($file['name']); - $params = array('file_id' => $file['id'], 'project_id' => $this->request->getIntegerParam('project_id')); - - if ($file['model'] === 'taskFile') { - $params['task_id'] = $file['task_id']; - } - - $this->response->html($this->template->render('file_viewer/show', array( - 'file' => $file, - 'params' => $params, - 'type' => $type, - 'content' => $this->getFileContent($file), - ))); - } - - /** - * Display image - * - * @access public - */ - public function image() - { - $file = $this->getFile(); - $etag = md5($file['path']); - $this->response->withContentType($this->helper->file->getImageMimeType($file['name'])); - $this->response->withCache(5 * 86400, $etag); - - if ($this->request->getHeader('If-None-Match') === '"'.$etag.'"') { - $this->response->status(304); - } else { - - try { - $this->response->send(); - $this->objectStorage->output($file['path']); - } catch (ObjectStorageException $e) { - $this->logger->error($e->getMessage()); - } - } - } - - /** - * Display image thumbnail - * - * @access public - */ - public function thumbnail() - { - $file = $this->getFile(); - $model = $file['model']; - $filename = $this->$model->getThumbnailPath($file['path']); - $etag = md5($filename); - - $this->response->withCache(5 * 86400, $etag); - $this->response->withContentType('image/jpeg'); - - if ($this->request->getHeader('If-None-Match') === '"'.$etag.'"') { - $this->response->status(304); - } else { - - $this->response->send(); - - try { - - $this->objectStorage->output($filename); - } catch (ObjectStorageException $e) { - $this->logger->error($e->getMessage()); - - // Try to generate thumbnail on the fly for images uploaded before Kanboard < 1.0.19 - $data = $this->objectStorage->get($file['path']); - $this->$model->generateThumbnailFromData($file['path'], $data); - $this->objectStorage->output($this->$model->getThumbnailPath($file['path'])); - } - } - } - - /** - * File download - * - * @access public - */ - public function download() - { - try { - $file = $this->getFile(); - $this->response->withFileDownload($file['name']); - $this->response->send(); - $this->objectStorage->output($file['path']); - } catch (ObjectStorageException $e) { - $this->logger->error($e->getMessage()); - } - } -} diff --git a/app/Controller/FileViewerController.php b/app/Controller/FileViewerController.php new file mode 100644 index 00000000..245845c7 --- /dev/null +++ b/app/Controller/FileViewerController.php @@ -0,0 +1,136 @@ +objectStorage->get($file['path']); + } + } catch (ObjectStorageException $e) { + $this->logger->error($e->getMessage()); + } + + return $content; + } + + /** + * Show file content in a popover + * + * @access public + */ + public function show() + { + $file = $this->getFile(); + $type = $this->helper->file->getPreviewType($file['name']); + $params = array('file_id' => $file['id'], 'project_id' => $this->request->getIntegerParam('project_id')); + + if ($file['model'] === 'taskFile') { + $params['task_id'] = $file['task_id']; + } + + $this->response->html($this->template->render('file_viewer/show', array( + 'file' => $file, + 'params' => $params, + 'type' => $type, + 'content' => $this->getFileContent($file), + ))); + } + + /** + * Display image + * + * @access public + */ + public function image() + { + $file = $this->getFile(); + $etag = md5($file['path']); + $this->response->withContentType($this->helper->file->getImageMimeType($file['name'])); + $this->response->withCache(5 * 86400, $etag); + + if ($this->request->getHeader('If-None-Match') === '"'.$etag.'"') { + $this->response->status(304); + } else { + + try { + $this->response->send(); + $this->objectStorage->output($file['path']); + } catch (ObjectStorageException $e) { + $this->logger->error($e->getMessage()); + } + } + } + + /** + * Display image thumbnail + * + * @access public + */ + public function thumbnail() + { + $file = $this->getFile(); + $model = $file['model']; + $filename = $this->$model->getThumbnailPath($file['path']); + $etag = md5($filename); + + $this->response->withCache(5 * 86400, $etag); + $this->response->withContentType('image/jpeg'); + + if ($this->request->getHeader('If-None-Match') === '"'.$etag.'"') { + $this->response->status(304); + } else { + + $this->response->send(); + + try { + + $this->objectStorage->output($filename); + } catch (ObjectStorageException $e) { + $this->logger->error($e->getMessage()); + + // Try to generate thumbnail on the fly for images uploaded before Kanboard < 1.0.19 + $data = $this->objectStorage->get($file['path']); + $this->$model->generateThumbnailFromData($file['path'], $data); + $this->objectStorage->output($this->$model->getThumbnailPath($file['path'])); + } + } + } + + /** + * File download + * + * @access public + */ + public function download() + { + try { + $file = $this->getFile(); + $this->response->withFileDownload($file['name']); + $this->response->send(); + $this->objectStorage->output($file['path']); + } catch (ObjectStorageException $e) { + $this->logger->error($e->getMessage()); + } + } +} diff --git a/app/Controller/Link.php b/app/Controller/Link.php deleted file mode 100644 index d28f5e4e..00000000 --- a/app/Controller/Link.php +++ /dev/null @@ -1,150 +0,0 @@ -link->getById($this->request->getIntegerParam('link_id')); - - if (empty($link)) { - throw new PageNotFoundException(); - } - - return $link; - } - - /** - * List of links - * - * @access public - * @param array $values - * @param array $errors - */ - public function index(array $values = array(), array $errors = array()) - { - $this->response->html($this->helper->layout->config('link/index', array( - 'links' => $this->link->getMergedList(), - 'values' => $values, - 'errors' => $errors, - 'title' => t('Settings').' > '.t('Task\'s links'), - ))); - } - - /** - * Validate and save a new link - * - * @access public - */ - public function save() - { - $values = $this->request->getValues(); - list($valid, $errors) = $this->linkValidator->validateCreation($values); - - if ($valid) { - if ($this->link->create($values['label'], $values['opposite_label']) !== false) { - $this->flash->success(t('Link added successfully.')); - return $this->response->redirect($this->helper->url->to('link', 'index')); - } else { - $this->flash->failure(t('Unable to create your link.')); - } - } - - return $this->index($values, $errors); - } - - /** - * Edit form - * - * @access public - * @param array $values - * @param array $errors - * @throws PageNotFoundException - */ - public function edit(array $values = array(), array $errors = array()) - { - $link = $this->getLink(); - $link['label'] = t($link['label']); - - $this->response->html($this->helper->layout->config('link/edit', array( - 'values' => $values ?: $link, - 'errors' => $errors, - 'labels' => $this->link->getList($link['id']), - 'link' => $link, - 'title' => t('Link modification') - ))); - } - - /** - * Edit a link (validate the form and update the database) - * - * @access public - */ - public function update() - { - $values = $this->request->getValues(); - list($valid, $errors) = $this->linkValidator->validateModification($values); - - if ($valid) { - if ($this->link->update($values)) { - $this->flash->success(t('Link updated successfully.')); - return $this->response->redirect($this->helper->url->to('link', 'index')); - } else { - $this->flash->failure(t('Unable to update your link.')); - } - } - - return $this->edit($values, $errors); - } - - /** - * Confirmation dialog before removing a link - * - * @access public - */ - public function confirm() - { - $link = $this->getLink(); - - $this->response->html($this->helper->layout->config('link/remove', array( - 'link' => $link, - 'title' => t('Remove a link') - ))); - } - - /** - * Remove a link - * - * @access public - */ - public function remove() - { - $this->checkCSRFParam(); - $link = $this->getLink(); - - if ($this->link->remove($link['id'])) { - $this->flash->success(t('Link removed successfully.')); - } else { - $this->flash->failure(t('Unable to remove this link.')); - } - - $this->response->redirect($this->helper->url->to('link', 'index')); - } -} diff --git a/app/Controller/LinkController.php b/app/Controller/LinkController.php new file mode 100644 index 00000000..08627d40 --- /dev/null +++ b/app/Controller/LinkController.php @@ -0,0 +1,150 @@ +link->getById($this->request->getIntegerParam('link_id')); + + if (empty($link)) { + throw new PageNotFoundException(); + } + + return $link; + } + + /** + * List of links + * + * @access public + * @param array $values + * @param array $errors + */ + public function index(array $values = array(), array $errors = array()) + { + $this->response->html($this->helper->layout->config('link/index', array( + 'links' => $this->link->getMergedList(), + 'values' => $values, + 'errors' => $errors, + 'title' => t('Settings').' > '.t('Task\'s links'), + ))); + } + + /** + * Validate and save a new link + * + * @access public + */ + public function save() + { + $values = $this->request->getValues(); + list($valid, $errors) = $this->linkValidator->validateCreation($values); + + if ($valid) { + if ($this->link->create($values['label'], $values['opposite_label']) !== false) { + $this->flash->success(t('Link added successfully.')); + return $this->response->redirect($this->helper->url->to('LinkController', 'index')); + } else { + $this->flash->failure(t('Unable to create your link.')); + } + } + + return $this->index($values, $errors); + } + + /** + * Edit form + * + * @access public + * @param array $values + * @param array $errors + * @throws PageNotFoundException + */ + public function edit(array $values = array(), array $errors = array()) + { + $link = $this->getLink(); + $link['label'] = t($link['label']); + + $this->response->html($this->helper->layout->config('link/edit', array( + 'values' => $values ?: $link, + 'errors' => $errors, + 'labels' => $this->link->getList($link['id']), + 'link' => $link, + 'title' => t('Link modification') + ))); + } + + /** + * Edit a link (validate the form and update the database) + * + * @access public + */ + public function update() + { + $values = $this->request->getValues(); + list($valid, $errors) = $this->linkValidator->validateModification($values); + + if ($valid) { + if ($this->link->update($values)) { + $this->flash->success(t('Link updated successfully.')); + return $this->response->redirect($this->helper->url->to('LinkController', 'index')); + } else { + $this->flash->failure(t('Unable to update your link.')); + } + } + + return $this->edit($values, $errors); + } + + /** + * Confirmation dialog before removing a link + * + * @access public + */ + public function confirm() + { + $link = $this->getLink(); + + $this->response->html($this->helper->layout->config('link/remove', array( + 'link' => $link, + 'title' => t('Remove a link') + ))); + } + + /** + * Remove a link + * + * @access public + */ + public function remove() + { + $this->checkCSRFParam(); + $link = $this->getLink(); + + if ($this->link->remove($link['id'])) { + $this->flash->success(t('Link removed successfully.')); + } else { + $this->flash->failure(t('Unable to remove this link.')); + } + + $this->response->redirect($this->helper->url->to('LinkController', 'index')); + } +} diff --git a/app/Controller/Listing.php b/app/Controller/Listing.php deleted file mode 100644 index 93a7b836..00000000 --- a/app/Controller/Listing.php +++ /dev/null @@ -1,45 +0,0 @@ -getProject(); - $search = $this->helper->projectHeader->getSearchQuery($project); - - $paginator = $this->paginator - ->setUrl('listing', 'show', array('project_id' => $project['id'])) - ->setMax(30) - ->setOrder(TaskModel::TABLE.'.id') - ->setDirection('DESC') - ->setQuery($this->taskLexer - ->build($search) - ->withFilter(new TaskProjectFilter($project['id'])) - ->getQuery() - ) - ->calculate(); - - $this->response->html($this->helper->layout->app('listing/show', array( - 'project' => $project, - 'title' => $project['name'], - 'description' => $this->helper->projectHeader->getDescription($project), - 'paginator' => $paginator, - ))); - } -} diff --git a/app/Controller/OAuthController.php b/app/Controller/OAuthController.php new file mode 100644 index 00000000..7663ddcc --- /dev/null +++ b/app/Controller/OAuthController.php @@ -0,0 +1,130 @@ +request->getStringParam('code'); + $state = $this->request->getStringParam('state'); + + if (! empty($code)) { + $this->step2($provider, $code, $state); + } else { + $this->response->redirect($this->authenticationManager->getProvider($provider)->getService()->getAuthorizationUrl()); + } + } + + /** + * Link or authenticate the user + * + * @access protected + * @param string $providerName + * @param string $code + * @param string $state + */ + protected function step2($providerName, $code, $state) + { + $provider = $this->authenticationManager->getProvider($providerName); + $provider->setCode($code); + $hasValidState = $provider->getService()->isValidateState($state); + + if ($this->userSession->isLogged()) { + if ($hasValidState) { + $this->link($provider); + } else { + $this->flash->failure(t('The OAuth2 state parameter is invalid')); + $this->response->redirect($this->helper->url->to('UserViewController', 'external', array('user_id' => $this->userSession->getId()))); + } + } else { + if ($hasValidState) { + $this->authenticate($providerName); + } else { + $this->authenticationFailure(t('The OAuth2 state parameter is invalid')); + } + } + } + + /** + * Link the account + * + * @access protected + * @param OAuthAuthenticationProviderInterface $provider + */ + protected function link(OAuthAuthenticationProviderInterface $provider) + { + if (! $provider->authenticate()) { + $this->flash->failure(t('External authentication failed')); + } else { + $this->userProfile->assign($this->userSession->getId(), $provider->getUser()); + $this->flash->success(t('Your external account is linked to your profile successfully.')); + } + + $this->response->redirect($this->helper->url->to('UserViewController', 'external', array('user_id' => $this->userSession->getId()))); + } + + /** + * Unlink external account + * + * @access public + */ + public function unlink() + { + $backend = $this->request->getStringParam('backend'); + $this->checkCSRFParam(); + + if ($this->authenticationManager->getProvider($backend)->unlink($this->userSession->getId())) { + $this->flash->success(t('Your external account is not linked anymore to your profile.')); + } else { + $this->flash->failure(t('Unable to unlink your external account.')); + } + + $this->response->redirect($this->helper->url->to('UserViewController', 'external', array('user_id' => $this->userSession->getId()))); + } + + /** + * Authenticate the account + * + * @access protected + * @param string $providerName + */ + protected function authenticate($providerName) + { + if ($this->authenticationManager->oauthAuthentication($providerName)) { + $this->response->redirect($this->helper->url->to('DashboardController', 'show')); + } else { + $this->authenticationFailure(t('External authentication failed')); + } + } + + /** + * Show login failure page + * + * @access protected + * @param string $message + */ + protected function authenticationFailure($message) + { + $this->response->html($this->helper->layout->app('auth/index', array( + 'errors' => array('login' => $message), + 'values' => array(), + 'no_layout' => true, + 'title' => t('Login') + ))); + } +} diff --git a/app/Controller/Oauth.php b/app/Controller/Oauth.php deleted file mode 100644 index 04adf154..00000000 --- a/app/Controller/Oauth.php +++ /dev/null @@ -1,130 +0,0 @@ -request->getStringParam('code'); - $state = $this->request->getStringParam('state'); - - if (! empty($code)) { - $this->step2($provider, $code, $state); - } else { - $this->response->redirect($this->authenticationManager->getProvider($provider)->getService()->getAuthorizationUrl()); - } - } - - /** - * Link or authenticate the user - * - * @access protected - * @param string $providerName - * @param string $code - * @param string $state - */ - protected function step2($providerName, $code, $state) - { - $provider = $this->authenticationManager->getProvider($providerName); - $provider->setCode($code); - $hasValidState = $provider->getService()->isValidateState($state); - - if ($this->userSession->isLogged()) { - if ($hasValidState) { - $this->link($provider); - } else { - $this->flash->failure(t('The OAuth2 state parameter is invalid')); - $this->response->redirect($this->helper->url->to('UserViewController', 'external', array('user_id' => $this->userSession->getId()))); - } - } else { - if ($hasValidState) { - $this->authenticate($providerName); - } else { - $this->authenticationFailure(t('The OAuth2 state parameter is invalid')); - } - } - } - - /** - * Link the account - * - * @access protected - * @param OAuthAuthenticationProviderInterface $provider - */ - protected function link(OAuthAuthenticationProviderInterface $provider) - { - if (! $provider->authenticate()) { - $this->flash->failure(t('External authentication failed')); - } else { - $this->userProfile->assign($this->userSession->getId(), $provider->getUser()); - $this->flash->success(t('Your external account is linked to your profile successfully.')); - } - - $this->response->redirect($this->helper->url->to('UserViewController', 'external', array('user_id' => $this->userSession->getId()))); - } - - /** - * Unlink external account - * - * @access public - */ - public function unlink() - { - $backend = $this->request->getStringParam('backend'); - $this->checkCSRFParam(); - - if ($this->authenticationManager->getProvider($backend)->unlink($this->userSession->getId())) { - $this->flash->success(t('Your external account is not linked anymore to your profile.')); - } else { - $this->flash->failure(t('Unable to unlink your external account.')); - } - - $this->response->redirect($this->helper->url->to('UserViewController', 'external', array('user_id' => $this->userSession->getId()))); - } - - /** - * Authenticate the account - * - * @access protected - * @param string $providerName - */ - protected function authenticate($providerName) - { - if ($this->authenticationManager->oauthAuthentication($providerName)) { - $this->response->redirect($this->helper->url->to('DashboardController', 'show')); - } else { - $this->authenticationFailure(t('External authentication failed')); - } - } - - /** - * Show login failure page - * - * @access protected - * @param string $message - */ - protected function authenticationFailure($message) - { - $this->response->html($this->helper->layout->app('auth/index', array( - 'errors' => array('login' => $message), - 'values' => array(), - 'no_layout' => true, - 'title' => t('Login') - ))); - } -} diff --git a/app/Controller/PasswordReset.php b/app/Controller/PasswordReset.php deleted file mode 100644 index 7050d6d2..00000000 --- a/app/Controller/PasswordReset.php +++ /dev/null @@ -1,122 +0,0 @@ -checkActivation(); - - $this->response->html($this->helper->layout->app('password_reset/create', array( - 'errors' => $errors, - 'values' => $values, - 'no_layout' => true, - ))); - } - - /** - * Validate and send the email - */ - public function save() - { - $this->checkActivation(); - - $values = $this->request->getValues(); - list($valid, $errors) = $this->passwordResetValidator->validateCreation($values); - - if ($valid) { - $this->sendEmail($values['username']); - $this->response->redirect($this->helper->url->to('auth', 'login')); - } else { - $this->create($values, $errors); - } - } - - /** - * Show the form to set a new password - */ - public function change(array $values = array(), array $errors = array()) - { - $this->checkActivation(); - - $token = $this->request->getStringParam('token'); - $user_id = $this->passwordReset->getUserIdByToken($token); - - if ($user_id !== false) { - $this->response->html($this->helper->layout->app('password_reset/change', array( - 'token' => $token, - 'errors' => $errors, - 'values' => $values, - 'no_layout' => true, - ))); - } else { - $this->response->redirect($this->helper->url->to('auth', 'login')); - } - } - - /** - * Set the new password - */ - public function update() - { - $this->checkActivation(); - - $token = $this->request->getStringParam('token'); - $values = $this->request->getValues(); - list($valid, $errors) = $this->passwordResetValidator->validateModification($values); - - if ($valid) { - $user_id = $this->passwordReset->getUserIdByToken($token); - - if ($user_id !== false) { - $this->user->update(array('id' => $user_id, 'password' => $values['password'])); - $this->passwordReset->disable($user_id); - } - - return $this->response->redirect($this->helper->url->to('auth', 'login')); - } - - return $this->change($values, $errors); - } - - /** - * Send the email - */ - private function sendEmail($username) - { - $token = $this->passwordReset->create($username); - - if ($token !== false) { - $user = $this->user->getByUsername($username); - - $this->emailClient->send( - $user['email'], - $user['name'] ?: $user['username'], - t('Password Reset for Kanboard'), - $this->template->render('password_reset/email', array('token' => $token)) - ); - } - } - - /** - * Check feature availability - */ - private function checkActivation() - { - if ($this->config->get('password_reset', 0) == 0) { - throw AccessForbiddenException::getInstance()->withoutLayout(); - } - } -} diff --git a/app/Controller/PasswordResetController.php b/app/Controller/PasswordResetController.php new file mode 100644 index 00000000..9036b3e7 --- /dev/null +++ b/app/Controller/PasswordResetController.php @@ -0,0 +1,122 @@ +checkActivation(); + + $this->response->html($this->helper->layout->app('password_reset/create', array( + 'errors' => $errors, + 'values' => $values, + 'no_layout' => true, + ))); + } + + /** + * Validate and send the email + */ + public function save() + { + $this->checkActivation(); + + $values = $this->request->getValues(); + list($valid, $errors) = $this->passwordResetValidator->validateCreation($values); + + if ($valid) { + $this->sendEmail($values['username']); + $this->response->redirect($this->helper->url->to('AuthController', 'login')); + } else { + $this->create($values, $errors); + } + } + + /** + * Show the form to set a new password + */ + public function change(array $values = array(), array $errors = array()) + { + $this->checkActivation(); + + $token = $this->request->getStringParam('token'); + $user_id = $this->passwordReset->getUserIdByToken($token); + + if ($user_id !== false) { + $this->response->html($this->helper->layout->app('password_reset/change', array( + 'token' => $token, + 'errors' => $errors, + 'values' => $values, + 'no_layout' => true, + ))); + } else { + $this->response->redirect($this->helper->url->to('AuthController', 'login')); + } + } + + /** + * Set the new password + */ + public function update() + { + $this->checkActivation(); + + $token = $this->request->getStringParam('token'); + $values = $this->request->getValues(); + list($valid, $errors) = $this->passwordResetValidator->validateModification($values); + + if ($valid) { + $user_id = $this->passwordReset->getUserIdByToken($token); + + if ($user_id !== false) { + $this->user->update(array('id' => $user_id, 'password' => $values['password'])); + $this->passwordReset->disable($user_id); + } + + return $this->response->redirect($this->helper->url->to('AuthController', 'login')); + } + + return $this->change($values, $errors); + } + + /** + * Send the email + */ + private function sendEmail($username) + { + $token = $this->passwordReset->create($username); + + if ($token !== false) { + $user = $this->user->getByUsername($username); + + $this->emailClient->send( + $user['email'], + $user['name'] ?: $user['username'], + t('Password Reset for Kanboard'), + $this->template->render('password_reset/email', array('token' => $token)) + ); + } + } + + /** + * Check feature availability + */ + private function checkActivation() + { + if ($this->config->get('password_reset', 0) == 0) { + throw AccessForbiddenException::getInstance()->withoutLayout(); + } + } +} diff --git a/app/Controller/ProjectActionDuplicationController.php b/app/Controller/ProjectActionDuplicationController.php new file mode 100644 index 00000000..790b7ed3 --- /dev/null +++ b/app/Controller/ProjectActionDuplicationController.php @@ -0,0 +1,38 @@ +getProject(); + $projects = $this->projectUserRole->getProjectsByUser($this->userSession->getId()); + unset($projects[$project['id']]); + + $this->response->html($this->template->render('project_action_duplication/show', array( + 'project' => $project, + 'projects_list' => $projects, + ))); + } + + public function save() + { + $project = $this->getProject(); + $src_project_id = $this->request->getValue('src_project_id'); + + if ($this->action->duplicate($src_project_id, $project['id'])) { + $this->flash->success(t('Actions duplicated successfully.')); + } else { + $this->flash->failure(t('Unable to duplicate actions.')); + } + + $this->response->redirect($this->helper->url->to('ActionController', 'index', array('project_id' => $project['id']))); + } +} diff --git a/app/Controller/ProjectCreation.php b/app/Controller/ProjectCreation.php deleted file mode 100644 index 0ffa2174..00000000 --- a/app/Controller/ProjectCreation.php +++ /dev/null @@ -1,129 +0,0 @@ - t('Do not duplicate anything')) + $this->projectUserRole->getActiveProjectsByUser($this->userSession->getId()); - - $this->response->html($this->helper->layout->app('project_creation/create', array( - 'values' => $values, - 'errors' => $errors, - 'is_private' => $is_private, - 'projects_list' => $projects_list, - 'title' => $is_private ? t('New private project') : t('New project'), - ))); - } - - /** - * Display a form to create a private project - * - * @access public - * @param array $values - * @param array $errors - */ - public function createPrivate(array $values = array(), array $errors = array()) - { - $values['is_private'] = 1; - $this->create($values, $errors); - } - - /** - * Validate and save a new project - * - * @access public - */ - public function save() - { - $values = $this->request->getValues(); - list($valid, $errors) = $this->projectValidator->validateCreation($values); - - if ($valid) { - $project_id = $this->createOrDuplicate($values); - - if ($project_id > 0) { - $this->flash->success(t('Your project have been created successfully.')); - return $this->response->redirect($this->helper->url->to('ProjectViewController', 'show', array('project_id' => $project_id))); - } - - $this->flash->failure(t('Unable to create your project.')); - } - - return $this->create($values, $errors); - } - - /** - * Create or duplicate a project - * - * @access private - * @param array $values - * @return boolean|integer - */ - private function createOrDuplicate(array $values) - { - if (empty($values['src_project_id'])) { - return $this->createNewProject($values); - } - - return $this->duplicateNewProject($values); - } - - /** - * Save a new project - * - * @access private - * @param array $values - * @return boolean|integer - */ - private function createNewProject(array $values) - { - $project = array( - 'name' => $values['name'], - 'is_private' => $values['is_private'], - ); - - return $this->project->create($project, $this->userSession->getId(), true); - } - - /** - * Creatte from another project - * - * @access private - * @param array $values - * @return boolean|integer - */ - private function duplicateNewProject(array $values) - { - $selection = array(); - - foreach ($this->projectDuplication->getOptionalSelection() as $item) { - if (isset($values[$item]) && $values[$item] == 1) { - $selection[] = $item; - } - } - - return $this->projectDuplication->duplicate( - $values['src_project_id'], - $selection, - $this->userSession->getId(), - $values['name'], - $values['is_private'] == 1 - ); - } -} diff --git a/app/Controller/ProjectCreationController.php b/app/Controller/ProjectCreationController.php new file mode 100644 index 00000000..4166ead1 --- /dev/null +++ b/app/Controller/ProjectCreationController.php @@ -0,0 +1,129 @@ + t('Do not duplicate anything')) + $this->projectUserRole->getActiveProjectsByUser($this->userSession->getId()); + + $this->response->html($this->helper->layout->app('project_creation/create', array( + 'values' => $values, + 'errors' => $errors, + 'is_private' => $is_private, + 'projects_list' => $projects_list, + 'title' => $is_private ? t('New private project') : t('New project'), + ))); + } + + /** + * Display a form to create a private project + * + * @access public + * @param array $values + * @param array $errors + */ + public function createPrivate(array $values = array(), array $errors = array()) + { + $values['is_private'] = 1; + $this->create($values, $errors); + } + + /** + * Validate and save a new project + * + * @access public + */ + public function save() + { + $values = $this->request->getValues(); + list($valid, $errors) = $this->projectValidator->validateCreation($values); + + if ($valid) { + $project_id = $this->createOrDuplicate($values); + + if ($project_id > 0) { + $this->flash->success(t('Your project have been created successfully.')); + return $this->response->redirect($this->helper->url->to('ProjectViewController', 'show', array('project_id' => $project_id))); + } + + $this->flash->failure(t('Unable to create your project.')); + } + + return $this->create($values, $errors); + } + + /** + * Create or duplicate a project + * + * @access private + * @param array $values + * @return boolean|integer + */ + private function createOrDuplicate(array $values) + { + if (empty($values['src_project_id'])) { + return $this->createNewProject($values); + } + + return $this->duplicateNewProject($values); + } + + /** + * Save a new project + * + * @access private + * @param array $values + * @return boolean|integer + */ + private function createNewProject(array $values) + { + $project = array( + 'name' => $values['name'], + 'is_private' => $values['is_private'], + ); + + return $this->project->create($project, $this->userSession->getId(), true); + } + + /** + * Creatte from another project + * + * @access private + * @param array $values + * @return boolean|integer + */ + private function duplicateNewProject(array $values) + { + $selection = array(); + + foreach ($this->projectDuplication->getOptionalSelection() as $item) { + if (isset($values[$item]) && $values[$item] == 1) { + $selection[] = $item; + } + } + + return $this->projectDuplication->duplicate( + $values['src_project_id'], + $selection, + $this->userSession->getId(), + $values['name'], + $values['is_private'] == 1 + ); + } +} diff --git a/app/Controller/ProjectEditController.php b/app/Controller/ProjectEditController.php index 774c6909..64e02d1a 100644 --- a/app/Controller/ProjectEditController.php +++ b/app/Controller/ProjectEditController.php @@ -97,11 +97,11 @@ class ProjectEditController extends BaseController { if ($redirect === 'edit') { if (isset($values['is_private'])) { - if (! $this->helper->user->hasProjectAccess('ProjectCreation', 'create', $project['id'])) { + if (! $this->helper->user->hasProjectAccess('ProjectCreationController', 'create', $project['id'])) { unset($values['is_private']); } } elseif ($project['is_private'] == 1 && ! isset($values['is_private'])) { - if ($this->helper->user->hasProjectAccess('ProjectCreation', 'create', $project['id'])) { + if ($this->helper->user->hasProjectAccess('ProjectCreationController', 'create', $project['id'])) { $values += array('is_private' => 0); } } diff --git a/app/Controller/ProjectFile.php b/app/Controller/ProjectFile.php deleted file mode 100644 index 6ec5ff27..00000000 --- a/app/Controller/ProjectFile.php +++ /dev/null @@ -1,79 +0,0 @@ -getProject(); - - $this->response->html($this->template->render('project_file/create', array( - 'project' => $project, - 'max_size' => $this->helper->text->phpToBytes(ini_get('upload_max_filesize')), - ))); - } - - /** - * Save uploaded files - * - * @access public - */ - public function save() - { - $project = $this->getProject(); - - if (! $this->projectFile->uploadFiles($project['id'], $this->request->getFileInfo('files'))) { - $this->flash->failure(t('Unable to upload the file.')); - } - - $this->response->redirect($this->helper->url->to('ProjectOverview', 'show', array('project_id' => $project['id'])), true); - } - - /** - * Remove a file - * - * @access public - */ - public function remove() - { - $this->checkCSRFParam(); - $project = $this->getProject(); - $file = $this->projectFile->getById($this->request->getIntegerParam('file_id')); - - if ($this->projectFile->remove($file['id'])) { - $this->flash->success(t('File removed successfully.')); - } else { - $this->flash->failure(t('Unable to remove this file.')); - } - - $this->response->redirect($this->helper->url->to('ProjectOverview', 'show', array('project_id' => $project['id']))); - } - - /** - * Confirmation dialog before removing a file - * - * @access public - */ - public function confirm() - { - $project = $this->getProject(); - $file = $this->projectFile->getById($this->request->getIntegerParam('file_id')); - - $this->response->html($this->template->render('project_file/remove', array( - 'project' => $project, - 'file' => $file, - ))); - } -} diff --git a/app/Controller/ProjectFileController.php b/app/Controller/ProjectFileController.php new file mode 100644 index 00000000..f1bce09d --- /dev/null +++ b/app/Controller/ProjectFileController.php @@ -0,0 +1,79 @@ +getProject(); + + $this->response->html($this->template->render('project_file/create', array( + 'project' => $project, + 'max_size' => $this->helper->text->phpToBytes(ini_get('upload_max_filesize')), + ))); + } + + /** + * Save uploaded files + * + * @access public + */ + public function save() + { + $project = $this->getProject(); + + if (! $this->projectFile->uploadFiles($project['id'], $this->request->getFileInfo('files'))) { + $this->flash->failure(t('Unable to upload the file.')); + } + + $this->response->redirect($this->helper->url->to('ProjectOverviewController', 'show', array('project_id' => $project['id'])), true); + } + + /** + * Remove a file + * + * @access public + */ + public function remove() + { + $this->checkCSRFParam(); + $project = $this->getProject(); + $file = $this->projectFile->getById($this->request->getIntegerParam('file_id')); + + if ($this->projectFile->remove($file['id'])) { + $this->flash->success(t('File removed successfully.')); + } else { + $this->flash->failure(t('Unable to remove this file.')); + } + + $this->response->redirect($this->helper->url->to('ProjectOverviewController', 'show', array('project_id' => $project['id']))); + } + + /** + * Confirmation dialog before removing a file + * + * @access public + */ + public function confirm() + { + $project = $this->getProject(); + $file = $this->projectFile->getById($this->request->getIntegerParam('file_id')); + + $this->response->html($this->template->render('project_file/remove', array( + 'project' => $project, + 'file' => $file, + ))); + } +} diff --git a/app/Controller/ProjectOverview.php b/app/Controller/ProjectOverview.php deleted file mode 100644 index f8837f95..00000000 --- a/app/Controller/ProjectOverview.php +++ /dev/null @@ -1,32 +0,0 @@ -getProject(); - $this->project->getColumnStats($project); - - $this->response->html($this->helper->layout->app('project_overview/show', array( - 'project' => $project, - 'title' => $project['name'], - 'description' => $this->helper->projectHeader->getDescription($project), - 'users' => $this->projectUserRole->getAllUsersGroupedByRole($project['id']), - 'roles' => $this->role->getProjectRoles(), - 'events' => $this->helper->projectActivity->getProjectEvents($project['id'], 10), - 'images' => $this->projectFile->getAllImages($project['id']), - 'files' => $this->projectFile->getAllDocuments($project['id']), - ))); - } -} diff --git a/app/Controller/ProjectOverviewController.php b/app/Controller/ProjectOverviewController.php new file mode 100644 index 00000000..75cf25ba --- /dev/null +++ b/app/Controller/ProjectOverviewController.php @@ -0,0 +1,32 @@ +getProject(); + $this->project->getColumnStats($project); + + $this->response->html($this->helper->layout->app('project_overview/show', array( + 'project' => $project, + 'title' => $project['name'], + 'description' => $this->helper->projectHeader->getDescription($project), + 'users' => $this->projectUserRole->getAllUsersGroupedByRole($project['id']), + 'roles' => $this->role->getProjectRoles(), + 'events' => $this->helper->projectActivity->getProjectEvents($project['id'], 10), + 'images' => $this->projectFile->getAllImages($project['id']), + 'files' => $this->projectFile->getAllDocuments($project['id']), + ))); + } +} diff --git a/app/Controller/ProjectUserOverviewController.php b/app/Controller/ProjectUserOverviewController.php new file mode 100644 index 00000000..90887a8a --- /dev/null +++ b/app/Controller/ProjectUserOverviewController.php @@ -0,0 +1,130 @@ +request->getIntegerParam('user_id', UserModel::EVERYBODY_ID); + + if ($this->userSession->isAdmin()) { + $project_ids = $this->project->getAllIds(); + } else { + $project_ids = $this->projectPermission->getActiveProjectIds($this->userSession->getId()); + } + + return array($user_id, $project_ids, $this->user->getActiveUsersList(true)); + } + + private function role($role, $action, $title, $title_user) + { + list($user_id, $project_ids, $users) = $this->common(); + + $query = $this->projectPermission->getQueryByRole($project_ids, $role)->callback(array($this->project, 'applyColumnStats')); + + if ($user_id !== UserModel::EVERYBODY_ID && isset($users[$user_id])) { + $query->eq(UserModel::TABLE.'.id', $user_id); + $title = t($title_user, $users[$user_id]); + } + + $paginator = $this->paginator + ->setUrl('ProjectUserOverviewController', $action, array('user_id' => $user_id)) + ->setMax(30) + ->setOrder('projects.name') + ->setQuery($query) + ->calculate(); + + $this->response->html($this->helper->layout->projectUser('project_user_overview/roles', array( + 'paginator' => $paginator, + 'title' => $title, + 'user_id' => $user_id, + 'users' => $users, + ))); + } + + private function tasks($is_active, $action, $title, $title_user) + { + list($user_id, $project_ids, $users) = $this->common(); + + $query = $this->taskFinder->getProjectUserOverviewQuery($project_ids, $is_active); + + if ($user_id !== UserModel::EVERYBODY_ID && isset($users[$user_id])) { + $query->eq(TaskModel::TABLE.'.owner_id', $user_id); + $title = t($title_user, $users[$user_id]); + } + + $paginator = $this->paginator + ->setUrl('ProjectUserOverviewController', $action, array('user_id' => $user_id)) + ->setMax(50) + ->setOrder(TaskModel::TABLE.'.id') + ->setQuery($query) + ->calculate(); + + $this->response->html($this->helper->layout->projectUser('project_user_overview/tasks', array( + 'paginator' => $paginator, + 'title' => $title, + 'user_id' => $user_id, + 'users' => $users, + ))); + } + + /** + * Display the list of project managers + * + */ + public function managers() + { + $this->role(Role::PROJECT_MANAGER, 'managers', t('People who are project managers'), 'Projects where "%s" is manager'); + } + + /** + * Display the list of project members + * + */ + public function members() + { + $this->role(Role::PROJECT_MEMBER, 'members', t('People who are project members'), 'Projects where "%s" is member'); + } + + /** + * Display the list of open taks + * + */ + public function opens() + { + $this->tasks(TaskModel::STATUS_OPEN, 'opens', t('Open tasks'), 'Open tasks assigned to "%s"'); + } + + /** + * Display the list of closed tasks + * + */ + public function closed() + { + $this->tasks(TaskModel::STATUS_CLOSED, 'closed', t('Closed tasks'), 'Closed tasks assigned to "%s"'); + } + + /** + * Users tooltip + */ + public function users() + { + $project = $this->getProject(); + + return $this->response->html($this->template->render('project_user_overview/tooltip_users', array( + 'users' => $this->projectUserRole->getAllUsersGroupedByRole($project['id']), + 'roles' => $this->role->getProjectRoles(), + ))); + } +} diff --git a/app/Controller/Projectuser.php b/app/Controller/Projectuser.php deleted file mode 100644 index fe1fe0f1..00000000 --- a/app/Controller/Projectuser.php +++ /dev/null @@ -1,130 +0,0 @@ -request->getIntegerParam('user_id', UserModel::EVERYBODY_ID); - - if ($this->userSession->isAdmin()) { - $project_ids = $this->project->getAllIds(); - } else { - $project_ids = $this->projectPermission->getActiveProjectIds($this->userSession->getId()); - } - - return array($user_id, $project_ids, $this->user->getActiveUsersList(true)); - } - - private function role($role, $action, $title, $title_user) - { - list($user_id, $project_ids, $users) = $this->common(); - - $query = $this->projectPermission->getQueryByRole($project_ids, $role)->callback(array($this->project, 'applyColumnStats')); - - if ($user_id !== UserModel::EVERYBODY_ID && isset($users[$user_id])) { - $query->eq(UserModel::TABLE.'.id', $user_id); - $title = t($title_user, $users[$user_id]); - } - - $paginator = $this->paginator - ->setUrl('projectuser', $action, array('user_id' => $user_id)) - ->setMax(30) - ->setOrder('projects.name') - ->setQuery($query) - ->calculate(); - - $this->response->html($this->helper->layout->projectUser('project_user/roles', array( - 'paginator' => $paginator, - 'title' => $title, - 'user_id' => $user_id, - 'users' => $users, - ))); - } - - private function tasks($is_active, $action, $title, $title_user) - { - list($user_id, $project_ids, $users) = $this->common(); - - $query = $this->taskFinder->getProjectUserOverviewQuery($project_ids, $is_active); - - if ($user_id !== UserModel::EVERYBODY_ID && isset($users[$user_id])) { - $query->eq(TaskModel::TABLE.'.owner_id', $user_id); - $title = t($title_user, $users[$user_id]); - } - - $paginator = $this->paginator - ->setUrl('projectuser', $action, array('user_id' => $user_id)) - ->setMax(50) - ->setOrder(TaskModel::TABLE.'.id') - ->setQuery($query) - ->calculate(); - - $this->response->html($this->helper->layout->projectUser('project_user/tasks', array( - 'paginator' => $paginator, - 'title' => $title, - 'user_id' => $user_id, - 'users' => $users, - ))); - } - - /** - * Display the list of project managers - * - */ - public function managers() - { - $this->role(Role::PROJECT_MANAGER, 'managers', t('People who are project managers'), 'Projects where "%s" is manager'); - } - - /** - * Display the list of project members - * - */ - public function members() - { - $this->role(Role::PROJECT_MEMBER, 'members', t('People who are project members'), 'Projects where "%s" is member'); - } - - /** - * Display the list of open taks - * - */ - public function opens() - { - $this->tasks(TaskModel::STATUS_OPEN, 'opens', t('Open tasks'), 'Open tasks assigned to "%s"'); - } - - /** - * Display the list of closed tasks - * - */ - public function closed() - { - $this->tasks(TaskModel::STATUS_CLOSED, 'closed', t('Closed tasks'), 'Closed tasks assigned to "%s"'); - } - - /** - * Users tooltip - */ - public function users() - { - $project = $this->getProject(); - - return $this->response->html($this->template->render('project_user/tooltip_users', array( - 'users' => $this->projectUserRole->getAllUsersGroupedByRole($project['id']), - 'roles' => $this->role->getProjectRoles(), - ))); - } -} diff --git a/app/Controller/Swimlane.php b/app/Controller/Swimlane.php deleted file mode 100644 index 4575e909..00000000 --- a/app/Controller/Swimlane.php +++ /dev/null @@ -1,314 +0,0 @@ -swimlane->getById($this->request->getIntegerParam('swimlane_id')); - - if (empty($swimlane)) { - throw new PageNotFoundException(); - } - - return $swimlane; - } - - /** - * List of swimlanes for a given project - * - * @access public - */ - public function index() - { - $project = $this->getProject(); - - $this->response->html($this->helper->layout->project('swimlane/index', array( - 'default_swimlane' => $this->swimlane->getDefault($project['id']), - 'active_swimlanes' => $this->swimlane->getAllByStatus($project['id'], SwimlaneModel::ACTIVE), - 'inactive_swimlanes' => $this->swimlane->getAllByStatus($project['id'], SwimlaneModel::INACTIVE), - 'project' => $project, - 'title' => t('Swimlanes') - ))); - } - - /** - * Create a new swimlane - * - * @access public - * @param array $values - * @param array $errors - * @throws \Kanboard\Core\Controller\PageNotFoundException - */ - public function create(array $values = array(), array $errors = array()) - { - $project = $this->getProject(); - - $this->response->html($this->template->render('swimlane/create', array( - 'values' => $values + array('project_id' => $project['id']), - 'errors' => $errors, - 'project' => $project, - ))); - } - - /** - * Validate and save a new swimlane - * - * @access public - */ - public function save() - { - $project = $this->getProject(); - $values = $this->request->getValues(); - list($valid, $errors) = $this->swimlaneValidator->validateCreation($values); - - if ($valid) { - if ($this->swimlane->create($values)) { - $this->flash->success(t('Your swimlane have been created successfully.')); - return $this->response->redirect($this->helper->url->to('swimlane', 'index', array('project_id' => $project['id']))); - } else { - $errors = array('name' => array(t('Another swimlane with the same name exists in the project'))); - } - } - - return $this->create($values, $errors); - } - - /** - * Edit default swimlane (display the form) - * - * @access public - * @param array $values - * @param array $errors - * @throws \Kanboard\Core\Controller\PageNotFoundException - */ - public function editDefault(array $values = array(), array $errors = array()) - { - $project = $this->getProject(); - $swimlane = $this->swimlane->getDefault($project['id']); - - $this->response->html($this->helper->layout->project('swimlane/edit_default', array( - 'values' => empty($values) ? $swimlane : $values, - 'errors' => $errors, - 'project' => $project, - ))); - } - - /** - * Change the default swimlane - * - * @access public - */ - public function updateDefault() - { - $project = $this->getProject(); - - $values = $this->request->getValues() + array('show_default_swimlane' => 0); - list($valid, $errors) = $this->swimlaneValidator->validateDefaultModification($values); - - if ($valid) { - if ($this->swimlane->updateDefault($values)) { - $this->flash->success(t('The default swimlane have been updated successfully.')); - return $this->response->redirect($this->helper->url->to('swimlane', 'index', array('project_id' => $project['id'])), true); - } else { - $this->flash->failure(t('Unable to update this swimlane.')); - } - } - - return $this->editDefault($values, $errors); - } - - /** - * Edit a swimlane (display the form) - * - * @access public - * @param array $values - * @param array $errors - * @throws \Kanboard\Core\Controller\PageNotFoundException - */ - public function edit(array $values = array(), array $errors = array()) - { - $project = $this->getProject(); - $swimlane = $this->getSwimlane(); - - $this->response->html($this->helper->layout->project('swimlane/edit', array( - 'values' => empty($values) ? $swimlane : $values, - 'errors' => $errors, - 'project' => $project, - ))); - } - - /** - * Edit a swimlane (validate the form and update the database) - * - * @access public - */ - public function update() - { - $project = $this->getProject(); - - $values = $this->request->getValues(); - list($valid, $errors) = $this->swimlaneValidator->validateModification($values); - - if ($valid) { - if ($this->swimlane->update($values)) { - $this->flash->success(t('Swimlane updated successfully.')); - return $this->response->redirect($this->helper->url->to('swimlane', 'index', array('project_id' => $project['id']))); - } else { - $errors = array('name' => array(t('Another swimlane with the same name exists in the project'))); - } - } - - return $this->edit($values, $errors); - } - - /** - * Confirmation dialog before removing a swimlane - * - * @access public - */ - public function confirm() - { - $project = $this->getProject(); - $swimlane = $this->getSwimlane(); - - $this->response->html($this->helper->layout->project('swimlane/remove', array( - 'project' => $project, - 'swimlane' => $swimlane, - ))); - } - - /** - * Remove a swimlane - * - * @access public - */ - public function remove() - { - $this->checkCSRFParam(); - $project = $this->getProject(); - $swimlane_id = $this->request->getIntegerParam('swimlane_id'); - - if ($this->swimlane->remove($project['id'], $swimlane_id)) { - $this->flash->success(t('Swimlane removed successfully.')); - } else { - $this->flash->failure(t('Unable to remove this swimlane.')); - } - - $this->response->redirect($this->helper->url->to('swimlane', 'index', array('project_id' => $project['id']))); - } - - /** - * Disable a swimlane - * - * @access public - */ - public function disable() - { - $this->checkCSRFParam(); - $project = $this->getProject(); - $swimlane_id = $this->request->getIntegerParam('swimlane_id'); - - if ($this->swimlane->disable($project['id'], $swimlane_id)) { - $this->flash->success(t('Swimlane updated successfully.')); - } else { - $this->flash->failure(t('Unable to update this swimlane.')); - } - - $this->response->redirect($this->helper->url->to('swimlane', 'index', array('project_id' => $project['id']))); - } - - /** - * Disable default swimlane - * - * @access public - */ - public function disableDefault() - { - $this->checkCSRFParam(); - $project = $this->getProject(); - - if ($this->swimlane->disableDefault($project['id'])) { - $this->flash->success(t('Swimlane updated successfully.')); - } else { - $this->flash->failure(t('Unable to update this swimlane.')); - } - - $this->response->redirect($this->helper->url->to('swimlane', 'index', array('project_id' => $project['id']))); - } - - /** - * Enable a swimlane - * - * @access public - */ - public function enable() - { - $this->checkCSRFParam(); - $project = $this->getProject(); - $swimlane_id = $this->request->getIntegerParam('swimlane_id'); - - if ($this->swimlane->enable($project['id'], $swimlane_id)) { - $this->flash->success(t('Swimlane updated successfully.')); - } else { - $this->flash->failure(t('Unable to update this swimlane.')); - } - - $this->response->redirect($this->helper->url->to('swimlane', 'index', array('project_id' => $project['id']))); - } - - /** - * Enable default swimlane - * - * @access public - */ - public function enableDefault() - { - $this->checkCSRFParam(); - $project = $this->getProject(); - - if ($this->swimlane->enableDefault($project['id'])) { - $this->flash->success(t('Swimlane updated successfully.')); - } else { - $this->flash->failure(t('Unable to update this swimlane.')); - } - - $this->response->redirect($this->helper->url->to('swimlane', 'index', array('project_id' => $project['id']))); - } - - /** - * Move swimlane position - * - * @access public - */ - public function move() - { - $project = $this->getProject(); - $values = $this->request->getJson(); - - if (! empty($values) && isset($values['swimlane_id']) && isset($values['position'])) { - $result = $this->swimlane->changePosition($project['id'], $values['swimlane_id'], $values['position']); - $this->response->json(array('result' => $result)); - } else { - throw new AccessForbiddenException(); - } - } -} diff --git a/app/Controller/SwimlaneController.php b/app/Controller/SwimlaneController.php new file mode 100644 index 00000000..13a64d40 --- /dev/null +++ b/app/Controller/SwimlaneController.php @@ -0,0 +1,314 @@ +swimlane->getById($this->request->getIntegerParam('swimlane_id')); + + if (empty($swimlane)) { + throw new PageNotFoundException(); + } + + return $swimlane; + } + + /** + * List of swimlanes for a given project + * + * @access public + */ + public function index() + { + $project = $this->getProject(); + + $this->response->html($this->helper->layout->project('swimlane/index', array( + 'default_swimlane' => $this->swimlane->getDefault($project['id']), + 'active_swimlanes' => $this->swimlane->getAllByStatus($project['id'], SwimlaneModel::ACTIVE), + 'inactive_swimlanes' => $this->swimlane->getAllByStatus($project['id'], SwimlaneModel::INACTIVE), + 'project' => $project, + 'title' => t('Swimlanes') + ))); + } + + /** + * Create a new swimlane + * + * @access public + * @param array $values + * @param array $errors + * @throws \Kanboard\Core\Controller\PageNotFoundException + */ + public function create(array $values = array(), array $errors = array()) + { + $project = $this->getProject(); + + $this->response->html($this->template->render('swimlane/create', array( + 'values' => $values + array('project_id' => $project['id']), + 'errors' => $errors, + 'project' => $project, + ))); + } + + /** + * Validate and save a new swimlane + * + * @access public + */ + public function save() + { + $project = $this->getProject(); + $values = $this->request->getValues(); + list($valid, $errors) = $this->swimlaneValidator->validateCreation($values); + + if ($valid) { + if ($this->swimlane->create($values)) { + $this->flash->success(t('Your swimlane have been created successfully.')); + return $this->response->redirect($this->helper->url->to('SwimlaneController', 'index', array('project_id' => $project['id']))); + } else { + $errors = array('name' => array(t('Another swimlane with the same name exists in the project'))); + } + } + + return $this->create($values, $errors); + } + + /** + * Edit default swimlane (display the form) + * + * @access public + * @param array $values + * @param array $errors + * @throws \Kanboard\Core\Controller\PageNotFoundException + */ + public function editDefault(array $values = array(), array $errors = array()) + { + $project = $this->getProject(); + $swimlane = $this->swimlane->getDefault($project['id']); + + $this->response->html($this->helper->layout->project('swimlane/edit_default', array( + 'values' => empty($values) ? $swimlane : $values, + 'errors' => $errors, + 'project' => $project, + ))); + } + + /** + * Change the default swimlane + * + * @access public + */ + public function updateDefault() + { + $project = $this->getProject(); + + $values = $this->request->getValues() + array('show_default_swimlane' => 0); + list($valid, $errors) = $this->swimlaneValidator->validateDefaultModification($values); + + if ($valid) { + if ($this->swimlane->updateDefault($values)) { + $this->flash->success(t('The default swimlane have been updated successfully.')); + return $this->response->redirect($this->helper->url->to('SwimlaneController', 'index', array('project_id' => $project['id'])), true); + } else { + $this->flash->failure(t('Unable to update this swimlane.')); + } + } + + return $this->editDefault($values, $errors); + } + + /** + * Edit a swimlane (display the form) + * + * @access public + * @param array $values + * @param array $errors + * @throws \Kanboard\Core\Controller\PageNotFoundException + */ + public function edit(array $values = array(), array $errors = array()) + { + $project = $this->getProject(); + $swimlane = $this->getSwimlane(); + + $this->response->html($this->helper->layout->project('swimlane/edit', array( + 'values' => empty($values) ? $swimlane : $values, + 'errors' => $errors, + 'project' => $project, + ))); + } + + /** + * Edit a swimlane (validate the form and update the database) + * + * @access public + */ + public function update() + { + $project = $this->getProject(); + + $values = $this->request->getValues(); + list($valid, $errors) = $this->swimlaneValidator->validateModification($values); + + if ($valid) { + if ($this->swimlane->update($values)) { + $this->flash->success(t('Swimlane updated successfully.')); + return $this->response->redirect($this->helper->url->to('SwimlaneController', 'index', array('project_id' => $project['id']))); + } else { + $errors = array('name' => array(t('Another swimlane with the same name exists in the project'))); + } + } + + return $this->edit($values, $errors); + } + + /** + * Confirmation dialog before removing a swimlane + * + * @access public + */ + public function confirm() + { + $project = $this->getProject(); + $swimlane = $this->getSwimlane(); + + $this->response->html($this->helper->layout->project('swimlane/remove', array( + 'project' => $project, + 'swimlane' => $swimlane, + ))); + } + + /** + * Remove a swimlane + * + * @access public + */ + public function remove() + { + $this->checkCSRFParam(); + $project = $this->getProject(); + $swimlane_id = $this->request->getIntegerParam('swimlane_id'); + + if ($this->swimlane->remove($project['id'], $swimlane_id)) { + $this->flash->success(t('Swimlane removed successfully.')); + } else { + $this->flash->failure(t('Unable to remove this swimlane.')); + } + + $this->response->redirect($this->helper->url->to('SwimlaneController', 'index', array('project_id' => $project['id']))); + } + + /** + * Disable a swimlane + * + * @access public + */ + public function disable() + { + $this->checkCSRFParam(); + $project = $this->getProject(); + $swimlane_id = $this->request->getIntegerParam('swimlane_id'); + + if ($this->swimlane->disable($project['id'], $swimlane_id)) { + $this->flash->success(t('Swimlane updated successfully.')); + } else { + $this->flash->failure(t('Unable to update this swimlane.')); + } + + $this->response->redirect($this->helper->url->to('SwimlaneController', 'index', array('project_id' => $project['id']))); + } + + /** + * Disable default swimlane + * + * @access public + */ + public function disableDefault() + { + $this->checkCSRFParam(); + $project = $this->getProject(); + + if ($this->swimlane->disableDefault($project['id'])) { + $this->flash->success(t('Swimlane updated successfully.')); + } else { + $this->flash->failure(t('Unable to update this swimlane.')); + } + + $this->response->redirect($this->helper->url->to('SwimlaneController', 'index', array('project_id' => $project['id']))); + } + + /** + * Enable a swimlane + * + * @access public + */ + public function enable() + { + $this->checkCSRFParam(); + $project = $this->getProject(); + $swimlane_id = $this->request->getIntegerParam('swimlane_id'); + + if ($this->swimlane->enable($project['id'], $swimlane_id)) { + $this->flash->success(t('Swimlane updated successfully.')); + } else { + $this->flash->failure(t('Unable to update this swimlane.')); + } + + $this->response->redirect($this->helper->url->to('SwimlaneController', 'index', array('project_id' => $project['id']))); + } + + /** + * Enable default swimlane + * + * @access public + */ + public function enableDefault() + { + $this->checkCSRFParam(); + $project = $this->getProject(); + + if ($this->swimlane->enableDefault($project['id'])) { + $this->flash->success(t('Swimlane updated successfully.')); + } else { + $this->flash->failure(t('Unable to update this swimlane.')); + } + + $this->response->redirect($this->helper->url->to('SwimlaneController', 'index', array('project_id' => $project['id']))); + } + + /** + * Move swimlane position + * + * @access public + */ + public function move() + { + $project = $this->getProject(); + $values = $this->request->getJson(); + + if (! empty($values) && isset($values['swimlane_id']) && isset($values['position'])) { + $result = $this->swimlane->changePosition($project['id'], $values['swimlane_id'], $values['position']); + $this->response->json(array('result' => $result)); + } else { + throw new AccessForbiddenException(); + } + } +} diff --git a/app/Controller/TaskBulkController.php b/app/Controller/TaskBulkController.php index 4b4a2594..c0214ea7 100644 --- a/app/Controller/TaskBulkController.php +++ b/app/Controller/TaskBulkController.php @@ -6,6 +6,7 @@ namespace Kanboard\Controller; * Class TaskBulkController * * @package Kanboard\Controller + * @author Frederic Guillot */ class TaskBulkController extends BaseController { diff --git a/app/Controller/TaskDuplicationController.php b/app/Controller/TaskDuplicationController.php new file mode 100644 index 00000000..ab7b6b42 --- /dev/null +++ b/app/Controller/TaskDuplicationController.php @@ -0,0 +1,141 @@ +getTask(); + + if ($this->request->getStringParam('confirmation') === 'yes') { + $this->checkCSRFParam(); + $task_id = $this->taskDuplication->duplicate($task['id']); + + if ($task_id > 0) { + $this->flash->success(t('Task created successfully.')); + return $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('project_id' => $task['project_id'], 'task_id' => $task_id))); + } else { + $this->flash->failure(t('Unable to create this task.')); + return $this->response->redirect($this->helper->url->to('TaskDuplicationController', 'duplicate', array('project_id' => $task['project_id'], 'task_id' => $task['id'])), true); + } + } + + return $this->response->html($this->template->render('task_duplication/duplicate', array( + 'task' => $task, + ))); + } + + /** + * Move a task to another project + * + * @access public + */ + public function move() + { + $task = $this->getTask(); + + if ($this->request->isPost()) { + $values = $this->request->getValues(); + list($valid, ) = $this->taskValidator->validateProjectModification($values); + + if ($valid && $this->taskDuplication->moveToProject($task['id'], + $values['project_id'], + $values['swimlane_id'], + $values['column_id'], + $values['category_id'], + $values['owner_id'])) { + $this->flash->success(t('Task updated successfully.')); + return $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('project_id' => $values['project_id'], 'task_id' => $task['id']))); + } + + $this->flash->failure(t('Unable to update your task.')); + } + + return $this->chooseDestination($task, 'task_duplication/move'); + } + + /** + * Duplicate a task to another project + * + * @access public + */ + public function copy() + { + $task = $this->getTask(); + + if ($this->request->isPost()) { + $values = $this->request->getValues(); + list($valid, ) = $this->taskValidator->validateProjectModification($values); + + if ($valid) { + $task_id = $this->taskDuplication->duplicateToProject( + $task['id'], $values['project_id'], $values['swimlane_id'], + $values['column_id'], $values['category_id'], $values['owner_id'] + ); + + if ($task_id > 0) { + $this->flash->success(t('Task created successfully.')); + return $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('project_id' => $values['project_id'], 'task_id' => $task_id))); + } + } + + $this->flash->failure(t('Unable to create your task.')); + } + + return $this->chooseDestination($task, 'task_duplication/copy'); + } + + /** + * Choose destination when move/copy task to another project + * + * @access private + * @param array $task + * @param string $template + */ + private function chooseDestination(array $task, $template) + { + $values = array(); + $projects_list = $this->projectUserRole->getActiveProjectsByUser($this->userSession->getId()); + + unset($projects_list[$task['project_id']]); + + if (! empty($projects_list)) { + $dst_project_id = $this->request->getIntegerParam('dst_project_id', key($projects_list)); + + $swimlanes_list = $this->swimlane->getList($dst_project_id, false, true); + $columns_list = $this->column->getList($dst_project_id); + $categories_list = $this->category->getList($dst_project_id); + $users_list = $this->projectUserRole->getAssignableUsersList($dst_project_id); + + $values = $this->taskDuplication->checkDestinationProjectValues($task); + $values['project_id'] = $dst_project_id; + } else { + $swimlanes_list = array(); + $columns_list = array(); + $categories_list = array(); + $users_list = array(); + } + + $this->response->html($this->template->render($template, array( + 'values' => $values, + 'task' => $task, + 'projects_list' => $projects_list, + 'swimlanes_list' => $swimlanes_list, + 'columns_list' => $columns_list, + 'categories_list' => $categories_list, + 'users_list' => $users_list, + ))); + } +} diff --git a/app/Controller/TaskExternalLink.php b/app/Controller/TaskExternalLink.php deleted file mode 100644 index 0bd55dba..00000000 --- a/app/Controller/TaskExternalLink.php +++ /dev/null @@ -1,178 +0,0 @@ -getTask(); - - $this->response->html($this->template->render('task_external_link/find', array( - 'values' => $values, - 'errors' => $errors, - 'task' => $task, - 'types' => $this->externalLinkManager->getTypes(), - ))); - } - - /** - * Second creation form - * - * @access public - */ - public function create() - { - $task = $this->getTask(); - $values = $this->request->getValues(); - - try { - $provider = $this->externalLinkManager->setUserInput($values)->find(); - $link = $provider->getLink(); - - $this->response->html($this->template->render('task_external_link/create', array( - 'values' => array( - 'title' => $link->getTitle(), - 'url' => $link->getUrl(), - 'link_type' => $provider->getType(), - ), - 'dependencies' => $provider->getDependencies(), - 'errors' => array(), - 'task' => $task, - ))); - - } catch (ExternalLinkProviderNotFound $e) { - $errors = array('text' => array(t('Unable to fetch link information.'))); - $this->find($values, $errors); - } - } - - /** - * Save link - * - * @access public - */ - public function save() - { - $task = $this->getTask(); - $values = $this->request->getValues(); - list($valid, $errors) = $this->externalLinkValidator->validateCreation($values); - - if ($valid && $this->taskExternalLink->create($values)) { - $this->flash->success(t('Link added successfully.')); - return $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])), true); - } - - return $this->edit($values, $errors); - } - - /** - * Edit form - * - * @access public - * @param array $values - * @param array $errors - * @throws ExternalLinkProviderNotFound - * @throws PageNotFoundException - * @throws \Kanboard\Core\Controller\AccessForbiddenException - */ - public function edit(array $values = array(), array $errors = array()) - { - $task = $this->getTask(); - $link_id = $this->request->getIntegerParam('link_id'); - - if ($link_id > 0) { - $values = $this->taskExternalLink->getById($link_id); - } - - if (empty($values)) { - throw new PageNotFoundException(); - } - - $provider = $this->externalLinkManager->getProvider($values['link_type']); - - $this->response->html($this->template->render('task_external_link/edit', array( - 'values' => $values, - 'errors' => $errors, - 'task' => $task, - 'dependencies' => $provider->getDependencies(), - ))); - } - - /** - * Update link - * - * @access public - */ - public function update() - { - $task = $this->getTask(); - $values = $this->request->getValues(); - list($valid, $errors) = $this->externalLinkValidator->validateModification($values); - - if ($valid && $this->taskExternalLink->update($values)) { - $this->flash->success(t('Link updated successfully.')); - return $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])), true); - } - - return $this->edit($values, $errors); - } - - /** - * Confirmation dialog before removing a link - * - * @access public - */ - public function confirm() - { - $task = $this->getTask(); - $link_id = $this->request->getIntegerParam('link_id'); - $link = $this->taskExternalLink->getById($link_id); - - if (empty($link)) { - throw new PageNotFoundException(); - } - - $this->response->html($this->template->render('task_external_link/remove', array( - 'link' => $link, - 'task' => $task, - ))); - } - - /** - * Remove a link - * - * @access public - */ - public function remove() - { - $this->checkCSRFParam(); - $task = $this->getTask(); - - if ($this->taskExternalLink->remove($this->request->getIntegerParam('link_id'))) { - $this->flash->success(t('Link removed successfully.')); - } else { - $this->flash->failure(t('Unable to remove this link.')); - } - - $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))); - } -} diff --git a/app/Controller/TaskExternalLinkController.php b/app/Controller/TaskExternalLinkController.php new file mode 100644 index 00000000..91dc734a --- /dev/null +++ b/app/Controller/TaskExternalLinkController.php @@ -0,0 +1,178 @@ +getTask(); + + $this->response->html($this->template->render('task_external_link/find', array( + 'values' => $values, + 'errors' => $errors, + 'task' => $task, + 'types' => $this->externalLinkManager->getTypes(), + ))); + } + + /** + * Second creation form + * + * @access public + */ + public function create() + { + $task = $this->getTask(); + $values = $this->request->getValues(); + + try { + $provider = $this->externalLinkManager->setUserInput($values)->find(); + $link = $provider->getLink(); + + $this->response->html($this->template->render('task_external_link/create', array( + 'values' => array( + 'title' => $link->getTitle(), + 'url' => $link->getUrl(), + 'link_type' => $provider->getType(), + ), + 'dependencies' => $provider->getDependencies(), + 'errors' => array(), + 'task' => $task, + ))); + + } catch (ExternalLinkProviderNotFound $e) { + $errors = array('text' => array(t('Unable to fetch link information.'))); + $this->find($values, $errors); + } + } + + /** + * Save link + * + * @access public + */ + public function save() + { + $task = $this->getTask(); + $values = $this->request->getValues(); + list($valid, $errors) = $this->externalLinkValidator->validateCreation($values); + + if ($valid && $this->taskExternalLink->create($values)) { + $this->flash->success(t('Link added successfully.')); + return $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])), true); + } + + return $this->edit($values, $errors); + } + + /** + * Edit form + * + * @access public + * @param array $values + * @param array $errors + * @throws ExternalLinkProviderNotFound + * @throws PageNotFoundException + * @throws \Kanboard\Core\Controller\AccessForbiddenException + */ + public function edit(array $values = array(), array $errors = array()) + { + $task = $this->getTask(); + $link_id = $this->request->getIntegerParam('link_id'); + + if ($link_id > 0) { + $values = $this->taskExternalLink->getById($link_id); + } + + if (empty($values)) { + throw new PageNotFoundException(); + } + + $provider = $this->externalLinkManager->getProvider($values['link_type']); + + $this->response->html($this->template->render('task_external_link/edit', array( + 'values' => $values, + 'errors' => $errors, + 'task' => $task, + 'dependencies' => $provider->getDependencies(), + ))); + } + + /** + * Update link + * + * @access public + */ + public function update() + { + $task = $this->getTask(); + $values = $this->request->getValues(); + list($valid, $errors) = $this->externalLinkValidator->validateModification($values); + + if ($valid && $this->taskExternalLink->update($values)) { + $this->flash->success(t('Link updated successfully.')); + return $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])), true); + } + + return $this->edit($values, $errors); + } + + /** + * Confirmation dialog before removing a link + * + * @access public + */ + public function confirm() + { + $task = $this->getTask(); + $link_id = $this->request->getIntegerParam('link_id'); + $link = $this->taskExternalLink->getById($link_id); + + if (empty($link)) { + throw new PageNotFoundException(); + } + + $this->response->html($this->template->render('task_external_link/remove', array( + 'link' => $link, + 'task' => $task, + ))); + } + + /** + * Remove a link + * + * @access public + */ + public function remove() + { + $this->checkCSRFParam(); + $task = $this->getTask(); + + if ($this->taskExternalLink->remove($this->request->getIntegerParam('link_id'))) { + $this->flash->success(t('Link removed successfully.')); + } else { + $this->flash->failure(t('Unable to remove this link.')); + } + + $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))); + } +} diff --git a/app/Controller/TaskFile.php b/app/Controller/TaskFile.php deleted file mode 100644 index 544c1ea7..00000000 --- a/app/Controller/TaskFile.php +++ /dev/null @@ -1,98 +0,0 @@ -getTask(); - - if ($this->request->isPost() && $this->taskFile->uploadScreenshot($task['id'], $this->request->getValue('screenshot')) !== false) { - $this->flash->success(t('Screenshot uploaded successfully.')); - return $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])), true); - } - - return $this->response->html($this->template->render('task_file/screenshot', array( - 'task' => $task, - ))); - } - - /** - * File upload form - * - * @access public - */ - public function create() - { - $task = $this->getTask(); - - $this->response->html($this->template->render('task_file/create', array( - 'task' => $task, - 'max_size' => $this->helper->text->phpToBytes(ini_get('upload_max_filesize')), - ))); - } - - /** - * File upload (save files) - * - * @access public - */ - public function save() - { - $task = $this->getTask(); - - if (! $this->taskFile->uploadFiles($task['id'], $this->request->getFileInfo('files'))) { - $this->flash->failure(t('Unable to upload the file.')); - } - - $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])), true); - } - - /** - * Remove a file - * - * @access public - */ - public function remove() - { - $this->checkCSRFParam(); - $task = $this->getTask(); - $file = $this->taskFile->getById($this->request->getIntegerParam('file_id')); - - if ($file['task_id'] == $task['id'] && $this->taskFile->remove($file['id'])) { - $this->flash->success(t('File removed successfully.')); - } else { - $this->flash->failure(t('Unable to remove this file.')); - } - - $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))); - } - - /** - * Confirmation dialog before removing a file - * - * @access public - */ - public function confirm() - { - $task = $this->getTask(); - $file = $this->taskFile->getById($this->request->getIntegerParam('file_id')); - - $this->response->html($this->template->render('task_file/remove', array( - 'task' => $task, - 'file' => $file, - ))); - } -} diff --git a/app/Controller/TaskFileController.php b/app/Controller/TaskFileController.php new file mode 100644 index 00000000..44c19c27 --- /dev/null +++ b/app/Controller/TaskFileController.php @@ -0,0 +1,98 @@ +getTask(); + + if ($this->request->isPost() && $this->taskFile->uploadScreenshot($task['id'], $this->request->getValue('screenshot')) !== false) { + $this->flash->success(t('Screenshot uploaded successfully.')); + return $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])), true); + } + + return $this->response->html($this->template->render('task_file/screenshot', array( + 'task' => $task, + ))); + } + + /** + * File upload form + * + * @access public + */ + public function create() + { + $task = $this->getTask(); + + $this->response->html($this->template->render('task_file/create', array( + 'task' => $task, + 'max_size' => $this->helper->text->phpToBytes(ini_get('upload_max_filesize')), + ))); + } + + /** + * File upload (save files) + * + * @access public + */ + public function save() + { + $task = $this->getTask(); + + if (! $this->taskFile->uploadFiles($task['id'], $this->request->getFileInfo('files'))) { + $this->flash->failure(t('Unable to upload the file.')); + } + + $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])), true); + } + + /** + * Remove a file + * + * @access public + */ + public function remove() + { + $this->checkCSRFParam(); + $task = $this->getTask(); + $file = $this->taskFile->getById($this->request->getIntegerParam('file_id')); + + if ($file['task_id'] == $task['id'] && $this->taskFile->remove($file['id'])) { + $this->flash->success(t('File removed successfully.')); + } else { + $this->flash->failure(t('Unable to remove this file.')); + } + + $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))); + } + + /** + * Confirmation dialog before removing a file + * + * @access public + */ + public function confirm() + { + $task = $this->getTask(); + $file = $this->taskFile->getById($this->request->getIntegerParam('file_id')); + + $this->response->html($this->template->render('task_file/remove', array( + 'task' => $task, + 'file' => $file, + ))); + } +} diff --git a/app/Controller/TaskListController.php b/app/Controller/TaskListController.php new file mode 100644 index 00000000..898c14c8 --- /dev/null +++ b/app/Controller/TaskListController.php @@ -0,0 +1,45 @@ +getProject(); + $search = $this->helper->projectHeader->getSearchQuery($project); + + $paginator = $this->paginator + ->setUrl('TaskListController', 'show', array('project_id' => $project['id'])) + ->setMax(30) + ->setOrder(TaskModel::TABLE.'.id') + ->setDirection('DESC') + ->setQuery($this->taskLexer + ->build($search) + ->withFilter(new TaskProjectFilter($project['id'])) + ->getQuery() + ) + ->calculate(); + + $this->response->html($this->helper->layout->app('task_list/show', array( + 'project' => $project, + 'title' => $project['name'], + 'description' => $this->helper->projectHeader->getDescription($project), + 'paginator' => $paginator, + ))); + } +} diff --git a/app/Controller/Taskduplication.php b/app/Controller/Taskduplication.php deleted file mode 100644 index 1ea3a3f9..00000000 --- a/app/Controller/Taskduplication.php +++ /dev/null @@ -1,141 +0,0 @@ -getTask(); - - if ($this->request->getStringParam('confirmation') === 'yes') { - $this->checkCSRFParam(); - $task_id = $this->taskDuplication->duplicate($task['id']); - - if ($task_id > 0) { - $this->flash->success(t('Task created successfully.')); - return $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('project_id' => $task['project_id'], 'task_id' => $task_id))); - } else { - $this->flash->failure(t('Unable to create this task.')); - return $this->response->redirect($this->helper->url->to('taskduplication', 'duplicate', array('project_id' => $task['project_id'], 'task_id' => $task['id'])), true); - } - } - - return $this->response->html($this->template->render('task_duplication/duplicate', array( - 'task' => $task, - ))); - } - - /** - * Move a task to another project - * - * @access public - */ - public function move() - { - $task = $this->getTask(); - - if ($this->request->isPost()) { - $values = $this->request->getValues(); - list($valid, ) = $this->taskValidator->validateProjectModification($values); - - if ($valid && $this->taskDuplication->moveToProject($task['id'], - $values['project_id'], - $values['swimlane_id'], - $values['column_id'], - $values['category_id'], - $values['owner_id'])) { - $this->flash->success(t('Task updated successfully.')); - return $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('project_id' => $values['project_id'], 'task_id' => $task['id']))); - } - - $this->flash->failure(t('Unable to update your task.')); - } - - return $this->chooseDestination($task, 'task_duplication/move'); - } - - /** - * Duplicate a task to another project - * - * @access public - */ - public function copy() - { - $task = $this->getTask(); - - if ($this->request->isPost()) { - $values = $this->request->getValues(); - list($valid, ) = $this->taskValidator->validateProjectModification($values); - - if ($valid) { - $task_id = $this->taskDuplication->duplicateToProject( - $task['id'], $values['project_id'], $values['swimlane_id'], - $values['column_id'], $values['category_id'], $values['owner_id'] - ); - - if ($task_id > 0) { - $this->flash->success(t('Task created successfully.')); - return $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('project_id' => $values['project_id'], 'task_id' => $task_id))); - } - } - - $this->flash->failure(t('Unable to create your task.')); - } - - return $this->chooseDestination($task, 'task_duplication/copy'); - } - - /** - * Choose destination when move/copy task to another project - * - * @access private - * @param array $task - * @param string $template - */ - private function chooseDestination(array $task, $template) - { - $values = array(); - $projects_list = $this->projectUserRole->getActiveProjectsByUser($this->userSession->getId()); - - unset($projects_list[$task['project_id']]); - - if (! empty($projects_list)) { - $dst_project_id = $this->request->getIntegerParam('dst_project_id', key($projects_list)); - - $swimlanes_list = $this->swimlane->getList($dst_project_id, false, true); - $columns_list = $this->column->getList($dst_project_id); - $categories_list = $this->category->getList($dst_project_id); - $users_list = $this->projectUserRole->getAssignableUsersList($dst_project_id); - - $values = $this->taskDuplication->checkDestinationProjectValues($task); - $values['project_id'] = $dst_project_id; - } else { - $swimlanes_list = array(); - $columns_list = array(); - $categories_list = array(); - $users_list = array(); - } - - $this->response->html($this->template->render($template, array( - 'values' => $values, - 'task' => $task, - 'projects_list' => $projects_list, - 'swimlanes_list' => $swimlanes_list, - 'columns_list' => $columns_list, - 'categories_list' => $categories_list, - 'users_list' => $users_list, - ))); - } -} -- cgit v1.2.3