PostRepository getPostWithComments() method added. PostController#showAction() now uses it.
This commit is contained in:
parent
cf08978c58
commit
0ceaf43ff3
|
@ -20,8 +20,7 @@ class PostController extends Controller
|
||||||
$userApi = $this->container->get('skobkin_point_tools.api_user');
|
$userApi = $this->container->get('skobkin_point_tools.api_user');
|
||||||
|
|
||||||
return $this->render('SkobkinPointToolsBundle:Post:show.html.twig', [
|
return $this->render('SkobkinPointToolsBundle:Post:show.html.twig', [
|
||||||
'post' => $post,
|
'post' => $this->getDoctrine()->getRepository('SkobkinPointToolsBundle:Blogs\Post')->getPostWithComments($post->getId()),
|
||||||
'avatar_url' => $userApi->getAvatarUrl($post->getAuthor(), UserApi::AVATAR_SIZE_LARGE),
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,21 @@
|
||||||
namespace Skobkin\Bundle\PointToolsBundle\Repository\Blogs;
|
namespace Skobkin\Bundle\PointToolsBundle\Repository\Blogs;
|
||||||
|
|
||||||
use Doctrine\ORM\EntityRepository;
|
use Doctrine\ORM\EntityRepository;
|
||||||
|
use Doctrine\ORM\QueryBuilder;
|
||||||
|
|
||||||
class PostRepository extends EntityRepository
|
class PostRepository extends EntityRepository
|
||||||
{
|
{
|
||||||
|
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'))
|
||||||
|
->setParameter('post_id', $postId)
|
||||||
|
->getQuery()->getOneOrNullResult()
|
||||||
|
;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue