コード例 #1
0
 /**
  * @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)));
 }
コード例 #2
0
 /**
  * @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)));
 }
コード例 #3
0
 /**
  * @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);
 }
コード例 #4
0
 /**
  * @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;
 }
コード例 #5
0
 /**
  * @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())));
 }
コード例 #6
0
ファイル: CommentService.php プロジェクト: Junyue/zidisha2
 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;
 }
コード例 #7
0
ファイル: CommentPeer.php プロジェクト: ratibus/Crew
 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;
 }
コード例 #8
0
ファイル: fileListAction.class.php プロジェクト: ratibus/Crew
 /**
  * @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());
 }
コード例 #9
0
ファイル: fileAction.class.php プロジェクト: ratibus/Crew
 /**
  * @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;
     }
 }
コード例 #10
0
ファイル: BaseCommentQuery.php プロジェクト: ratibus/Crew
 /**
  * Returns a new CommentQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param     Criteria $criteria Optional Criteria to build the query from
  *
  * @return    CommentQuery
  */
 public static function create($modelAlias = null, $criteria = null)
 {
     if ($criteria instanceof CommentQuery) {
         return $criteria;
     }
     $query = new CommentQuery();
     if (null !== $modelAlias) {
         $query->setModelAlias($modelAlias);
     }
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
コード例 #11
0
<?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>";
    }
}
コード例 #12
0
ファイル: BasesfGuardUser.php プロジェクト: ratibus/Crew
 /**
  * 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);
 }
コード例 #13
0
ファイル: Post.php プロジェクト: motin/php-orm-benchmark
 public function getMostRecentComment()
 {
     return CommentQuery::create()->filterByPost($this)->orderByCreatedAt(Criteria::DESC)->findOne();
 }
コード例 #14
0
<?php

require_once '../database_access.php';
$q = new CommentQuery();
$q->join("Comment.Author")->withColumn("Author.first_name", 'authorFirstName')->withColumn("Author.last_name", 'authorLastName');
if (isset($_GET['event_id'])) {
    $event = EventQuery::create()->findPk($_GET['event_id']);
    if ($event) {
        $q->filterByTarget_Event($event);
    } else {
        // TODO: throw error instead of blank page
        echo "<p>tried to filter by nonexistent event</p>";
    }
}
echo $q->find()->toJson();
コード例 #15
0
ファイル: BaseComment.php プロジェクト: ratibus/Crew
 /**
  * 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;
     }
 }