コード例 #1
0
 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();
         }
     }
 }
コード例 #2
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();
 }
コード例 #3
0
 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();
 }
コード例 #4
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();
 }
コード例 #5
0
 public function executeDelete(sfWebRequest $request)
 {
     $noteLabel = $request->getParameter('noteLabel');
     $noteLabelInfo = explode('_', $noteLabel);
     $note = PcNotePeer::retrieveByPk($noteLabelInfo[1]);
     PcUtils::checkLoggedInUserPermission($note->getCreator());
     $note->delete();
     if ($request->isXmlHttpRequest()) {
         return sfView::NONE;
     }
 }
コード例 #6
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;
 }
コード例 #7
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;
 }
コード例 #8
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();
 }