Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
caldera-forms-query
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
plugins
cf-dependencies
caldera-forms-query
Commits
4233b012
Commit
4233b012
authored
6 years ago
by
Josh Pollock
Browse files
Options
Downloads
Patches
Plain Diff
select by user id on main class
parent
75906515
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Tests/Integration/Features/QueryByUserIdTest.php
+46
-0
46 additions, 0 deletions
Tests/Integration/Features/QueryByUserIdTest.php
src/EntryQueries.php
+85
-0
85 additions, 0 deletions
src/EntryQueries.php
with
131 additions
and
0 deletions
Tests/Integration/Features/QueryByUserIdTest.php
0 → 100644
+
46
−
0
View file @
4233b012
<?php
namespace
calderawp\CalderaFormsQuery\Tests\Integration\Features
;
use
calderawp\CalderaFormsQuery\QueriesEntries
;
use
calderawp\CalderaFormsQuery\Tests\Integration\IntegrationTestCase
;
use
calderawp\CalderaFormsQuery\Tests\Traits\CanCreateEntryWithEmailField
;
class
QueryByUserIdTest
extends
IntegrationTestCase
{
use
CanCreateEntryWithEmailField
;
/**
* Test selecting by entry ID
*
* @covers QueriesEntries::selectByUserId()
*/
public
function
testByUserId
()
{
$email
=
'nom@noms.noms'
;
//Create an entry for a known user.
$userId
=
$this
->
factory
()
->
user
->
create
(
[
'user_email'
=>
$email
]
);
wp_set_current_user
(
$userId
);
$entryId
=
$this
->
createEntryWithEmail
(
$email
);
$queries
=
$this
->
entryQueriesFactory
();
$results
=
$queries
->
selectByUserId
(
$userId
);
$this
->
assertEquals
(
$entryId
,
$results
[
0
][
'entry'
]
->
id
);
$this
->
assertEquals
(
$entryId
,
$results
[
0
][
'entry'
]
->
id
);
$found
=
false
;
foreach
(
$results
[
0
][
'values'
]
as
$entryValue
)
{
if
(
$entryValue
->
slug
===
$this
->
getEmailFieldSlug
()
){
$this
->
assertSame
(
$email
,
$entryValue
->
value
);
$found
=
true
;
}
}
$this
->
assertTrue
(
$found
);
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/EntryQueries.php
+
85
−
0
View file @
4233b012
...
...
@@ -61,4 +61,89 @@ class EntryQueries implements QueriesEntries
{
return
$this
->
entryGenerator
;
}
/**
* Get all data for a user by Id
*
* @param $userId
* @return array
*/
public
function
selectByUserId
(
$userId
)
{
$this
->
resetEntryGenerator
();
$this
->
getEntryGenerator
()
->
queryByUserId
(
$userId
);
$entries
=
$this
->
getResults
(
$this
->
getEntryGenerator
()
->
getPreparedSql
());
return
$this
->
collectResults
(
$entries
);
}
/**
* Reset entry generator
*/
private
function
resetEntryGenerator
()
{
$this
->
entryGenerator
->
resetQuery
();
}
/**
* Reset entry value generator
*/
private
function
resetEntryValueGenerator
()
{
$this
->
entryValueGenerator
->
resetQuery
();
}
/**
* Collect results using Caldera_Forms_Entry_Entry and Caldera_Forms_Entry_Field to represent values
*
* @param \stdClass[] $entriesValues
* @return array
*/
private
function
collectResults
(
$entriesValues
)
{
$results
=
[];
foreach
(
$entriesValues
as
$entry
)
{
$this
->
resetEntryValueGenerator
();
$entry
=
new
\Caldera_Forms_Entry_Entry
(
$entry
);
$this
->
getEntryValueGenerator
()
->
queryByEntryId
(
$entry
->
id
);
$entriesValues
=
$this
->
getResults
(
$this
->
getEntryValueGenerator
()
->
getPreparedSql
()
);
$entryValuesPrepared
=
$this
->
collectEntryValues
(
$entriesValues
);
$results
[]
=
[
'entry'
=>
$entry
,
'values'
=>
$entryValuesPrepared
];
}
return
$results
;
}
/**
* Collect entry values as Caldera_Forms_Entry_Field objects
*
* @param \stdClass[] $entriesValues
* @return array
*/
private
function
collectEntryValues
(
$entriesValues
):
array
{
$entryValuesPrepared
=
[];
if
(
!
empty
(
$entriesValues
))
{
foreach
(
$entriesValues
as
$entryValue
)
{
$entryValuesPrepared
[]
=
new
\Caldera_Forms_Entry_Field
(
$entryValue
);
}
}
return
$entryValuesPrepared
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment