]> _ Git - cubist_cms-back.git/commitdiff
wip #7434
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 3 Apr 2025 10:25:39 +0000 (12:25 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 3 Apr 2025 10:25:39 +0000 (12:25 +0200)
src/app/Magic/Fields/Field.php
src/resources/views/when.blade.php

index 40d97aeb8672c19b42c03e20a4796ded4db7b3e4..5eacfd07e875e32eae9dbfc6b7d8b11d063dc6c8 100644 (file)
@@ -421,6 +421,7 @@ class Field implements \ArrayAccess
     protected function when(): bool|string
     {
         $defaultOperator = '=';
+        $defaultLogicalOperator = 'AND';
         if (!$this->hasAttribute('when')) {
             return false;
         }
@@ -429,7 +430,7 @@ class Field implements \ArrayAccess
         $res = [];
         foreach ($when as $attr => $w) {
             if (is_scalar($w)) {
-                $w = ['values' => [$w], 'operator' => $defaultOperator];
+                $w = ['values' => [$w], 'operator' => $defaultOperator, 'logical_operator' => $defaultLogicalOperator];
             } else {
                 if (isset($w['value'])) {
                     $w['values'] = $w['value'];
@@ -443,8 +444,11 @@ class Field implements \ArrayAccess
                     if (!isset($w['operator'])) {
                         $w['operator'] = $defaultOperator;
                     }
+                    if (!isset($w['logical_operator'])) {
+                        $w['logical_operator'] = $defaultLogicalOperator;
+                    }
                 } else {
-                    $w = ['values' => $w, 'operator' => $defaultOperator];
+                    $w = ['values' => $w, 'operator' => $defaultOperator, 'logical_operator' => $defaultLogicalOperator];
                 }
             }
             $res[$attr] = $w;
index 66e3002ef2579c9744da18900484cbcbf9939602..b1feb424fd784458661e708904c4f19e5aca0905 100644 (file)
                                 order = Math.min(order, condition.order);
                             }
                         });
-                        if (matchproperty === false) {
-                            match = false
-                            return false;
+
+                        if (conditions.logical_operator === 'AND') {
+                            match = match && matchproperty;
+                        } else if (conditions.logical_operator === 'OR') {
+                            match = match || matchproperty;
                         }
                     });
 
@@ -83,7 +85,7 @@
 
             function checkCondition(condition, operator, val) {
                 try {
-                    if(val==='/index.html') {
+                    if (val === '/index.html') {
                         console.log(condition, operator, val);
                     }
                     if (condition.id === undefined) {