summaryrefslogtreecommitdiff
path: root/app/Subscriber/SubtaskTimeTrackingSubscriber.php
blob: 02f14c40c911ae78d37d73077d935e4a7e9dcb26 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php

namespace Subscriber;

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Model\Subtask;
use Event\SubtaskEvent;

class SubtaskTimeTrackingSubscriber extends \Core\Base implements EventSubscriberInterface
{
    public static function getSubscribedEvents()
    {
        return array(
            Subtask::EVENT_CREATE => array('updateTaskTime', 0),
            Subtask::EVENT_UPDATE => array(
                array('logStartEnd', 10),
                array('updateTaskTime', 0),
            )
        );
    }

    public function updateTaskTime(SubtaskEvent $event)
    {
        if (isset($event['task_id'])) {
            $this->subtaskTimeTracking->updateTaskTimeTracking($event['task_id']);
        }
    }

    public function logStartEnd(SubtaskEvent $event)
    {
        if (isset($event['status'])) {

            $subtask = $this->subtask->getById($event['id']);

            if (empty($subtask['user_id'])) {
                return false;
            }

            if ($subtask['status'] == Subtask::STATUS_INPROGRESS) {
                return $this->subtaskTimeTracking->logStartTime($subtask['id'], $subtask['user_id']);
            }
            else {
                return $this->subtaskTimeTracking->logEndTime($subtask['id'], $subtask['user_id']);
            }
        }
    }
}