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/Subscriber/ProjectActivitySubscriber.php

91 lines
2.8 KiB
PHP
Raw Normal View History

2015-01-16 14:23:05 +01:00
<?php
namespace Subscriber;
use Event\GenericEvent;
use Model\Task;
use Model\Comment;
2015-02-25 17:29:06 +01:00
use Model\Subtask;
2015-01-16 14:23:05 +01:00
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class ProjectActivitySubscriber extends Base implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return array(
Task::EVENT_ASSIGNEE_CHANGE => array('execute', 0),
Task::EVENT_UPDATE => array('execute', 0),
Task::EVENT_CREATE => array('execute', 0),
Task::EVENT_CLOSE => array('execute', 0),
Task::EVENT_OPEN => array('execute', 0),
Task::EVENT_MOVE_COLUMN => array('execute', 0),
Task::EVENT_MOVE_POSITION => array('execute', 0),
Comment::EVENT_UPDATE => array('execute', 0),
Comment::EVENT_CREATE => array('execute', 0),
2015-02-25 17:29:06 +01:00
Subtask::EVENT_UPDATE => array('execute', 0),
Subtask::EVENT_CREATE => array('execute', 0),
2015-01-16 14:23:05 +01:00
);
}
public function execute(GenericEvent $event, $event_name)
{
// Executed only when someone is logged
if ($this->userSession->isLogged() && isset($event['task_id'])) {
$values = $this->getValues($event);
$this->projectActivity->createEvent(
$values['task']['project_id'],
$values['task']['id'],
$this->userSession->getId(),
$event_name,
$values
);
2015-04-21 17:56:16 +02:00
$this->sendSlackNotification($event_name, $values);
$this->sendHipchatNotification($event_name, $values);
}
}
private function sendSlackNotification($event_name, array $values)
{
if ($this->config->get('integration_slack_webhook') == 1) {
$this->slackWebhook->notify(
$values['task']['project_id'],
$values['task']['id'],
$event_name,
$values
);
}
}
private function sendHipchatNotification($event_name, array $values)
{
if ($this->config->get('integration_hipchat') == 1) {
$this->hipchat->notify(
$values['task']['project_id'],
$values['task']['id'],
$event_name,
$values
);
2015-01-16 14:23:05 +01:00
}
}
private function getValues(GenericEvent $event)
{
$values = array();
$values['task'] = $this->taskFinder->getDetails($event['task_id']);
switch (get_class($event)) {
case 'Event\SubtaskEvent':
2015-02-25 17:29:06 +01:00
$values['subtask'] = $this->subtask->getById($event['id'], true);
2015-01-16 14:23:05 +01:00
break;
case 'Event\CommentEvent':
$values['comment'] = $this->comment->getById($event['id']);
break;
}
return $values;
}
}