Add categories for projects and tasks

This commit is contained in:
Frédéric Guillot
2014-05-21 22:33:57 -04:00
parent 57e40671af
commit a750b8ab2a
39 changed files with 815 additions and 44 deletions

View File

@@ -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')

View File

@@ -130,6 +130,14 @@ abstract class Base
*/
protected $google;
/**
* Category model
*
* @accesss protected
* @var \Model\Category
*/
protected $category;
/**
* Event instance
*
@@ -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');
}

View File

@@ -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 {

191
controllers/category.php Normal file
View File

@@ -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']);
}
}

View File

@@ -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.')'

View File

@@ -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')