| @@ 47-66 (lines=20) @@ | ||
| 44 | /** |
|
| 45 | * @return Comment[] |
|
| 46 | */ |
|
| 47 | public function findAllByPostId( |
|
| 48 | PostId $postId, |
|
| 49 | array $orderByList = ['publishedAt' => 'DESC'], |
|
| 50 | int $maxResults = null |
|
| 51 | ): ResultCollectionInterface { |
|
| 52 | $this->dqlQueryBuilder->create(Comment::class); |
|
| 53 | ||
| 54 | $this->dqlQueryBuilder->where('Comment.post = :post') |
|
| 55 | ->setParameter('post', $postId); |
|
| 56 | ||
| 57 | foreach ($orderByList as $property => $direction) { |
|
| 58 | $this->dqlQueryBuilder->orderBy('Comment.' . $property, $direction); |
|
| 59 | } |
|
| 60 | ||
| 61 | if ($maxResults) { |
|
| 62 | $this->dqlQueryBuilder->setMaxResults($maxResults); |
|
| 63 | } |
|
| 64 | ||
| 65 | return $this->queryService->query($this->dqlQueryBuilder->build()); |
|
| 66 | } |
|
| 67 | } |
|
| 68 | ||
| @@ 85-104 (lines=20) @@ | ||
| 82 | /** |
|
| 83 | * @return Post[] |
|
| 84 | */ |
|
| 85 | public function findAllByUserId( |
|
| 86 | UserId $userId, |
|
| 87 | array $orderByList = ['publishedAt' => 'DESC'], |
|
| 88 | int $maxResults = null |
|
| 89 | ): ResultCollectionInterface { |
|
| 90 | $this->dqlQueryBuilder->create(Post::class); |
|
| 91 | ||
| 92 | $this->dqlQueryBuilder->where('Post.authorId = :user') |
|
| 93 | ->setParameter('user', $userId); |
|
| 94 | ||
| 95 | foreach ($orderByList as $property => $direction) { |
|
| 96 | $this->dqlQueryBuilder->orderBy('Post.' . $property, $direction); |
|
| 97 | } |
|
| 98 | ||
| 99 | if ($maxResults) { |
|
| 100 | $this->dqlQueryBuilder->setMaxResults($maxResults); |
|
| 101 | } |
|
| 102 | ||
| 103 | return $this->queryService->query($this->dqlQueryBuilder->build()); |
|
| 104 | } |
|
| 105 | ||
| 106 | public function find(PostId $id): Post |
|
| 107 | { |
|