protected function configureShowField(ShowMapper $showMapper)
{
$showMapper
->with('Checkout Details')
->add('created')
->add('amount')
->add('gateway.name')
->end()
->with('Consumer Details')
->add('consumer.id', null, array('label' => 'User ID'))
->add('consumer.username', null, array('label' => 'User Name'))
->end()
->with('Last Checkouts')
->add('last_checkouts', 'entity', array(
'class' => 'VendorMyBundle:Checkout',
'query_builder' => function(EntityRepository $er) {
// how to query to fetch last 10 checkout requests for the current consumer.id ???
},
'template' => 'VendorMyBundle:CRUD:last_checkouts.html.twig'
))
->end()
;
}
and I would like to make a custom query to fetch last 10 checkout request for the same user.
could anyone let me know how can I fetch the data and display it in Twig template?
first, you need the actual consumer id, with something like this:$consumer_id = $this->getSubject()->getId();
$consumer_id = $this->getSubject()->getConsumer()->getId();
protected function configureShowField(ShowMapper $showMapper)
{
$consumer_id = $this->getSubject()->getConsumer()->getId();
$showMapper
->with('Checkout Details')
->add('created')
->add('amount')
->add('gateway.name')
->end()
->with('Consumer Details')
->add('consumer.id', null, array('label' => 'User ID'))
->add('consumer.username', null, array('label' => 'User Name'))
->end()
->with('Last Checkouts')
->add('last_checkouts', 'entity', array(
'class' => 'VendorMyBundle:Checkout',
'query_builder' => function (EntityRepository $er) use ($consumer_id) {
$queryBuilder = $er->createQueryBuilder('cr');
$queryBuilder
->where('consumer = :consumer_id')
->orderBy('created', 'DESC')
->limit(10)
->setParameter(':consumer_id', $consumer_id);
return $queryBuilder;
},
'template' => 'VendorMyBundle:CRUD:last_checkouts.html.twig'))
->end();
}