summaryrefslogtreecommitdiff
path: root/app/Model/SubtaskTimeTracking.php
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-09-20 18:24:15 -0400
committerFrederic Guillot <fred@kanboard.net>2015-09-20 18:24:15 -0400
commite6f547abcfe684658a7498391db72d13b6aa7d9a (patch)
tree75b709c12fb03e11d7cb85558558f89f19abb284 /app/Model/SubtaskTimeTracking.php
parent2021dccc5a444f60c5ba1673d94b39999912cd26 (diff)
Move timetable to a plugin
Plugin repository: https://github.com/kanboard/plugin-timetable
Diffstat (limited to 'app/Model/SubtaskTimeTracking.php')
-rw-r--r--app/Model/SubtaskTimeTracking.php38
1 files changed, 28 insertions, 10 deletions
diff --git a/app/Model/SubtaskTimeTracking.php b/app/Model/SubtaskTimeTracking.php
index 56998769..d65f2f75 100644
--- a/app/Model/SubtaskTimeTracking.php
+++ b/app/Model/SubtaskTimeTracking.php
@@ -150,13 +150,14 @@ class SubtaskTimeTracking extends Base
*
* @access public
* @param integer $user_id
- * @param integer $start
- * @param integer $end
+ * @param string $start ISO-8601 format
+ * @param string $end
* @return array
*/
public function getUserCalendarEvents($user_id, $start, $end)
{
- $result = $this->getUserQuery($user_id)
+ $hook = 'model:subtask-time-tracking:calendar:events';
+ $events = $this->getUserQuery($user_id)
->addCondition($this->getCalendarCondition(
$this->dateParser->getTimestampFromIsoFormat($start),
$this->dateParser->getTimestampFromIsoFormat($end),
@@ -165,9 +166,16 @@ class SubtaskTimeTracking extends Base
))
->findAll();
- $result = $this->timetable->calculateEventsIntersect($user_id, $result, $start, $end);
+ if ($this->hook->exists($hook)) {
+ $events = $this->hook->first($hook, array(
+ 'user_id' => $user_id,
+ 'events' => $events,
+ 'start' => $start,
+ 'end' => $end,
+ ));
+ }
- return $this->toCalendarEvents($result);
+ return $this->toCalendarEvents($events);
}
/**
@@ -293,6 +301,7 @@ class SubtaskTimeTracking extends Base
*/
public function getTimeSpent($subtask_id, $user_id)
{
+ $hook = 'model:subtask-time-tracking:calculate:time-spent';
$start_time = $this->db
->table(self::TABLE)
->eq('subtask_id', $subtask_id)
@@ -300,14 +309,23 @@ class SubtaskTimeTracking extends Base
->eq('end', 0)
->findOneColumn('start');
- if ($start_time) {
- $start = new DateTime;
- $start->setTimestamp($start_time);
+ if (empty($start_time)) {
+ return 0;
+ }
+
+ $end = new DateTime;
+ $start = new DateTime;
+ $start->setTimestamp($start_time);
- return $this->timetable->calculateEffectiveDuration($user_id, $start, new DateTime);
+ if ($this->hook->exists($hook)) {
+ return $this->hook->first($hook, array(
+ 'user_id' => $user_id,
+ 'start' => $start,
+ 'end' => $end,
+ ));
}
- return 0;
+ return $this->dateParser->getHours($start, $end);
}
/**