Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor 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
justinfreeman (Agileware)
Core
Commits
79828a2d
Commit
79828a2d
authored
11 years ago
by
colemanw
Browse files
Options
Downloads
Plain Diff
Merge pull request #1699 from eileenmcnaughton/master
CRM-13234 profile submit api - support propert DB fields
parents
e480ea92
f5c68f3c
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
api/v3/Profile.php
+23
-7
23 additions, 7 deletions
api/v3/Profile.php
tests/phpunit/api/v3/ProfileTest.php
+16
-1
16 additions, 1 deletion
tests/phpunit/api/v3/ProfileTest.php
with
39 additions
and
8 deletions
api/v3/Profile.php
+
23
−
7
View file @
79828a2d
...
...
@@ -490,9 +490,15 @@ function _civicrm_api3_buildprofile_submitfields($profileID, $optionsBehaviour =
'help_pre'
=>
CRM_Utils_Array
::
value
(
'help_pre'
,
$field
),
'help_post'
=>
CRM_Utils_Array
::
value
(
'help_post'
,
$field
),
'entity'
=>
$entity
,
'weight'
=>
CRM_Utils_Array
::
value
(
'weight'
,
$field
),
),
$aliasArray
);
$realFieldName
=
$field
[
'field_name'
];
$ufFieldTaleFieldName
=
$field
[
'field_name'
];
if
(
isset
(
$entity
[
$ufFieldTaleFieldName
][
'name'
]))
{
// in the case where we are dealing with an alias we map back to a name
// this will be tested by 'membership_type_id' field
$ufFieldTaleFieldName
=
$entity
[
$ufFieldTaleFieldName
][
'name'
];
}
//see function notes
// as we build up a list of these we should be able to determine a generic approach
//
...
...
@@ -507,11 +513,11 @@ function _civicrm_api3_buildprofile_submitfields($profileID, $optionsBehaviour =
'tag'
=>
'tag_id'
,
);
if
(
array_key_exists
(
$
re
alFieldName
,
$hardCodedEntityFields
))
{
$
re
alFieldName
=
$hardCodedEntityFields
[
$
re
alFieldName
];
if
(
array_key_exists
(
$
ufFieldT
al
e
FieldName
,
$hardCodedEntityFields
))
{
$
ufFieldT
al
e
FieldName
=
$hardCodedEntityFields
[
$
ufFieldT
al
e
FieldName
];
}
$entities
[
$entity
][
$fieldName
]
=
$
re
alFieldName
;
$entities
[
$entity
][
$fieldName
]
=
$
ufFieldT
al
e
FieldName
;
}
foreach
(
$entities
as
$entity
=>
$entityFields
)
{
...
...
@@ -528,12 +534,18 @@ function _civicrm_api3_buildprofile_submitfields($profileID, $optionsBehaviour =
$fieldName
=
strtolower
(
$realName
);
}
if
(
isset
(
$entityGetFieldsResult
[
$realName
][
'uniqueName'
]))
{
// we won't alias the field name on here are we are using uniqueNames for the possibility of needing to differentiate
// which entity 'status_id' belongs to
// we won't alias the field name on here are we are using uniqueNames for the possibility of needing to differentiate
// which entity 'status_id' belongs to
$fieldName
=
$entityGetFieldsResult
[
$realName
][
'uniqueName'
];
}
else
{
if
(
isset
(
$entityGetFieldsResult
[
$realName
][
'name'
]))
{
// this will sort out membership_type_id vs membership_type
$fieldName
=
$entityGetFieldsResult
[
$realName
][
'name'
];
}
}
}
$profileFields
[
$profileID
][
$fieldName
]
=
array_merge
(
$profileFields
[
$profileID
][
$entityfield
]
,
$entityGetFieldsResult
[
$realName
]
);
$profileFields
[
$profileID
][
$fieldName
]
=
array_merge
(
$entityGetFieldsResult
[
$realName
],
$profileFields
[
$profileID
][
$entityfield
]);
if
(
!
isset
(
$profileFields
[
$profileID
][
$fieldName
][
'api.aliases'
]))
{
$profileFields
[
$profileID
][
$fieldName
][
'api.aliases'
]
=
array
();
}
...
...
@@ -560,9 +572,13 @@ function _civicrm_api3_buildprofile_submitfields($profileID, $optionsBehaviour =
*/
}
}
uasort
(
$profileFields
[
$profileID
],
"_civicrm_api3_order_by_weight"
);
return
$profileFields
[
$profileID
];
}
function
_civicrm_api3_order_by_weight
(
$a
,
$b
)
{
return
CRM_Utils_Array
::
value
(
'weight'
,
$b
)
<
CRM_Utils_Array
::
value
(
'weight'
,
$a
)
?
TRUE
:
FALSE
;
}
/**
* Here we map the profile fields as stored in the uf_field table to their 'real entity'
* we also return the profile fieldname
...
...
This diff is collapsed.
Click to expand it.
tests/phpunit/api/v3/ProfileTest.php
+
16
−
1
View file @
79828a2d
...
...
@@ -463,9 +463,24 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
$profileFields
=
$this
->
callAPISuccess
(
'profile'
,
'getfields'
,
array
(
'get_options'
=>
'all'
,
'action'
=>
'submit'
,
'profile_id'
=>
'membership_batch_entry'
));
$getoptions
=
$this
->
callAPISuccess
(
'membership'
,
'getoptions'
,
array
(
'field'
=>
'membership_type'
,
'context'
=>
'validate'
));
$this
->
assertEquals
(
array_keys
(
$membershipTypes
[
'values'
]),
array_keys
(
$getoptions
[
'values'
]));
$this
->
assertEquals
(
array_keys
(
$membershipTypes
[
'values'
]),
array_keys
(
$profileFields
[
'values'
][
'membership_type'
][
'options'
]));
$this
->
assertEquals
(
array_keys
(
$membershipTypes
[
'values'
]),
array_keys
(
$profileFields
[
'values'
][
'membership_type
_id
'
][
'options'
]));
}
/**
* Test that the fields are returned in the right order despite the faffing around that goes on
*/
function
testMembershipGetFieldsOrder
()
{
$result
=
$this
->
callAPISuccess
(
'profile'
,
'getfields'
,
array
(
'action'
=>
'submit'
,
'profile_id'
=>
'membership_batch_entry'
));
$weight
=
1
;
foreach
(
$result
[
'values'
]
as
$fieldName
=>
$field
)
{
if
(
$fieldName
==
'profile_id'
)
{
continue
;
}
$this
->
assertEquals
(
$field
[
'weight'
],
$weight
);
$weight
++
;
}
}
/**
* Check we can submit membership batch profiles (create mode)
*/
...
...
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