forked from gravitywiz/snippet-library
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
/** | ||
* Gravity Perks // Conditional Logic Dates // Auto Rule Groups | ||
* https://gravitywiz.com/documentation/gravity-forms-conditional-logic-dates/#relative-dates | ||
* | ||
* This snippet introduces the concept of automatic rule groups to Conditional Logic Dates. Auto rule groups are intelligently | ||
* modified time-based rules, adjusted based on the date-and-time-based rules that precede them. | ||
* | ||
* For example, if a rule is configured where the Current Time is greater than 5:00pm and second rule where the Current | ||
* Time is less than 8:00am, it is logical that the second rule is intended to check for 8:00am tomorrow. This snippet | ||
* set a base date modifier to increment the date used to calculate the time value for the next day. | ||
* | ||
* In the future, we look forward to adding support for enhancing this snippet with support for applying the same logic | ||
* when a Current Time rule is preceded by a Date field rule. | ||
*/ | ||
add_filter( 'gform_form_post_get_meta', function( $form ) { | ||
|
||
if ( ! is_callable( array( 'GFForms', 'get_page' ) ) || GFForms::get_page() ) { | ||
return $form; | ||
} | ||
|
||
foreach ( $form['fields'] as $field ) { | ||
|
||
if ( empty( $field->conditionalLogic ) || $field->conditionalLogic['logicType'] !== 'all' ) { | ||
continue; | ||
} | ||
|
||
$start_time_rule = null; | ||
|
||
foreach ( $field->conditionalLogic['rules'] as &$rule ) { | ||
|
||
if ( $start_time_rule ) { | ||
$start_time = strtotime( $start_time_rule['value'] ); | ||
$end_time = strtotime( $rule['value'] ); | ||
if ( $rule['operator'] === '<' && $start_time > $end_time ) { | ||
$rule['gpcldBaseDate'] = 1; | ||
} | ||
$start_time_rule = null; | ||
} else if ( $rule['fieldId'] === '_gpcld_current_time' && $rule['operator'] === '>' ) { | ||
$start_time_rule = $rule; | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
return $form; | ||
} ); |