From e94a2f6a00b59a6e2b63d461794b01a2b9d07473 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sat, 16 May 2015 21:04:46 -0400 Subject: Display tasks in the calendar + improve settings --- app/Model/SubtaskTimeTracking.php | 45 ++++++++++++++------------------------- 1 file changed, 16 insertions(+), 29 deletions(-) (limited to 'app/Model/SubtaskTimeTracking.php') diff --git a/app/Model/SubtaskTimeTracking.php b/app/Model/SubtaskTimeTracking.php index a984533f..6d4a3467 100644 --- a/app/Model/SubtaskTimeTracking.php +++ b/app/Model/SubtaskTimeTracking.php @@ -135,8 +135,13 @@ class SubtaskTimeTracking extends Base public function getUserCalendarEvents($user_id, $start, $end) { $result = $this->getUserQuery($user_id) - ->addCondition($this->getCalendarCondition($start, $end)) - ->findAll(); + ->addCondition($this->getCalendarCondition( + $this->dateParser->getTimestampFromIsoFormat($start), + $this->dateParser->getTimestampFromIsoFormat($end), + 'start', + 'end' + )) + ->findAll(); $result = $this->timetable->calculateEventsIntersect($user_id, $result, $start, $end); @@ -154,37 +159,19 @@ class SubtaskTimeTracking extends Base */ public function getProjectCalendarEvents($project_id, $start, $end) { - $result = $this->getProjectQuery($project_id) - ->addCondition($this->getCalendarCondition($start, $end)) - ->findAll(); + $result = $this + ->getProjectQuery($project_id) + ->addCondition($this->getCalendarCondition( + $this->dateParser->getTimestampFromIsoFormat($start), + $this->dateParser->getTimestampFromIsoFormat($end), + 'start', + 'end' + )) + ->findAll(); return $this->toCalendarEvents($result); } - /** - * Get time slots that should be displayed in the calendar time range - * - * @access private - * @param string $start ISO8601 start date - * @param string $end ISO8601 end date - * @return string - */ - private function getCalendarCondition($start, $end) - { - $start_time = $this->dateParser->getTimestampFromIsoFormat($start); - $end_time = $this->dateParser->getTimestampFromIsoFormat($end); - $start_column = $this->db->escapeIdentifier('start'); - $end_column = $this->db->escapeIdentifier('end'); - - $conditions = array( - "($start_column >= '$start_time' AND $start_column <= '$end_time')", - "($start_column <= '$start_time' AND $end_column >= '$start_time')", - "($start_column <= '$start_time' AND $end_column = '0')", - ); - - return '('.implode(' OR ', $conditions).')'; - } - /** * Convert a record set to calendar events * -- cgit v1.2.3