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
5 months ago
class-where.php
5 months ago
class-where-integer.php
43 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SearchRegex\Sql\Where; |
| 4 | |
| 5 | use SearchRegex\Sql; |
| 6 | |
| 7 | /** |
| 8 | * WHERE for an integer |
| 9 | */ |
| 10 | class Where_Integer extends Where { |
| 11 | /** |
| 12 | * Constructor |
| 13 | * |
| 14 | * @param Sql\Select\Select $column Column. |
| 15 | * @param string $logic Logic. |
| 16 | * @param integer $value Value. |
| 17 | */ |
| 18 | public function __construct( Sql\Select\Select $column, $logic, $value ) { |
| 19 | $map = [ |
| 20 | 'notequals' => '!=', |
| 21 | 'greater' => '>', |
| 22 | 'less' => '<', |
| 23 | ]; |
| 24 | |
| 25 | $logic_sql = '='; |
| 26 | if ( isset( $map[ $logic ] ) ) { |
| 27 | $logic_sql = $map[ $logic ]; |
| 28 | } |
| 29 | |
| 30 | if ( in_array( $logic, [ '=', '>', '<', '!=', '<=', '>=' ], true ) ) { |
| 31 | $logic_sql = $logic; |
| 32 | } |
| 33 | |
| 34 | parent::__construct( $column, $logic_sql, intval( $value, 10 ) ); |
| 35 | } |
| 36 | |
| 37 | public function get_value() { |
| 38 | global $wpdb; |
| 39 | |
| 40 | return $wpdb->prepare( '%d', $this->value ); |
| 41 | } |
| 42 | } |
| 43 |