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

merge conflict

parents 27edae54 527d79ed
Branches
Tags
No related merge requests found
......@@ -50,7 +50,6 @@ CalderaFormsQueries()->deleteByEntryIds([1,1,2,3,5,8,42]);
CalderaFormsQueries()->deleteByUserId(42);
```
### Paginated Queries
The selectByFieldValue feature method defaults to limiting queries to 25. You can set the page and limit with the 4th & 5th arguments.
```php
......@@ -72,12 +71,9 @@ $entries = CalderaFormsQueries()->selectByFieldValue( 'email', 'delete@please.eu
$entries = CalderaFormsQueries()->selectByFieldValue( 'email', 'delete@please.eu', true, 2 );
//Get 5th page, with 50 results per page
$entries = CalderaFormsQueries()->selectByFieldValue( 'email', 'delete@please.eu', true, 5, 50 );
```
## Development
### Install
Requires git and Composer
......
......@@ -132,6 +132,7 @@ class FeatureContainer extends Container
return $this->collectResults($this->select($query));
}
<<<<<<< HEAD
/**
* Find all entries that have or do not have field with a slug and value
*
......@@ -162,6 +163,54 @@ class FeatureContainer extends Container
->entrySelect()
->addPagination($page,$limit)
->queryByEntryIds($results);
=======
/**
* Select entries by form ID
*
* @param string $formId ID of form to select
*
* @param bool $addValues Optional Add entry values? Default is true.
* @return array
*/
public function selectByFormId($formId, $addValues = true )
{
$query = $this
->getQueries()
->entrySelect()
->queryByFormsId($formId);
return $this->collectResults($this->select($query), $addValues);
}
>>>>>>> 527d79ed169861a0db38e730e1ed8f374b533d04
/**
* Find all entries that have or do not have field with a slug and value
*
* @param string $fieldSlug Field slug
* @param string $fieldValue Field value
* @param bool $have Optional. Default: true. If true query is for fields with this value
*
* @return array
*/
public function selectByFieldValue($fieldSlug, $fieldValue, $have = true)
{
$type = $have ? 'equals' : 'notEquals';
$queryForEntryValues = $this
->getQueries()
->entryValuesSelect()
->queryByFieldValue($fieldSlug, $fieldValue, $type, 'AND', [
'entry_id'
]);
$results = $this->select($queryForEntryValues);
if (empty($results) || 0 >= count($results)) {
return [];
}
$results = $this->reduceResultsToEntryId($results);
$queryForValues = $this
->getQueries()
->entrySelect()
->queryByEntryIds($results);
return $this->collectResults($this->select($queryForValues));
}
......@@ -239,9 +288,10 @@ class FeatureContainer extends Container
* Collect results using Caldera_Forms_Entry_Entry and Caldera_Forms_Entry_Field to represent values
*
* @param \stdClass[] $entriesValues
* @param bool $addValues Optional Add entry values? Default is true.
* @return array
*/
private function collectResults($entriesValues)
private function collectResults($entriesValues, $addValues = true)
{
$results = [];
foreach ($entriesValues as $entry) {
......@@ -250,9 +300,12 @@ class FeatureContainer extends Container
->getQueries()
->entryValuesSelect()
->queryByEntryId($entry->id);
$entriesValues = $this->select($query);
$entryValuesPrepared = [];
if ($addValues) {
$entriesValues = $this->select($query);
$entryValuesPrepared = $this->collectEntryValues($entriesValues);
}
$results[] = [
'entry' => $entry,
'values' => $entryValuesPrepared
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment