diff options
Diffstat (limited to 'controllers')
-rw-r--r-- | controllers/action.php | 2 | ||||
-rw-r--r-- | controllers/base.php | 9 | ||||
-rw-r--r-- | controllers/board.php | 14 | ||||
-rw-r--r-- | controllers/category.php | 191 | ||||
-rw-r--r-- | controllers/project.php | 4 | ||||
-rw-r--r-- | controllers/task.php | 6 |
6 files changed, 223 insertions, 3 deletions
diff --git a/controllers/action.php b/controllers/action.php index b4006940..5c5d5726 100644 --- a/controllers/action.php +++ b/controllers/action.php @@ -38,6 +38,7 @@ class Action extends Base 'users_list' => $this->project->getUsersList($project['id'], false), 'projects_list' => $this->project->getList(false), 'colors_list' => $this->task->getColors(), + 'categories_list' => $this->category->getList($project['id'], false), 'menu' => 'projects', 'title' => t('Automatic actions') ))); @@ -68,6 +69,7 @@ class Action extends Base 'users_list' => $this->project->getUsersList($project['id'], false), 'projects_list' => $this->project->getList(false), 'colors_list' => $this->task->getColors(), + 'categories_list' => $this->category->getList($project['id'], false), 'project' => $project, 'menu' => 'projects', 'title' => t('Automatic actions') diff --git a/controllers/base.php b/controllers/base.php index 07c5db63..49376dce 100644 --- a/controllers/base.php +++ b/controllers/base.php @@ -131,6 +131,14 @@ abstract class Base protected $google; /** + * Category model + * + * @accesss protected + * @var \Model\Category + */ + protected $category; + + /** * Event instance * * @accesss protected @@ -157,6 +165,7 @@ abstract class Base $this->rememberMe = $registry->rememberMe; $this->lastLogin = $registry->lastLogin; $this->google = $registry->google; + $this->category = $registry->category; $this->event = $registry->shared('event'); } diff --git a/controllers/board.php b/controllers/board.php index 02669e3a..f7128210 100644 --- a/controllers/board.php +++ b/controllers/board.php @@ -128,6 +128,7 @@ class Board extends Base $this->response->html($this->template->layout('board_public', array( 'project' => $project, 'columns' => $this->board->get($project['id']), + 'categories' => $this->category->getList($project['id'], false), 'title' => $project['name'], 'no_layout' => true, 'auto_refresh' => true, @@ -195,6 +196,7 @@ class Board extends Base 'current_project_id' => $project_id, 'current_project_name' => $projects[$project_id], 'board' => $this->board->get($project_id), + 'categories' => $this->category->getList($project_id, true, true), 'menu' => 'boards', 'title' => $projects[$project_id] ))); @@ -369,7 +371,11 @@ class Board extends Base } $this->response->html( - $this->template->load('board_show', array('current_project_id' => $project_id, 'board' => $this->board->get($project_id))), + $this->template->load('board_show', array( + 'current_project_id' => $project_id, + 'board' => $this->board->get($project_id), + 'categories' => $this->category->getList($project_id, false), + )), 201 ); } @@ -390,7 +396,11 @@ class Board extends Base if ($this->project->isModifiedSince($project_id, $timestamp)) { $this->response->html( - $this->template->load('board_show', array('current_project_id' => $project_id, 'board' => $this->board->get($project_id))) + $this->template->load('board_show', array( + 'current_project_id' => $project_id, + 'board' => $this->board->get($project_id), + 'categories' => $this->category->getList($project_id, false), + )) ); } else { diff --git a/controllers/category.php b/controllers/category.php new file mode 100644 index 00000000..23de2735 --- /dev/null +++ b/controllers/category.php @@ -0,0 +1,191 @@ +<?php + +namespace Controller; + +require_once __DIR__.'/base.php'; + +/** + * Categories management + * + * @package controller + * @author Frederic Guillot + */ +class Category extends Base +{ + /** + * Get the current project (common method between actions) + * + * @access private + * @return array + */ + private function getProject() + { + $project_id = $this->request->getIntegerParam('project_id'); + $project = $this->project->getById($project_id); + + if (! $project) { + $this->session->flashError(t('Project not found.')); + $this->response->redirect('?controller=project'); + } + + return $project; + } + + /** + * Get the category (common method between actions) + * + * @access private + * @return array + */ + private function getCategory($project_id) + { + $category = $this->category->getById($this->request->getIntegerParam('category_id')); + + if (! $category) { + $this->session->flashError(t('Category not found.')); + $this->response->redirect('?controller=category&action=index&project_id='.$project_id); + } + + return $category; + } + + /** + * List of categories for a given project + * + * @access public + */ + public function index() + { + $project = $this->getProject(); + + $this->response->html($this->template->layout('category_index', array( + 'categories' => $this->category->getList($project['id'], false), + 'values' => array('project_id' => $project['id']), + 'errors' => array(), + 'project' => $project, + 'menu' => 'projects', + 'title' => t('Categories') + ))); + } + + /** + * Validate and save a new project + * + * @access public + */ + public function save() + { + $project = $this->getProject(); + + $values = $this->request->getValues(); + list($valid, $errors) = $this->category->validateCreation($values); + + if ($valid) { + + if ($this->category->create($values)) { + $this->session->flash(t('Your category have been created successfully.')); + $this->response->redirect('?controller=category&action=index&project_id='.$project['id']); + } + else { + $this->session->flashError(t('Unable to create your category.')); + } + } + + $this->response->html($this->template->layout('category_index', array( + 'categories' => $this->category->getList($project['id'], false), + 'values' => $values, + 'errors' => $errors, + 'project' => $project, + 'menu' => 'projects', + 'title' => t('Categories') + ))); + } + + /** + * Edit a category (display the form) + * + * @access public + */ + public function edit() + { + $project = $this->getProject(); + $category = $this->getCategory($project['id']); + + $this->response->html($this->template->layout('category_edit', array( + 'values' => $category, + 'errors' => array(), + 'project' => $project, + 'menu' => 'projects', + '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->category->validateModification($values); + + if ($valid) { + + if ($this->category->update($values)) { + $this->session->flash(t('Your category have been updated successfully.')); + $this->response->redirect('?controller=category&action=index&project_id='.$project['id']); + } + else { + $this->session->flashError(t('Unable to update your category.')); + } + } + + $this->response->html($this->template->layout('category_edit', array( + 'values' => $values, + 'errors' => $errors, + 'project' => $project, + 'menu' => 'projects', + 'title' => t('Categories') + ))); + } + + /** + * Confirmation dialog before removing a category + * + * @access public + */ + public function confirm() + { + $project = $this->getProject(); + $category = $this->getCategory($project['id']); + + $this->response->html($this->template->layout('category_remove', array( + 'project' => $project, + 'category' => $category, + 'menu' => 'projects', + 'title' => t('Remove a category') + ))); + } + + /** + * Remove a category + * + * @access public + */ + public function remove() + { + $project = $this->getProject(); + $category = $this->getCategory($project['id']); + + if ($this->category->remove($category['id'])) { + $this->session->flash(t('Category removed successfully.')); + } else { + $this->session->flashError(t('Unable to remove this category.')); + } + + $this->response->redirect('?controller=category&action=index&project_id='.$project['id']); + } +} diff --git a/controllers/project.php b/controllers/project.php index a9ce8634..1b9fd110 100644 --- a/controllers/project.php +++ b/controllers/project.php @@ -52,7 +52,7 @@ class Project extends Base array('column' => 'project_id', 'operator' => 'eq', 'value' => $project_id), 'or' => array( array('column' => 'title', 'operator' => 'like', 'value' => '%'.$search.'%'), - array('column' => 'description', 'operator' => 'like', 'value' => '%'.$search.'%'), + //array('column' => 'description', 'operator' => 'like', 'value' => '%'.$search.'%'), ) ); @@ -72,6 +72,7 @@ class Project extends Base 'menu' => 'projects', 'project' => $project, 'columns' => $this->board->getColumnsList($project_id), + 'categories' => $this->category->getList($project['id'], false), 'title' => $project['name'].($nb_tasks > 0 ? ' ('.$nb_tasks.')' : '') ))); } @@ -105,6 +106,7 @@ class Project extends Base 'menu' => 'projects', 'project' => $project, 'columns' => $this->board->getColumnsList($project_id), + 'categories' => $this->category->getList($project['id'], false), 'tasks' => $tasks, 'nb_tasks' => $nb_tasks, 'title' => $project['name'].' ('.$nb_tasks.')' diff --git a/controllers/task.php b/controllers/task.php index f5738a55..bdedb9dd 100644 --- a/controllers/task.php +++ b/controllers/task.php @@ -34,6 +34,7 @@ class Task extends Base 'project_id' => $this->request->getIntegerParam('project_id', $defaultProject['id']), 'owner_id' => $this->request->getIntegerParam('owner_id'), 'column_id' => $this->request->getIntegerParam('column_id'), + 'category_id' => $this->request->getIntegerParam('category_id'), ); if ($values['column_id'] == 0) { @@ -121,6 +122,7 @@ class Task extends Base 'columns_list' => $this->board->getColumnsList($project_id), 'users_list' => $this->project->getUsersList($project_id), 'colors_list' => $this->task->getColors(), + 'categories_list' => $this->category->getList($project_id), 'menu' => 'tasks', 'title' => t('New task') ))); @@ -164,6 +166,7 @@ class Task extends Base 'columns_list' => $this->board->getColumnsList($values['project_id']), 'users_list' => $this->project->getUsersList($values['project_id']), 'colors_list' => $this->task->getColors(), + 'categories_list' => $this->category->getList($values['project_id']), 'menu' => 'tasks', 'title' => t('New task') ))); @@ -196,6 +199,7 @@ class Task extends Base 'columns_list' => $this->board->getColumnsList($task['project_id']), 'users_list' => $this->project->getUsersList($task['project_id']), 'colors_list' => $this->task->getColors(), + 'categories_list' => $this->category->getList($task['project_id']), 'menu' => 'tasks', 'title' => t('Edit a task') ))); @@ -230,6 +234,7 @@ class Task extends Base 'columns_list' => $this->board->getColumnsList($values['project_id']), 'users_list' => $this->project->getUsersList($values['project_id']), 'colors_list' => $this->task->getColors(), + 'categories_list' => $this->category->getList($values['project_id']), 'menu' => 'tasks', 'title' => t('Edit a task') ))); @@ -383,6 +388,7 @@ class Task extends Base 'columns_list' => $this->board->getColumnsList($task['project_id']), 'users_list' => $this->project->getUsersList($task['project_id']), 'colors_list' => $this->task->getColors(), + 'categories_list' => $this->category->getList($task['project_id']), 'duplicate' => true, 'menu' => 'tasks', 'title' => t('New task') |