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/Action.php

169 lines
5.4 KiB
PHP
Raw Normal View History

2014-07-20 12:26:15 +02:00
<?php
namespace Controller;
/**
* Automatic actions management
*
* @package controller
* @author Frederic Guillot
*/
class Action extends Base
{
/**
* List of automatic actions for a given project
*
* @access public
*/
public function index()
{
2014-11-23 20:13:38 +01:00
$project = $this->getProjectManagement();
2014-07-20 12:26:15 +02:00
2014-12-22 19:15:38 +01:00
$this->response->html($this->projectLayout('action/index', array(
2014-07-20 12:26:15 +02:00
'values' => array('project_id' => $project['id']),
'project' => $project,
'actions' => $this->action->getAllByProject($project['id']),
'available_actions' => $this->action->getAvailableActions(),
'available_events' => $this->action->getAvailableEvents(),
'available_params' => $this->action->getAllActionParameters(),
'columns_list' => $this->board->getColumnsList($project['id']),
2014-12-22 19:15:38 +01:00
'users_list' => $this->projectPermission->getMemberList($project['id']),
2014-07-20 12:26:15 +02:00
'projects_list' => $this->project->getList(false),
2014-11-23 20:13:38 +01:00
'colors_list' => $this->color->getList(),
2014-07-20 12:26:15 +02:00
'categories_list' => $this->category->getList($project['id']),
'title' => t('Automatic actions')
)));
}
/**
2014-11-23 20:13:38 +01:00
* Choose the event according to the action (step 2)
*
* @access public
*/
public function event()
{
$project = $this->getProjectManagement();
$values = $this->request->getValues();
if (empty($values['action_name']) || empty($values['project_id'])) {
$this->response->redirect('?controller=action&action=index&project_id='.$project['id']);
}
2014-12-22 19:15:38 +01:00
$this->response->html($this->projectLayout('action/event', array(
2014-11-23 20:13:38 +01:00
'values' => $values,
'project' => $project,
'events' => $this->action->getCompatibleEvents($values['action_name']),
'title' => t('Automatic actions')
)));
}
/**
* Define action parameters (step 3)
2014-07-20 12:26:15 +02:00
*
* @access public
*/
public function params()
{
2014-11-23 20:13:38 +01:00
$project = $this->getProjectManagement();
2014-07-20 12:26:15 +02:00
$values = $this->request->getValues();
2014-11-23 20:13:38 +01:00
if (empty($values['action_name']) || empty($values['project_id']) || empty($values['event_name'])) {
$this->response->redirect('?controller=action&action=index&project_id='.$project['id']);
}
$action = $this->action->load($values['action_name'], $values['project_id'], $values['event_name']);
$action_params = $action->getActionRequiredParameters();
if (empty($action_params)) {
$this->doCreation($project, $values + array('params' => array()));
}
$projects_list = $this->project->getList(false);
unset($projects_list[$project['id']]);
2014-07-20 12:26:15 +02:00
2014-12-22 19:15:38 +01:00
$this->response->html($this->projectLayout('action/params', array(
2014-07-20 12:26:15 +02:00
'values' => $values,
2014-11-23 20:13:38 +01:00
'action_params' => $action_params,
2014-07-20 12:26:15 +02:00
'columns_list' => $this->board->getColumnsList($project['id']),
2014-12-22 19:15:38 +01:00
'users_list' => $this->projectPermission->getMemberList($project['id']),
2014-11-23 20:13:38 +01:00
'projects_list' => $projects_list,
'colors_list' => $this->color->getList(),
2014-07-20 12:26:15 +02:00
'categories_list' => $this->category->getList($project['id']),
'project' => $project,
'title' => t('Automatic actions')
)));
}
/**
* Create a new action (last step)
*
* @access public
*/
public function create()
{
2014-11-23 20:13:38 +01:00
$this->doCreation($this->getProjectManagement(), $this->request->getValues());
}
2014-07-20 12:26:15 +02:00
2014-11-23 20:13:38 +01:00
/**
* Save the action
*
* @access private
* @param array $project Project properties
* @param array $values Form values
*/
private function doCreation(array $project, array $values)
{
2014-07-20 12:26:15 +02:00
list($valid,) = $this->action->validateCreation($values);
if ($valid) {
if ($this->action->create($values)) {
$this->session->flash(t('Your automatic action have been created successfully.'));
}
else {
$this->session->flashError(t('Unable to create your automatic action.'));
}
}
$this->response->redirect('?controller=action&action=index&project_id='.$project['id']);
}
/**
* Confirmation dialog before removing an action
*
* @access public
*/
public function confirm()
{
2014-11-23 20:13:38 +01:00
$project = $this->getProjectManagement();
2014-10-22 19:59:09 +02:00
2014-12-22 19:15:38 +01:00
$this->response->html($this->projectLayout('action/remove', array(
2014-07-20 12:26:15 +02:00
'action' => $this->action->getById($this->request->getIntegerParam('action_id')),
'available_events' => $this->action->getAvailableEvents(),
'available_actions' => $this->action->getAvailableActions(),
2014-10-22 19:59:09 +02:00
'project' => $project,
2014-07-20 12:26:15 +02:00
'title' => t('Remove an action')
)));
}
/**
* Remove an action
*
* @access public
*/
public function remove()
{
$this->checkCSRFParam();
2014-11-23 20:13:38 +01:00
$project = $this->getProjectManagement();
2014-07-20 12:26:15 +02:00
$action = $this->action->getById($this->request->getIntegerParam('action_id'));
if ($action && $this->action->remove($action['id'])) {
$this->session->flash(t('Action removed successfully.'));
} else {
$this->session->flashError(t('Unable to remove this action.'));
}
2014-11-23 20:13:38 +01:00
$this->response->redirect('?controller=action&action=index&project_id='.$project['id']);
2014-07-20 12:26:15 +02:00
}
}