summaryrefslogtreecommitdiff
path: root/app/Subscriber/SubtaskTimesheetSubscriber.php
blob: df10fc43b687c9270f689ea7e4fb7a322283f505 (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']);
            }
        }
    }
}