Skip to content

Commit 3b07d86

Browse files
authored
gcgs-gppa-query-builder-args.php: Added snippet to customize query builder arguments.
1 parent b5a0be7 commit 3b07d86

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
/**
3+
* Gravity Connect // Google Sheets // Custom Query Build Arguments
4+
*
5+
* This snippet customizes the generation of query builder arguments for Google Sheets queries.
6+
*
7+
* Installation:
8+
* 1. Install per https://gravitywiz.com/documentation/how-do-i-install-a-snippet/
9+
*/
10+
add_filter( 'gcgs_gppa_query_builder_args', function( $query_builder_args, $args, $object ) {
11+
/** @var string|string[] */
12+
$filter_value = null;
13+
14+
/** @var array */
15+
$filter = null;
16+
17+
/** @var int */
18+
$filter_group_index = null;
19+
20+
/** @var string */
21+
$property_id = null;
22+
23+
// phpcs:ignore WordPress.PHP.DontExtract.extract_extract
24+
extract( $args );
25+
26+
$column_letter = $object->get_column_letter( $args['primary_property_value'], $property_id );
27+
28+
if ( ! empty( $filter_value ) ) {
29+
$conditions = array();
30+
// Loop over the $value array and create conditions.
31+
foreach ( $filter_value as $v ) {
32+
if ( ! empty( $v ) ) {
33+
$conditions[] = sprintf( "lower(%s) = '%s'", $column_letter, strtolower( $v ) );
34+
}
35+
}
36+
37+
// Implode the conditions array with ' OR ' to form the $clause.
38+
$query_builder_args['where'][ $filter_group_index ][ $filter_group_index ] = implode( ' OR ', $conditions );
39+
}
40+
41+
return $query_builder_args;
42+
}, 10, 3);

0 commit comments

Comments
 (0)