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
9fe6051a
Commit
9fe6051a
authored
12 years ago
by
eileen
Browse files
Options
Downloads
Patches
Plain Diff
fixes to value and weight handling CRM-12133
parent
e99c9805
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
CRM/Core/BAO/OptionValue.php
+33
-17
33 additions, 17 deletions
CRM/Core/BAO/OptionValue.php
api/v3/CustomSearch.php
+0
-1
0 additions, 1 deletion
api/v3/CustomSearch.php
api/v3/ReportTemplate.php
+0
-1
0 additions, 1 deletion
api/v3/ReportTemplate.php
with
33 additions
and
19 deletions
CRM/Core/BAO/OptionValue.php
+
33
−
17
View file @
9fe6051a
...
...
@@ -40,11 +40,9 @@ class CRM_Core_BAO_OptionValue extends CRM_Core_DAO_OptionValue {
function
__construct
()
{
parent
::
__construct
();
}
/*
/*
*
* Create option value - note that the create function calls 'add' but
* has more business logic
* Note that this is the right place to add pre & post hooks if we want them
* ? any reason not to?
*
* @param array $params input parameters
*/
...
...
@@ -64,11 +62,13 @@ class CRM_Core_BAO_OptionValue extends CRM_Core_DAO_OptionValue {
* This functions sets default parameters if not set:
* - name & label are set to each other as required (it might make more sense for one
* to be required but this would mean a change to the api level)
* - ditto weight & value - but they both default to next weight
* NB am not sure that weight should be set to value as higher priority to
* setting it to the next weight - although this is existing logic
* - weight & value will be set to their respective option groups next values
* if nothing is passed in.
*
* Note this function does not check for presence of $params['id'] so should only be called
* if 'id' is not present
*
* @param
unknown_type
$params
* @param
array
$params
*/
static
function
setDefaults
(
&
$params
){
if
(
empty
(
$params
[
'label'
])){
...
...
@@ -78,19 +78,32 @@ class CRM_Core_BAO_OptionValue extends CRM_Core_DAO_OptionValue {
$params
[
'name'
]
=
$params
[
'label'
];
}
if
(
empty
(
$params
[
'weight'
])){
//@todo consider this logic - see block comments
$params
[
'weight'
]
=
CRM_Utils_Array
::
value
(
'value'
,
$params
,
(
int
)
CRM_Utils_Weight
::
getDefaultWeight
(
'CRM_Core_DAO_OptionValue'
,
array
(
'option_group_id'
=>
$params
[
'option_group_id'
]))
);
$params
[
'weight'
]
=
(
int
)
CRM_Utils_Weight
::
getDefaultWeight
(
'CRM_Core_DAO_OptionValue'
,
array
(
'option_group_id'
=>
$params
[
'option_group_id'
]));
}
if
(
empty
(
$params
[
'value'
])){
$params
[
'value'
]
=
CRM_Utils_Array
::
value
(
'weight'
,
$params
,
(
int
)
CRM_Utils_Weight
::
getDefaultWeight
(
'CRM_Core_DAO_OptionValue'
,
array
(
'option_group_id'
=>
$params
[
'option_group_id'
]))
);
$params
[
'value'
]
=
self
::
getNextValue
(
$params
);
}
}
/**
* Get next available value
* We will take the highest numeric value (or 0 if no numeric values exist)
* and add one. The calling function is responsible for any
* more complex decision making
* @param array $params
*/
static
function
getNextValue
(
$params
){
$bao
=
new
CRM_Core_BAO_OptionValue
();
$bao
->
option_group_id
=
$params
[
'option_group_id'
];
if
(
isset
(
$params
[
'domain_id'
])){
$bao
->
domain_id
=
$params
[
'domain_id'
];
}
$bao
->
selectAdd
();
$bao
->
whereAdd
(
"value REGEXP '^[0-9]+$'"
);
$bao
->
selectAdd
(
'(ROUND(COALESCE(MAX(value),0)) +1) as nextvalue'
);
$bao
->
find
(
TRUE
);
return
$bao
->
nextvalue
;
}
/**
* Takes a bunch of params that are needed to match certain criteria and
* retrieves the relevant objects. Typically the valid params are only
...
...
@@ -141,6 +154,10 @@ class CRM_Core_BAO_OptionValue extends CRM_Core_DAO_OptionValue {
*/
static
function
add
(
&
$params
,
&
$ids
)
{
// CRM-10921: do not reset attributes to default if this is an update
//@todo consider if defaults are being set in the right place. 'dumb' defaults like
// these would be usefully set @ the api layer so they are visible to api users
// complex defaults like the domain id below would make sense in the setDefauls function
// but unclear what other ways this function is being used
if
(
!
CRM_Utils_Array
::
value
(
'optionValue'
,
$ids
))
{
$params
[
'is_active'
]
=
CRM_Utils_Array
::
value
(
'is_active'
,
$params
,
FALSE
);
$params
[
'is_default'
]
=
CRM_Utils_Array
::
value
(
'is_default'
,
$params
,
FALSE
);
...
...
@@ -167,7 +184,6 @@ class CRM_Core_BAO_OptionValue extends CRM_Core_DAO_OptionValue {
$p
=
array
(
1
=>
array
(
$params
[
'option_group_id'
],
'Integer'
));
CRM_Core_DAO
::
executeQuery
(
$query
,
$p
);
}
$groupName
=
CRM_Core_DAO
::
getFieldValue
(
'CRM_Core_DAO_OptionGroup'
,
$params
[
'option_group_id'
],
'name'
,
'id'
);
...
...
This diff is collapsed.
Click to expand it.
api/v3/CustomSearch.php
+
0
−
1
View file @
9fe6051a
...
...
@@ -54,7 +54,6 @@ function civicrm_api3_custom_search_create($params) {
function
_civicrm_api3_custom_search_create_spec
(
&
$params
)
{
require_once
'api/v3/OptionValue.php'
;
_civicrm_api3_option_value_create_spec
(
$params
);
$params
[
'weight'
][
'api.default'
]
=
'next'
;
$params
[
'name'
][
'api.aliases'
]
=
array
(
'class_name'
);
}
...
...
This diff is collapsed.
Click to expand it.
api/v3/ReportTemplate.php
+
0
−
1
View file @
9fe6051a
...
...
@@ -50,7 +50,6 @@ function civicrm_api3_report_template_create($params) {
function
_civicrm_api3_report_template_create_spec
(
&
$params
)
{
require_once
'api/v3/OptionValue.php'
;
_civicrm_api3_option_value_create_spec
(
$params
);
$params
[
'weight'
][
'api.default'
]
=
'next'
;
$params
[
'value'
][
'api.aliases'
]
=
array
(
'report_url'
);
$params
[
'name'
][
'api.aliases'
]
=
array
(
'class_name'
);
// $params['component']['api.required'] = TRUE;
...
...
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