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(); }
/** * 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; }