Thank you for the answers, guys!
Oh, it's just product options. Product type, and some parameters, which allows/disallows usage of some other fields. For example:
If product_3D_geometry=polys;
than next Integer fields will be shown: product_3D_tris, product_3D_vertex, product_3D_polys; but product_3D_voxels Integer field will be ignored.
or
If product_3D_geometry=nurbs;
than product_3D_vertex Integer field will be shown; but next Integer fields will be ignored: product_3D_tris, product_3D_polys, product_3D_voxels.
etc...
Some parameters may change over time, and hidden fields continue to be stored in the database. That's I want to render lines from loop only for actual parameters. Maybe I'm wrong, but don't see a simple solution at the moment.
I had wrote small filter for this task:
function compareCondVals( $fieldName, $op, $fieldValue ) {
//Allowed operators for Inputfield Dependencies
switch( $op ) {
case '!=': return !in_array($fieldName, $fieldValue);
case '=': return in_array($fieldName, $fieldValue);
case '<=': return $fieldName <= min( $fieldValue ); //I know it is stupid to use multiple values in such cases, but just in case.
case '<': return $fieldName < min( $fieldValue );
case '>': return $fieldName > max( $fieldValue );
case '>=': return $fieldName >= max( $fieldValue );
case '%=': return $fieldName %= $fieldValue[0];
case '*=': return $fieldName *= $fieldValue[0];
}
}
function extractConditionalRule ($conditionString) {
$patternOperators = '/>=|>|!==|!=|==|=|\*=|%=|<=|</x';
preg_match( $patternOperators, $conditionString, $op );
$op = $op[0];
$conditionValues = explode( $op, $conditionString );
$conditionMultiple = explode( "|", $conditionValues[1] );
$conditionFieldName = $conditionValues[0];
$conditionFieldObj = wire( 'page' )->get( $conditionFieldName );
$conditionFieldType = wire( 'page' )->wire( 'fields' )->get($conditionFieldName)->type->name;
if ( $conditionFieldType == "FieldtypeOptions" ) {
$conditionFieldValue = $conditionFieldObj->id; //I use IDs for Options fields.
} else {
$conditionFieldValue = $conditionFieldObj->value;
}
return compareCondVals( $conditionFieldValue, $op, $conditionMultiple );
};
function extractMultipleConditionalRules ($conditionArray) {
$patternSeparator = '/\,\s|\,|\s/';
$conditionArray = preg_split( $patternSeparator, $conditionArray );
foreach ( $conditionArray as $conditionString ) {
$conditionSubArray []= extractConditionalRule( $conditionString );
}
return min( $conditionSubArray );
}
foreach ($page->fields as $field) {
$name = $field->name;
$showIf = $field->showIf;
... //Other data here
$isShown = $showIf != null ? extractMultipleConditionalRules ($showIf) : true;
if ( $isShown ) {
$fieldsArray[$name] = array(
... //Some data here
);
}
}