/** * @param sfWebRequest $request * @return application/json data */ public function execute($request) { $con = Propel::getConnection(); $con->beginTransaction(); $html = ''; try { $type = $request->getParameter('type'); $this->forward404Unless($type, 'Comment Type Not Found'); $id = $request->getParameter('id'); $this->forward404Unless($id, 'Comment ID Not Found'); $aComment = CommentQuery::create()->filterByType($type)->filterById($id)->findOne(); $this->forward404Unless($aComment, sprintf('%s Comment Not Found', ucfirst($type))); $this->forward404Unless($aComment->getUserId() == $this->getUser()->getId(), 'Your are not authorized to delete this comment'); // construction of returns array switch ($type) { case CommentPeer::TYPE_BRANCH: $returns = array('id' => $aComment->getBranchId(), 'type' => $type); break; case CommentPeer::TYPE_FILE: $returns = array('id' => $aComment->getFileId(), 'type' => $type); break; } $aComment->delete($con); $html = $this->getComponent('default', 'commentGlobal', $returns); $con->commit(); } catch (Exception $e) { $con->rollBack(); throw $e; } // returns a json object $this->getResponse()->setContentType('application/json'); return $this->renderText(json_encode(array('html' => $html))); }
/** * @param sfWebRequest $request * @return application/json data */ public function execute($request) { $con = Propel::getConnection(); $con->beginTransaction(); $html = ''; try { $id = $request->getParameter('id'); $this->forward404Unless($id, 'Line Comment Id Not Found'); $aComment = CommentQuery::create()->filterByType(CommentPeer::TYPE_LINE)->filterById($id)->findOne(); $this->forward404Unless($aComment, 'Line Comment Not Found'); $this->forward404Unless($aComment->getUserId() == $this->getUser()->getId(), 'Your are not authorized to delete this comment'); $countLineComment = CommentQuery::create()->filterByCommit($aComment->getCommit())->filterByFileId($aComment->getFileId())->filterByPosition($aComment->getPosition())->filterByLine($aComment->getLine())->filterByType(CommentPeer::TYPE_LINE)->count($con); $datas = array('commit' => $aComment->getCommit(), 'file_id' => $aComment->getFileId(), 'position' => $aComment->getPosition(), 'line' => $aComment->getLine(), 'user_id' => $this->getUser()->getId(), 'form_visible' => false); $aComment->delete($con); if ($countLineComment - 1 > 0) { $html = $this->getComponent('default', 'commentLine', $datas); } $con->commit(); } catch (Exception $e) { $con->rollBack(); throw $e; } // returns a json object $this->getResponse()->setContentType('application/json'); return $this->renderText(json_encode(array('html' => $html))); }
/** * @param sfWebRequest $request * @return void */ public function execute($request) { if (null === $this->type) { throw new Exception('Type has not been awarded to the component.'); } if (null === $this->id) { throw new Exception('ID has not been awarded to the component.'); } switch ($this->type) { case CommentPeer::TYPE_BRANCH: // data to be transmitted to the form $dataForm = array('type' => $this->type, 'id' => $this->id); // data to be transmitted to the view $this->commentGlobals = CommentQuery::create()->filterByType($this->type)->filterByBranchId($this->id)->leftJoin('sfGuardUserRelatedByUserId')->find(); break; case CommentPeer::TYPE_FILE: // data to be transmitted to the form $dataForm = array('type' => $this->type, 'id' => $this->id); // data to be transmitted to the view $this->commentGlobals = CommentQuery::create()->filterByType($this->type)->filterByFileId($this->id)->leftJoin('sfGuardUserRelatedByUserId')->find(); break; } $this->userId = $this->getUser()->getId(); $this->form = new CommentGlobalForm(null, $dataForm); }
/** * @param sfWebRequest $request * @return void */ public function execute($request) { // create CommentLineForm $this->form = new CommentLineForm(null, array('commit' => $this->commit, 'file_id' => $this->file_id, 'user_id' => $this->user_id, 'position' => $this->position, 'line' => $this->line, 'type' => CommentPeer::TYPE_LINE)); // retrieves all line comments of this file $fileId $this->comments = CommentQuery::create()->filterByCommit($this->commit)->filterByFileId($this->file_id)->filterByPosition($this->position)->filterByLine($this->line)->leftJoin('sfGuardUserRelatedByUserId')->find(); $this->userId = $this->getUser()->getId(); $this->formVisible = isset($this->form_visible) ? $this->form_visible : true; }
/** * @param sfWebRequest $request * @return void */ public function execute($request) { $id = $request->getParameter('comment_id'); $status = $request->getParameter('status') ? true : false; $this->forward404Unless($id || $status, 'Bad parameters'); $comment = CommentQuery::create()->filterById($id)->findOne(); $this->forward404Unless($comment, sprintf('Comment (%s) not found', $id)); if ($status) { $comment->setCheckUserId($this->getUser()->getId())->setCheckedAt('now')->save(); } else { $comment->setCheckUserId(null)->setCheckedAt(null)->save(); } $this->getResponse()->setContentType('application/json'); return $this->renderText(json_encode(array('id' => $id, 'status' => $status, 'message' => $comment->getCheckMessage()))); }
public function getPaginatedComments(Borrower $borrower, $page, $maxPerPage) { $roots = CommentQuery::create()->filterByBorrowerId($borrower->getId())->filterByLevel(0)->orderById('desc')->paginate($page, $maxPerPage); $comments = CommentQuery::create()->filterByRootId($roots->toKeyValue('id', 'id'))->filterByLevel(['min' => 1])->orderById('asc')->find(); $idToComments = []; foreach ($roots as $root) { $idToComments[$root->getId()] = $root; } foreach ($comments as $comment) { $idToComments[$comment->getId()] = $comment; } foreach ($comments as $comment) { if (!$comment->isRoot()) { $parentComment = $idToComments[$comment->getParentId()]; $parentComment->addChild($comment); } } return $roots; }
public static function getCommentsForBoard($userId = null, $repositoryId = null, $branchId = null) { $board = array(); $commentsQuery = CommentQuery::create(); if (!is_null($userId)) { $commentsQuery->filterByUserId($userId); } if (!is_null($repositoryId)) { $commentsQuery->useBranchQuery()->filterByRepositoryId($repositoryId)->endUse(); } if (!is_null($branchId)) { $commentsQuery->filterByBranchId($branchId); } $comments = $commentsQuery->orderByCreatedAt(Criteria::DESC)->limit(50)->find(); foreach ($comments as $comment) { $board[$comment->getCreatedAt('YmdHisu')] = array('ProjectName' => $comment->getBranch()->getRepository(), 'ProjectId' => $comment->getBranch()->getRepositoryId(), 'UserName' => $comment->getAuthorName(), 'UserId' => $comment->getUserId(), 'UserEmail' => $comment->getsfGuardUserRelatedByUserId()->getProfile()->getEmail(), 'BranchName' => $comment->getBranch(), 'BranchId' => $comment->getBranchId(), 'FileName' => $comment->getFile(), 'FileId' => $comment->getFileId(), 'Position' => $comment->getPosition(), 'Line' => $comment->getLine(), 'Message' => $comment->getValue(), 'CreatedAt' => $comment->getCreatedAt('d/m/Y H:i:s'), 'CheckedBy' => $comment->getCheckUserId()); } krsort($board); return $board; }
/** * @param sfWebRequest $request * @return void */ public function execute($request) { $this->branch = null; if ($request->hasParameter('name') && $request->hasParameter('repository')) { $repository = RepositoryQuery::create()->filterByName($request->getParameter('repository'))->findOne(); $this->forward404Unless($repository, "Repository not found"); $this->branch = BranchQuery::create()->filterByName($request->getParameter('name'))->filterByRepository($repository)->findOne(); // Dirty hack to make the breadcrumb work /!\ if ($this->branch) { $this->redirect('default/fileList?branch=' . $this->branch->getId()); } } elseif ($request->hasParameter('branch')) { $this->branch = BranchPeer::retrieveByPK($request->getParameter('branch')); } $this->forward404Unless($this->branch, "Branch not found"); $this->getResponse()->setTitle($this->branch->getName()); $this->repository = RepositoryPeer::retrieveByPK($this->branch->getRepositoryId()); $this->forward404Unless($this->repository, "Repository not found"); $files = FileQuery::create()->filterByBranchId($this->branch->getId())->find(); $this->files = array(); foreach ($files as $file) { $fileCommentsCount = CommentQuery::create()->filterByFileId($file->getId())->filterByType(CommentPeer::TYPE_FILE)->count(); $fileCommentsCountNotChecked = CommentQuery::create()->filterByFileId($file->getId())->filterByType(CommentPeer::TYPE_FILE)->filterByCheckUserId(null)->count(); $lineCommentsCount = CommentQuery::create()->filterByFileId($file->getId())->filterByCommit($file->getLastChangeCommit())->filterByType(CommentPeer::TYPE_LINE)->count(); $lineCommentsCountNotChecked = CommentQuery::create()->filterByFileId($file->getId())->filterByCommit($file->getLastChangeCommit())->filterByType(CommentPeer::TYPE_LINE)->filterByCheckUserId(null)->count(); $lastCommentId = 0; if ($fileCommentsCount || $lineCommentsCount) { $lastComment = CommentQuery::create()->filterByFileId($file->getId())->filterByCommit($file->getLastChangeCommit())->_or()->filterByType(CommentPeer::TYPE_FILE)->orderById(Criteria::DESC)->findOne(); if ($lastComment) { $lastCommentId = $lastComment->getId(); } } $this->files[] = array_merge($file->toArray(), array('NbFileComments' => $fileCommentsCount + $lineCommentsCount, 'NbFileCommentsNotChecked' => $fileCommentsCountNotChecked + $lineCommentsCountNotChecked, 'LastCommentId' => $lastCommentId)); } usort($this->files, array('self', 'sortPath')); $this->statusActions = StatusActionPeer::getStatusActionsForBoard(null, $this->repository->getId(), $this->branch->getId()); $this->commentBoards = CommentPeer::getCommentsForBoard(null, $this->repository->getId(), $this->branch->getId()); }
/** * @param sfWebRequest $request * @return void */ public function execute($request) { $this->file = FilePeer::retrieveByPK($request->getParameter('file')); $this->forward404Unless($this->file, "File not found"); $this->getResponse()->setTitle(basename($this->file->getFilename())); $this->previousFileId = FileQuery::create()->select('Id')->filterByBranchId($this->file->getBranchId())->filterByFilename($this->file->getFilename(), Criteria::LESS_THAN)->filterByIsBinary(false)->orderByFilename(Criteria::DESC)->findOne(); $this->nextFileId = FileQuery::create()->select('Id')->filterByBranchId($this->file->getBranchId())->filterByFilename($this->file->getFilename(), Criteria::GREATER_THAN)->filterByIsBinary(false)->orderByFilename(Criteria::ASC)->findOne(); $this->branch = BranchPeer::retrieveByPK($this->file->getBranchId()); $this->forward404Unless($this->branch, "Branch not found"); $this->repository = RepositoryPeer::retrieveByPK($this->branch->getRepositoryId()); $this->forward404Unless($this->repository, "Repository not found"); $options = array(); if ($request->getParameter('s', false)) { $options['ignore-all-space'] = true; } $this->fileContentLines = $this->gitCommand->getShowFileFromBranch($this->repository->getGitDir(), $this->branch->getCommitReference(), $this->file->getLastChangeCommit(), $this->file->getFilename(), $options); $fileLineCommentsModel = CommentQuery::create()->filterByFileId($this->file->getId())->filterByCommit($this->file->getLastChangeCommit())->filterByType(CommentPeer::TYPE_LINE)->find(); $this->userId = $this->getUser()->getId(); $this->fileLineComments = array(); foreach ($fileLineCommentsModel as $fileLineCommentModel) { $this->fileLineComments[$fileLineCommentModel->getPosition()][] = $fileLineCommentModel; } }
<?php require_once '../database_access.php'; echo "text"; if (isset($_POST['comment_id'])) { $comment = CommentQuery::create()->findPk($_POST['comment_id']); if ($comment) { $comment->delete(); echo '<p>Successfully deleted comment</p>'; } else { echo "<p>Tried to delete nonexistent comment</p>"; } }
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this sfGuardUser is new, it will return * an empty collection; or if this sfGuardUser has previously * been saved, it will retrieve related CommentsRelatedByCheckUserId from storage. * * This method is protected by default in order to keep the public * api reasonable. You can provide public methods for those you * actually need in sfGuardUser. * * @param Criteria $criteria optional Criteria object to narrow the query * @param PropelPDO $con optional connection object * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN) * @return PropelCollection|array Comment[] List of Comment objects */ public function getCommentsRelatedByCheckUserIdJoinFile($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN) { $query = CommentQuery::create(null, $criteria); $query->joinWith('File', $join_behavior); return $this->getCommentsRelatedByCheckUserId($query, $con); }
public function getMostRecentComment() { return CommentQuery::create()->filterByPost($this)->orderByCreatedAt(Criteria::DESC)->findOne(); }
/** * Removes this object from datastore and sets delete attribute. * * @param PropelPDO $con * @return void * @throws PropelException * @see BaseObject::setDeleted() * @see BaseObject::isDeleted() */ public function delete(PropelPDO $con = null) { if ($this->isDeleted()) { throw new PropelException("This object has already been deleted."); } if ($con === null) { $con = Propel::getConnection(CommentPeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } $con->beginTransaction(); try { $deleteQuery = CommentQuery::create()->filterByPrimaryKey($this->getPrimaryKey()); $ret = $this->preDelete($con); // symfony_behaviors behavior foreach (sfMixer::getCallables('BaseComment:delete:pre') as $callable) { if (call_user_func($callable, $this, $con)) { $con->commit(); return; } } if ($ret) { $deleteQuery->delete($con); $this->postDelete($con); // symfony_behaviors behavior foreach (sfMixer::getCallables('BaseComment:delete:post') as $callable) { call_user_func($callable, $this, $con); } $con->commit(); $this->setDeleted(true); } else { $con->commit(); } } catch (Exception $e) { $con->rollBack(); throw $e; } }