2011-04-15 01:23:10 +02:00
|
|
|
<?php
|
|
|
|
|
2011-05-10 02:52:06 +02:00
|
|
|
namespace FOQ\ElasticaBundle\Paginator;
|
2011-04-15 01:23:10 +02:00
|
|
|
|
2011-04-27 09:59:04 +02:00
|
|
|
use FOQ\ElasticaBundle\Transformer\ElasticaToModelTransformerInterface;
|
2011-04-15 01:23:10 +02:00
|
|
|
use Elastica_Searchable;
|
|
|
|
use Elastica_Query;
|
|
|
|
|
|
|
|
/**
|
2011-07-05 19:42:14 +02:00
|
|
|
* Implements the Pagerfanta\Adapter\AdapterInterface Interface for use with Zend\Paginator\Paginator
|
2011-04-15 01:23:10 +02:00
|
|
|
*
|
|
|
|
* Allows pagination of Elastica_Query
|
|
|
|
*/
|
2011-05-10 02:52:06 +02:00
|
|
|
class TransformedPaginatorAdapter extends AbstractPaginatorAdapter
|
2011-04-15 01:23:10 +02:00
|
|
|
{
|
2011-04-27 09:59:04 +02:00
|
|
|
protected $transformer;
|
2011-04-15 01:23:10 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Elastica_SearchableInterface the object to search in
|
|
|
|
* @param Elastica_Query the query to search
|
2011-04-27 09:59:04 +02:00
|
|
|
* @param ElasticaToModelTransformerInterface the transformer for fetching the results
|
2011-04-15 01:23:10 +02:00
|
|
|
*/
|
2011-04-27 09:59:04 +02:00
|
|
|
public function __construct(Elastica_Searchable $searchable, Elastica_Query $query, ElasticaToModelTransformerInterface $transformer)
|
2011-04-15 01:23:10 +02:00
|
|
|
{
|
|
|
|
parent::__construct($searchable, $query);
|
2011-04-27 09:59:04 +02:00
|
|
|
|
|
|
|
$this->transformer = $transformer;
|
2011-04-15 01:23:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-07-05 19:42:14 +02:00
|
|
|
* @see Pagerfanta\Adapter\AdapterInterface::getSlice
|
2011-04-15 01:23:10 +02:00
|
|
|
*/
|
2011-07-05 19:42:14 +02:00
|
|
|
public function getSlice($offset, $length)
|
2011-04-15 01:23:10 +02:00
|
|
|
{
|
2011-07-05 19:42:14 +02:00
|
|
|
$results = $this->getElasticaResults($offset, $length);
|
2011-04-15 01:23:10 +02:00
|
|
|
|
2011-04-27 09:59:04 +02:00
|
|
|
return $this->transformer->transform($results);
|
2011-04-15 01:23:10 +02:00
|
|
|
}
|
|
|
|
}
|