PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 3.6.62
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v3.6.62
6.2.14 6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 3.6.65 All 196 releases
fluentform / app / Services / ConditionAssesor.php

ConditionAssesor.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 3.6.62, at app/Services/ConditionAssesor.php

110 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentForm\App\Services;
4
5 use FluentForm\App\Helpers\Str;
6 use FluentForm\Framework\Helpers\ArrayHelper as Arr;
7
8 class ConditionAssesor
9 {
10 public static function evaluate(&$field, &$inputs)
11 {
12 $status = Arr::get($field, 'conditionals.status');
13
14
15 $conditionals = $status ? Arr::get($field, 'conditionals.conditions') : false;
16
17
18 $hasConditionMet = true;
19
20 if ($conditionals) {
21 $toMatch = Arr::get($field, 'conditionals.type');
22
23
24 foreach ($conditionals as $conditional) {
25
26 $hasConditionMet = static::assess($conditional, $inputs);
27
28 if($hasConditionMet && $toMatch == 'any') {
29 return true;
30 }
31
32 if ($toMatch === 'all' && !$hasConditionMet) {
33 return false;
34 }
35 }
36 }
37
38 return $hasConditionMet;
39 }
40
41 public static function assess(&$conditional, &$inputs)
42 {
43 if ($conditional['field']) {
44 $inputValue = Arr::get($inputs, $conditional['field']);
45
46 switch ($conditional['operator']) {
47 case '=':
48 if(is_array($inputValue)) {
49 return in_array($conditional['value'], $inputValue);
50 }
51 return $inputValue == $conditional['value'];
52 break;
53 case '!=':
54 if(is_array($inputValue)) {
55 return !in_array($conditional['value'], $inputValue);
56 }
57 return $inputValue != $conditional['value'];
58 break;
59 case '>':
60 return $inputValue > $conditional['value'];
61 break;
62 case '<':
63 return $inputValue < $conditional['value'];
64 break;
65 case '>=':
66 return $inputValue >= $conditional['value'];
67 break;
68 case '<=':
69 return $inputValue <= $conditional['value'];
70 break;
71 case 'startsWith':
72 return Str::startsWith($inputValue, $conditional['value']);
73 break;
74 case 'endsWith':
75 return Str::endsWith($inputValue, $conditional['value']);
76 break;
77 case 'contains':
78 return Str::contains($inputValue, $conditional['value']);
79 break;
80 case 'doNotContains':
81 return !Str::contains($inputValue, $conditional['value']);
82 break;
83 case 'length_equal':
84 if(is_array($inputValue)) {
85 return count($inputValue) == $conditional['value'];
86 }
87 $inputValue = strval($inputValue);
88 return strlen($inputValue) == $conditional['value'];
89 break;
90 case 'length_less_than':
91 if(is_array($inputValue)) {
92 return count($inputValue) < $conditional['value'];
93 }
94 $inputValue = strval($inputValue);
95 return strlen($inputValue) < $conditional['value'];
96 break;
97 case 'length_greater_than':
98 if(is_array($inputValue)) {
99 return count($inputValue) > $conditional['value'];
100 }
101 $inputValue = strval($inputValue);
102 return strlen($inputValue) > $conditional['value'];
103 break;
104 }
105 }
106
107 return false;
108 }
109 }
110