Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
{
"name": "adt/query-object-data-source",
"description": "Ublaboo Datagrid data source bindings for Kdyby Doctrine query objects.",
"description": "Ublaboo Datagrid data source bindings for adt/base-query query objects.",
"type": "library",
"license": [
"MIT",
"BSD-3-Clause",
"GPL-2.0",
"GPL-3.0"
"MIT"
],
"require": {
"php": ">=7.1"
},
"require-dev": {
"kdyby/doctrine": "^3.1 || ~4.0",
"ublaboo/datagrid": "^5.0 || ~6.0",
"nette/utils": "^2.4 || ~3.0",
"nette/di": "^2.4 || ~3.0"
"php": ">=7.4",
"adt/base-query": "^2.0",
"ublaboo/datagrid": "^6.0",
"nette/di": "^2.4|^3.0"
},
"autoload": {
"psr-4": {
Expand Down
6 changes: 3 additions & 3 deletions src/IQueryObjectDataSourceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
interface IQueryObjectDataSourceFactory {

/**
* @param \Kdyby\Doctrine\QueryObject $queryObject
* @param \Kdyby\Doctrine\EntityRepository|null $repo
* @param \ADT\DoctrineComponents\QueryObject $queryObject
* @param \Doctrine\ORM\EntityRepository|null $repo
* @return QueryObjectDataSource
*/
function create(\Kdyby\Doctrine\QueryObject $queryObject, \Kdyby\Doctrine\EntityRepository $repo = null);
function create(\ADT\DoctrineComponents\QueryObject $queryObject, \Doctrine\ORM\EntityRepository $repo = null);

}
27 changes: 11 additions & 16 deletions src/QueryObjectDataSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,15 @@
use Ublaboo\DataGrid\Utils\DateTimeHelper;
use Ublaboo\DataGrid\DataSource\IDataSource;

class QueryObjectDataSource implements IDataSource {

use \Nette\SmartObject;

/** @var \Kdyby\Doctrine\ResultSet */
class QueryObjectDataSource implements IDataSource
{
/** @var \ADT\DoctrineComponents\ResultSet */
protected $resultSet;

/** @var \Kdyby\Doctrine\EntityRepository */
/** @var \Doctrine\ORM\EntityRepository */
protected $repo;

/** @var \Kdyby\Doctrine\QueryObject|IQueryObject */
/** @var \ADT\DoctrineComponents\QueryObject|IQueryObject */
protected $queryObject;

/** @var callable */
Expand All @@ -39,11 +37,11 @@ class QueryObjectDataSource implements IDataSource {

/**
* QueryObjectDataSource constructor.
* @param \Kdyby\Doctrine\QueryObject $queryObject
* @param \Kdyby\Doctrine\EntityRepository|null $repo
* @param \ADT\DoctrineComponents\QueryObject $queryObject
* @param \Doctrine\ORM\EntityRepository|null $repo
* @throws \Exception
*/
public function __construct(\Kdyby\Doctrine\QueryObject $queryObject, \Kdyby\Doctrine\EntityRepository $repo = null)
public function __construct(\ADT\DoctrineComponents\QueryObject $queryObject, \Doctrine\ORM\EntityRepository $repo = null)
{
if (!$repo && (!$queryObject instanceof IQueryObject)) {
throw new \Exception('"repo" must be set or "queryObject" has to implement IQueryObject interface.');
Expand Down Expand Up @@ -94,8 +92,7 @@ public function setLimitCallback($callback) {

protected function getResultSet() {
if (!$this->resultSet) {
$this->resultSet = $this->repo
->fetch($this->queryObject);
$this->resultSet = $this->queryObject->fetch();
}

return $this->resultSet;
Expand All @@ -106,9 +103,7 @@ protected function getResultSet() {
* @return int
*/
public function getCount(): int {
return $this->repo
->fetch($this->queryObject)
->getTotalCount();
return $this->queryObject->fetch()->getTotalCount();
}

/**
Expand Down Expand Up @@ -176,7 +171,7 @@ public function filterOne(array $filter): IDataSource {
* @param int $limit
* @return static
*/
public function limit($offset, $limit): IDataSource {
public function limit(int $offset, int $limit): IDataSource {
$defaultCallback = function () use ($offset, $limit) {
$this->getResultSet()->applyPaging($offset, $limit);
};
Expand Down