Project

General

Profile

Feature #18211 » 7531.patch

Administrator Admin, 2009-06-26 22:32

View differences:

t3lib/class.t3lib_tceforms.php (working copy)
/**
* Returns true, if the evaluation of the required-field code is OK.
* may contain displayCond arrays
*
* @param string or array The required-field code
* @param array The record to evaluate
* @param string FlexForm value key, eg. vDEF
* @return boolean
*/
function isDisplayCondition($displayCondition, $row, $ffValueKey = '', $recursion = 0) {
if (is_array($displayCondition)) { // conditions givens as array ('AND|OR' => condition array) ?
$conditionEval = array('AND' => array(), 'OR' => array()); // collects AND and OR evaluations
foreach ($displayCondition as $andOr => $groupedDisplayConditions) {
if ($andOr != 'AND' && $andOr != 'OR' || !is_array($groupedDisplayConditions)) {
continue; // invalid line.
} else {
foreach ($groupedDisplayConditions as $key => $singleDisplayCondition) {
if (($key == 'AND' || $key == 'OR') && is_array($singleDisplayCondition)) {
// recursion statement: condition is 'AND' or 'OR' and there is an array (should be conditions again)
$conditionEval[$andOr][] = $this->isDisplayCondition(
array($key => $singleDisplayCondition),
$row,
$ffValueKey,
$recursion + 1
);
} else {
// condition statement: collect evaluation of this single condition.
$conditionEval[$andOr][] = $this->isDisplaySingleCondition($singleDisplayCondition, $row, $ffValueKey);
}
}
}
}
if (count($conditionEval['OR']) > 0 && in_array(true, $conditionEval['OR'], true)) {
// there were OR conditions and at least one of them is true
$conditionsOkay = true;
} elseif (count($conditionEval['AND']) > 0 && !in_array(false, $conditionEval['AND'], true)) {
// there were AND conditions and none of them is false
$conditionsOkay = true;
} elseif(count($conditionEval['OR']) > 0 || count($conditionEval['AND']) > 0) {
// there were some conditions. But no OR was true and at least one AND was false
$conditionsOkay = false;
} else {
// there were no proper conditions - misconfigured. Return true.
$conditionsOkay = true;
}
} else { // displayCond is not an array - just get its value
$conditionsOkay = $this->isDisplaySingleCondition($displayCondition, $row, $ffValueKey='');
}
return $conditionsOkay;
}
/**
* Returns true, if the evaluation of a single condition against the required-field code is OK.
*
* @param string The required-field code
* @param array The record to evaluate
* @param string FlexForm value key, eg. vDEF
* @return boolean
*/
function isDisplayCondition($displayCond,$row,$ffValueKey='') {
function isDisplaySingleCondition($displayCond,$row,$ffValueKey='') {
$output = FALSE;
$parts = explode(':',$displayCond);
(1-1/4)