2016-03-16 19:03:08 +00:00
|
|
|
<?php
|
|
|
|
|
2016-03-23 16:59:06 +00:00
|
|
|
namespace Skobkin\Bundle\PointToolsBundle\Repository\Blogs;
|
2016-03-16 19:03:08 +00:00
|
|
|
|
|
|
|
use Doctrine\ORM\EntityRepository;
|
2016-03-29 04:11:12 +00:00
|
|
|
use Doctrine\ORM\QueryBuilder;
|
2017-01-11 16:17:52 +00:00
|
|
|
use Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Post;
|
2016-03-16 19:03:08 +00:00
|
|
|
|
|
|
|
class PostRepository extends EntityRepository
|
|
|
|
{
|
2017-01-11 16:17:52 +00:00
|
|
|
public function add(Post $entity)
|
|
|
|
{
|
|
|
|
$this->getEntityManager()->persist($entity);
|
|
|
|
}
|
|
|
|
|
2016-03-29 04:11:12 +00:00
|
|
|
public function getPostWithComments($postId)
|
|
|
|
{
|
|
|
|
/** @var QueryBuilder $qb */
|
|
|
|
$qb = $this->createQueryBuilder('p');
|
|
|
|
return $qb
|
|
|
|
->select(['p', 'c', 'a'])
|
|
|
|
->leftJoin('p.comments', 'c')
|
|
|
|
->leftJoin('c.author', 'a')
|
|
|
|
->where($qb->expr()->eq('p.id', ':post_id'))
|
2016-03-29 06:52:21 +00:00
|
|
|
->orderBy('c.number', 'asc')
|
2016-03-29 04:11:12 +00:00
|
|
|
->setParameter('post_id', $postId)
|
|
|
|
->getQuery()->getOneOrNullResult()
|
|
|
|
;
|
|
|
|
}
|
2016-03-16 19:03:08 +00:00
|
|
|
}
|