Exemplo n.º 1
0
 public function executeReorder(sfWebRequest $request)
 {
     $taskIds = $request->getParameter('task_panel1');
     if (!$taskIds) {
         $taskIds = $request->getParameter('task_panel2');
     }
     $task = null;
     $taskIds = array_reverse($taskIds);
     $i = 1;
     foreach ($taskIds as $taskId) {
         // the action actually could have been deleted via AJAX
         if ($task = PcTaskPeer::retrieveByPk($taskId)) {
             PcUtils::checkLoggedInUserPermission($task->getList()->getCreator());
             $task->setSortOrder($i);
             $task->save();
             $i++;
         }
     }
     return $this->renderDefault();
 }
Exemplo n.º 2
0
 /**
  * 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);
         /* 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->aPcTask->addPcDirtyTasks($this);
         		 */
     }
     return $this->aPcTask;
 }
Exemplo n.º 3
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.º 4
0
 public function executeEdit(sfWebRequest $request)
 {
     $allowedOps = array('delete', 'edit');
     $op = $request->getParameter('op');
     if (!in_array($op, $allowedOps)) {
         return false;
     }
     $taskId = (int) $request->getParameter('taskId');
     $task = PcTaskPeer::retrieveByPk($taskId);
     if (!is_object($task)) {
         die("ERROR: " . __('ACCOUNT_ERROR_ERROR_OCCURRED_PLEASE_RETRY'));
     }
     PcUtils::checkLoggedInUserPermission($task->getList()->getCreator());
     if ($op == "delete") {
         $task->delete();
         return $this->renderDefault();
     }
     if ($op == "edit") {
         // the 'add' action will manage also the edit action
         return $this->executeAdd($request);
     }
     return sfView::NONE;
 }
 /**
  * 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;
 }