1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/kanboard_ynh.git synced 2024-09-03 19:36:17 +02:00
kanboard_ynh/sources/app/Controller/Project.php

543 lines
16 KiB
PHP
Raw Normal View History

2014-07-20 12:26:15 +02:00
<?php
namespace Controller;
use Model\Task as TaskModel;
/**
* Project controller
*
* @package controller
* @author Frederic Guillot
*/
class Project extends Base
{
/**
2014-10-22 19:59:09 +02:00
* List of projects
2014-07-20 12:26:15 +02:00
*
* @access public
*/
2014-10-22 19:59:09 +02:00
public function index()
2014-07-20 12:26:15 +02:00
{
2014-10-22 19:59:09 +02:00
$projects = $this->project->getAll($this->acl->isRegularUser());
$nb_projects = count($projects);
$active_projects = array();
$inactive_projects = array();
2014-07-20 12:26:15 +02:00
2014-10-22 19:59:09 +02:00
foreach ($projects as $project) {
if ($project['is_active'] == 1) {
$active_projects[] = $project;
}
else {
$inactive_projects[] = $project;
}
2014-07-20 12:26:15 +02:00
}
2014-10-22 19:59:09 +02:00
$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.')'
)));
}
2014-07-20 12:26:15 +02:00
2014-10-22 19:59:09 +02:00
/**
* Show the project information page
*
* @access public
*/
public function show()
{
$project = $this->getProject();
2014-07-20 12:26:15 +02:00
2014-10-22 19:59:09 +02:00
$this->response->html($this->projectLayout('project_show', array(
'project' => $project,
'stats' => $this->project->getStats($project['id']),
2014-11-23 20:13:38 +01:00
'webhook_token' => $this->config->get('webhook_token'),
2014-10-22 19:59:09 +02:00
'title' => $project['name'],
)));
}
2014-07-20 12:26:15 +02:00
2014-10-22 19:59:09 +02:00
/**
* Task export
*
* @access public
*/
public function export()
{
2014-11-23 20:13:38 +01:00
$project = $this->getProjectManagement();
2014-10-22 19:59:09 +02:00
$from = $this->request->getStringParam('from');
$to = $this->request->getStringParam('to');
if ($from && $to) {
2014-11-23 20:13:38 +01:00
$data = $this->taskExport->export($project['id'], $from, $to);
2014-10-22 19:59:09 +02:00
$this->response->forceDownload('Export_'.date('Y_m_d_H_i_S').'.csv');
$this->response->csv($data);
2014-07-20 12:26:15 +02:00
}
2014-10-22 19:59:09 +02:00
$this->response->html($this->projectLayout('project_export', array(
2014-07-20 12:26:15 +02:00
'values' => array(
'controller' => 'project',
2014-10-22 19:59:09 +02:00
'action' => 'export',
2014-07-20 12:26:15 +02:00
'project_id' => $project['id'],
2014-10-22 19:59:09 +02:00
'from' => $from,
'to' => $to,
2014-07-20 12:26:15 +02:00
),
2014-10-22 19:59:09 +02:00
'errors' => array(),
2014-11-23 20:13:38 +01:00
'date_format' => $this->config->get('application_date_format'),
'date_formats' => $this->dateParser->getAvailableFormats(),
2014-07-20 12:26:15 +02:00
'project' => $project,
2014-10-22 19:59:09 +02:00
'title' => t('Tasks Export')
2014-07-20 12:26:15 +02:00
)));
}
/**
2014-10-22 19:59:09 +02:00
* Public access management
2014-07-20 12:26:15 +02:00
*
* @access public
*/
2014-10-22 19:59:09 +02:00
public function share()
2014-07-20 12:26:15 +02:00
{
2014-11-23 20:13:38 +01:00
$project = $this->getProjectManagement();
$switch = $this->request->getStringParam('switch');
2014-07-20 12:26:15 +02:00
2014-11-23 20:13:38 +01:00
if ($switch === 'enable' || $switch === 'disable') {
2014-07-20 12:26:15 +02:00
2014-11-23 20:13:38 +01:00
$this->checkCSRFParam();
2014-07-20 12:26:15 +02:00
2014-11-23 20:13:38 +01:00
if ($this->project->{$switch.'PublicAccess'}($project['id'])) {
$this->session->flash(t('Project updated successfully.'));
} else {
$this->session->flashError(t('Unable to update this project.'));
}
2014-07-20 12:26:15 +02:00
2014-11-23 20:13:38 +01:00
$this->response->redirect('?controller=project&action=share&project_id='.$project['id']);
2014-10-22 19:59:09 +02:00
}
2014-11-23 20:13:38 +01:00
$this->response->html($this->projectLayout('project_share', array(
'project' => $project,
'title' => t('Public access'),
)));
2014-07-20 12:26:15 +02:00
}
/**
2014-10-22 19:59:09 +02:00
* Display a form to edit a project
2014-07-20 12:26:15 +02:00
*
* @access public
*/
2014-10-22 19:59:09 +02:00
public function edit()
2014-07-20 12:26:15 +02:00
{
2014-11-23 20:13:38 +01:00
$project = $this->getProjectManagement();
2014-10-22 19:59:09 +02:00
$this->response->html($this->projectLayout('project_edit', array(
2014-07-20 12:26:15 +02:00
'errors' => array(),
2014-10-22 19:59:09 +02:00
'values' => $project,
'project' => $project,
'title' => t('Edit project')
2014-07-20 12:26:15 +02:00
)));
}
/**
2014-10-22 19:59:09 +02:00
* Validate and update a project
2014-07-20 12:26:15 +02:00
*
* @access public
*/
2014-10-22 19:59:09 +02:00
public function update()
2014-07-20 12:26:15 +02:00
{
2014-11-23 20:13:38 +01:00
$project = $this->getProjectManagement();
2014-10-22 19:59:09 +02:00
$values = $this->request->getValues() + array('is_active' => 0);
list($valid, $errors) = $this->project->validateModification($values);
2014-07-20 12:26:15 +02:00
if ($valid) {
2014-10-22 19:59:09 +02:00
if ($this->project->update($values)) {
$this->session->flash(t('Project updated successfully.'));
$this->response->redirect('?controller=project&action=edit&project_id='.$project['id']);
2014-07-20 12:26:15 +02:00
}
else {
2014-10-22 19:59:09 +02:00
$this->session->flashError(t('Unable to update this project.'));
2014-07-20 12:26:15 +02:00
}
}
2014-10-22 19:59:09 +02:00
$this->response->html($this->projectLayout('project_edit', array(
2014-07-20 12:26:15 +02:00
'errors' => $errors,
'values' => $values,
2014-10-22 19:59:09 +02:00
'project' => $project,
'title' => t('Edit Project')
2014-07-20 12:26:15 +02:00
)));
}
2014-11-23 20:13:38 +01:00
/**
2014-10-22 19:59:09 +02:00
* Users list for the selected project
2014-07-20 12:26:15 +02:00
*
* @access public
*/
2014-10-22 19:59:09 +02:00
public function users()
2014-07-20 12:26:15 +02:00
{
2014-11-23 20:13:38 +01:00
$project = $this->getProjectManagement();
2014-07-20 12:26:15 +02:00
2014-10-22 19:59:09 +02:00
$this->response->html($this->projectLayout('project_users', array(
'project' => $project,
2014-11-23 20:13:38 +01:00
'users' => $this->projectPermission->getAllUsers($project['id']),
2014-10-22 19:59:09 +02:00
'title' => t('Edit project access list')
2014-07-20 12:26:15 +02:00
)));
}
/**
2014-11-23 20:13:38 +01:00
* Allow everybody
*
* @access public
*/
public function allowEverybody()
{
$project = $this->getProjectManagement();
$values = $this->request->getValues() + array('is_everybody_allowed' => 0);
list($valid,) = $this->projectPermission->validateProjectModification($values);
if ($valid) {
if ($this->project->update($values)) {
$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='.$project['id']);
}
/**
* Allow a specific user (admin only)
2014-07-20 12:26:15 +02:00
*
* @access public
*/
2014-10-22 19:59:09 +02:00
public function allow()
2014-07-20 12:26:15 +02:00
{
2014-10-22 19:59:09 +02:00
$values = $this->request->getValues();
2014-11-23 20:13:38 +01:00
list($valid,) = $this->projectPermission->validateUserModification($values);
2014-07-20 12:26:15 +02:00
if ($valid) {
2014-11-23 20:13:38 +01:00
if ($this->projectPermission->allowUser($values['project_id'], $values['user_id'])) {
2014-07-20 12:26:15 +02:00
$this->session->flash(t('Project updated successfully.'));
}
else {
$this->session->flashError(t('Unable to update this project.'));
}
}
2014-10-22 19:59:09 +02:00
$this->response->redirect('?controller=project&action=users&project_id='.$values['project_id']);
2014-07-20 12:26:15 +02:00
}
/**
2014-11-23 20:13:38 +01:00
* Revoke user access (admin only)
2014-07-20 12:26:15 +02:00
*
* @access public
*/
2014-10-22 19:59:09 +02:00
public function revoke()
2014-07-20 12:26:15 +02:00
{
2014-10-22 19:59:09 +02:00
$this->checkCSRFParam();
2014-07-20 12:26:15 +02:00
2014-10-22 19:59:09 +02:00
$values = array(
'project_id' => $this->request->getIntegerParam('project_id'),
'user_id' => $this->request->getIntegerParam('user_id'),
);
2014-11-23 20:13:38 +01:00
list($valid,) = $this->projectPermission->validateUserModification($values);
2014-10-22 19:59:09 +02:00
if ($valid) {
2014-11-23 20:13:38 +01:00
if ($this->projectPermission->revokeUser($values['project_id'], $values['user_id'])) {
2014-10-22 19:59:09 +02:00
$this->session->flash(t('Project updated successfully.'));
}
else {
$this->session->flashError(t('Unable to update this project.'));
}
2014-07-20 12:26:15 +02:00
}
2014-10-22 19:59:09 +02:00
$this->response->redirect('?controller=project&action=users&project_id='.$values['project_id']);
}
2014-07-20 12:26:15 +02:00
/**
* Remove a project
*
* @access public
*/
public function remove()
{
2014-11-23 20:13:38 +01:00
$project = $this->getProjectManagement();
2014-07-20 12:26:15 +02:00
2014-11-23 20:13:38 +01:00
if ($this->request->getStringParam('remove') === 'yes') {
2014-07-20 12:26:15 +02:00
2014-11-23 20:13:38 +01:00
$this->checkCSRFParam();
2014-07-20 12:26:15 +02:00
2014-11-23 20:13:38 +01:00
if ($this->project->remove($project['id'])) {
$this->session->flash(t('Project removed successfully.'));
} else {
$this->session->flashError(t('Unable to remove this project.'));
}
2014-10-22 19:59:09 +02:00
2014-11-23 20:13:38 +01:00
$this->response->redirect('?controller=project');
}
$this->response->html($this->projectLayout('project_remove', array(
2014-10-22 19:59:09 +02:00
'project' => $project,
2014-11-23 20:13:38 +01:00
'title' => t('Remove project')
2014-10-22 19:59:09 +02:00
)));
}
/**
* Duplicate a project
*
* @author Antonio Rabelo
* @access public
*/
public function duplicate()
2014-07-20 12:26:15 +02:00
{
2014-11-23 20:13:38 +01:00
$project = $this->getProjectManagement();
2014-07-20 12:26:15 +02:00
2014-11-23 20:13:38 +01:00
if ($this->request->getStringParam('duplicate') === 'yes') {
2014-07-20 12:26:15 +02:00
2014-11-23 20:13:38 +01:00
$this->checkCSRFParam();
2014-07-20 12:26:15 +02:00
2014-11-23 20:13:38 +01:00
if ($this->project->duplicate($project['id'])) {
$this->session->flash(t('Project cloned successfully.'));
} else {
$this->session->flashError(t('Unable to clone this project.'));
}
2014-10-22 19:59:09 +02:00
2014-11-23 20:13:38 +01:00
$this->response->redirect('?controller=project');
}
$this->response->html($this->projectLayout('project_duplicate', array(
2014-10-22 19:59:09 +02:00
'project' => $project,
2014-11-23 20:13:38 +01:00
'title' => t('Clone this project')
2014-10-22 19:59:09 +02:00
)));
}
2014-07-20 12:26:15 +02:00
/**
* Disable a project
*
* @access public
*/
public function disable()
{
2014-11-23 20:13:38 +01:00
$project = $this->getProjectManagement();
2014-07-20 12:26:15 +02:00
2014-11-23 20:13:38 +01:00
if ($this->request->getStringParam('disable') === 'yes') {
2014-07-20 12:26:15 +02:00
2014-11-23 20:13:38 +01:00
$this->checkCSRFParam();
2014-07-20 12:26:15 +02:00
2014-11-23 20:13:38 +01:00
if ($this->project->disable($project['id'])) {
$this->session->flash(t('Project disabled successfully.'));
} else {
$this->session->flashError(t('Unable to disable this project.'));
}
2014-10-22 19:59:09 +02:00
2014-11-23 20:13:38 +01:00
$this->response->redirect('?controller=project&action=show&project_id='.$project['id']);
}
$this->response->html($this->projectLayout('project_disable', array(
2014-10-22 19:59:09 +02:00
'project' => $project,
'title' => t('Project activation')
)));
}
/**
* Enable a project
*
* @access public
*/
public function enable()
2014-07-20 12:26:15 +02:00
{
2014-11-23 20:13:38 +01:00
$project = $this->getProjectManagement();
if ($this->request->getStringParam('enable') === 'yes') {
2014-10-22 19:59:09 +02:00
2014-11-23 20:13:38 +01:00
$this->checkCSRFParam();
if ($this->project->enable($project['id'])) {
$this->session->flash(t('Project activated successfully.'));
} else {
$this->session->flashError(t('Unable to activate this project.'));
}
$this->response->redirect('?controller=project&action=show&project_id='.$project['id']);
2014-10-22 19:59:09 +02:00
}
2014-07-20 12:26:15 +02:00
2014-11-23 20:13:38 +01:00
$this->response->html($this->projectLayout('project_enable', array(
'project' => $project,
'title' => t('Project activation')
)));
2014-10-22 19:59:09 +02:00
}
/**
2014-11-23 20:13:38 +01:00
* RSS feed for a project (public)
2014-10-22 19:59:09 +02:00
*
* @access public
*/
public function feed()
{
$token = $this->request->getStringParam('token');
$project = $this->project->getByToken($token);
// Token verification
2014-07-20 12:26:15 +02:00
if (! $project) {
2014-10-22 19:59:09 +02:00
$this->forbidden(true);
2014-07-20 12:26:15 +02:00
}
2014-10-22 19:59:09 +02:00
$this->response->xml($this->template->load('project_feed', array(
2014-11-23 20:13:38 +01:00
'events' => $this->projectActivity->getProject($project['id']),
2014-07-20 12:26:15 +02:00
'project' => $project,
2014-10-22 19:59:09 +02:00
)));
}
/**
* Activity page for a project
*
* @access public
*/
public function activity()
{
$project = $this->getProject();
$this->response->html($this->template->layout('project_activity', array(
2014-11-23 20:13:38 +01:00
'events' => $this->projectActivity->getProject($project['id']),
2014-07-20 12:26:15 +02:00
'menu' => 'projects',
2014-10-22 19:59:09 +02:00
'project' => $project,
'title' => t('%s\'s activity', $project['name'])
2014-07-20 12:26:15 +02:00
)));
}
/**
2014-10-22 19:59:09 +02:00
* Task search for a given project
2014-07-20 12:26:15 +02:00
*
* @access public
*/
2014-10-22 19:59:09 +02:00
public function search()
2014-07-20 12:26:15 +02:00
{
2014-10-22 19:59:09 +02:00
$project = $this->getProject();
$search = $this->request->getStringParam('search');
2014-11-23 20:13:38 +01:00
$direction = $this->request->getStringParam('direction', 'DESC');
$order = $this->request->getStringParam('order', 'tasks.id');
$offset = $this->request->getIntegerParam('offset', 0);
2014-10-22 19:59:09 +02:00
$tasks = array();
$nb_tasks = 0;
2014-11-23 20:13:38 +01:00
$limit = 25;
2014-07-20 12:26:15 +02:00
2014-10-22 19:59:09 +02:00
if ($search !== '') {
2014-11-23 20:13:38 +01:00
$tasks = $this->taskFinder->search($project['id'], $search, $offset, $limit, $order, $direction);
$nb_tasks = $this->taskFinder->countSearch($project['id'], $search);
2014-07-20 12:26:15 +02:00
}
2014-10-22 19:59:09 +02:00
$this->response->html($this->template->layout('project_search', array(
'tasks' => $tasks,
'nb_tasks' => $nb_tasks,
2014-11-23 20:13:38 +01:00
'pagination' => array(
'controller' => 'project',
'action' => 'search',
'params' => array('search' => $search, 'project_id' => $project['id']),
'direction' => $direction,
'order' => $order,
'total' => $nb_tasks,
'offset' => $offset,
'limit' => $limit,
),
2014-10-22 19:59:09 +02:00
'values' => array(
'search' => $search,
'controller' => 'project',
'action' => 'search',
'project_id' => $project['id'],
),
'project' => $project,
2014-11-23 20:13:38 +01:00
'menu' => 'projects',
2014-10-22 19:59:09 +02:00
'columns' => $this->board->getColumnsList($project['id']),
'categories' => $this->category->getList($project['id'], false),
'title' => $project['name'].($nb_tasks > 0 ? ' ('.$nb_tasks.')' : '')
)));
2014-07-20 12:26:15 +02:00
}
/**
2014-10-22 19:59:09 +02:00
* List of completed tasks for a given project
2014-07-20 12:26:15 +02:00
*
* @access public
*/
2014-10-22 19:59:09 +02:00
public function tasks()
2014-07-20 12:26:15 +02:00
{
2014-10-22 19:59:09 +02:00
$project = $this->getProject();
2014-11-23 20:13:38 +01:00
$direction = $this->request->getStringParam('direction', 'DESC');
$order = $this->request->getStringParam('order', 'tasks.date_completed');
$offset = $this->request->getIntegerParam('offset', 0);
$limit = 25;
2014-07-20 12:26:15 +02:00
2014-11-23 20:13:38 +01:00
$tasks = $this->taskFinder->getClosedTasks($project['id'], $offset, $limit, $order, $direction);
$nb_tasks = $this->taskFinder->countByProjectId($project['id'], array(TaskModel::STATUS_CLOSED));
2014-10-22 19:59:09 +02:00
$this->response->html($this->template->layout('project_tasks', array(
2014-11-23 20:13:38 +01:00
'pagination' => array(
'controller' => 'project',
'action' => 'tasks',
'params' => array('project_id' => $project['id']),
'direction' => $direction,
'order' => $order,
'total' => $nb_tasks,
'offset' => $offset,
'limit' => $limit,
),
2014-10-22 19:59:09 +02:00
'project' => $project,
2014-11-23 20:13:38 +01:00
'menu' => 'projects',
2014-10-22 19:59:09 +02:00
'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(),
2014-11-23 20:13:38 +01:00
'values' => array(
'is_private' => $this->request->getIntegerParam('private', $this->acl->isRegularUser()),
),
2014-10-22 19:59:09 +02:00
'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);
2014-07-20 12:26:15 +02:00
if ($valid) {
2014-11-23 20:13:38 +01:00
if ($this->project->create($values, $this->acl->getUserId())) {
2014-10-22 19:59:09 +02:00
$this->session->flash(t('Your project have been created successfully.'));
$this->response->redirect('?controller=project');
2014-07-20 12:26:15 +02:00
}
else {
2014-10-22 19:59:09 +02:00
$this->session->flashError(t('Unable to create your project.'));
2014-07-20 12:26:15 +02:00
}
}
2014-10-22 19:59:09 +02:00
$this->response->html($this->template->layout('project_new', array(
'errors' => $errors,
'values' => $values,
'title' => t('New Project')
)));
2014-07-20 12:26:15 +02:00
}
}