summaryrefslogtreecommitdiff
path: root/app/Controller/Project.php
diff options
context:
space:
mode:
authorFrédéric Guillot <fred@kanboard.net>2014-08-30 14:08:46 -0800
committerFrédéric Guillot <fred@kanboard.net>2014-08-30 14:08:46 -0800
commit9194a2604d79ef97994d01c35fb454f745b5412c (patch)
tree365dd4294e536c440610bee4f07a1bffb00d00eb /app/Controller/Project.php
parente1eba08398c6c6ece684f9db6dedb0dff5d43071 (diff)
Projects management refactoring
Diffstat (limited to 'app/Controller/Project.php')
-rw-r--r--app/Controller/Project.php435
1 files changed, 284 insertions, 151 deletions
diff --git a/app/Controller/Project.php b/app/Controller/Project.php
index 0d430b44..deca7e1a 100644
--- a/app/Controller/Project.php
+++ b/app/Controller/Project.php
@@ -13,26 +13,52 @@ use Core\Translator;
*/
class Project extends Base
{
+ /**
+ * List of projects
+ *
+ * @access public
+ */
+ public function index()
+ {
+ $projects = $this->project->getAll($this->acl->isRegularUser());
+ $nb_projects = count($projects);
+ $active_projects = array();
+ $inactive_projects = array();
+
+ foreach ($projects as $project) {
+ if ($project['is_active'] == 1) {
+ $active_projects[] = $project;
+ }
+ else {
+ $inactive_projects[] = $project;
+ }
+ }
+
+ $this->response->html($this->template->layout('project_index', array(
+ 'active_projects' => $active_projects,
+ 'inactive_projects' => $inactive_projects,
+ 'nb_projects' => $nb_projects,
+ 'menu' => 'projects',
+ 'title' => t('Projects').' ('.$nb_projects.')'
+ )));
+ }
+
+ /**
+ * Show the project information page
+ *
+ * @access public
+ */
+ public function show()
+ {
+ $project = $this->getProject();
- /**
- * Clone Project
- *
- * @author Antonio Rabelo
- * @access public
- */
- public function duplicate()
- {
- $this->checkCSRFParam();
- $project_id = $this->request->getIntegerParam('project_id');
-
- if ($project_id && $this->project->duplicate($project_id)) {
- $this->session->flash(t('Project cloned successfully.'));
- } else {
- $this->session->flashError(t('Unable to clone this project.'));
- }
-
- $this->response->redirect('?controller=project');
- }
+ $this->response->html($this->projectLayout('project_show', array(
+ 'project' => $project,
+ 'stats' => $this->project->getStats($project['id']),
+ 'menu' => 'projects',
+ 'title' => $project['name'],
+ )));
+ }
/**
* Task export
@@ -52,7 +78,7 @@ class Project extends Base
$this->response->csv($data);
}
- $this->response->html($this->template->layout('project_export', array(
+ $this->response->html($this->projectLayout('project_export', array(
'values' => array(
'controller' => 'project',
'action' => 'export',
@@ -68,182 +94,175 @@ class Project extends Base
}
/**
- * Task search for a given project
+ * Public access management
*
* @access public
*/
- public function search()
+ public function share()
{
$project = $this->getProject();
- $search = $this->request->getStringParam('search');
- $tasks = array();
- $nb_tasks = 0;
-
- if ($search !== '') {
-
- $filters = array(
- 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.'%'),
- )
- );
-
- $tasks = $this->task->find($filters);
- $nb_tasks = count($tasks);
- }
- $this->response->html($this->template->layout('project_search', array(
- 'tasks' => $tasks,
- 'nb_tasks' => $nb_tasks,
- 'values' => array(
- 'search' => $search,
- 'controller' => 'project',
- 'action' => 'search',
- 'project_id' => $project['id'],
- ),
- 'menu' => 'projects',
+ $this->response->html($this->projectLayout('project_share', array(
'project' => $project,
- 'columns' => $this->board->getColumnsList($project['id']),
- 'categories' => $this->category->getList($project['id'], false),
- 'title' => $project['name'].($nb_tasks > 0 ? ' ('.$nb_tasks.')' : '')
+ 'menu' => 'projects',
+ 'title' => t('Public access'),
)));
}
/**
- * List of completed tasks for a given project
+ * Enable public access for a project
*
* @access public
*/
- public function tasks()
+ public function enablePublic()
{
- $project = $this->getProject();
-
- $filters = array(
- array('column' => 'project_id', 'operator' => 'eq', 'value' => $project['id']),
- array('column' => 'is_active', 'operator' => 'eq', 'value' => TaskModel::STATUS_CLOSED),
- );
+ $this->checkCSRFParam();
+ $project_id = $this->request->getIntegerParam('project_id');
- $tasks = $this->task->find($filters);
- $nb_tasks = count($tasks);
+ if ($project_id && $this->project->enablePublicAccess($project_id)) {
+ $this->session->flash(t('Project updated successfully.'));
+ } else {
+ $this->session->flashError(t('Unable to update this project.'));
+ }
- $this->response->html($this->template->layout('project_tasks', array(
- '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.')'
- )));
+ $this->response->redirect('?controller=project&action=share&project_id='.$project_id);
}
/**
- * List of projects
+ * Disable public access for a project
*
* @access public
*/
- public function index()
+ public function disablePublic()
{
- $projects = $this->project->getAll(true, $this->acl->isRegularUser());
- $nb_projects = count($projects);
+ $this->checkCSRFParam();
+ $project_id = $this->request->getIntegerParam('project_id');
- $this->response->html($this->template->layout('project_index', array(
- 'projects' => $projects,
- 'nb_projects' => $nb_projects,
- 'menu' => 'projects',
- 'title' => t('Projects').' ('.$nb_projects.')'
- )));
+ if ($project_id && $this->project->disablePublicAccess($project_id)) {
+ $this->session->flash(t('Project updated successfully.'));
+ } else {
+ $this->session->flashError(t('Unable to update this project.'));
+ }
+
+ $this->response->redirect('?controller=project&action=share&project_id='.$project_id);
}
/**
- * Display a form to create a new project
+ * Display a form to edit a project
*
* @access public
*/
- public function create()
+ public function edit()
{
- $this->response->html($this->template->layout('project_new', array(
+ $project = $this->getProject();
+
+ $this->response->html($this->projectLayout('project_edit', array(
'errors' => array(),
- 'values' => array(),
+ 'values' => $project,
+ 'project' => $project,
'menu' => 'projects',
- 'title' => t('New project')
+ 'title' => t('Edit project')
)));
}
/**
- * Validate and save a new project
+ * Validate and update a project
*
* @access public
*/
- public function save()
+ public function update()
{
- $values = $this->request->getValues();
- list($valid, $errors) = $this->project->validateCreation($values);
+ $project = $this->getProject();
+ $values = $this->request->getValues() + array('is_active' => 0);
+ list($valid, $errors) = $this->project->validateModification($values);
if ($valid) {
- if ($this->project->create($values)) {
- $this->session->flash(t('Your project have been created successfully.'));
- $this->response->redirect('?controller=project');
+ if ($this->project->update($values)) {
+ $this->session->flash(t('Project updated successfully.'));
+ $this->response->redirect('?controller=project&action=edit&project_id='.$project['id']);
}
else {
- $this->session->flashError(t('Unable to create your project.'));
+ $this->session->flashError(t('Unable to update this project.'));
}
}
- $this->response->html($this->template->layout('project_new', array(
+ $this->response->html($this->projectLayout('project_edit', array(
'errors' => $errors,
'values' => $values,
+ 'project' => $project,
'menu' => 'projects',
- 'title' => t('New Project')
+ 'title' => t('Edit Project')
)));
}
- /**
- * Display a form to edit a project
+ /**
+ * Users list for the selected project
*
* @access public
*/
- public function edit()
+ public function users()
{
$project = $this->getProject();
- $this->response->html($this->template->layout('project_edit', array(
- 'errors' => array(),
- 'values' => $project,
+ $this->response->html($this->projectLayout('project_users', array(
+ 'project' => $project,
+ 'users' => $this->project->getAllUsers($project['id']),
'menu' => 'projects',
- 'title' => t('Edit project')
+ 'title' => t('Edit project access list')
)));
}
/**
- * Validate and update a project
+ * Allow a specific user for the selected project
*
* @access public
*/
- public function update()
+ public function allow()
{
- $values = $this->request->getValues() + array('is_active' => 0);
- list($valid, $errors) = $this->project->validateModification($values);
+ $values = $this->request->getValues();
+ list($valid,) = $this->project->validateUserAccess($values);
if ($valid) {
- if ($this->project->update($values)) {
+ if ($this->project->allowUser($values['project_id'], $values['user_id'])) {
$this->session->flash(t('Project updated successfully.'));
- $this->response->redirect('?controller=project');
}
else {
$this->session->flashError(t('Unable to update this project.'));
}
}
- $this->response->html($this->template->layout('project_edit', array(
- 'errors' => $errors,
- 'values' => $values,
- 'menu' => 'projects',
- 'title' => t('Edit Project')
- )));
+ $this->response->redirect('?controller=project&action=users&project_id='.$values['project_id']);
+ }
+
+ /**
+ * Revoke user access
+ *
+ * @access public
+ */
+ public function revoke()
+ {
+ $this->checkCSRFParam();
+
+ $values = array(
+ 'project_id' => $this->request->getIntegerParam('project_id'),
+ 'user_id' => $this->request->getIntegerParam('user_id'),
+ );
+
+ list($valid,) = $this->project->validateUserAccess($values);
+
+ if ($valid) {
+
+ if ($this->project->revokeUser($values['project_id'], $values['user_id'])) {
+ $this->session->flash(t('Project updated successfully.'));
+ }
+ else {
+ $this->session->flashError(t('Unable to update this project.'));
+ }
+ }
+
+ $this->response->redirect('?controller=project&action=users&project_id='.$values['project_id']);
}
/**
@@ -251,11 +270,11 @@ class Project extends Base
*
* @access public
*/
- public function confirm()
+ public function confirmRemove()
{
$project = $this->getProject();
- $this->response->html($this->template->layout('project_remove', array(
+ $this->response->html($this->projectLayout('project_remove', array(
'project' => $project,
'menu' => 'projects',
'title' => t('Remove project')
@@ -282,25 +301,58 @@ class Project extends Base
}
/**
- * Enable a project
+ * Confirmation dialog before to clone a project
*
* @access public
*/
- public function enable()
+ public function confirmDuplicate()
+ {
+ $project = $this->getProject();
+
+ $this->response->html($this->projectLayout('project_duplicate', array(
+ 'project' => $project,
+ 'menu' => 'projects',
+ 'title' => t('Clone this project')
+ )));
+ }
+
+ /**
+ * Duplicate a project
+ *
+ * @author Antonio Rabelo
+ * @access public
+ */
+ public function duplicate()
{
$this->checkCSRFParam();
$project_id = $this->request->getIntegerParam('project_id');
- if ($project_id && $this->project->enable($project_id)) {
- $this->session->flash(t('Project activated successfully.'));
+ if ($project_id && $this->project->duplicate($project_id)) {
+ $this->session->flash(t('Project cloned successfully.'));
} else {
- $this->session->flashError(t('Unable to activate this project.'));
+ $this->session->flashError(t('Unable to clone this project.'));
}
$this->response->redirect('?controller=project');
}
/**
+ * Confirmation dialog before to disable a project
+ *
+ * @access public
+ */
+ public function confirmDisable()
+ {
+ $project = $this->getProject();
+
+ $this->response->html($this->projectLayout('project_disable', array(
+ 'project' => $project,
+ 'menu' => 'projects',
+ 'title' => t('Project activation')
+ )));
+ }
+
+ /**
* Disable a project
*
* @access public
@@ -316,75 +368,156 @@ class Project extends Base
$this->session->flashError(t('Unable to disable this project.'));
}
- $this->response->redirect('?controller=project');
+ $this->response->redirect('?controller=project&action=show&project_id='.$project_id);
}
/**
- * Users list for the selected project
+ * Confirmation dialog before to enable a project
*
* @access public
*/
- public function users()
+ public function confirmEnable()
{
$project = $this->getProject();
- $this->response->html($this->template->layout('project_users', array(
+ $this->response->html($this->projectLayout('project_enable', array(
'project' => $project,
- 'users' => $this->project->getAllUsers($project['id']),
'menu' => 'projects',
- 'title' => t('Edit project access list')
+ 'title' => t('Project activation')
)));
}
/**
- * Allow a specific user for the selected project
+ * Enable a project
*
* @access public
*/
- public function allow()
+ public function enable()
{
- $values = $this->request->getValues();
- list($valid,) = $this->project->validateUserAccess($values);
+ $this->checkCSRFParam();
+ $project_id = $this->request->getIntegerParam('project_id');
- if ($valid) {
+ if ($project_id && $this->project->enable($project_id)) {
+ $this->session->flash(t('Project activated successfully.'));
+ } else {
+ $this->session->flashError(t('Unable to activate this project.'));
+ }
- if ($this->project->allowUser($values['project_id'], $values['user_id'])) {
- $this->session->flash(t('Project updated successfully.'));
- }
- else {
- $this->session->flashError(t('Unable to update this project.'));
- }
+ $this->response->redirect('?controller=project&action=show&project_id='.$project_id);
+ }
+
+ /**
+ * Task search for a given project
+ *
+ * @access public
+ */
+ public function search()
+ {
+ $project = $this->getProject();
+ $search = $this->request->getStringParam('search');
+ $tasks = array();
+ $nb_tasks = 0;
+
+ if ($search !== '') {
+
+ $filters = array(
+ 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.'%'),
+ )
+ );
+
+ $tasks = $this->task->find($filters);
+ $nb_tasks = count($tasks);
}
- $this->response->redirect('?controller=project&action=users&project_id='.$values['project_id']);
+ $this->response->html($this->template->layout('project_search', array(
+ 'tasks' => $tasks,
+ 'nb_tasks' => $nb_tasks,
+ 'values' => array(
+ 'search' => $search,
+ 'controller' => 'project',
+ 'action' => 'search',
+ 'project_id' => $project['id'],
+ ),
+ '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.')' : '')
+ )));
}
/**
- * Revoke user access
+ * List of completed tasks for a given project
*
* @access public
*/
- public function revoke()
+ public function tasks()
{
- $this->checkCSRFParam();
+ $project = $this->getProject();
- $values = array(
- 'project_id' => $this->request->getIntegerParam('project_id'),
- 'user_id' => $this->request->getIntegerParam('user_id'),
+ $filters = array(
+ array('column' => 'project_id', 'operator' => 'eq', 'value' => $project['id']),
+ array('column' => 'is_active', 'operator' => 'eq', 'value' => TaskModel::STATUS_CLOSED),
);
- list($valid,) = $this->project->validateUserAccess($values);
+ $tasks = $this->task->find($filters);
+ $nb_tasks = count($tasks);
+
+ $this->response->html($this->template->layout('project_tasks', array(
+ '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.')'
+ )));
+ }
+
+ /**
+ * Display a form to create a new project
+ *
+ * @access public
+ */
+ public function create()
+ {
+ $this->response->html($this->template->layout('project_new', array(
+ 'errors' => array(),
+ 'values' => array(),
+ 'menu' => 'projects',
+ 'title' => t('New project')
+ )));
+ }
+
+ /**
+ * Validate and save a new project
+ *
+ * @access public
+ */
+ public function save()
+ {
+ $values = $this->request->getValues();
+ list($valid, $errors) = $this->project->validateCreation($values);
if ($valid) {
- if ($this->project->revokeUser($values['project_id'], $values['user_id'])) {
- $this->session->flash(t('Project updated successfully.'));
+ if ($this->project->create($values)) {
+ $this->session->flash(t('Your project have been created successfully.'));
+ $this->response->redirect('?controller=project');
}
else {
- $this->session->flashError(t('Unable to update this project.'));
+ $this->session->flashError(t('Unable to create your project.'));
}
}
- $this->response->redirect('?controller=project&action=users&project_id='.$values['project_id']);
+ $this->response->html($this->template->layout('project_new', array(
+ 'errors' => $errors,
+ 'values' => $values,
+ 'menu' => 'projects',
+ 'title' => t('New Project')
+ )));
}
}