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-or.php
57 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SearchRegex\Sql\Where; |
| 4 | |
| 5 | class Where_Or extends Where { |
| 6 | /** |
| 7 | * Array of WHERE objects that will be ORd together |
| 8 | * |
| 9 | * @readonly |
| 10 | * @var array<Where> |
| 11 | */ |
| 12 | protected array $wheres; |
| 13 | |
| 14 | /** |
| 15 | * Constructor |
| 16 | * |
| 17 | * @param array<Where> $wheres Wheres. |
| 18 | * @phpstan-ignore constructor.missingParentCall |
| 19 | */ |
| 20 | public function __construct( array $wheres ) { |
| 21 | $this->wheres = $wheres; |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * Get the WHEREs as a group |
| 26 | * |
| 27 | * @param string $logic Logic. |
| 28 | * @return string |
| 29 | */ |
| 30 | protected function get_group( $logic ) { |
| 31 | $start = ''; |
| 32 | $end = ''; |
| 33 | |
| 34 | if ( count( $this->wheres ) > 1 ) { |
| 35 | $start = '('; |
| 36 | $end = ')'; |
| 37 | } |
| 38 | |
| 39 | $sql = array_map( |
| 40 | fn( $where ) => $where->get_as_sql(), |
| 41 | $this->wheres |
| 42 | ); |
| 43 | |
| 44 | return $start . implode( ' ' . $logic . ' ', $sql ) . $end; |
| 45 | } |
| 46 | |
| 47 | public function get_as_sql() { |
| 48 | return $this->get_group( 'OR' ); |
| 49 | } |
| 50 | |
| 51 | public function update_column( $column, $updated_column ) { |
| 52 | foreach ( $this->wheres as $where ) { |
| 53 | $where->update_column( $column, $updated_column ); |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 |