From f38e03dc02c96344677fd2720912605b21c90b5d Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sun, 7 Feb 2016 16:52:59 +0100 Subject: Comment work with annotator v2 - add missing annotator.js file and fix typo - edit & delete routes, started tests - basic tests --- .../CommentBundle/Repository/CommentRepository.php | 94 ++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 src/Wallabag/CommentBundle/Repository/CommentRepository.php (limited to 'src/Wallabag/CommentBundle/Repository') diff --git a/src/Wallabag/CommentBundle/Repository/CommentRepository.php b/src/Wallabag/CommentBundle/Repository/CommentRepository.php new file mode 100644 index 00000000..15acffbf --- /dev/null +++ b/src/Wallabag/CommentBundle/Repository/CommentRepository.php @@ -0,0 +1,94 @@ +createQueryBuilder('c') + ->leftJoin('c.user', 'u') + ->andWhere('u.id = :userId')->setParameter('userId', $userId) + ->orderBy('c.id', 'desc') + ; + } + + /** + * Retrieves all comments for a user. + * + * @param int $userId + * + * @return QueryBuilder + */ + public function getBuilderForAllByUser($userId) + { + return $this + ->getBuilderByUser($userId) + ; + } + + /** + * Get comment for this id. + * + * @param int $commentId + * + * @return array + */ + public function findCommentById($commentId) + { + return $this->createQueryBuilder('c') + ->andWhere('c.id = :commentId')->setParameter('commentId', $commentId) + ->getQuery()->getSingleResult() + ; + } + + /** + * Find comments for entry id. + * + * @param int $entryId + * @param int $userId + * + * @return array + */ + public function findCommentsByPageId($entryId, $userId) + { + return $this->createQueryBuilder('c') + ->where('c.entry = :entryId')->setParameter('entryId', $entryId) + ->andwhere('c.user = :userId')->setParameter('userId', $userId) + ->getQuery()->getResult() + ; + } + + /** + * Find last comment for a given entry id. Used only for tests. + * + * @param int $entryId + * + * @return array + */ + public function findLastCommentByPageId($entryId, $userId) + { + return $this->createQueryBuilder('c') + ->where('c.entry = :entryId')->setParameter('entryId', $entryId) + ->andwhere('c.user = :userId')->setParameter('userId', $userId) + ->orderBy('c.id', 'DESC') + ->setMaxResults(1) + ->getQuery() + ->getOneOrNullResult(); + } +} -- cgit v1.2.3