[TYPO3-core] RFC #8897: BUG: "displayCond" => "FIELD:myfield:IN:1, 2" is not working correct on DB relations
Martin Kutschker
masi-no at spam-typo3.org
Sat Jul 12 16:04:10 CEST 2008
alex widschwendter schrieb:
> This is an SVN patch request.
>
> Type: New feature
>
> Bugtracker references:
> http://bugs.typo3.org/view.php?id=8897
>
> Branches:
> TYPO3_4-2 and trunk
>
> Problem:
> if setting a displayCond of type FIELD with IN the check is not correct
> for DB relations because the field value to evaluate is transported with
> the label in form
> uid|label. additonal the check routine fails if you want to test against
> multiple values in list.
>
> Solution:
> attached patch converts the malformed values into arrays for proper
> testing. addtional to that, a new keyword "ALL" is introduced for this
> type of displayCond to specify if all id's must exist in the field to
> test against for true evaluation.
No functional test but some comments on the code.
a)
Instead of
$tmpArr2 = explode('|',$value);
$newFieldValue .= $tmpArr2[0].',';
use
list($tmpFieldvalue) = explode('|',$value);
$newFieldValue .= $tmpFieldvalue.',';
No need for an extra array here.
b)
$theFieldValueArr = explode(',',$theFieldValue);
$theReferenceValueArr = explode(',',$parts[3]);
...
if (is_array($theFieldValueArr) && is_array($theReferenceValueArr) ) {
...
}
IMHO the if condition will always be true as explode() always returns an
array. Probably a count() on $theFieldValueArr is enough to determine if
t3lib_div:inList() is the right choice or not.
And please change the order of the conditions in the if clauses! In the
worst case you do a count() on the same array_intersect() twice. Moving
the comparsion with 'ALL' to the front will allow for a short cut
evaluation. Anway I suggest this code:
$matchingValuesCount =
count(array_intersect($theReferenceValueArr,$theFieldValueArr));
if ($parts[4] == 'ALL' && $matchingValuesCount == $valueCount) {
$output = TRUE;
} elseif ($parts[4] != 'ALL' && $matchingValuesCount > 0) {
$output = TRUE;
}
Masi
More information about the TYPO3-team-core
mailing list