/**
  *
  * @param PcUser $user
  * @param PcTask $task
  * @return boolean - return true if the entry has been actually added
  */
 public static function addEntry($user, $task)
 {
     if ($user == null) {
         return false;
     }
     if ($task == null) {
         return false;
     }
     $entry = self::retrieveByPK($user->getId(), $task->getId());
     if (is_object($entry)) {
         // the entry already exists
         return false;
     }
     $dirtyTask = new PcDirtyTask();
     $dirtyTask->setUserId($user->getId())->setTaskId($task->getId())->save();
     return true;
 }
 /**
  * Get the associated PcTask object
  *
  * @param      PropelPDO Optional Connection object.
  * @return     PcTask The associated PcTask object.
  * @throws     PropelException
  */
 public function getPcTask(PropelPDO $con = null)
 {
     if ($this->aPcTask === null && $this->task_id !== null) {
         $this->aPcTask = PcTaskPeer::retrieveByPk($this->task_id);
         // Because this foreign key represents a one-to-one relationship, we will create a bi-directional association.
         $this->aPcTask->setPcGoogleCalendarEvent($this);
     }
     return $this->aPcTask;
 }
Example #3
0
 /**
  *
  * @param string $taskDescription
  */
 public function addToInbox($taskDescription)
 {
     $task = new PcTask();
     $task->setListId($this->getInbox()->getId())->setIsFromSystem(true)->setDescription($taskDescription)->save();
 }
 /**
  * Inserts or updates an event to the specific calendar.
  * If we try to edit a task without due date, it deletes it
  *
  * @param PcTask $task
  * @param string $calendarUrl
  * @param bool $updateEmailAddress (=false)
  * @return int|bool the id of the event - false if the event we try to add/edit hasn't got due date
  */
 public function createOrUpdateEvent(PcTask $task, $updateEmailAddress = false)
 {
     $event = null;
     $googleCalendarEventId = $task->getGoogleCalendarEventId();
     $mode = self::EVENT_CREATE_MODE;
     if (strlen($googleCalendarEventId)) {
         $event = $this->getEvent($googleCalendarEventId);
         if (is_object($event)) {
             $mode = self::EVENT_UPDATE_MODE;
         }
         if ($this->hasEventBeenDeleted($event)) {
             return;
         }
     }
     if (SfConfig::get('app_gcal_debug')) {
         if ($mode == self::EVENT_CREATE_MODE) {
             error_log('Creating task on GCal for the Plancake task ' . $task->getId() . ' ' . $task->getDescription());
         } else {
             error_log('Editing task on GCal for the Plancake task ' . $task->getId() . ' ' . $task->getDescription());
         }
     }
     if ($mode == self::EVENT_CREATE_MODE) {
         $event = $this->service->newEventEntry();
     }
     if (!$task->getDueDate() || $task->isCompleted()) {
         // A task without due date or completed shouldn't be on Google Calendar
         $this->deleteEventById($googleCalendarEventId);
         $task->removeGoogleCalendarEventId();
         return false;
     }
     // {{{ Adding extended property to patch a problem we have this the integration:
     // search 'EVENT_EXTENDED_PROPERTY_TASK_ID' in this file
     $this->setExtendedProperty($event, self::EVENT_EXTENDED_PROPERTY_TASK_ID, $task->getId());
     // }}}
     $event->title = $this->service->newTitle($task->getDescription());
     $event->where = array($this->service->newWhere(""));
     $event->content = $this->service->newContent($task->getNote());
     // Setting the date using RFC 3339 format
     list($startDate, $startTime) = DateFormat::fromLocalDateAndTime2GMTDateAndTime($task->getDueDate("Y-m-d"), $task->getDueTime());
     $timeObject = new PcTime();
     if ($startTime > 0) {
         $startTime = $timeObject->createFromIntegerValue($startTime)->get5CharsRepresentation();
     } else {
         $startTime = null;
     }
     //$endDate = "2011-01-20";
     //$endTime = "16:00";
     //$userTimezone = $this->user->getPcTimezone();
     //$tzOffset = ($userTimezone->getOffset()/60);
     // right now, $tzOffset can be -8, but we need -08
     //$tzOffset = "-08";
     if ($task->getRepetitionId() > 0) {
         //            $recurrence = "DTSTART;VALUE=DATE:20110501\r\n" .
         //                    "DTEND;VALUE=DATE:20110502\r\n" .
         //                    "RRULE:FREQ=WEEKLY;BYDAY=Tu;UNTIL=20110904\r\n";
         $dtStart = $task->getDueDate("Ymd");
         if ($startTime !== null) {
             $dtStart = $dtStart . 'T' . str_replace(':', '', $startTime) . '00Z';
         }
         $recurrence = "DTSTART:{$dtStart}\r\n" . "RRULE:{$task->getRepetitionICalRrule()}\r\n";
         $event->recurrence = $this->service->newRecurrence($recurrence);
     } else {
         $when = $this->service->newWhen();
         if ($startTime !== null) {
             $when->startTime = "{$startDate}T{$startTime}:00.000Z";
         } else {
             $when->startTime = $startDate;
         }
         // $when->endTime = "{$endDate}T{$endTime}:00.000{$tzOffset}:00";
         $event->when = array($when);
     }
     if ($mode == self::EVENT_CREATE_MODE) {
         $newEvent = null;
         try {
             $newEvent = $this->service->insertEvent($event, $this->getCalendarUrl());
         } catch (Exception $e) {
             $newEvent = $this->service->insertEvent($event, $this->getCalendarUrl());
         }
     } else {
         // {{{ rather then running just $event->save() ,
         // we try many times, as sometimes the updating is a bit
         //quirky on Google Calendar end
         try {
             $event->save();
         } catch (Exception $e) {
             try {
                 $event->save();
             } catch (Exception $e) {
                 $event->save();
             }
         }
         // }}}
         $newEvent = $event;
     }
     if ($updateEmailAddress) {
         $dbEntry = PcGoogleCalendarPeer::retrieveByUser($this->user);
         $dbEntry->setEmailAddress($newEvent->author[0]->email->text)->save();
     }
     $eventId = $this->getEventId($newEvent);
     if ($mode == self::EVENT_CREATE_MODE) {
         $task->setGoogleCalendarEventId($eventId);
     }
     return $eventId;
 }
 /**
  * Declares an association between this object and a PcTask object.
  *
  * @param      PcTask $v
  * @return     PcDirtyTask The current object (for fluent API support)
  * @throws     PropelException
  */
 public function setPcTask(PcTask $v = null)
 {
     if ($v === null) {
         $this->setTaskId(NULL);
     } else {
         $this->setTaskId($v->getId());
     }
     $this->aPcTask = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the PcTask object, it will not be re-added.
     if ($v !== null) {
         $v->addPcDirtyTask($this);
     }
     return $this;
 }
Example #6
0
 /**
  * Inserts the update message into the inbox of each user
  *
  * @param string $description
  * @param string $url
  */
 public static function broadcastUpdate($description, $url)
 {
     $taskContent = "{$description} - " . __('ACCOUNT_MISC_READ_MORE_ON_OUR_BLOG') . " {$url}.";
     foreach (PcListPeer::getAllInboxes() as $inbox) {
         $task = new PcTask();
         $task->setDescription($taskContent)->setListId($inbox->getId())->setIsFromSystem(1)->save();
     }
 }
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      PcTask $value A PcTask object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(PcTask $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }