class-where-and.php
5 months ago
class-where-date.php
5 months ago
class-where-in.php
5 months ago
class-where-integer.php
5 months ago
class-where-null.php
5 months ago
class-where-or.php
5 months ago
class-where-string.php
1 month ago
class-where.php
5 months ago
class-where-in.php
48 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SearchRegex\Sql\Where; |
| 4 | |
| 5 | use SearchRegex\Sql; |
| 6 | |
| 7 | /** |
| 8 | * WHERE for a IN |
| 9 | */ |
| 10 | class Where_In extends Where { |
| 11 | /** |
| 12 | * Constructor |
| 13 | * |
| 14 | * @param Sql\Select\Select $column Column. |
| 15 | * @param string $logic Logic. |
| 16 | * @param list<string|int> $value Value. |
| 17 | */ |
| 18 | public function __construct( Sql\Select\Select $column, $logic, $value ) { |
| 19 | $logic_sql = 'IN'; |
| 20 | |
| 21 | if ( $logic === 'NOT IN' ) { |
| 22 | $logic_sql = 'NOT IN'; |
| 23 | } |
| 24 | |
| 25 | parent::__construct( $column, $logic_sql, $value ); |
| 26 | } |
| 27 | |
| 28 | public function get_value() { |
| 29 | global $wpdb; |
| 30 | |
| 31 | if ( ! is_array( $this->value ) ) { |
| 32 | return ''; |
| 33 | } |
| 34 | |
| 35 | $values = array_map( |
| 36 | function ( $item ) use ( $wpdb ) { |
| 37 | if ( is_numeric( $item ) ) { |
| 38 | return $wpdb->prepare( '%d', $item ); |
| 39 | } |
| 40 | |
| 41 | return $wpdb->prepare( '%s', $item ); |
| 42 | }, $this->value |
| 43 | ); |
| 44 | |
| 45 | return '(' . implode( ', ', $values ) . ')'; |
| 46 | } |
| 47 | } |
| 48 |