/** * Toggles completion status of this task. Moves a recurring task * to the next occurence on completion. */ public function toggleComplete() { if ($this->completed) { $this->completed_date = null; $this->completed = false; if ($this->recurs()) { /* What do we want do delete here? All completions? * The latest completion? Any completion in the * future?. */ foreach ($this->recurrence->getCompletions() as $completion) { $this->recurrence->deleteCompletion(substr($completion, 0, 4), substr($completion, 4, 2), substr($completion, 6, 2)); } } return; } if ($this->recurs()) { /* Get current occurrence (task due date) */ $current = $this->recurrence->nextActiveRecurrence(new Horde_Date($this->due)); if ($current) { $this->recurrence->addCompletion($current->year, $current->month, $current->mday); /* Advance this occurence by a day to indicate that we * want the following occurence (Recurrence uses days * as minimal time duration between occurrences). */ $current->mday++; /* Only mark this due date completed if there is another * occurence. */ if ($next = $this->recurrence->nextActiveRecurrence($current)) { $this->completed = false; return; } } } $this->completed_date = time(); $this->completed = true; }
/** * Toggles completion status of this task. Moves a recurring task * to the next occurence on completion. */ public function toggleComplete() { if ($this->completed) { $this->completed_date = null; $this->completed = false; if ($this->recurs()) { /* Only delete the latest completion. */ $completions = $this->recurrence->getCompletions(); sort($completions); list($year, $month, $mday) = sscanf(end($completions), '%04d%02d%02d'); $this->recurrence->deleteCompletion($year, $month, $mday); } return; } if ($this->recurs()) { /* Get current occurrence (task due date) */ $current = $this->recurrence->nextActiveRecurrence(new Horde_Date($this->due)); if ($current) { $this->recurrence->addCompletion($current->year, $current->month, $current->mday); /* Advance this occurence by a day to indicate that we want the * following occurence (Recurrence uses days as minimal time * duration between occurrences). */ $current->mday++; /* Only mark this due date completed if there is another * occurence. */ if ($next = $this->recurrence->nextActiveRecurrence($current)) { $this->completed = false; return; } } } $this->completed_date = time(); $this->completed = true; }
/** */ public function testCompletions() { $r = new Horde_Date_Recurrence(new Horde_Date(1970, 1, 1)); $r->setRecurType(Horde_Date_Recurrence::RECUR_DAILY); $r->addCompletion(1970, 1, 2); $this->assertTrue($r->hasCompletion(1970, 1, 2)); $this->assertEquals(1, count($r->getCompletions())); $r->addCompletion(1970, 1, 4); $this->assertEquals(2, count($r->getCompletions())); $r->deleteCompletion(1970, 1, 2); $this->assertEquals(1, count($r->getCompletions())); $this->assertFalse($r->hasCompletion(1970, 1, 2)); $r->addCompletion(1970, 1, 2); $r->addException(1970, 1, 1); $r->addException(1970, 1, 3); $next = $r->nextRecurrence(new Horde_Date($r->start)); $this->assertEquals(1, $next->mday); $this->assertTrue($r->hasException($next->year, $next->month, $next->mday)); $next->mday++; $next = $r->nextRecurrence($next); $this->assertTrue($r->hasCompletion($next->year, $next->month, $next->mday)); $next->mday++; $next = $r->nextRecurrence($next); $this->assertTrue($r->hasException($next->year, $next->month, $next->mday)); $next->mday++; $next = $r->nextRecurrence($next); $this->assertTrue($r->hasCompletion($next->year, $next->month, $next->mday)); $r->setRecurEnd(new Horde_Date(1970, 1, 4)); $this->assertTrue($r->hasRecurEnd()); $this->assertFalse($r->hasActiveRecurrence()); $s = new Horde_Date_Recurrence(new Horde_Date(1970, 1, 1)); $s->fromKolab($r->toKolab()); $this->assertTrue($s->hasRecurEnd()); $next = $s->nextRecurrence(new Horde_Date($s->start)); $this->assertEquals(1, $next->mday); $this->assertTrue($s->hasException($next->year, $next->month, $next->mday)); $next->mday++; $next = $s->nextRecurrence($next); $this->assertTrue($s->hasCompletion($next->year, $next->month, $next->mday)); $next->mday++; $next = $s->nextRecurrence($next); $this->assertTrue($s->hasException($next->year, $next->month, $next->mday)); $next->mday++; $next = $s->nextRecurrence($next); $this->assertTrue($s->hasCompletion($next->year, $next->month, $next->mday)); $this->assertEquals(2, count($s->getCompletions())); $this->assertEquals(2, count($s->getExceptions())); $this->assertFalse($s->hasActiveRecurrence()); $this->assertEquals(2, count($s->getCompletions())); $s->deleteCompletion(1970, 1, 2); $this->assertEquals(1, count($s->getCompletions())); $s->deleteCompletion(1970, 1, 4); $this->assertEquals(0, count($s->getCompletions())); }