Exemplo n.º 1
0
 public function executeReorder(sfWebRequest $request)
 {
     $listIds = $request->getParameter('list');
     $i = 1;
     foreach ($listIds as $listId) {
         $list = PcListPeer::retrieveByPK($listId);
         PcUtils::checkLoggedInUserPermission($list->getCreator());
         $list->setSortOrder($i)->save();
         $i++;
     }
     return $this->renderDefault();
 }
Exemplo n.º 2
0
 public function executeEdit(sfWebRequest $request)
 {
     $allowedOps = array('delete', 'edit', 'add');
     $op = $request->getParameter('op');
     if (!in_array($op, $allowedOps)) {
         return false;
     }
     if ($op == 'add') {
         return $this->executeAdd($request);
     }
     $listId = $request->getParameter('listId');
     $list = PcListPeer::retrieveByPk($listId);
     if ($list && $op == 'delete') {
         $creator = $list->getCreator();
         PcUtils::checkLoggedInUserPermission($creator);
         if ($list->isSystem()) {
             die("ERROR: " . __('ACCOUNT_ERROR_CANT_EDIT_SYSTEM_LIST'));
         }
         $list->delete();
         return $this->renderDefault();
     }
     if ($op == 'edit') {
         $creator = $list->getCreator();
         PcUtils::checkLoggedInUserPermission($creator);
         if ($list->isInbox()) {
             die("ERROR: " . __('ACCOUNT_ERROR_CANT_EDIT_SYSTEM_LIST'));
         }
         $newTitle = $request->getParameter('listTitle');
         $isHeader = $request->getParameter('isHeader') ? $request->getParameter('isHeader') : 0;
         $isHeader = (bool) $isHeader;
         $list->setTitle($newTitle);
         $list->setIsHeader($isHeader);
         $list->save();
         $ret = array('id' => $list->getId(), 'name' => $list->getTitle(), 'isHeader' => (int) $list->isHeader());
         return $this->renderJson($ret);
     }
     return $this->renderDefault();
 }
Exemplo n.º 3
0
 /**
  * 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(PcListPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(PcListPeer::DATABASE_NAME);
         $criteria->add(PcListPeer::ID, $pks, Criteria::IN);
         $objs = PcListPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
Exemplo n.º 4
0
 /**
  * Get the associated PcList object
  *
  * @param      PropelPDO Optional Connection object.
  * @return     PcList The associated PcList object.
  * @throws     PropelException
  */
 public function getPcList(PropelPDO $con = null)
 {
     if ($this->aPcList === null && $this->list_id !== null) {
         $this->aPcList = PcListPeer::retrieveByPk($this->list_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->aPcList->addPcTasks($this);
         		 */
     }
     return $this->aPcList;
 }
Exemplo n.º 5
0
 /**
  * @return PcList
  */
 public function getTodo()
 {
     $criteria = new Criteria();
     $criteria->add(PcListPeer::CREATOR_ID, $this->getId(), Criteria::EQUAL);
     $criteria->add(PcListPeer::IS_TODO, 1, Criteria::EQUAL);
     return PcListPeer::doSelectOne($criteria);
 }
Exemplo n.º 6
0
 /**
  * @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;
 }
Exemplo n.º 7
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();
     }
 }
Exemplo n.º 8
0
 /**
  * Selects a collection of PcTask objects pre-filled with all related objects except PcRepetition.
  *
  * @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 PcTask objects.
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function doSelectJoinAllExceptPcRepetition(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);
     }
     PcTaskPeer::addSelectColumns($criteria);
     $startcol2 = PcTaskPeer::NUM_COLUMNS - PcTaskPeer::NUM_LAZY_LOAD_COLUMNS;
     PcListPeer::addSelectColumns($criteria);
     $startcol3 = $startcol2 + (PcListPeer::NUM_COLUMNS - PcListPeer::NUM_LAZY_LOAD_COLUMNS);
     $criteria->addJoin(PcTaskPeer::LIST_ID, PcListPeer::ID, $join_behavior);
     // symfony_behaviors behavior
     foreach (sfMixer::getCallables(self::getMixerPreSelectHook(__FUNCTION__)) as $sf_hook) {
         call_user_func($sf_hook, 'BasePcTaskPeer', $criteria, $con);
     }
     $stmt = BasePeer::doSelect($criteria, $con);
     $results = array();
     while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $key1 = PcTaskPeer::getPrimaryKeyHashFromRow($row, 0);
         if (null !== ($obj1 = PcTaskPeer::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 = PcTaskPeer::getOMClass(false);
             $obj1 = new $cls();
             $obj1->hydrate($row);
             PcTaskPeer::addInstanceToPool($obj1, $key1);
         }
         // if obj1 already loaded
         // Add objects for joined PcList rows
         $key2 = PcListPeer::getPrimaryKeyHashFromRow($row, $startcol2);
         if ($key2 !== null) {
             $obj2 = PcListPeer::getInstanceFromPool($key2);
             if (!$obj2) {
                 $cls = PcListPeer::getOMClass(false);
                 $obj2 = new $cls();
                 $obj2->hydrate($row, $startcol2);
                 PcListPeer::addInstanceToPool($obj2, $key2);
             }
             // if $obj2 already loaded
             // Add the $obj1 (PcTask) to the collection in $obj2 (PcList)
             $obj2->addPcTask($obj1);
         }
         // if joined row is not null
         $results[] = $obj1;
     }
     $stmt->closeCursor();
     return $results;
 }
Exemplo n.º 9
0
 /**
  * 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 = PcListPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setCreatorId($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setTitle($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setSortOrder($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setIsHeader($arr[$keys[4]]);
     }
     if (array_key_exists($keys[5], $arr)) {
         $this->setIsInbox($arr[$keys[5]]);
     }
     if (array_key_exists($keys[6], $arr)) {
         $this->setIsTodo($arr[$keys[6]]);
     }
     if (array_key_exists($keys[7], $arr)) {
         $this->setUpdatedAt($arr[$keys[7]]);
     }
     if (array_key_exists($keys[8], $arr)) {
         $this->setCreatedAt($arr[$keys[8]]);
     }
 }
Exemplo n.º 10
0
 /**
  * Returns the header of the list (if any)
  * 
  * @return     string
  */
 public function getHeaderTitle()
 {
     if ($this->isSystem()) {
         return '';
     }
     if ($this->isHeader()) {
         return '';
     }
     $sortOrder = $this->getSortOrder();
     $c = new Criteria();
     $c->add(PcListPeer::SORT_ORDER, $sortOrder, Criteria::GREATER_THAN);
     $c->add(PcListPeer::IS_HEADER, 1, Criteria::EQUAL);
     $c->add(PcListPeer::CREATOR_ID, $this->getCreatorId(), Criteria::EQUAL);
     $header = PcListPeer::doSelectOne($c);
     return is_object($header) ? $header->getTitle() : '';
 }
Exemplo n.º 11
0
 /**
  * Returns the number of related PcList objects.
  *
  * @param      Criteria $criteria
  * @param      boolean $distinct
  * @param      PropelPDO $con
  * @return     int Count of related PcList objects.
  * @throws     PropelException
  */
 public function countPcLists(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->collPcLists === null) {
         if ($this->isNew()) {
             $count = 0;
         } else {
             $criteria->add(PcListPeer::CREATOR_ID, $this->id);
             $count = PcListPeer::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(PcListPeer::CREATOR_ID, $this->id);
             if (!isset($this->lastPcListCriteria) || !$this->lastPcListCriteria->equals($criteria)) {
                 $count = PcListPeer::doCount($criteria, false, $con);
             } else {
                 $count = count($this->collPcLists);
             }
         } else {
             $count = count($this->collPcLists);
         }
     }
     return $count;
 }
Exemplo n.º 12
0
 /**
  * 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;
 }
Exemplo n.º 13
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);
 }
Exemplo n.º 14
0
 /**
  * Returns whether the user is the correct owner of the task
  *
  * @param PcUser $user
  * @return bool
  */
 public function validateOwner(PcUser $user)
 {
     $list = PcListPeer::retrieveByPK($this->getListId());
     return $list->getCreatorId() == $user->getId();
 }