Skip to content

Commit

Permalink
[jan] Fix listing of recurring tasks with start dates.
Browse files Browse the repository at this point in the history
  • Loading branch information
yunosh committed Sep 26, 2014
1 parent 4b693f5 commit 82f3e3d
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 8 deletions.
62 changes: 56 additions & 6 deletions nag/lib/Driver/Kolab.php
Expand Up @@ -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 {
Expand Down
28 changes: 26 additions & 2 deletions nag/lib/Driver/Sql.php
Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -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. */
Expand Down

0 comments on commit 82f3e3d

Please sign in to comment.