Skip to content

Commit 4656d8a

Browse files
authored
gppa-use-choice-labels-when-populating-from-another-field.php: Added support for skipping conditionally hidden Round Robin fields.
* Added support for skipping conditionally hidden Round Robin fields. * `gppa-use-choice-labels-when-populating-from-another-field.php`: Updated to use CSS class to initialize.
1 parent 0f0121e commit 4656d8a

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

gravity-forms/gw-round-robin.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* employees are assigned to the next available shift, and/or balancing the responsibility of any task-oriented
1111
* submission (e.g. support request, job application, contest entry).
1212
*
13-
* @version 1.5
13+
* @version 1.6
1414
* @author David Smith <[email protected]>
1515
* @license GPL-2.0+
1616
* @link http://gravitywiz.com/
@@ -66,14 +66,22 @@ public function apply_round_robin( $entry, $form ) {
6666
return $entry;
6767
}
6868

69+
$field = GFAPI::get_field( $entry['form_id'], $this->_args['field_id'] );
70+
71+
// Ignore if Round Robin field is hidden by conditional logic.
72+
if ( GFFormsModel::is_field_hidden( $form, $field, array() ) ) {
73+
return $entry;
74+
}
75+
6976
$rotation = $this->get_rotation_values( $this->_args['field_id'], $form );
70-
$last_entry = $this->get_last_entry( $entry, GFAPI::get_field( $entry['form_id'], $this->_args['field_id'] ) );
77+
$last_entry = $this->get_last_entry( $entry, $field );
7178

7279
// Get the value submitted for our designated field in the last entry.
7380
$last_value = rgar( $last_entry, $this->_args['field_id'] );
7481

7582
// Determine the next index at which to fetch our value.
76-
$next_index = empty( $last_value ) ? 0 : array_search( $last_value, $rotation ) + 1;
83+
$next_index = empty( $last_value ) ? array_search( $entry[ $this->_args['field_id'] ], $rotation ) : array_search( $last_value, $rotation ) + 1;
84+
7785
if ( $next_index > count( $rotation ) - 1 ) {
7886
$next_index = 0;
7987
}
@@ -92,7 +100,14 @@ public function apply_round_robin( $entry, $form ) {
92100

93101
public function get_last_entry( $entry, $field ) {
94102

95-
$field_filters = array();
103+
// Find the last entry that has a value in our Round Robin field.
104+
$field_filters = array(
105+
array(
106+
'key' => $this->_args['field_id'],
107+
'operator' => 'ISNOT',
108+
'value' => '',
109+
),
110+
);
96111

97112
// GPPA integration only supports the first group of filters and filters that are field-specific (no custom values).
98113
if ( is_callable( 'gp_populate_anything' ) && $field->{'gppa-choices-enabled'} ) {

0 commit comments

Comments
 (0)