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

113 lines
3 KiB
PHP
Raw Normal View History

2014-07-20 12:26:15 +02:00
<?php
namespace Action;
2015-01-16 14:23:05 +01:00
use Integration\GitlabWebhook;
use Integration\GithubWebhook;
2015-02-25 17:29:06 +01:00
use Integration\BitbucketWebhook;
2014-07-20 12:26:15 +02:00
use Model\Task;
/**
* Close automatically a task
*
* @package action
* @author Frederic Guillot
*/
class TaskClose extends Base
{
/**
2014-11-23 20:13:38 +01:00
* Get the list of compatible events
2014-07-20 12:26:15 +02:00
*
* @access public
2014-11-23 20:13:38 +01:00
* @return array
2014-07-20 12:26:15 +02:00
*/
2014-11-23 20:13:38 +01:00
public function getCompatibleEvents()
2014-07-20 12:26:15 +02:00
{
2014-11-23 20:13:38 +01:00
return array(
Task::EVENT_MOVE_COLUMN,
GithubWebhook::EVENT_COMMIT,
GithubWebhook::EVENT_ISSUE_CLOSED,
2015-01-16 14:23:05 +01:00
GitlabWebhook::EVENT_COMMIT,
GitlabWebhook::EVENT_ISSUE_CLOSED,
2015-02-25 17:29:06 +01:00
BitbucketWebhook::EVENT_COMMIT,
2015-08-16 17:04:56 +02:00
BitbucketWebhook::EVENT_ISSUE_CLOSED,
2014-11-23 20:13:38 +01:00
);
2014-07-20 12:26:15 +02:00
}
/**
* Get the required parameter for the action (defined by the user)
*
* @access public
* @return array
*/
public function getActionRequiredParameters()
{
2014-11-23 20:13:38 +01:00
switch ($this->event_name) {
case GithubWebhook::EVENT_COMMIT:
case GithubWebhook::EVENT_ISSUE_CLOSED:
2015-01-16 14:23:05 +01:00
case GitlabWebhook::EVENT_COMMIT:
case GitlabWebhook::EVENT_ISSUE_CLOSED:
2015-02-25 17:29:06 +01:00
case BitbucketWebhook::EVENT_COMMIT:
2015-08-16 17:04:56 +02:00
case BitbucketWebhook::EVENT_ISSUE_CLOSED:
2014-11-23 20:13:38 +01:00
return array();
default:
return array('column_id' => t('Column'));
}
2014-07-20 12:26:15 +02:00
}
/**
* Get the required parameter for the event
*
* @access public
* @return string[]
*/
public function getEventRequiredParameters()
{
2014-11-23 20:13:38 +01:00
switch ($this->event_name) {
case GithubWebhook::EVENT_COMMIT:
case GithubWebhook::EVENT_ISSUE_CLOSED:
2015-01-16 14:23:05 +01:00
case GitlabWebhook::EVENT_COMMIT:
case GitlabWebhook::EVENT_ISSUE_CLOSED:
2015-02-25 17:29:06 +01:00
case BitbucketWebhook::EVENT_COMMIT:
2015-08-16 17:04:56 +02:00
case BitbucketWebhook::EVENT_ISSUE_CLOSED:
2014-11-23 20:13:38 +01:00
return array('task_id');
default:
return array('task_id', 'column_id');
}
2014-07-20 12:26:15 +02:00
}
/**
2014-11-23 20:13:38 +01:00
* Execute the action (close the task)
2014-07-20 12:26:15 +02:00
*
* @access public
* @param array $data Event data dictionary
* @return bool True if the action was executed or false when not executed
*/
public function doAction(array $data)
{
2014-12-22 19:15:38 +01:00
return $this->taskStatus->close($data['task_id']);
2014-11-23 20:13:38 +01:00
}
2014-07-20 12:26:15 +02:00
2014-11-23 20:13:38 +01:00
/**
* Check if the event data meet the action condition
*
* @access public
* @param array $data Event data dictionary
* @return bool
*/
public function hasRequiredCondition(array $data)
{
switch ($this->event_name) {
case GithubWebhook::EVENT_COMMIT:
case GithubWebhook::EVENT_ISSUE_CLOSED:
2015-01-16 14:23:05 +01:00
case GitlabWebhook::EVENT_COMMIT:
case GitlabWebhook::EVENT_ISSUE_CLOSED:
2015-02-25 17:29:06 +01:00
case BitbucketWebhook::EVENT_COMMIT:
2015-08-16 17:04:56 +02:00
case BitbucketWebhook::EVENT_ISSUE_CLOSED:
2014-11-23 20:13:38 +01:00
return true;
default:
return $data['column_id'] == $this->getParam('column_id');
}
2014-07-20 12:26:15 +02:00
}
}