Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
CiviCRM Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Analyze
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
Development
CiviCRM Core
Commits
faf8c53b
Commit
faf8c53b
authored
11 years ago
by
eileen
Browse files
Options
Downloads
Patches
Plain Diff
CRM-13149 array filter now working on relationship type
parent
75638074
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
CRM/Contact/BAO/Relationship.php
+1
-1
1 addition, 1 deletion
CRM/Contact/BAO/Relationship.php
CRM/Core/DAO.php
+55
-1
55 additions, 1 deletion
CRM/Core/DAO.php
with
56 additions
and
2 deletions
CRM/Contact/BAO/Relationship.php
+
1
−
1
View file @
faf8c53b
...
...
@@ -890,7 +890,7 @@ LEFT JOIN civicrm_country ON (civicrm_address.country_id = civicrm_country.id)
if
(
!
empty
(
$params
[
'relationship_type_id'
]))
{
if
(
is_array
(
$params
[
'relationship_type_id'
]))
{
// get our special function from DAO to deal with this
//
$where .=
$this->
createSQLFilter('relationship_type_id', $params['relationship_type_id'], 'Integer');
$where
.
=
" AND "
.
CRM_Core_DAO
::
createSQLFilter
(
'relationship_type_id'
,
$params
[
'relationship_type_id'
],
'Integer'
);
}
else
{
$where
.
=
' AND relationship_type_id = '
.
CRM_Utils_Type
::
escape
(
$params
[
'relationship_type_id'
],
'Positive'
);
...
...
This diff is collapsed.
Click to expand it.
CRM/Core/DAO.php
+
55
−
1
View file @
faf8c53b
...
...
@@ -1811,5 +1811,59 @@ EOS;
return
$contexts
;
}
}
/**
* SQL version of api function to assign filters to the DAO based on the syntax
* $field => array('IN' => array(4,6,9))
* OR
* $field => array('LIKE' => array('%me%))
* etc
*
* @param $field sql filter to be applied
* @param $fi
*/
public
function
createSQLFilter
(
$fieldName
,
$filter
,
$type
,
$alias
=
NULL
)
{
// http://issues.civicrm.org/jira/browse/CRM-9150 - stick with 'simple' operators for now
// support for other syntaxes is discussed in ticket but being put off for now
//@todo consolidate this and the version from api/v3/utils.php into one location
$acceptedSQLOperators
=
array
(
'='
,
'<='
,
'>='
,
'>'
,
'<'
,
'LIKE'
,
"<>"
,
"!="
,
"NOT LIKE"
,
'IN'
,
'NOT IN'
,
'BETWEEN'
,
'NOT BETWEEN'
);
foreach
(
$filter
as
$operator
=>
$criteria
)
{
if
(
in_array
(
$operator
,
$acceptedSQLOperators
))
{
switch
(
$operator
)
{
// unary operators
case
'IS NULL'
:
case
'IS NOT NULL'
:
return
(
sprintf
(
'%s %s'
,
$fieldName
,
$operator
));
break
;
// ternary operators
case
'BETWEEN'
:
case
'NOT BETWEEN'
:
if
(
empty
(
$criteria
[
0
])
||
empty
(
$criteria
[
1
]))
{
throw
new
exception
(
"invalid criteria for
$operator
"
);
}
return
(
sprintf
(
'%s '
.
$operator
.
' "%s" AND "%s"'
,
$fieldName
,
CRM_Core_DAO
::
escapeString
(
$criteria
[
0
]),
CRM_Core_DAO
::
escapeString
(
$criteria
[
1
])));
break
;
// n-ary operators
case
'IN'
:
case
'NOT IN'
:
if
(
empty
(
$criteria
))
{
throw
new
exception
(
"invalid criteria for
$operator
"
);
}
$escapedCriteria
=
array_map
(
array
(
'CRM_Core_DAO'
,
'escapeString'
),
$criteria
);
return
(
sprintf
(
'%s %s ("%s")'
,
$fieldName
,
$operator
,
implode
(
'", "'
,
$escapedCriteria
)));
break
;
// binary operators
default
:
return
(
sprintf
(
'%s %s "%s"'
,
$fieldName
,
$operator
,
CRM_Core_DAO
::
escapeString
(
$criteria
)));
}
}
}
}
}
\ No newline at end of file
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