Skip to content

Commit

Permalink
Add constructor for Query
Browse files Browse the repository at this point in the history
  • Loading branch information
cundd committed Jan 6, 2019
1 parent e09455c commit 2d4a403
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
5 changes: 3 additions & 2 deletions Classes/Authentication/UserProvider/FeUserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

use Cundd\Rest\Authentication\UserProviderInterface;
use Cundd\Rest\VirtualObject\Persistence\BackendFactory;
use Cundd\Rest\VirtualObject\Persistence\Query;
use Cundd\Rest\VirtualObject\Persistence\QueryInterface;

/**
Expand Down Expand Up @@ -52,7 +53,7 @@ public function checkCredentials($username, $password)
],
];

return 0 < $backend->getObjectCountByQuery('fe_users', array_merge($query, $endtimeZero))
|| 0 < $backend->getObjectCountByQuery('fe_users', array_merge($query, $endtimeGtNow));
return 0 < $backend->getObjectCountByQuery('fe_users', new Query(array_merge($query, $endtimeZero)))
|| 0 < $backend->getObjectCountByQuery('fe_users', new Query(array_merge($query, $endtimeGtNow)));
}
}
30 changes: 30 additions & 0 deletions Classes/VirtualObject/Persistence/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,32 @@ class Query implements QueryInterface
*/
protected $statement;

/**
* Query constructor.
*
* @param array $constraint
* @param array $orderings
* @param int $limit
* @param int $offset
* @param string $sourceIdentifier
* @param PersistenceManager $persistenceManager
*/
public function __construct(
array $constraint = [],
array $orderings = [],
int $limit = 0,
int $offset = 0,
string $sourceIdentifier = '',
PersistenceManager $persistenceManager = null
) {
$this->persistenceManager = $persistenceManager;
$this->constraint = $constraint;
$this->orderings = $orderings;
$this->limit = $limit;
$this->offset = $offset;
$this->sourceIdentifier = $sourceIdentifier;
}

public function execute()
{
return $this->persistenceManager->getObjectDataByQuery($this);
Expand Down Expand Up @@ -148,6 +174,10 @@ public function setConfiguration($configuration)

public function getConfiguration()
{
if (!$this->persistenceManager) {
return null;
}

return $this->persistenceManager->getConfiguration();
}

Expand Down
4 changes: 2 additions & 2 deletions Classes/VirtualObject/Persistence/QueryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ interface QueryInterface
/**
* Ascending ordering of results
*/
const ORDER_ASCENDING = \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING;
const ORDER_ASCENDING = 'ASC';

/**
* Descending ordering of results
*/
const ORDER_DESCENDING = \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING;
const ORDER_DESCENDING = 'DESC';

/**
* Executes the query and returns the result
Expand Down
3 changes: 2 additions & 1 deletion Tests/Unit/VirtualObject/Backend/WhereClauseBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Cundd\Rest\VirtualObject\Persistence\Backend;

use Cundd\Rest\VirtualObject\Persistence\Query;
use Cundd\Rest\VirtualObject\Persistence\QueryInterface;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -136,7 +137,7 @@ public function testBuild()
$where->getBoundVariables()
);

$this->fixture->build([]);
$this->fixture->build(new Query());
$this->assertEmptyWhere();
}

Expand Down

0 comments on commit 2d4a403

Please sign in to comment.