summaryrefslogtreecommitdiff
path: root/app/Subscriber/SubtaskTimeTrackingSubscriber.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/Subscriber/SubtaskTimeTrackingSubscriber.php')
-rw-r--r--app/Subscriber/SubtaskTimeTrackingSubscriber.php47
1 files changed, 47 insertions, 0 deletions
diff --git a/app/Subscriber/SubtaskTimeTrackingSubscriber.php b/app/Subscriber/SubtaskTimeTrackingSubscriber.php
new file mode 100644
index 00000000..02f14c40
--- /dev/null
+++ b/app/Subscriber/SubtaskTimeTrackingSubscriber.php
@@ -0,0 +1,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']);
+ }
+ }
+ }
+}