Example #1
0
 /**
  *
  * @param int $fromTs (=null) - GMT
  * @param int $toTs (=null) - GMT
  * @return array (of PcTrashbinTask)
  */
 public function getDeletedTasksSince($fromTs, $toTs)
 {
     $c = new Criteria();
     // this method returns only the non-deleted lists
     $listIds = $this->getAllListIds();
     // but most of the deleted lists will carry deleted tasks with them
     $deletedLists = $this->getDeletedListsSince($fromTs, $toTs);
     foreach ($deletedLists as $deletedList) {
         $listIds[] = $deletedList->getId();
     }
     $c->add(PcTrashbinTaskPeer::LIST_ID, $listIds, Criteria::IN);
     return PcTrashbinTaskPeer::getDeletedTasksSince($fromTs, $toTs, $c);
 }
 /**
  * Populates the object using an array.
  *
  * This is particularly useful when populating an object from one of the
  * request arrays (e.g. $_POST).  This method goes through the column
  * names, checking to see whether a matching key exists in populated
  * array. If so the setByName() method is called for that column.
  *
  * You can specify the key type of the array by additionally passing one
  * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
  * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  * The default key type is the column's phpname (e.g. 'AuthorId')
  *
  * @param      array  $arr     An array to populate the object from.
  * @param      string $keyType The type of keys the array uses.
  * @return     void
  */
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = PcTrashbinTaskPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setListId($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setDescription($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setSortOrder($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setDueDate($arr[$keys[4]]);
     }
     if (array_key_exists($keys[5], $arr)) {
         $this->setRepetitionId($arr[$keys[5]]);
     }
     if (array_key_exists($keys[6], $arr)) {
         $this->setRepetitionParam($arr[$keys[6]]);
     }
     if (array_key_exists($keys[7], $arr)) {
         $this->setIsCompleted($arr[$keys[7]]);
     }
     if (array_key_exists($keys[8], $arr)) {
         $this->setIsHeader($arr[$keys[8]]);
     }
     if (array_key_exists($keys[9], $arr)) {
         $this->setIsFromSystem($arr[$keys[9]]);
     }
     if (array_key_exists($keys[10], $arr)) {
         $this->setNote($arr[$keys[10]]);
     }
     if (array_key_exists($keys[11], $arr)) {
         $this->setContexts($arr[$keys[11]]);
     }
     if (array_key_exists($keys[12], $arr)) {
         $this->setContactId($arr[$keys[12]]);
     }
     if (array_key_exists($keys[13], $arr)) {
         $this->setCompletedAt($arr[$keys[13]]);
     }
     if (array_key_exists($keys[14], $arr)) {
         $this->setUpdatedAt($arr[$keys[14]]);
     }
     if (array_key_exists($keys[15], $arr)) {
         $this->setCreatedAt($arr[$keys[15]]);
     }
     if (array_key_exists($keys[16], $arr)) {
         $this->setDeletedAt($arr[$keys[16]]);
     }
 }
 /**
  * Retrieve multiple objects by pkey.
  *
  * @param      array $pks List of primary keys
  * @param      PropelPDO $con the connection to use
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function retrieveByPKs($pks, PropelPDO $con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(PcTrashbinTaskPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(PcTrashbinTaskPeer::DATABASE_NAME);
         $criteria->add(PcTrashbinTaskPeer::ID, $pks, Criteria::IN);
         $objs = PcTrashbinTaskPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
 /**
  * Updates the corresponding Plancake task.
  * If there is not a corresponding Plancake task,
  * we create a new one.
  *
  * @param -Google Calendar Event- $event
  */
 private function updatePlancakeTask($event)
 {
     $eventId = $this->getEventId($event);
     // retrieving the Plancake task: we use this method, rather than the EVENT_EXTENDED_PROPERTY_TASK_ID
     // extended property, because it should be more reliable
     $task = PcTaskPeer::getTaskByGoogleCalendarEventId($eventId);
     // {{{ PATCH: we have this problem something Google was trying to send us back some events that
     // had been either completed or deleted on the Plancake side.
     // This is the reason why we have decided to use an extended property to keep a record of the link
     // CalendarEvent<-->PlancakeTask
     $taskIdFromExtendedProperty = $this->getExtendedProperty($event, self::EVENT_EXTENDED_PROPERTY_TASK_ID);
     if ($taskIdFromExtendedProperty) {
         $taskFromExtendedProperty = PcTaskPeer::retrieveByPK($taskIdFromExtendedProperty);
         if ($taskFromExtendedProperty && $taskFromExtendedProperty->isCompleted()) {
             $taskFromExtendedProperty->removeGoogleCalendarEventId();
             return;
         }
         if (PcTrashbinTaskPeer::retrieveByPK($taskIdFromExtendedProperty)) {
             return;
         }
     }
     // }}} // end PATCH
     // {{{ checking whether the event has been deleted
     if ($this->hasEventBeenDeleted($event)) {
         // event has been deleted
         if (is_object($task)) {
             if (SfConfig::get('app_gcal_debug')) {
                 error_log('Deleting Plancake task ' . $task->getId() . ' ' . $task->getDescription());
             }
             $task->removeGoogleCalendarEventId();
             // In order to avoid potential disasters, we disable the possibility
             // for GCal to delete tasks
             // $task->delete();
             return;
         }
     }
     // }}}
     $eventDescription = $event->title->text;
     $eventNote = $event->content->text;
     $eventDueDate = '';
     $eventDueTime = '';
     $eventRepetitionId = 0;
     $eventRepetitionParam = 0;
     $eventIsRecurrent = true;
     foreach ($event->when as $when) {
         $startTime = $when->startTime;
         $eventIsRecurrent = false;
         if (strlen($startTime) == 10) {
             $eventDueDate = $startTime;
             $eventDueTime = '';
         } else {
             preg_match('!([^T]+)T([0-9]{2}):([0-9]{2}):.*!', $startTime, $matches);
             $eventDueDate = $matches[1];
             $eventDueTime = $matches[2] . $matches[3];
             $eventDueTime = (int) $eventDueTime;
         }
         break;
         // getting just the first due date
     }
     if ($eventIsRecurrent) {
         $recurrentData = $event->recurrence->text;
         // $recurrentData is something like:
         // DTSTART;VALUE=DATE:20110215 DTEND;VALUE=DATE:20110216 RRULE:FREQ=WEEKLY;INTERVAL=2;BYDAY=TU
         // DTSTART:20110228T110000Z DTEND:20110228T120000Z RRULE:FREQ=WEEKLY;BYDAY=MO
         list($eventDueDate, $eventDueTime, $eventRepetitionId, $eventRepetitionParam) = DateFormat::fromICalRecurrentStringToInternalParams($recurrentData);
     }
     foreach ($event->when as $when) {
         break;
         // we only consider the first 'when' parameter
     }
     list($eventLocalDueDate, $eventLocalDueTime) = DateFormat::fromGmtDateAndTime2LocalDateAndTime($eventDueDate, $eventDueTime);
     if (is_object($task)) {
         $task->edit($eventDescription, null, null, null, $eventNote, $eventLocalDueDate, $eventLocalDueTime, null, $eventRepetitionId, $eventRepetitionParam, 'gcal');
         if (SfConfig::get('app_gcal_debug')) {
             error_log('Updated Plancake task ' . $task->getId() . ' ' . $task->getDescription());
         }
     } else {
         $dbEntry = PcGoogleCalendarPeer::retrieveByUser($this->user);
         if (!is_object($dbEntry)) {
             throw new Exception("You need a session token in order to create a new task.");
         }
         // we have to create a new Plancake task
         $task = PcTaskPeer::createOrEdit($eventDescription, null, 0, '', false, $eventNote, $eventLocalDueDate, $eventLocalDueTime, 0, $eventRepetitionId, $eventRepetitionParam, 0, 'gcal', 'Y-m-d');
         if (SfConfig::get('app_gcal_debug')) {
             error_log('Created Plancake task ' . $task->getId() . ' ' . $task->getDescription());
         }
     }
     $task->setGoogleCalendarEventId($eventId);
 }
Example #5
0
 private function copyObjectToTrashBin()
 {
     $taskId = $this->getId();
     if (!($trashBin = PcTrashbinTaskPeer::retrieveByPK($taskId))) {
         $trashBin = new PcTrashbinTask();
     }
     $trashBin->setId($taskId)->setListId($this->getListId())->setDescription($this->getDescription())->setSortOrder($this->getSortOrder())->setDueDate($this->getDueDate())->setRepetitionId($this->getRepetitionId())->setRepetitionParam($this->getRepetitionParam())->setIsHeader($this->isHeader())->setIsCompleted($this->isCompleted())->setIsFromSystem($this->isFromSystem())->setNote($this->getNote())->setContexts($this->getContexts())->setContactId($this->getContactId())->setCompletedAt($this->getCompletedAt())->setUpdatedAt($this->getUpdatedAt())->setCreatedAt($this->getCreatedAt())->setDeletedAt(time('U'))->save();
 }