Content Length Logic Condition (#63)

This commit is contained in:
Chirag 2023-01-21 17:28:01 +05:30 committed by GitHub
parent 970893329b
commit e073ca02a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 267 additions and 1 deletions

View File

@ -50,6 +50,24 @@ class FormPropertyLogicRule implements Rule, DataAwareRule
'type' => 'enum', 'type' => 'enum',
'values' => [true] 'values' => [true]
] ]
],
'content_length_equals' => [
'expected_type' => 'number'
],
'content_length_does_not_equal' => [
'expected_type' => 'number'
],
'content_length_greater_than' => [
'expected_type' => 'number'
],
'content_length_greater_than_or_equal_to' => [
'expected_type' => 'number'
],
'content_length_less_than' => [
'expected_type' => 'number'
],
'content_length_less_than_or_equal_to' => [
'expected_type' => 'number'
] ]
] ]
], ],
@ -86,6 +104,24 @@ class FormPropertyLogicRule implements Rule, DataAwareRule
'type' => 'enum', 'type' => 'enum',
'values' => [true] 'values' => [true]
] ]
],
'content_length_equals' => [
'expected_type' => 'number'
],
'content_length_does_not_equal' => [
'expected_type' => 'number'
],
'content_length_greater_than' => [
'expected_type' => 'number'
],
'content_length_greater_than_or_equal_to' => [
'expected_type' => 'number'
],
'content_length_less_than' => [
'expected_type' => 'number'
],
'content_length_less_than_or_equal_to' => [
'expected_type' => 'number'
] ]
] ]
], ],
@ -122,6 +158,24 @@ class FormPropertyLogicRule implements Rule, DataAwareRule
'type' => 'enum', 'type' => 'enum',
'values' => [true] 'values' => [true]
] ]
],
'content_length_equals' => [
'expected_type' => 'number'
],
'content_length_does_not_equal' => [
'expected_type' => 'number'
],
'content_length_greater_than' => [
'expected_type' => 'number'
],
'content_length_greater_than_or_equal_to' => [
'expected_type' => 'number'
],
'content_length_less_than' => [
'expected_type' => 'number'
],
'content_length_less_than_or_equal_to' => [
'expected_type' => 'number'
] ]
] ]
], ],
@ -158,6 +212,24 @@ class FormPropertyLogicRule implements Rule, DataAwareRule
'type' => 'enum', 'type' => 'enum',
'values' => [true] 'values' => [true]
] ]
],
'content_length_equals' => [
'expected_type' => 'number'
],
'content_length_does_not_equal' => [
'expected_type' => 'number'
],
'content_length_greater_than' => [
'expected_type' => 'number'
],
'content_length_greater_than_or_equal_to' => [
'expected_type' => 'number'
],
'content_length_less_than' => [
'expected_type' => 'number'
],
'content_length_less_than_or_equal_to' => [
'expected_type' => 'number'
] ]
] ]
], ],
@ -194,6 +266,24 @@ class FormPropertyLogicRule implements Rule, DataAwareRule
'type' => 'enum', 'type' => 'enum',
'values' => [true] 'values' => [true]
] ]
],
'content_length_equals' => [
'expected_type' => 'number'
],
'content_length_does_not_equal' => [
'expected_type' => 'number'
],
'content_length_greater_than' => [
'expected_type' => 'number'
],
'content_length_greater_than_or_equal_to' => [
'expected_type' => 'number'
],
'content_length_less_than' => [
'expected_type' => 'number'
],
'content_length_less_than_or_equal_to' => [
'expected_type' => 'number'
] ]
] ]
], ],

View File

@ -173,6 +173,25 @@ class FormLogicConditionChecker
return ($fieldDate >= now()->toDateString() && $fieldDate <= now()->addYears(1)->toDateString()); return ($fieldDate >= now()->toDateString() && $fieldDate <= now()->addYears(1)->toDateString());
} }
private function checkLength ($condition, $fieldValue, $operator = '==='): bool {
if(!$fieldValue || strlen($fieldValue) === 0) return false;
switch ($operator) {
case '===':
return strlen($fieldValue) === (int)$condition['value'];
case '!==':
return strlen($fieldValue) !== (int)$condition['value'];
case '>':
return strlen($fieldValue) > (int)$condition['value'];
case '>=':
return strlen($fieldValue) >= (int)$condition['value'];
case '<':
return strlen($fieldValue) < (int)$condition['value'];
case '<=':
return strlen($fieldValue) <= (int)$condition['value'];
}
return false;
}
private function textConditionMet (array $propertyCondition, $value): bool { private function textConditionMet (array $propertyCondition, $value): bool {
switch ($propertyCondition['operator']) { switch ($propertyCondition['operator']) {
@ -192,6 +211,18 @@ class FormLogicConditionChecker
return $this->checkIsEmpty($propertyCondition, $value); return $this->checkIsEmpty($propertyCondition, $value);
case 'is_not_empty': case 'is_not_empty':
return !$this->checkIsEmpty($propertyCondition, $value); return !$this->checkIsEmpty($propertyCondition, $value);
case 'content_length_equals':
return $this->checkLength($propertyCondition, $value, '===');
case 'content_length_does_not_equal':
return $this->checkLength($propertyCondition, $value, '!==');
case 'content_length_greater_than':
return $this->checkLength($propertyCondition, $value, '>');
case 'content_length_greater_than_or_equal_to':
return $this->checkLength($propertyCondition, $value, '>=');
case 'content_length_less_than':
return $this->checkLength($propertyCondition, $value, '<');
case 'content_length_less_than_or_equal_to':
return $this->checkLength($propertyCondition, $value, '<=');
} }
return false; return false;
} }
@ -214,6 +245,18 @@ class FormLogicConditionChecker
return $this->checkIsEmpty($propertyCondition, $value); return $this->checkIsEmpty($propertyCondition, $value);
case 'is_not_empty': case 'is_not_empty':
return !$this->checkIsEmpty($propertyCondition, $value); return !$this->checkIsEmpty($propertyCondition, $value);
case 'content_length_equals':
return $this->checkLength($propertyCondition, $value, '===');
case 'content_length_does_not_equal':
return $this->checkLength($propertyCondition, $value, '!==');
case 'content_length_greater_than':
return $this->checkLength($propertyCondition, $value, '>');
case 'content_length_greater_than_or_equal_to':
return $this->checkLength($propertyCondition, $value, '>=');
case 'content_length_less_than':
return $this->checkLength($propertyCondition, $value, '<');
case 'content_length_less_than_or_equal_to':
return $this->checkLength($propertyCondition, $value, '<=');
} }
return false; return false;
} }

View File

@ -36,6 +36,24 @@
true true
] ]
} }
},
"content_length_equals": {
"expected_type": "number"
},
"content_length_does_not_equal": {
"expected_type": "number"
},
"content_length_greater_than": {
"expected_type": "number"
},
"content_length_greater_than_or_equal_to": {
"expected_type": "number"
},
"content_length_less_than": {
"expected_type": "number"
},
"content_length_less_than_or_equal_to": {
"expected_type": "number"
} }
} }
}, },
@ -76,6 +94,24 @@
true true
] ]
} }
},
"content_length_equals": {
"expected_type": "number"
},
"content_length_does_not_equal": {
"expected_type": "number"
},
"content_length_greater_than": {
"expected_type": "number"
},
"content_length_greater_than_or_equal_to": {
"expected_type": "number"
},
"content_length_less_than": {
"expected_type": "number"
},
"content_length_less_than_or_equal_to": {
"expected_type": "number"
} }
} }
}, },
@ -116,6 +152,24 @@
true true
] ]
} }
},
"content_length_equals": {
"expected_type": "number"
},
"content_length_does_not_equal": {
"expected_type": "number"
},
"content_length_greater_than": {
"expected_type": "number"
},
"content_length_greater_than_or_equal_to": {
"expected_type": "number"
},
"content_length_less_than": {
"expected_type": "number"
},
"content_length_less_than_or_equal_to": {
"expected_type": "number"
} }
} }
}, },
@ -156,6 +210,24 @@
true true
] ]
} }
},
"content_length_equals": {
"expected_type": "number"
},
"content_length_does_not_equal": {
"expected_type": "number"
},
"content_length_greater_than": {
"expected_type": "number"
},
"content_length_greater_than_or_equal_to": {
"expected_type": "number"
},
"content_length_less_than": {
"expected_type": "number"
},
"content_length_less_than_or_equal_to": {
"expected_type": "number"
} }
} }
}, },
@ -196,6 +268,24 @@
true true
] ]
} }
},
"content_length_equals": {
"expected_type": "number"
},
"content_length_does_not_equal": {
"expected_type": "number"
},
"content_length_greater_than": {
"expected_type": "number"
},
"content_length_greater_than_or_equal_to": {
"expected_type": "number"
},
"content_length_less_than": {
"expected_type": "number"
},
"content_length_less_than_or_equal_to": {
"expected_type": "number"
} }
} }
}, },

View File

@ -159,6 +159,25 @@ function checkNextYear (condition, fieldValue) {
return (fieldDate >= today && fieldDate <= new Date(today.getFullYear() + 1, today.getMonth(), today.getDate())) return (fieldDate >= today && fieldDate <= new Date(today.getFullYear() + 1, today.getMonth(), today.getDate()))
} }
function checkLength (condition, fieldValue, operator = '===') {
if(!fieldValue || fieldValue.length === 0) return false;
switch (operator) {
case '===':
return fieldValue.length === parseInt(condition.value)
case '!==':
return fieldValue.length !== parseInt(condition.value)
case '>':
return fieldValue.length > parseInt(condition.value)
case '>=':
return fieldValue.length >= parseInt(condition.value)
case '<':
return fieldValue.length < parseInt(condition.value)
case '<=':
return fieldValue.length <= parseInt(condition.value)
}
return false
}
function textConditionMet (propertyCondition, value) { function textConditionMet (propertyCondition, value) {
switch (propertyCondition.operator) { switch (propertyCondition.operator) {
case 'equals': case 'equals':
@ -177,6 +196,18 @@ function textConditionMet (propertyCondition, value) {
return checkIsEmpty(propertyCondition, value) return checkIsEmpty(propertyCondition, value)
case 'is_not_empty': case 'is_not_empty':
return !checkIsEmpty(propertyCondition, value) return !checkIsEmpty(propertyCondition, value)
case 'content_length_equals':
return checkLength(propertyCondition, value, '===')
case 'content_length_does_not_equal':
return checkLength(propertyCondition, value, '!==')
case 'content_length_greater_than':
return checkLength(propertyCondition, value, '>')
case 'content_length_greater_than_or_equal_to':
return checkLength(propertyCondition, value, '>=')
case 'content_length_less_than':
return checkLength(propertyCondition, value, '<')
case 'content_length_less_than_or_equal_to':
return checkLength(propertyCondition, value, '<=')
} }
return false return false
} }
@ -198,7 +229,19 @@ function numberConditionMet (propertyCondition, value) {
case 'is_empty': case 'is_empty':
return checkIsEmpty(propertyCondition, value) return checkIsEmpty(propertyCondition, value)
case 'is_not_empty': case 'is_not_empty':
return !checkIsEmpty(propertyCondition, value) return checkIsEmpty(propertyCondition, value)
case 'content_length_equals':
return checkLength(propertyCondition, value, '===')
case 'content_length_does_not_equal':
return checkLength(propertyCondition, value, '!==')
case 'content_length_greater_than':
return checkLength(propertyCondition, value, '>')
case 'content_length_greater_than_or_equal_to':
return checkLength(propertyCondition, value, '>=')
case 'content_length_less_than':
return checkLength(propertyCondition, value, '<')
case 'content_length_less_than_or_equal_to':
return checkLength(propertyCondition, value, '<=')
} }
return false return false
} }