public function executeAddEdit(sfWebRequest $request)
 {
     $op = $request->getParameter('op');
     $contextId = $request->getParameter('id');
     $contextName = trim($request->getParameter('name'));
     $newContext = null;
     if ($contextName && strpos($contextName, ' ') !== FALSE) {
         die("ERROR: " . __('ACCOUNT_ERROR_TAG_CANT_HAVE_SPACE'));
     }
     $existingContexts = PcUserPeer::getLoggedInUser()->getContextsArray(true);
     if (count($existingContexts)) {
         if (in_array(strtolower($contextName), $existingContexts)) {
             die("ERROR: " . __('ACCOUNT_ERROR_TAG_ALREADY_EXIST'));
         }
     }
     if ($op == 'delete' && $contextId) {
         $contextToDelete = PcUsersContextsPeer::retrieveByPk($contextId);
         PcUtils::checkLoggedInUserPermission(PcUserPeer::retrieveByPk($contextToDelete->getUserId()));
         $contextToDelete->delete();
     } else {
         if ($op == 'edit' && $contextId && $contextName) {
             $contextToEdit = PcUsersContextsPeer::retrieveByPk($contextId);
             PcUtils::checkLoggedInUserPermission(PcUserPeer::retrieveByPk($contextToEdit->getUserId()));
             $contextToEdit->setContext($contextName)->save();
             // {{{
             // this lines to make sure the list details we sent back via AJAX
             // are the ones stored in the database
             $contextToEdit = PcUsersContextsPeer::retrieveByPk($contextId);
             // }}}
         } else {
             if ($op == 'add' && $contextName) {
                 // getting max sortOrder
                 $c = new Criteria();
                 $c->addDescendingOrderByColumn(PcUsersContextsPeer::SORT_ORDER);
                 $maxSortOrder = PcUsersContextsPeer::doSelectOne($c)->getSortOrder();
                 $context = new PcUsersContexts();
                 $context->setContext($contextName)->setPcUser(PcUserPeer::getLoggedInUser())->setSortOrder($maxSortOrder + 1)->save();
                 // {{{
                 // this lines to make sure the list details we sent back via AJAX
                 // are the ones stored in the database
                 $newContext = PcUsersContextsPeer::retrieveByPk($context->getId());
                 // }}}
             }
         }
     }
     $tag = isset($contextToEdit) && $contextToEdit ? $contextToEdit : $newContext;
     if ($request->isXmlHttpRequest()) {
         if ($tag) {
             $ret = array('id' => $tag->getId(), 'name' => $tag->getContext());
             return $this->renderJson($ret);
         } else {
             return $this->renderDefault();
         }
     }
 }
 public function executeReorder(sfWebRequest $request)
 {
     $tagIds = $request->getParameter('tag');
     $i = 1;
     foreach ($tagIds as $tagId) {
         $tag = PcUsersContextsPeer::retrieveByPk($tagId);
         PcUtils::checkLoggedInUserPermission(PcUserPeer::retrieveByPK($tag->getUserId()));
         $tag->setSortOrder($i)->save();
         $i++;
     }
     return $this->renderDefault();
 }
 /**
  * @see sfTask
  */
 protected function executeTask($env, $arguments = array(), $options = array())
 {
     $tasks = PcTaskPeer::doSelect(new Criteria());
     foreach ($tasks as $task) {
         $contextsBlob = $task->getContexts();
         if (strlen($contextsBlob) > 0) {
             $contextIds = explode(',', $contextsBlob);
             foreach ($contextIds as $contextId) {
                 // checking the context exists
                 $context = PcUsersContextsPeer::retrieveByPK($contextId);
                 if (is_object($context)) {
                     $tasksContextsEntry = new PcTasksContexts();
                     $tasksContextsEntry->setTaskId($task->getId())->setUsersContextsId($contextId)->save();
                 }
             }
         }
     }
     echo "\nDone migration to 1.6.7 \n\n";
 }
Beispiel #4
0
 /**
  * Returns all the contexts.
  * Similar to getContexts() BUT:
  * Every element of the array is a contextName, having the contextId as a key
  *
  * @param boolean $returnLowercase (=false)
  * @return array
  */
 public function getContextsArray($returnLowercase = false)
 {
     if ($cache = PcCache::getInstance()) {
         $key = __METHOD__ . $this->getId();
         if ($cache->has($key)) {
             return $cache->get($key);
         }
     }
     $criteria = new Criteria();
     $criteria->add(PcUsersContextsPeer::USER_ID, $this->getId(), Criteria::EQUAL);
     $contexts = PcUsersContextsPeer::doSelect($criteria);
     foreach ($contexts as $context) {
         $contextName = $returnLowercase ? strtolower($context->getContext()) : $context->getContext();
         $ret[$context->getId()] = $contextName;
     }
     if ($cache) {
         $cache->set($key, $ret);
     }
     return $ret;
 }
 /**
  * @return string (XML format)
  */
 public function getXmlString()
 {
     $dump = '<?xml version="1.0" encoding="UTF-8" ?>' . "\n";
     $dump .= '<backup version="1" title="Plancake backup" link="http://www.plancake.com">' . "\n";
     $dump .= "\t<plancake_tasks>\n";
     // This Ids are to make the dump more portable:
     // tasks will be related to tags and lists via these "virtual" ids
     $tagLocalIds = array();
     $listLocalIds = array();
     $c = new Criteria();
     $c->add(PcUsersContextsPeer::USER_ID, $this->user->getId(), Criteria::EQUAL);
     $c->addDescendingOrderByColumn(PcUsersContextsPeer::SORT_ORDER);
     $c->addDescendingOrderByColumn(PcUsersContextsPeer::ID);
     $tags = PcUsersContextsPeer::doSelect($c);
     $dump .= "\t\t<tags>\n";
     $localId = 1;
     foreach ($tags as $tag) {
         $dump .= "\t\t\t<tag>\n";
         $dump .= "\t\t\t\t<localId>{$localId}</localId>\n";
         $dump .= "\t\t\t\t<id>{$tag->getId()}</id>\n";
         $dump .= "\t\t\t\t<name><![CDATA[{$tag->getContext()}]]></name>\n";
         $dump .= "\t\t\t\t<sortOrder>{$tag->getSortOrder()}</sortOrder>\n";
         $dump .= "\t\t\t\t<updatedAt>{$tag->getUpdatedAt()}</updatedAt>\n";
         $dump .= "\t\t\t\t<createdAt>{$tag->getCreatedAt()}</createdAt>\n";
         $dump .= "\t\t\t</tag>\n";
         $tagLocalIds[$tag->getId()] = $localId;
         $localId++;
     }
     $dump .= "\t\t</tags>\n\n";
     $c = new Criteria();
     $c->add(PcListPeer::CREATOR_ID, $this->user->getId(), Criteria::EQUAL);
     $c->addDescendingOrderByColumn(PcListPeer::SORT_ORDER);
     $c->addDescendingOrderByColumn(PcListPeer::ID);
     $lists = PcListPeer::doSelect($c);
     $dump .= "\t\t<lists>\n";
     $localId = 1;
     foreach ($lists as $list) {
         $listIsInbox = $list->getIsInbox() ? 1 : 0;
         $listIsTodo = $list->getIsTodo() ? 1 : 0;
         $listIsHeader = $list->getIsHeader() ? 1 : 0;
         $dump .= "\t\t\t<list>\n";
         $dump .= "\t\t\t\t<localId>{$localId}</localId>\n";
         $dump .= "\t\t\t\t<id>{$list->getId()}</id>\n";
         $dump .= "\t\t\t\t<name><![CDATA[{$list->getTitle()}]]></name>\n";
         $dump .= "\t\t\t\t<sortOrder>{$list->getSortOrder()}</sortOrder>\n";
         $dump .= "\t\t\t\t<isInbox>{$listIsInbox}</isInbox>\n";
         $dump .= "\t\t\t\t<isTodo>{$listIsTodo}</isTodo>\n";
         $dump .= "\t\t\t\t<isHeader>{$listIsHeader}</isHeader>\n";
         $dump .= "\t\t\t\t<updatedAt>{$list->getUpdatedAt()}</updatedAt>\n";
         $dump .= "\t\t\t\t<createdAt>{$list->getCreatedAt()}</createdAt>\n";
         $dump .= "\t\t\t</list>\n";
         $listLocalIds[$list->getId()] = $localId;
         $localId++;
     }
     $dump .= "\t\t</lists>\n";
     $tasks = $this->user->getTasksByMultipleCriteria();
     $c = new Criteria();
     $c->addJoin(PcTaskPeer::LIST_ID, PcListPeer::ID, Criteria::INNER_JOIN);
     $c->add(PcListPeer::CREATOR_ID, $this->user->getId());
     $c->addDescendingOrderByColumn(PcTaskPeer::LIST_ID);
     $c->addAscendingOrderByColumn(PcTaskPeer::SORT_ORDER);
     $c->addAscendingOrderByColumn(PcTaskPeer::ID);
     $tasks = PcTaskPeer::doSelect($c);
     $dump .= "\t\t<tasks>\n";
     $localId = 1;
     foreach ($tasks as $task) {
         $taskIsStarred = $task->getIsStarred() ? 1 : 0;
         $taskIsCompleted = $task->getIsCompleted() ? 1 : 0;
         $taskIsHeader = $task->getIsHeader() ? 1 : 0;
         $taskIsFromSystem = $task->getIsFromSystem() ? 1 : 0;
         $taskListId = $task->getListId();
         $taskListLocalId = $listLocalIds[$task->getListId()];
         $taskTagIds = $task->getContexts();
         // comma separated list of tagIds
         $taskTagIdsArray = PcUtils::explodeWithEmptyInputDetection(',', $taskTagIds);
         $taskTagLocalIdsArray = array();
         foreach ($taskTagIdsArray as $id) {
             $taskTagLocalIdsArray[] = $tagLocalIds[$id];
         }
         $taskTagLocalIds = implode(',', $taskTagLocalIdsArray);
         $dump .= "\t\t\t<task>\n";
         $dump .= "\t\t\t\t<id>{$task->getId()}</id>\n";
         $dump .= "\t\t\t\t<localId>{$localId}</localId>\n";
         $dump .= "\t\t\t\t<listName><![CDATA[{$task->getList()->getTitle()}]]></listName>\n";
         $dump .= "\t\t\t\t<listLocalId>{$taskListLocalId}</listLocalId>\n";
         $dump .= "\t\t\t\t<description><![CDATA[{$task->getDescription()}]]></description>\n";
         $dump .= "\t\t\t\t<sortOrder>{$list->getSortOrder()}</sortOrder>\n";
         $dump .= "\t\t\t\t<dueDate>{$task->getDueDate()}</dueDate>\n";
         $dump .= "\t\t\t\t<dueTime>{$task->getDueTime()}</dueTime>\n";
         $dump .= "\t\t\t\t<repetitionId>{$task->getRepetitionId()}</repetitionId>\n";
         $dump .= "\t\t\t\t<repetitionParam>{$task->getRepetitionParam()}</repetitionParam>\n";
         $dump .= "\t\t\t\t<isStarred>{$taskIsStarred}</isStarred>\n";
         $dump .= "\t\t\t\t<isCompleted>{$taskIsCompleted}</isCompleted>\n";
         $dump .= "\t\t\t\t<isHeader>{$taskIsHeader}</isHeader>\n";
         $dump .= "\t\t\t\t<isFromSystem>{$taskIsFromSystem}</isFromSystem>\n";
         $dump .= "\t\t\t\t<tagLocalIds>{$taskTagLocalIds}</tagLocalIds>\n";
         $dump .= "\t\t\t\t<note><![CDATA[{$task->getNote()}]]></note>\n";
         $dump .= "\t\t\t\t<completedAt>{$task->getCompletedAt()}</completedAt>\n";
         $dump .= "\t\t\t\t<updatedAt>{$task->getUpdatedAt()}</updatedAt>\n";
         $dump .= "\t\t\t\t<createdAt>{$task->getCreatedAt()}</createdAt>\n";
         $dump .= "\t\t\t</task>\n";
         $localId++;
     }
     $dump .= "\t\t</tasks>\n";
     $dump .= "\t</plancake_tasks>\n";
     $dump .= "\t<plancake_notes>\n";
     $c = new Criteria();
     $c->add(PcNotePeer::CREATOR_ID, $this->user->getId(), Criteria::EQUAL);
     $c->addDescendingOrderByColumn(PcNotePeer::ID);
     $notes = PcNotePeer::doSelect($c);
     $dump .= "\t\t<notes>\n";
     $localId = 1;
     foreach ($notes as $note) {
         $dump .= "\t\t\t<note>\n";
         $dump .= "\t\t\t\t<localId>{$localId}</localId>\n";
         $dump .= "\t\t\t\t<id>{$note->getId()}</id>\n";
         $dump .= "\t\t\t\t<title><![CDATA[{$note->getTitle()}]]></title>\n";
         $dump .= "\t\t\t\t<content><![CDATA[{$note->getContent()}]]></content>\n";
         $dump .= "\t\t\t\t<updatedAt>{$note->getUpdatedAt()}</updatedAt>\n";
         $dump .= "\t\t\t\t<createdAt>{$note->getCreatedAt()}</createdAt>\n";
         $dump .= "\t\t\t</note>\n";
         $localId++;
     }
     $dump .= "\t\t</notes>\n";
     $dump .= "\t</plancake_notes>";
     $dump .= "\n" . '</backup>';
     return $dump;
 }
 /**
  * Returns the number of related PcUsersContexts objects.
  *
  * @param      Criteria $criteria
  * @param      boolean $distinct
  * @param      PropelPDO $con
  * @return     int Count of related PcUsersContexts objects.
  * @throws     PropelException
  */
 public function countPcUsersContextss(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
 {
     if ($criteria === null) {
         $criteria = new Criteria(PcUserPeer::DATABASE_NAME);
     } else {
         $criteria = clone $criteria;
     }
     if ($distinct) {
         $criteria->setDistinct();
     }
     $count = null;
     if ($this->collPcUsersContextss === null) {
         if ($this->isNew()) {
             $count = 0;
         } else {
             $criteria->add(PcUsersContextsPeer::USER_ID, $this->id);
             $count = PcUsersContextsPeer::doCount($criteria, false, $con);
         }
     } else {
         // criteria has no effect for a new object
         if (!$this->isNew()) {
             // the following code is to determine if a new query is
             // called for.  If the criteria is the same as the last
             // one, just return count of the collection.
             $criteria->add(PcUsersContextsPeer::USER_ID, $this->id);
             if (!isset($this->lastPcUsersContextsCriteria) || !$this->lastPcUsersContextsCriteria->equals($criteria)) {
                 $count = PcUsersContextsPeer::doCount($criteria, false, $con);
             } else {
                 $count = count($this->collPcUsersContextss);
             }
         } else {
             $count = count($this->collPcUsersContextss);
         }
     }
     return $count;
 }
 /**
  * Selects a collection of PcTasksContexts objects pre-filled with all related objects except PcTask.
  *
  * @param      Criteria  $criteria
  * @param      PropelPDO $con
  * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
  * @return     array Array of PcTasksContexts objects.
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function doSelectJoinAllExceptPcTask(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     $criteria = clone $criteria;
     // Set the correct dbName if it has not been overridden
     // $criteria->getDbName() will return the same object if not set to another value
     // so == check is okay and faster
     if ($criteria->getDbName() == Propel::getDefaultDB()) {
         $criteria->setDbName(self::DATABASE_NAME);
     }
     PcTasksContextsPeer::addSelectColumns($criteria);
     $startcol2 = PcTasksContextsPeer::NUM_COLUMNS - PcTasksContextsPeer::NUM_LAZY_LOAD_COLUMNS;
     PcUsersContextsPeer::addSelectColumns($criteria);
     $startcol3 = $startcol2 + (PcUsersContextsPeer::NUM_COLUMNS - PcUsersContextsPeer::NUM_LAZY_LOAD_COLUMNS);
     $criteria->addJoin(PcTasksContextsPeer::USERS_CONTEXTS_ID, PcUsersContextsPeer::ID, $join_behavior);
     // symfony_behaviors behavior
     foreach (sfMixer::getCallables(self::getMixerPreSelectHook(__FUNCTION__)) as $sf_hook) {
         call_user_func($sf_hook, 'BasePcTasksContextsPeer', $criteria, $con);
     }
     $stmt = BasePeer::doSelect($criteria, $con);
     $results = array();
     while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $key1 = PcTasksContextsPeer::getPrimaryKeyHashFromRow($row, 0);
         if (null !== ($obj1 = PcTasksContextsPeer::getInstanceFromPool($key1))) {
             // We no longer rehydrate the object, since this can cause data loss.
             // See http://propel.phpdb.org/trac/ticket/509
             // $obj1->hydrate($row, 0, true); // rehydrate
         } else {
             $cls = PcTasksContextsPeer::getOMClass(false);
             $obj1 = new $cls();
             $obj1->hydrate($row);
             PcTasksContextsPeer::addInstanceToPool($obj1, $key1);
         }
         // if obj1 already loaded
         // Add objects for joined PcUsersContexts rows
         $key2 = PcUsersContextsPeer::getPrimaryKeyHashFromRow($row, $startcol2);
         if ($key2 !== null) {
             $obj2 = PcUsersContextsPeer::getInstanceFromPool($key2);
             if (!$obj2) {
                 $cls = PcUsersContextsPeer::getOMClass(false);
                 $obj2 = new $cls();
                 $obj2->hydrate($row, $startcol2);
                 PcUsersContextsPeer::addInstanceToPool($obj2, $key2);
             }
             // if $obj2 already loaded
             // Add the $obj1 (PcTasksContexts) to the collection in $obj2 (PcUsersContexts)
             $obj2->addPcTasksContexts($obj1);
         }
         // if joined row is not null
         $results[] = $obj1;
     }
     $stmt->closeCursor();
     return $results;
 }
 /**
  * Creates (or edits) a task
  * By default, it sets isFromSystem false. That is because a user may
  * edit a task from the system and make it meaningful to them. The problem
  * is the automatic cleaning up of system tasks would delete it. And this
  * method is used also when editing a task.
  * Repetition expression has got priority on dueDate
  * 
  * @param string $description
  * @param integer $listId (if listId not >0, we will use the user's Inbox)
  * @param integer $taskId (if we are editing an existing task)
  * @param string $contexts (comma separated list of ids)
  * @param boolean $isHeader
  * @param string $note
  * @param string $dueDate (no GMT but user's local date)
  * @param string $dueTime - formatted as an integer, ie: 0753 (no GMT but user's local time)
  * @param integer $repetitionId
  * @param integer $repetitionParam
  * @param integer $taskAboveId - if ($taskAboveId = -100000), that means to put at the end of the list
  * @param string $callerContext - can be either 'ajax' or 'email' or 'gcal'
  * @param string $dueDateFormat - to specify a particular format for parsing the dueDate param
  *               (otherwise the user's date format is used).
  *               Uses the PHP date() format
  * @param boolean $setNextOccurrence (=true)
  * @return     PcTask - the object that has been created
  */
 public static function createOrEdit($description, $listId = 0, $taskId = 0, $contexts = '', $isHeader = false, $note = '', $dueDate = '', $dueTime = '', $isStarred = 0, $repetitionId = 0, $repetitionParam = 0, $taskAboveId = 0, $callerContext = '', $dueDateFormat = '', $setNextOccurrence = true)
 {
     $dueDate = strtolower($dueDate);
     $loggedInUser = PcUserPeer::getLoggedInUser();
     if ($repetitionId < 0) {
         $repetitionId = 0;
     }
     if (!((int) $listId > 0)) {
         // Inserting into the default list: Inbox
         $listId = $loggedInUser->getInbox()->getId();
     }
     $listCreator = PcListPeer::retrieveByPk($listId)->getCreator();
     PcUtils::checkLoggedInUserPermission($listCreator);
     $mode = $taskId ? 'edit' : 'add';
     $task = $mode == 'add' ? new PcTask() : PcTaskPeer::retrieveByPk($taskId);
     if ($mode == 'edit' && !$task->validateOwner($loggedInUser)) {
         throw new sfException('User ' . $loggedInUser->getId() . ' trying to access the task ' . $task->getId() . ' illegitimately');
     }
     list($listIdFromShortcut, $contextIdsFromShortcut, $potentialDueDateExpressionsFromShortcut, $potentialDueTimeExpressionsFromShortcut) = $task->extractInfoFromTaskDescription($description);
     $listId = $listIdFromShortcut > 0 ? $listIdFromShortcut : $listId;
     // if we are here all the contexts (if any) are valid
     if (count($contextIdsFromShortcut)) {
         $task->setContexts(implode(',', $contextIdsFromShortcut));
     } else {
         $userContexts = $loggedInUser->getContextsArray(true);
         $contextIdsFromInput = PcUtils::explodeWithEmptyInputDetection(',', $contexts);
         $validatedContexts = array();
         foreach ($contextIdsFromInput as $cid) {
             $userContext = PcUsersContextsPeer::retrieveByPK($cid);
             if ($userContext) {
                 $validatedContexts[] = array_search(strtolower($userContext->getContext()), $userContexts);
             }
         }
         $task->setContexts(implode(',', $validatedContexts));
     }
     // {{{ START: looking for a contact
     $contactPrefix = 'cid';
     if (strpos($description, $contactPrefix) !== FALSE) {
         if (preg_match('/' . $contactPrefix . '([0-9]+)/', $description, $contactArray)) {
             $description = str_replace($contactArray[0], '', $description);
             // removing the contact bit from the description
             if (is_numeric($contactArray[1])) {
                 $task->setContactId($contactArray[1]);
             }
         }
     }
     // END: looking for a contact }}}
     $task->setDescription($description);
     // it is the actual content of the task
     if ($repetitionId == 34 && !($repetitionParam > 0)) {
         // $repetitionParam should have been > 0!
         $repetitionId = 0;
     }
     $oldRepetitionId = $task->getRepetitionId();
     if ($repetitionId > 0) {
         $task->setRepetitionId($repetitionId);
         $task->setRepetitionParam($repetitionParam);
     } else {
         $task->setRepetitionId(NULL);
         $task->setRepetitionParam(0);
     }
     $changeInRepetitionId = false;
     if ($oldRepetitionId != $task->getRepetitionId()) {
         $changeInRepetitionId = true;
     }
     try {
         $task->setListId($listId);
     } catch (sfException $e) {
         if ($callerContext == 'ajax') {
             die('ERROR: You can\'t insert a task in a header.');
         }
     }
     $task->setIsHeader($isHeader);
     if (!$isHeader) {
         $task->setNote($note);
     } else {
         $task->setDueDate(null);
     }
     $validDueDateExpression = false;
     $unrecognizedShortcuts = array();
     if (count($potentialDueDateExpressionsFromShortcut) && !$isHeader) {
         foreach ($potentialDueDateExpressionsFromShortcut as $potentialDueDateExpressionFromShortcut) {
             $validDueDateExpression = $task->setDueDate($potentialDueDateExpressionFromShortcut);
             if (!$validDueDateExpression) {
                 $unrecognizedShortcuts[] = $potentialDueDateExpressionFromShortcut;
             } else {
                 $validDueDateExpression = true;
                 break;
             }
         }
     }
     if (!$validDueDateExpression && $dueDate && !$isHeader) {
         $validDueDateExpression = $task->setDueDate($dueDate, $dueDateFormat);
     }
     if (!$task->getDueDate()) {
         $task->setDueDate(NULL);
     }
     if ($mode == 'add') {
         $list = $task->getPcList();
         if (!$list) {
             // this should not happen, but just in case...
             $list = $loggedInUser->getInbox();
         }
         if (!$taskAboveId) {
             $maxTasksSortOrder = self::getMaxTasksSortOrder($list);
             $task->setSortOrder($maxTasksSortOrder + 1);
         } else {
             if ($taskAboveId == -100000) {
                 $minTasksSortOrder = self::getMinTasksSortOrder($list);
                 $task->setSortOrder($minTasksSortOrder - 1);
             } else {
                 $maxTasksSortOrder = self::getMaxTasksSortOrder($list);
                 // they are inserting the new task below an old one
                 // I need to insert the new task after the task whose id is beforeListId
                 $allTasks = $list->getIncompletedTasks();
                 // the tasks are returned with sortOrder descending order
                 // and the tasks are displayed with the greatest sortOrder on top
                 $newSortOrder = $maxTasksSortOrder;
                 foreach ($allTasks as $oneOfTheOtherTasks) {
                     $delta = 1;
                     if ($oneOfTheOtherTasks->getId() == $taskAboveId) {
                         $task->setSortOrder($newSortOrder - 1);
                         $delta++;
                     }
                     $oneOfTheOtherTasks->setSortOrder($newSortOrder);
                     $oneOfTheOtherTasks->save();
                     $newSortOrder -= $delta;
                 }
             }
         }
     }
     if (count($unrecognizedShortcuts)) {
         if ($callerContext == 'ajax') {
             die("ERROR: {$unrecognizedShortcuts[0]} is not a tag neither a valid due date/time expression.");
         }
     }
     if ($potentialDueTimeExpressionsFromShortcut && $callerContext == 'ajax') {
         if (!$potentialDueTimeExpressionsFromShortcut->isValid()) {
             die("ERROR: the due time shortcut is not valid.");
         }
     }
     if ($dueTime || $potentialDueTimeExpressionsFromShortcut) {
         // it doesn't make sense to set a time if a date is not specified
         if ($task->getDueDate() || $task->getRepetitionId()) {
             if ($dueTime) {
                 $task->setDueTime($dueTime);
             } else {
                 $task->setDueTime($potentialDueTimeExpressionsFromShortcut->getIntegerValue());
             }
         } else {
             if ($callerContext == 'ajax') {
                 die('ERROR: You can\'t set a due time without a due date.');
             } else {
                 // if the user tried to insert a due time shortcuts but we couldn't take
                 // that value because there is no due date, we put the due time back in
                 // the description
                 if ($potentialDueTimeExpressionsFromShortcut) {
                     $descriptionWithDueTimeEmbedded = $task->getDescription() . ' @' . $potentialDueTimeExpressionsFromShortcut->getHumanFriendlyTime($loggedInUser);
                     $task->setDescription($descriptionWithDueTimeEmbedded);
                 }
             }
         }
     } else {
         $task->setDueTime(null);
     }
     if (!$task->isHeader()) {
         $task->setStarred((bool) $isStarred);
     }
     $task->save();
     if ($task->getRepetitionId() && $setNextOccurrence) {
         $task->setNextOccurrence(true);
         // N.B.: this saves the object!!!!!!!
     }
     // we need to do this operation here because we need the object
     // saved in the db to be able to refer to it via its ID
     $task->alignTasksContextsTable();
     // {{{
     // this is to fix a bug:
     // long task descriptions were cut (because of database schema contraint)
     // without a clear feedback on the user interface (Javascript was
     // inserting the whole string sent via AJAX)
     $task = PcTaskPeer::retrieveByPK($task->getId());
     // }}}
     // This is VERY IMPRTANT because a user may
     // edit a task from the system and make it meaningful to them. The problem
     // is the automatic cleaning up of system tasks would delete it. And this
     // method is used also when editing a task.
     $task->setIsFromSystem(false);
     if ($loggedInUser->hasGoogleCalendarIntegrationActive()) {
         if ($callerContext != 'gcal') {
             $gcal = new GoogleCalendarInterface($loggedInUser);
             $gcal->init();
             $gcal->createOrUpdateEvent($task);
         }
     }
     return $task;
 }
 /**
  * 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 = PcUsersContextsPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setUserId($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setContext($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setSortOrder($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setUpdatedAt($arr[$keys[4]]);
     }
     if (array_key_exists($keys[5], $arr)) {
         $this->setCreatedAt($arr[$keys[5]]);
     }
 }
Beispiel #10
0
 public function import($xml)
 {
     $originalMaxExecutionTime = ini_get('max_execution_time');
     ini_set('max_execution_time', 120);
     proc_nice(1);
     $tagLocalIds = array();
     $listLocalIds = array();
     $newTagIds = array();
     $newListIds = array();
     $newTaskIds = array();
     $newNoteIds = array();
     $tags = $xml->plancake_tasks->tags->tag;
     foreach ($tags as $tag) {
         $isNewTag = false;
         $tagId = (int) $tag->id > 0 ? $tag->id : null;
         $tagLocalId = (int) $tag->localId;
         $tagName = (string) $tag->name;
         $tagSortOrder = (int) $tag->sortOrder;
         $tagObj = null;
         if ($tagId && !in_array($tagId, $newTagIds)) {
             $tagObj = PcUsersContextsPeer::retrieveByPK($tagId);
         }
         if ($tagObj) {
             if ($tagObj->getUserId() != $this->user->getId()) {
                 die("Hacking attempt.");
             }
         } else {
             // tags are unique by name, thus
             // we check whether the tag is already in the instance
             // we are importing the dump to.
             $c = new Criteria();
             $c->add(PcUsersContextsPeer::CONTEXT, $tagName);
             $tagObj = PcUsersContextsPeer::doSelectOne($c);
             if (!is_object($tagObj)) {
                 $tagObj = new PcUsersContexts();
                 $isNewTag = true;
             }
         }
         $tagObj->setUserId($this->user->getId())->setContext($tagName)->setSortOrder($tagSortOrder)->save();
         $tagLocalIds[$tagLocalId] = $tagObj->getId();
         if ($isNewTag) {
             $newTagIds[] = $tagObj->getId();
         }
     }
     $lists = $xml->plancake_tasks->lists->list;
     foreach ($lists as $list) {
         $isNewList = false;
         $listId = (int) $list->id > 0 ? $list->id : null;
         $listLocalId = (int) $list->localId;
         $listName = (string) $list->name;
         $listSortOrder = (int) $list->sortOrder;
         $listIsInbox = (int) $list->isInbox == 1 ? true : false;
         $listIsTodo = (int) $list->isTodo == 1 ? true : false;
         $listIsHeader = (int) $list->isHeader == 1 ? true : false;
         $listObj = null;
         if ($listId && !in_array($listId, $newListIds)) {
             $listObj = PcListPeer::retrieveByPK($listId);
         }
         if ($listObj) {
             if ($listObj->getCreatorId() != $this->user->getId()) {
                 die("Hacking attempt.");
             }
         } else {
             if ($listIsInbox) {
                 $listObj = $this->user->getInbox();
             } else {
                 if ($listIsTodo) {
                     $listObj = $this->user->getTodo();
                 } else {
                     $listObj = new PcList();
                     $isNewList = true;
                 }
             }
         }
         $listObj->setCreatorId($this->user->getId())->setTitle($listName)->setSortOrder($listSortOrder)->setIsInbox($listIsInbox)->setIsTodo($listIsTodo)->setIsHeader($listIsHeader)->save();
         $listLocalIds[$listLocalId] = $listObj->getId();
         if ($isNewList) {
             $newListIds[] = $listObj->getId();
         }
     }
     $tasks = $xml->plancake_tasks->tasks->task;
     foreach ($tasks as $task) {
         $isNewTask = false;
         $taskId = (int) $task->id > 0 ? $task->id : 0;
         $taskListLocalId = (int) $task->listLocalId;
         $taskDescription = (string) $task->description;
         $taskSortOrder = (int) $task->sortOrder;
         $taskDueDate = (string) $task->dueDate;
         $taskDueTime = strlen($task->dueTime) > 0 ? (int) $task->dueTime : '';
         $taskRepetitionId = (int) $task->repetitionId;
         $taskRepetitionParam = (int) $task->repetitionParam;
         $taskIsStarred = (int) $task->isStarred == 1 ? true : false;
         $taskIsCompleted = (int) $task->isCompleted == 1 ? true : false;
         $taskIsHeader = (int) $task->isHeader == 1 ? true : false;
         $taskIsFromSystem = (int) $task->isFromSystem == 1 ? true : false;
         $taskTagLocalIds = (string) $task->tagLocalIds;
         $taskNote = (string) $task->note;
         $taskListId = $listLocalIds[$taskListLocalId];
         $taskTagIdsArray = array();
         $taskTagLocalIdsArray = PcUtils::explodeWithEmptyInputDetection(',', $taskTagLocalIds);
         foreach ($taskTagLocalIdsArray as $id) {
             $taskTagIdsArray[] = $tagLocalIds[$id];
         }
         $taskTagIds = '';
         if (count($taskTagIdsArray)) {
             $taskTagIds = implode(',', $taskTagIdsArray);
         }
         $taskFromDb = null;
         if ($taskId && !in_array($taskId, $newTaskIds)) {
             $taskFromDb = PcTaskPeer::retrieveByPK($taskId);
         }
         if (!is_object($taskFromDb)) {
             // if the task doesn't exist (even if the dump contains a taskId)
             // we want to add it.
             $taskId = 0;
             $isNewTask = true;
         }
         $newTask = PcTaskPeer::createOrEdit($taskDescription, $taskListId, $taskId, $taskTagIds, $taskIsHeader, $taskNote, $taskDueDate, $taskDueTime, $taskIsStarred, $taskRepetitionId, $taskRepetitionParam, 0, '', 'd-m-Y', false);
         if ($taskIsCompleted) {
             $newTask->setIsCompleted(1);
             $newTask->setCompletedAt($task->completedAt);
             $newTask->save();
         }
         if ($isNewTask) {
             $newTaskIds[] = $newTask->getId();
         }
         if (!$taskId) {
             $newTask->deleteDirtyEntry();
         }
     }
     $notes = $xml->plancake_notes->notes->note;
     foreach ($notes as $note) {
         $isNewNote = false;
         $noteId = (int) $note->id > 0 ? $note->id : null;
         $noteTitle = (string) $note->title;
         $noteContent = (string) $note->content;
         $noteObj = null;
         if ($noteId && !in_array($noteId, $newNoteIds)) {
             $noteObj = PcNotePeer::retrieveByPK($noteId);
         }
         if ($noteObj) {
             if ($noteObj->getCreatorId() != $this->user->getId()) {
                 die("Hacking attempt.");
             }
         } else {
             $noteObj = new PcNote();
             $isNewNote = true;
         }
         $noteObj->setCreatorId($this->user->getId())->setTitle($noteTitle)->setContent($noteContent)->save();
         if ($isNewNote) {
             $newNoteIds[] = $noteObj->getId();
         }
     }
     ini_set('max_execution_time', $originalMaxExecutionTime);
 }
Beispiel #11
0
 /**
  * Returns an array with all the contexts (the names, not the ids)
  * 
  * @return     array
  */
 public function getContextsArray()
 {
     $contexts = explode(',', $this->getContexts());
     // the variable contains ids
     $contexts = PcUsersContextsPeer::retrieveByPks($contexts);
     $ret = array();
     foreach ($contexts as $context) {
         $ret[] = $context->getContext();
     }
     return $ret;
 }
 /**
  * Get the associated PcUsersContexts object
  *
  * @param      PropelPDO Optional Connection object.
  * @return     PcUsersContexts The associated PcUsersContexts object.
  * @throws     PropelException
  */
 public function getPcUsersContexts(PropelPDO $con = null)
 {
     if ($this->aPcUsersContexts === null && $this->users_contexts_id !== null) {
         $this->aPcUsersContexts = PcUsersContextsPeer::retrieveByPk($this->users_contexts_id);
         /* The following can be used additionally to
         		   guarantee the related object contains a reference
         		   to this object.  This level of coupling may, however, be
         		   undesirable since it could result in an only partially populated collection
         		   in the referenced object.
         		   $this->aPcUsersContexts->addPcTasksContextss($this);
         		 */
     }
     return $this->aPcUsersContexts;
 }
 /**
  * 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(PcUsersContextsPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(PcUsersContextsPeer::DATABASE_NAME);
         $criteria->add(PcUsersContextsPeer::ID, $pks, Criteria::IN);
         $objs = PcUsersContextsPeer::doSelect($criteria, $con);
     }
     return $objs;
 }