Name: caldera-forms-query
Owner: Caldera Labs
Description: Query builder tool for Caldera Forms
Created: 2018-04-06 01:55:59.0
Updated: 2018-05-24 18:11:53.0
Pushed: 2018-05-24 18:11:51.0
Homepage: null
Size: 186
Language: PHP
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
This library provides for developer-friendly ways to query for or delete Caldera Forms entry data.
composer require calderawp/caldera-forms-query
xamples of simple queries
sing the class: \calderawp\CalderaFormsQuery\Features\FeatureContainer
ia the static accessor function: calderawp\CalderaFormsQueries\CalderaFormsQueries()
First make the function usable without a full namespace */
function calderawp\CalderaFormsQueries\CalderaFormsQueries;
Do Some Queries */
lect all data by user ID
ries = CalderaFormsQueries()->selectByUserId(42);
lect all entries that have a field whose slug is "email" and the value of that field's value is "delete@please.eu"
ries = CalderaFormsQueries()->selectByFieldValue( 'email', 'delete@please.eu' );
lect all entries that do not have field whose slug is "size" and the value of that field's value is "big"
ries = CalderaFormsQueries()->selectByFieldValue( 'size', 'big', false );
lete all data by Entry ID
eraFormsQueries()->deleteByEntryIds([1,1,2,3,5,8,42]);
lete all data by User ID
eraFormsQueries()->deleteByUserId(42);
The selectByFieldValue feature method defaults to limiting queries to 25. You can set the page and limit with the 4th & 5th arguments.
xamples of simple queries
sing the class: \calderawp\CalderaFormsQuery\Features\FeatureContainer
ia the static accessor function: calderawp\CalderaFormsQueries\CalderaFormsQueries()
First make the function usable without a full namespace */
function calderawp\CalderaFormsQueries\CalderaFormsQueries;
Do Some Queries */
lect all entries that have a field whose slug is "email" and the value of that field's value is "delete@please.eu"
e first 25 entries
ries = CalderaFormsQueries()->selectByFieldValue( 'email', 'delete@please.eu' );
e second 25 entries
ries = CalderaFormsQueries()->selectByFieldValue( 'email', 'delete@please.eu', true, 2 );
t 5th page, with 50 results per page
ries = CalderaFormsQueries()->selectByFieldValue( 'email', 'delete@please.eu', true, 5, 50 );
The feature container provides helper methods that allow for simple queries like those listed above. It also exposes the underlying query generators.
You can access any of the generators using the getQueries()
method. For example:
atureContainer = \calderawp\CalderaFormsQueries\CalderaFormsQueries();
$fieldValue = 'X@x.com';
$formId = 'CF5afb00e97d698';
$count = Caldera_Forms_Entry_Bulk::count($formId );
$entrySelector = $featureContainer
->getQueries()
->entrySelect();
is()
Helper MethodThis is a more complete example showing a selection of entry values where the field with the slug primary_email
is roy@hiroy.club
and the field with the slug of first_name
is Mike
. It is also using the is()
method to add WHERE statements, as well as the addPagination()
method to query for the second page of results with 50 results per page.
$featureContainer = \calderawp\CalderaFormsQueries\CalderaFormsQueries();
$entrySelector = $featureContainer
->getQueries()
->entrySelect()
->is( 'primary_email', 'roy@hiroy.club' )
->is( 'first_name', 'Mike' )
->addPagination(2,50 );
in()
Helper MethodThis example shows selection of all entry values where the entry ID is in an array of entry IDs.
$featureContainer = \calderawp\CalderaFormsQueries\CalderaFormsQueries();
$entrySelector = $featureContainer
->getQueries()
->entrySelect()
->in( 'entry_id', [ 42, 3 ] );
All query generators extend the \calderawp\CalderaFormsQuery\QueryBuilder
class and impairment \calderawp\CalderaFormsQuery\CreatesSqlQueries
.
Query generators are responsible for creating SQL queries. They do not perform sequel queries.
Select query generators extend \calderawp\CalderaFormsQuery\Select\SelectQueryBuilder
and impliment \calderawp\CalderaFormsQuery\Select\DoesSelectQuery
and \calderawp\CalderaFormsQuery\Select\DoesSelectQueryByEntryId
.
SelectQueryBuilder
sin()
The getQueries()
method of the FeatureContainer
returns a calderawp\CalderaFormsQuery\Features\Queries
instance. This provides us with a select
method when passed a SelectQueryBuilder
returns an array of stdClass
object of results.
$featureContainer = \calderawp\CalderaFormsQueries\CalderaFormsQueries();
$entryValueSelect = $featureContainer
->getQueries()
->entryValuesSelect()
->is( 'size', 'large' );
$featureContainer->getQueries()->select( $entryValueSelect );
You can also access the generated SQL as a string.
eatureContainer = \calderawp\CalderaFormsQueries\CalderaFormsQueries();
$sql = $featureContainer
->getQueries()
->entryValuesSelect()
->is( 'size', 'large' )
->getPreparedSql();
The Queries
class also has a delete
method we can pass a DeleteQueryBuilder
to perform a DELETE query against the database.
Requires git and Composer
git clone git@github.com:calderawp/caldera-forms-query.git
cd caldera-forms-query
composer install
A local development environment is included, and provided. It is used for integration tests. Requires Composer, Docker and Docker Compose.
composer wp-install
You should know have WordPress at http://localhost:8888/
composer wp-start
Follow the steps above to create local development environment, then you can use the commands listed in the next section.
Run these commands from the plugin's root directory.
composer tests
composer unit-tests
composer wp-tests
composer formatting
For now, this library is dependent on Caldera Forms and WordPress (for \WPDB
.) This will change, possibly with breaking changes, when caldera-interop is integrated with this tool.
Copyright 2018 CalderaWP LLC. License: GPL v2 or later.