Skip to content

Commit dc9152c

Browse files
committed
Merge pull request arnebratt#9 from arnebratt/translations-logic
Added support for choosing "and" and "or" logic between local filters
2 parents 2648f6c + d36c0fe commit dc9152c

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

classes/translations_filter.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ function eZTranslationsFilter()
99
function createSqlParts( $params )
1010
{
1111
$sqlJoins = '';
12+
$is_or_logic = isset( $params['or'] ) && ( $params['or'] === true );
1213

1314
if ( isset( $params['locales'] ) )
1415
{
@@ -23,7 +24,8 @@ function createSqlParts( $params )
2324
}
2425
if ( $language_mask )
2526
{
26-
$sqlJoins = " ezcontentobject.language_mask & $language_mask AND ";
27+
$sqlJoins = ( $is_or_logic ) ? " ezcontentobject.language_mask & $language_mask AND " :
28+
" ezcontentobject.language_mask & $language_mask = $language_mask AND ";
2729
}
2830
}
2931

filters/fetchnodelist.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ classname - A list of class identifiers separated by a colon
1515
depth - Max level of depth to fetch nodes from (default is current folder only)
1616
ignore_visibility - Fetch also hidden nodes
1717
locales - List of translation locale codes to filter on, separated by a colon (ex."nor-NO:eng-GB")
18+
The first locales parameter can be an optional "or" or "and", to specify the logic between the languages (default is "or")
1819
';
1920
}
2021

@@ -65,8 +66,14 @@ function getObjectList()
6566
}
6667
if ( !empty( $this->locales ) )
6768
{
69+
$is_or_logic = true;
70+
if ( $this->locales[0] == 'and' OR $this->locales[0] == 'or' )
71+
{
72+
$is_or_logic = !( array_shift( $this->locales ) == 'and' );
73+
}
6874
$parameters['extended_attribute_filter'] = array( 'id' => 'TranslationsFilter',
69-
'params' => array( 'locales' => $this->locales ) );
75+
'params' => array( 'or' => $is_or_logic,
76+
'locales' => $this->locales ) );
7077
}
7178
return eZFunctionHandler::execute( 'content', 'list', $parameters );
7279
}

0 commit comments

Comments
 (0)