Exemplo n.º 1
0
 /**
  * Marks the tasks as complete (unless the task has got repetitions)
  */
 public function markComplete()
 {
     // Initially we were thinking to delete system tasks straight-away.
     // But the 'welcome task' is a system task. If the newbie completes it
     // and they don't find it in the 'completed tasks' section, they will feel
     // quite puzzled.
     /*
     if ($this->isFromSystem())
     {
        $this->delete();
        return;
     }
     */
     $loggedInUser = PcUserPeer::getLoggedInUser();
     if (!$this->getRepetitionId()) {
         $this->setIsCompleted(1);
         $this->setCompletedAt(time());
         $this->save();
         if ($loggedInUser->hasGoogleCalendarIntegrationActive()) {
             // google calendar holds only tasks that haven't been completed
             $gcal = new GoogleCalendarInterface($loggedInUser);
             $gcal->init();
             $gcal->deleteEvent($this);
             // even if it sounds reasonable to do this:
             // $this->removeGoogleCalendarEventId();
             // we shouldn't do it, otherwise the GoogleCalendarInterface will re-create this task
         }
     } else {
         $dateFormat = DateFormat::getInstance();
         // inserting a copy of the task in the history
         $newTask = PcTaskPeer::createOrEdit($this->getDescription(), $this->getListId(), 0, $this->getContexts(), (bool) $this->getIsHeader(), $this->getNote(), $this->getDueDate($dateFormat->getPHPDateFormat()), $this->getDueTime());
         $newTask->markComplete();
         // I need to create the next repetition
         $this->setNextOccurrence();
         if ($loggedInUser->hasGoogleCalendarIntegrationActive()) {
             $gcal = new GoogleCalendarInterface($loggedInUser);
             $gcal->init();
             $gcal->createOrUpdateEvent($this);
         }
     }
 }