summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/Model/SubtaskModel.php15
-rw-r--r--app/Model/SubtaskStatusModel.php3
-rw-r--r--app/Model/SubtaskTimeTrackingModel.php23
-rw-r--r--app/ServiceProvider/EventDispatcherProvider.php2
-rw-r--r--app/Subscriber/SubtaskTimeTrackingSubscriber.php48
5 files changed, 35 insertions, 56 deletions
diff --git a/app/Model/SubtaskModel.php b/app/Model/SubtaskModel.php
index 568e27a4..608ffce7 100644
--- a/app/Model/SubtaskModel.php
+++ b/app/Model/SubtaskModel.php
@@ -173,6 +173,7 @@ class SubtaskModel extends Base
$subtask_id = $this->db->table(self::TABLE)->persist($values);
if ($subtask_id !== false) {
+ $this->subtaskTimeTrackingModel->updateTaskTimeTracking($values['task_id']);
$this->queueManager->push($this->subtaskEventJob->withParams($subtask_id, self::EVENT_CREATE));
}
@@ -183,17 +184,21 @@ class SubtaskModel extends Base
* Update
*
* @access public
- * @param array $values Form values
- * @param bool $fire_events If true, will be called an event
+ * @param array $values
+ * @param bool $fire_event
* @return bool
*/
- public function update(array $values, $fire_events = true)
+ public function update(array $values, $fire_event = true)
{
$this->prepare($values);
$result = $this->db->table(self::TABLE)->eq('id', $values['id'])->save($values);
- if ($result && $fire_events) {
- $this->queueManager->push($this->subtaskEventJob->withParams($values['id'], self::EVENT_UPDATE, $values));
+ if ($result) {
+ $this->subtaskTimeTrackingModel->updateTaskTimeTracking($values['task_id']);
+
+ if ($fire_event) {
+ $this->queueManager->push($this->subtaskEventJob->withParams($values['id'], self::EVENT_UPDATE, $values));
+ }
}
return $result;
diff --git a/app/Model/SubtaskStatusModel.php b/app/Model/SubtaskStatusModel.php
index 26cbb67d..c99d6055 100644
--- a/app/Model/SubtaskStatusModel.php
+++ b/app/Model/SubtaskStatusModel.php
@@ -63,8 +63,11 @@ class SubtaskStatusModel extends Base
if (empty($subtask['user_id']) && $this->userSession->isLogged()) {
$values['user_id'] = $this->userSession->getId();
+ $subtask['user_id'] = $values['user_id'];
}
+ $this->subtaskTimeTrackingModel->toggleTimer($subtask_id, $subtask['user_id'], $status);
+
return $this->subtaskModel->update($values) ? $status : false;
}
diff --git a/app/Model/SubtaskTimeTrackingModel.php b/app/Model/SubtaskTimeTrackingModel.php
index 062e594a..3b1b97e4 100644
--- a/app/Model/SubtaskTimeTrackingModel.php
+++ b/app/Model/SubtaskTimeTrackingModel.php
@@ -160,6 +160,28 @@ class SubtaskTimeTrackingModel extends Base
}
/**
+ * Start or stop timer according to subtask status
+ *
+ * @access public
+ * @param integer $subtask_id
+ * @param integer $user_id
+ * @param integer $status
+ * @return boolean
+ */
+ public function toggleTimer($subtask_id, $user_id, $status)
+ {
+ if ($this->configModel->get('subtask_time_tracking') == 1) {
+ if ($status == SubtaskModel::STATUS_INPROGRESS) {
+ return $this->subtaskTimeTrackingModel->logStartTime($subtask_id, $user_id);
+ } elseif ($status == SubtaskModel::STATUS_DONE) {
+ return $this->subtaskTimeTrackingModel->logEndTime($subtask_id, $user_id);
+ }
+ }
+
+ return false;
+ }
+
+ /**
* Log start time
*
* @access public
@@ -252,7 +274,6 @@ class SubtaskTimeTrackingModel extends Base
{
$subtask = $this->subtaskModel->getById($subtask_id);
- // Fire the event subtask.update
return $this->subtaskModel->update(array(
'id' => $subtask['id'],
'time_spent' => $subtask['time_spent'] + $time_spent,
diff --git a/app/ServiceProvider/EventDispatcherProvider.php b/app/ServiceProvider/EventDispatcherProvider.php
index 57543fe4..ebf42cbf 100644
--- a/app/ServiceProvider/EventDispatcherProvider.php
+++ b/app/ServiceProvider/EventDispatcherProvider.php
@@ -11,7 +11,6 @@ use Kanboard\Subscriber\BootstrapSubscriber;
use Kanboard\Subscriber\NotificationSubscriber;
use Kanboard\Subscriber\ProjectDailySummarySubscriber;
use Kanboard\Subscriber\ProjectModificationDateSubscriber;
-use Kanboard\Subscriber\SubtaskTimeTrackingSubscriber;
use Kanboard\Subscriber\TransitionSubscriber;
use Kanboard\Subscriber\RecurringTaskSubscriber;
@@ -31,7 +30,6 @@ class EventDispatcherProvider implements ServiceProviderInterface
$container['dispatcher']->addSubscriber(new ProjectDailySummarySubscriber($container));
$container['dispatcher']->addSubscriber(new ProjectModificationDateSubscriber($container));
$container['dispatcher']->addSubscriber(new NotificationSubscriber($container));
- $container['dispatcher']->addSubscriber(new SubtaskTimeTrackingSubscriber($container));
$container['dispatcher']->addSubscriber(new TransitionSubscriber($container));
$container['dispatcher']->addSubscriber(new RecurringTaskSubscriber($container));
diff --git a/app/Subscriber/SubtaskTimeTrackingSubscriber.php b/app/Subscriber/SubtaskTimeTrackingSubscriber.php
deleted file mode 100644
index 7e39c126..00000000
--- a/app/Subscriber/SubtaskTimeTrackingSubscriber.php
+++ /dev/null
@@ -1,48 +0,0 @@
-<?php
-
-namespace Kanboard\Subscriber;
-
-use Symfony\Component\EventDispatcher\EventSubscriberInterface;
-use Kanboard\Model\SubtaskModel;
-use Kanboard\Event\SubtaskEvent;
-
-class SubtaskTimeTrackingSubscriber extends BaseSubscriber implements EventSubscriberInterface
-{
- public static function getSubscribedEvents()
- {
- return array(
- SubtaskModel::EVENT_CREATE => 'updateTaskTime',
- SubtaskModel::EVENT_DELETE => 'updateTaskTime',
- SubtaskModel::EVENT_UPDATE => array(
- array('logStartEnd', 10),
- array('updateTaskTime', 0),
- )
- );
- }
-
- public function updateTaskTime(SubtaskEvent $event)
- {
- if (isset($event['task_id'])) {
- $this->logger->debug('Subscriber executed: '.__METHOD__);
- $this->subtaskTimeTrackingModel->updateTaskTimeTracking($event['task_id']);
- }
- }
-
- public function logStartEnd(SubtaskEvent $event)
- {
- if (isset($event['status']) && $this->configModel->get('subtask_time_tracking') == 1) {
- $this->logger->debug('Subscriber executed: '.__METHOD__);
- $subtask = $this->subtaskModel->getById($event['id']);
-
- if (empty($subtask['user_id'])) {
- return false;
- }
-
- if ($subtask['status'] == SubtaskModel::STATUS_INPROGRESS) {
- return $this->subtaskTimeTrackingModel->logStartTime($subtask['id'], $subtask['user_id']);
- } else {
- return $this->subtaskTimeTrackingModel->logEndTime($subtask['id'], $subtask['user_id']);
- }
- }
- }
-}