Skip to content
Snippets Groups Projects
Commit 6e413f57 authored by Josh Pollock's avatar Josh Pollock
Browse files

add pagination to select queries

parent 9fa2016d
No related branches found
No related tags found
No related merge requests found
...@@ -40,4 +40,9 @@ ...@@ -40,4 +40,9 @@
<path value="$PROJECT_DIR$/vendor/phpdocumentor/reflection-common" /> <path value="$PROJECT_DIR$/vendor/phpdocumentor/reflection-common" />
</include_path> </include_path>
</component> </component>
<component name="PhpUnit">
<phpunit_settings>
<PhpUnitSettings load_method="CUSTOM_LOADER" custom_loader_path="$PROJECT_DIR$/vendor/autoload.php" />
</phpunit_settings>
</component>
</project> </project>
\ No newline at end of file
This diff is collapsed.
...@@ -25,6 +25,23 @@ class EntryTest extends TestCase ...@@ -25,6 +25,23 @@ class EntryTest extends TestCase
$this->assertEquals($expectedSql, $actualSql); $this->assertEquals($expectedSql, $actualSql);
} }
/**
* Test query by form ID
*
* @covers Entry::queryByFormsId()
* @covers \calderawp\CalderaFormsQuery\addPagination::()
*/
public function testQueryByFormsIdPaginated()
{
$expectedSql = "SELECT `{$this->entryTableName()}`.* FROM `wp_cf_form_entries` WHERE (`{$this->entryTableName()}`.`form_id` = 'cf12345') LIMIT '26', '50'";
$actualSql = $this
->entryGeneratorFactory()
->queryByFormsId('cf12345')
->addPagination(2,25 )
->getPreparedSql();
$this->assertEquals($expectedSql, $actualSql);
}
/** /**
* Test query by entry ID * Test query by entry ID
* *
...@@ -57,6 +74,9 @@ class EntryTest extends TestCase ...@@ -57,6 +74,9 @@ class EntryTest extends TestCase
$this->assertEquals($expectedSql, $actualSql); $this->assertEquals($expectedSql, $actualSql);
} }
/** /**
* @param $generator * @param $generator
* @return bool * @return bool
......
...@@ -45,4 +45,6 @@ class SelectQueriesTest extends TestCase ...@@ -45,4 +45,6 @@ class SelectQueriesTest extends TestCase
$queries = $this->selectQueriesFactory(); $queries = $this->selectQueriesFactory();
$this->assertTrue(is_array($queries->getResults("SELECT `roy` FROM sivan WHERE mike = 'roy'"))); $this->assertTrue(is_array($queries->getResults("SELECT `roy` FROM sivan WHERE mike = 'roy'")));
} }
} }
{ {
"_readme": [ "_readme": [
"This file locks the dependencies of your project to a known state", "This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "736a984915e9e1f970336e5a8e5b38eb", "content-hash": "66049b1b98fbc3be0172f1d471393cb3",
"packages": [ "packages": [
{ {
"name": "calderawp/caldera-containers", "name": "calderawp/caldera-containers",
...@@ -273,7 +273,7 @@ ...@@ -273,7 +273,7 @@
"version": "dev-feature/2404", "version": "dev-feature/2404",
"source": { "source": {
"type": "git", "type": "git",
"url": "git@github.com:CalderaWP/Caldera-Forms.git", "url": "https://github.com/CalderaWP/Caldera-Forms",
"reference": "c4c2d1db6042c82f2229c89ed7140c8b214c9c8e" "reference": "c4c2d1db6042c82f2229c89ed7140c8b214c9c8e"
}, },
"type": "wordpress-plugin", "type": "wordpress-plugin",
...@@ -819,23 +819,23 @@ ...@@ -819,23 +819,23 @@
}, },
{ {
"name": "phpspec/prophecy", "name": "phpspec/prophecy",
"version": "1.7.5", "version": "1.7.6",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/phpspec/prophecy.git", "url": "https://github.com/phpspec/prophecy.git",
"reference": "dfd6be44111a7c41c2e884a336cc4f461b3b2401" "reference": "33a7e3c4fda54e912ff6338c48823bd5c0f0b712"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/phpspec/prophecy/zipball/dfd6be44111a7c41c2e884a336cc4f461b3b2401", "url": "https://api.github.com/repos/phpspec/prophecy/zipball/33a7e3c4fda54e912ff6338c48823bd5c0f0b712",
"reference": "dfd6be44111a7c41c2e884a336cc4f461b3b2401", "reference": "33a7e3c4fda54e912ff6338c48823bd5c0f0b712",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"doctrine/instantiator": "^1.0.2", "doctrine/instantiator": "^1.0.2",
"php": "^5.3|^7.0", "php": "^5.3|^7.0",
"phpdocumentor/reflection-docblock": "^2.0|^3.0.2|^4.0", "phpdocumentor/reflection-docblock": "^2.0|^3.0.2|^4.0",
"sebastian/comparator": "^1.1|^2.0", "sebastian/comparator": "^1.1|^2.0|^3.0",
"sebastian/recursion-context": "^1.0|^2.0|^3.0" "sebastian/recursion-context": "^1.0|^2.0|^3.0"
}, },
"require-dev": { "require-dev": {
...@@ -878,20 +878,20 @@ ...@@ -878,20 +878,20 @@
"spy", "spy",
"stub" "stub"
], ],
"time": "2018-02-19T10:16:54+00:00" "time": "2018-04-18T13:57:24+00:00"
}, },
{ {
"name": "phpunit/php-code-coverage", "name": "phpunit/php-code-coverage",
"version": "6.0.1", "version": "6.0.4",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sebastianbergmann/php-code-coverage.git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git",
"reference": "f8ca4b604baf23dab89d87773c28cc07405189ba" "reference": "52187754b0eed0b8159f62a6fa30073327e8c2ca"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/f8ca4b604baf23dab89d87773c28cc07405189ba", "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/52187754b0eed0b8159f62a6fa30073327e8c2ca",
"reference": "f8ca4b604baf23dab89d87773c28cc07405189ba", "reference": "52187754b0eed0b8159f62a6fa30073327e8c2ca",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
...@@ -902,7 +902,7 @@ ...@@ -902,7 +902,7 @@
"phpunit/php-text-template": "^1.2.1", "phpunit/php-text-template": "^1.2.1",
"phpunit/php-token-stream": "^3.0", "phpunit/php-token-stream": "^3.0",
"sebastian/code-unit-reverse-lookup": "^1.0.1", "sebastian/code-unit-reverse-lookup": "^1.0.1",
"sebastian/environment": "^3.0", "sebastian/environment": "^3.1",
"sebastian/version": "^2.0.1", "sebastian/version": "^2.0.1",
"theseer/tokenizer": "^1.1" "theseer/tokenizer": "^1.1"
}, },
...@@ -941,7 +941,7 @@ ...@@ -941,7 +941,7 @@
"testing", "testing",
"xunit" "xunit"
], ],
"time": "2018-02-02T07:01:41+00:00" "time": "2018-04-29T14:59:09+00:00"
}, },
{ {
"name": "phpunit/php-file-iterator", "name": "phpunit/php-file-iterator",
...@@ -1131,16 +1131,16 @@ ...@@ -1131,16 +1131,16 @@
}, },
{ {
"name": "phpunit/phpunit", "name": "phpunit/phpunit",
"version": "7.0.3", "version": "7.1.5",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git", "url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "536f4d853c12d8189963435088e8ff7c0daeab2e" "reference": "ca64dba53b88aba6af32aebc6b388068db95c435"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/536f4d853c12d8189963435088e8ff7c0daeab2e", "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/ca64dba53b88aba6af32aebc6b388068db95c435",
"reference": "536f4d853c12d8189963435088e8ff7c0daeab2e", "reference": "ca64dba53b88aba6af32aebc6b388068db95c435",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
...@@ -1158,8 +1158,8 @@ ...@@ -1158,8 +1158,8 @@
"phpunit/php-file-iterator": "^1.4.3", "phpunit/php-file-iterator": "^1.4.3",
"phpunit/php-text-template": "^1.2.1", "phpunit/php-text-template": "^1.2.1",
"phpunit/php-timer": "^2.0", "phpunit/php-timer": "^2.0",
"phpunit/phpunit-mock-objects": "^6.0", "phpunit/phpunit-mock-objects": "^6.1.1",
"sebastian/comparator": "^2.1", "sebastian/comparator": "^3.0",
"sebastian/diff": "^3.0", "sebastian/diff": "^3.0",
"sebastian/environment": "^3.1", "sebastian/environment": "^3.1",
"sebastian/exporter": "^3.1", "sebastian/exporter": "^3.1",
...@@ -1181,7 +1181,7 @@ ...@@ -1181,7 +1181,7 @@
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "7.0-dev" "dev-master": "7.1-dev"
} }
}, },
"autoload": { "autoload": {
...@@ -1207,20 +1207,20 @@ ...@@ -1207,20 +1207,20 @@
"testing", "testing",
"xunit" "xunit"
], ],
"time": "2018-03-26T07:36:48+00:00" "time": "2018-04-29T15:09:19+00:00"
}, },
{ {
"name": "phpunit/phpunit-mock-objects", "name": "phpunit/phpunit-mock-objects",
"version": "6.0.1", "version": "6.1.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git",
"reference": "e3249dedc2d99259ccae6affbc2684eac37c2e53" "reference": "70c740bde8fd9ea9ea295be1cd875dd7b267e157"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/e3249dedc2d99259ccae6affbc2684eac37c2e53", "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/70c740bde8fd9ea9ea295be1cd875dd7b267e157",
"reference": "e3249dedc2d99259ccae6affbc2684eac37c2e53", "reference": "70c740bde8fd9ea9ea295be1cd875dd7b267e157",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
...@@ -1238,7 +1238,7 @@ ...@@ -1238,7 +1238,7 @@
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "6.0.x-dev" "dev-master": "6.1-dev"
} }
}, },
"autoload": { "autoload": {
...@@ -1263,7 +1263,7 @@ ...@@ -1263,7 +1263,7 @@
"mock", "mock",
"xunit" "xunit"
], ],
"time": "2018-02-15T05:27:38+00:00" "time": "2018-04-11T04:50:36+00:00"
}, },
{ {
"name": "sebastian/code-unit-reverse-lookup", "name": "sebastian/code-unit-reverse-lookup",
...@@ -1312,30 +1312,30 @@ ...@@ -1312,30 +1312,30 @@
}, },
{ {
"name": "sebastian/comparator", "name": "sebastian/comparator",
"version": "2.1.3", "version": "3.0.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sebastianbergmann/comparator.git", "url": "https://github.com/sebastianbergmann/comparator.git",
"reference": "34369daee48eafb2651bea869b4b15d75ccc35f9" "reference": "ed5fd2281113729f1ebcc64d101ad66028aeb3d5"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/34369daee48eafb2651bea869b4b15d75ccc35f9", "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/ed5fd2281113729f1ebcc64d101ad66028aeb3d5",
"reference": "34369daee48eafb2651bea869b4b15d75ccc35f9", "reference": "ed5fd2281113729f1ebcc64d101ad66028aeb3d5",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": "^7.0", "php": "^7.1",
"sebastian/diff": "^2.0 || ^3.0", "sebastian/diff": "^3.0",
"sebastian/exporter": "^3.1" "sebastian/exporter": "^3.1"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^6.4" "phpunit/phpunit": "^7.1"
}, },
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "2.1.x-dev" "dev-master": "3.0-dev"
} }
}, },
"autoload": { "autoload": {
...@@ -1372,7 +1372,7 @@ ...@@ -1372,7 +1372,7 @@
"compare", "compare",
"equality" "equality"
], ],
"time": "2018-02-01T13:46:46+00:00" "time": "2018-04-18T13:33:00+00:00"
}, },
{ {
"name": "sebastian/diff", "name": "sebastian/diff",
......
...@@ -43,6 +43,22 @@ abstract class SelectQueryBuilder extends QueryBuilder implements DoesSelectQuer ...@@ -43,6 +43,22 @@ abstract class SelectQueryBuilder extends QueryBuilder implements DoesSelectQuer
return $this; return $this;
} }
/**
* Add pagination to a query
*
* @param int $page What page of query
* @param int $limit How many per page
*
* @return $this
*/
public function addPagination( $page, $limit = 25 )
{
$start = 1 + ( $page * $limit) - $limit;
$last = $page * $limit;
$this->getCurrentQuery()->limit((int)$start, (int)$last );
return $this;
}
/** /**
* @return Select * @return Select
*/ */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment