FOSElasticaBundle/Subscriber/PaginateElasticaQuerySubscriber.php
Jeremy Mikola 440c36f537 Merge remote-tracking branch 'cevou/master' into pr/245
Conflicts:
	Command/PopulateCommand.php
	Command/SearchCommand.php
	DependencyInjection/Configuration.php
	Doctrine/AbstractElasticaToModelTransformer.php
	Doctrine/AbstractListener.php
	Doctrine/MongoDB/ElasticaToModelTransformer.php
	Doctrine/ORM/ElasticaToModelTransformer.php
	Doctrine/RepositoryManager.php
	Finder/TransformedFinder.php
	Paginator/PaginatorAdapterInterface.php
	Paginator/RawPaginatorAdapter.php
	Persister/ObjectPersister.php
	Propel/ElasticaToModelTransformer.php
	Subscriber/PaginateElasticaQuerySubscriber.php
	Tests/DataCollector/ElasticaDataCollectorTest.php
	Tests/Doctrine/AbstractProviderTest.php
	Tests/Doctrine/RepositoryManagerTest.php
	Tests/Manager/RepositoryManagerTest.php
	Tests/RepositoryTest.php
	Transformer/ElasticaToModelTransformerCollection.php
	composer.json
2013-03-27 14:58:34 -04:00

35 lines
1.1 KiB
PHP

<?php
namespace FOS\ElasticaBundle\Subscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Knp\Component\Pager\Event\ItemsEvent;
use FOS\ElasticaBundle\Paginator\PaginatorAdapterInterface;
use FOS\ElasticaBundle\Paginator\PartialResultsInterface;
class PaginateElasticaQuerySubscriber implements EventSubscriberInterface
{
public function items(ItemsEvent $event)
{
if ($event->target instanceof PaginatorAdapterInterface) {
/** @var $results PartialResultsInterface */
$results = $event->target->getResults($event->getOffset(), $event->getLimit());
$event->count = $results->getTotalHits();
$event->items = $results->toArray();
$facets = $results->getFacets();
if (null != $facets) {
$event->setCustomPaginationParameter('facets', $facets);
}
$event->stopPropagation();
}
}
public static function getSubscribedEvents()
{
return array(
'knp_pager.items' => array('items', 1)
);
}
}