Fix pagination for CMS 9

This commit is contained in:
Daniel Siepmann 2019-06-06 15:25:41 +02:00
parent 96a1db31ed
commit c118d3cb87
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4

View file

@ -23,21 +23,21 @@ namespace Codappix\SearchCore\Domain\Model;
use Codappix\SearchCore\Connection\ConnectionInterface; use Codappix\SearchCore\Connection\ConnectionInterface;
use Codappix\SearchCore\Connection\FacetRequestInterface; use Codappix\SearchCore\Connection\FacetRequestInterface;
use Codappix\SearchCore\Connection\SearchRequestInterface; use Codappix\SearchCore\Connection\SearchRequestInterface;
use Codappix\SearchCore\Domain\Model\Query;
use Codappix\SearchCore\Domain\Search\SearchService; use Codappix\SearchCore\Domain\Search\SearchService;
use TYPO3\CMS\Extbase\Persistence\QueryInterface;
/** /**
* Represents a search request used to process an actual search. * Represents a search request used to process an actual search.
*/ */
class SearchRequest implements SearchRequestInterface class SearchRequest implements SearchRequestInterface
{ {
use QueryResultInterfaceStub;
/** /**
* The search string provided by the user, the actual term to search for. * The search string provided by the user, the actual term to search for.
* *
* @var string * @var string
*/ */
protected $queryString = ''; protected $query = '';
/** /**
* @var array * @var array
@ -50,9 +50,14 @@ class SearchRequest implements SearchRequestInterface
protected $facets = []; protected $facets = [];
/** /**
* @var Query * @var int
*/ */
private $query; protected $offset = 0;
/**
* @var int
*/
protected $limit = 10;
/** /**
* Used for QueryInterface implementation to allow execute method to work. * Used for QueryInterface implementation to allow execute method to work.
@ -69,15 +74,19 @@ class SearchRequest implements SearchRequestInterface
/** /**
* @param string $query * @param string $query
*/ */
public function __construct(string $queryString = '') public function __construct(string $query = '')
{ {
$this->queryString = $queryString; $this->query = $query;
$this->query = new Query(); }
public function getQuery() : string
{
return $this->query;
} }
public function getSearchTerm() : string public function getSearchTerm() : string
{ {
return $this->queryString; return $this->query;
} }
/** /**
@ -87,8 +96,7 @@ class SearchRequest implements SearchRequestInterface
{ {
$filter = \TYPO3\CMS\Core\Utility\ArrayUtility::removeArrayEntryByValue($filter, ''); $filter = \TYPO3\CMS\Core\Utility\ArrayUtility::removeArrayEntryByValue($filter, '');
$this->filter = \TYPO3\CMS\Core\Utility\ArrayUtility::filterRecursive($filter, function ($value) { $this->filter = \TYPO3\CMS\Core\Utility\ArrayUtility::filterRecursive($filter, function ($value) {
return (!is_array($value) && trim($value) !== '') return !empty($value);
|| is_array($value) && count($value) !== 0;
}); });
} }
@ -132,94 +140,182 @@ class SearchRequest implements SearchRequestInterface
$this->searchService = $searchService; $this->searchService = $searchService;
} }
public function setLimit(int $limit) // Extbase QueryInterface
// Current implementation covers only paginate widget support.
public function execute($returnRawQueryResult = false)
{ {
$this->query->setLimit($limit); if (! ($this->connection instanceof ConnectionInterface)) {
throw new \InvalidArgumentException(
'Connection was not set before, therefore execute can not work. Use `setConnection` before.',
1502197732
);
}
if (! ($this->searchService instanceof SearchService)) {
throw new \InvalidArgumentException(
'SearchService was not set before, therefore execute can not work. Use `setSearchService` before.',
1520325175
);
}
return $this->searchService->processResult($this->connection->search($this));
}
public function setLimit($limit)
{
$this->limit = (int) $limit;
return $this; return $this;
} }
public function setOffset(int $offset) public function setOffset($offset)
{ {
$this->query->setOffset($offset); $this->offset = (int) $offset;
return $this; return $this;
} }
public function getLimit(): int public function getLimit(): int
{ {
return $this->query->getLimit(); return $this->limit;
} }
public function getOffset(): int public function getOffset(): int
{ {
return $this->query->getOffset(); return $this->offset;
} }
// Implementation of QueryResultInterface public function getSource()
public function getQuery(): QueryInterface
{ {
return $this->query; throw new \BadMethodCallException('Method is not implemented yet.', 1502196146);
} }
/** public function setOrderings(array $orderings)
* Returns the first object in the result set
*
* @return object
*/
public function getFirst()
{ {
throw new \BadMethodCallException('Method is not implemented yet.', 1502196163);
} }
/** public function matching($constraint)
* Returns an array with the objects in the result set
*
* @return array
*/
public function toArray()
{ {
throw new \BadMethodCallException('Method is not implemented yet.', 1502196197);
} }
public function count(): int public function logicalAnd($constraint1)
{ {
throw new \BadMethodCallException('Method is not implemented yet.', 1502196166);
} }
public function current(): mixed public function logicalOr($constraint1)
{ {
throw new \BadMethodCallException('Method is not implemented yet.', 1502196198);
}
public function logicalNot(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface $constraint)
{
throw new \BadMethodCallException('Method is not implemented yet.', 1502196166);
}
public function equals($propertyName, $operand, $caseSensitive = true)
{
throw new \BadMethodCallException('Method is not implemented yet.', 1502196199);
}
public function contains($propertyName, $operand)
{
throw new \BadMethodCallException('Method is not implemented yet.', 1502196200);
}
public function in($propertyName, $operand)
{
throw new \BadMethodCallException('Method is not implemented yet.', 1502196167);
}
public function lessThan($propertyName, $operand)
{
throw new \BadMethodCallException('Method is not implemented yet.', 1502196201);
}
public function lessThanOrEqual($propertyName, $operand)
{
throw new \BadMethodCallException('Method is not implemented yet.', 1502196168);
}
public function greaterThan($propertyName, $operand)
{
throw new \BadMethodCallException('Method is not implemented yet.', 1502196202);
}
public function greaterThanOrEqual($propertyName, $operand)
{
throw new \BadMethodCallException('Method is not implemented yet.', 1502196168);
}
public function getType()
{
throw new \BadMethodCallException('Method is not implemented yet.', 1502196203);
}
public function setQuerySettings(\TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings)
{
throw new \BadMethodCallException('Method is not implemented yet.', 1502196168);
}
public function getQuerySettings()
{
throw new \BadMethodCallException('Method is not implemented yet.', 1502196205);
}
public function count()
{
throw new \BadMethodCallException('Method is not implemented yet.', 1502196169);
}
public function getOrderings()
{
throw new \BadMethodCallException('Method is not implemented yet.', 1502196206);
}
public function getConstraint()
{
throw new \BadMethodCallException('Method is not implemented yet.', 1502196171);
}
public function isEmpty($propertyName)
{
throw new \BadMethodCallException('Method is not implemented yet.', 1502196207);
}
public function setSource(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface $source)
{
throw new \BadMethodCallException('Method is not implemented yet.', 1502196172);
}
public function getStatement()
{
throw new \BadMethodCallException('Method is not implemented yet.', 1502196208);
}
public function current()
{
throw new \BadMethodCallException('Method is not implemented yet.', 1502196208);
}
public function next()
{
throw new \BadMethodCallException('Method is not implemented yet.', 1502196208);
} }
public function key() public function key()
{ {
throw new \BadMethodCallException('Method is not implemented yet.', 1502196208);
} }
public function next(): void public function valid()
{ {
throw new \BadMethodCallException('Method is not implemented yet.', 1502196208);
} }
public function rewind(): void public function rewind()
{
}
public function valid(): bool
{
}
public function offsetExists($offset): bool
{
// TODO: Implement
return false;
}
public function offsetGet($offset): mixed
{
}
public function offsetSet($offset, $value) : void
{
}
public function offsetUnset($offset): void
{ {
throw new \BadMethodCallException('Method is not implemented yet.', 1502196208);
} }
} }