summaryrefslogtreecommitdiff
path: root/app/Subscriber/SubtaskTimesheetSubscriber.php
blob: 687db80a4c967a3d3cb6a99e74c0dbfd75eb6c22 (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
<?php

namespace Subscriber;

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

class SubtaskTimesheetSubscriber extends Base implements EventSubscriberInterface
{
    public static function getSubscribedEvents()
    {
        return array(
            SubTask::EVENT_UPDATE => array('log', 0),
        );
    }

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

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

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