diff --git a/nag/lib/Driver/Kolab.php b/nag/lib/Driver/Kolab.php index 1695427c5c9..087e8bcbff5 100644 --- a/nag/lib/Driver/Kolab.php +++ b/nag/lib/Driver/Kolab.php @@ -412,13 +412,63 @@ public function retrieve($completed = Nag::VIEW_ALL) $start = $t->start; } - if (($completed == Nag::VIEW_INCOMPLETE && ($complete || $start > $_SERVER['REQUEST_TIME'])) || - ($completed == Nag::VIEW_COMPLETE && !$complete) || - ($completed == Nag::VIEW_FUTURE && - ($complete || $start == 0 || $start < $_SERVER['REQUEST_TIME'])) || - ($completed == Nag::VIEW_FUTURE_INCOMPLETE && $complete)) { - continue; + switch ($completed) { + case Nag::VIEW_INCOMPLETE: + if ($complete) { + continue; + } + if ($start && $t->recurs() && + ($completions = $t->recurrence->getCompletions())) { + sort($completions); + list($year, $month, $mday) = sscanf( + end($completions), + '%04d%02d%02d' + ); + $lastCompletion = new Horde_Date($year, $month, $mday); + $recurrence = clone $t->recurrence; + $recurrence->start = new Horde_Date($start); + $start = $recurrence + ->nextRecurrence($lastCompletion) + ->timestamp(); + if ($start > $_SERVER['REQUEST_TIME']) { + continue; + } + } + break; + case Nag::VIEW_COMPLETE: + if (!$complete) { + continue; + } + break; + case Nag::VIEW_FUTURE: + if ($complete || $start == 0) { + continue; + } + if ($start && $t->recurs() && + ($completions = $t->recurrence->getCompletions())) { + sort($completions); + list($year, $month, $mday) = sscanf( + end($completions), + '%04d%02d%02d' + ); + $lastCompletion = new Horde_Date($year, $month, $mday); + $recurrence = clone $t->recurrence; + $recurrence->start = new Horde_Date($start); + $start = $recurrence + ->nextRecurrence($lastCompletion) + ->timestamp(); + if ($start < $_SERVER['REQUEST_TIME']) { + continue; + } + } + break; + case Nag::VIEW_FUTURE_INCOMPLETE: + if ($complete) { + continue; + } + break; } + if (empty($t->parent_id)) { $this->tasks->add($t); } else { diff --git a/nag/lib/Driver/Sql.php b/nag/lib/Driver/Sql.php index 430123c69de..42f47ab1a3b 100644 --- a/nag/lib/Driver/Sql.php +++ b/nag/lib/Driver/Sql.php @@ -409,7 +409,7 @@ public function retrieve($completed = Nag::VIEW_ALL, $include_history = true) $values = array($this->_tasklist); switch ($completed) { case Nag::VIEW_INCOMPLETE: - $query .= ' AND task_completed = 0 AND (task_start IS NULL OR task_start = 0 OR task_start < ?)'; + $query .= ' AND task_completed = 0 AND (task_start IS NULL OR task_completions IS NOT NULL OR task_start = 0 OR task_start < ?)'; $values[] = $_SERVER['REQUEST_TIME']; break; @@ -418,7 +418,7 @@ public function retrieve($completed = Nag::VIEW_ALL, $include_history = true) break; case Nag::VIEW_FUTURE: - $query .= ' AND task_completed = 0 AND task_start > ?'; + $query .= ' AND task_completed = 0 AND (task_completions IS NOT NULL OR task_start > ?)'; $values[] = $_SERVER['REQUEST_TIME']; break; @@ -439,6 +439,30 @@ public function retrieve($completed = Nag::VIEW_ALL, $include_history = true) foreach ($result as $row) { $task = new Nag_Task($this, $this->_buildTask($row, $include_history)); + if (($completed == Nag::VIEW_INCOMPLETE || + $completed == Nag::VIEW_FUTURE) && + $task->start && + $task->recurs()) { + if ($completions = $task->recurrence->getCompletions()) { + sort($completions); + list($year, $month, $mday) = sscanf( + end($completions), + '%04d%02d%02d' + ); + $lastCompletion = new Horde_Date($year, $month, $mday); + $recurrence = clone $task->recurrence; + $recurrence->start = new Horde_Date($task->start); + $start = $recurrence->nextRecurrence($lastCompletion); + } else { + $start = new Horde_Date($task->start); + } + if (($completed == Nag::VIEW_INCOMPLETE && + $start->after($_SERVER['REQUEST_TIME'])) || + ($completed == Nag::VIEW_FUTURE && + $start->before($_SERVER['REQUEST_TIME']))) { + continue; + } + } /* Add task directly if it is a root task, otherwise store it in * the dictionary. */