class-clauses.php
2 years ago
class-database.php
2 years ago
class-escape.php
2 years ago
class-groupby.php
2 years ago
class-joins.php
2 years ago
class-orderby.php
2 years ago
class-query-builder.php
2 years ago
class-select.php
2 years ago
class-translate.php
2 years ago
class-where.php
2 years ago
index.php
2 years ago
class-joins.php
93 lines
| 1 | <?php |
| 2 | /** |
| 3 | * The joins functions. |
| 4 | * |
| 5 | * @since 1.0.0 |
| 6 | * @package MyThemeShop |
| 7 | * @subpackage MyThemeShop\Database |
| 8 | * @author MyThemeShop <admin@mythemeshop.com> |
| 9 | */ |
| 10 | |
| 11 | namespace MyThemeShop\Database; |
| 12 | |
| 13 | /** |
| 14 | * Joins class. |
| 15 | */ |
| 16 | trait Joins { |
| 17 | |
| 18 | /** |
| 19 | * Generate left join clause. |
| 20 | * |
| 21 | * @param string $table The SQL table. |
| 22 | * @param mixed $column1 The SQL Column. |
| 23 | * @param mixed $column2 The SQL Column. |
| 24 | * @param string $operator The Operator. |
| 25 | * @param string $alias The table alias. |
| 26 | * |
| 27 | * @return self The current query builder. |
| 28 | */ |
| 29 | public function leftJoin( $table, $column1, $column2, $operator = '=', $alias = '' ) { // @codingStandardsIgnoreLine |
| 30 | if ( empty( $table ) || empty( $column1 ) || empty( $column2 ) ) { |
| 31 | return $this; |
| 32 | } |
| 33 | |
| 34 | if ( ! empty( $alias ) ) { |
| 35 | $table = "{$table} AS {$alias}"; |
| 36 | } |
| 37 | |
| 38 | $this->add_sql_clause( 'left_join', "LEFT JOIN {$table} ON {$column1} {$operator} {$column2}" ); |
| 39 | |
| 40 | return $this; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Generate right join clause. |
| 45 | * |
| 46 | * @param string $table The SQL table. |
| 47 | * @param mixed $column1 The SQL Column. |
| 48 | * @param mixed $column2 The SQL Column. |
| 49 | * @param string $operator The Operator. |
| 50 | * @param string $alias The table alias. |
| 51 | * |
| 52 | * @return self The current query builder. |
| 53 | */ |
| 54 | public function rightJoin( $table, $column1, $column2, $operator = '=', $alias = '' ) { // @codingStandardsIgnoreLine |
| 55 | if ( empty( $table ) || empty( $column1 ) || empty( $column2 ) ) { |
| 56 | return $this; |
| 57 | } |
| 58 | |
| 59 | if ( ! empty( $alias ) ) { |
| 60 | $table = "{$table} AS {$alias}"; |
| 61 | } |
| 62 | |
| 63 | $this->add_sql_clause( 'right_join', "RIGHT JOIN {$table} ON {$column1} {$operator} {$column2}" ); |
| 64 | |
| 65 | return $this; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Generate left join clause. |
| 70 | * |
| 71 | * @param string $table The SQL table. |
| 72 | * @param mixed $column1 The SQL Column. |
| 73 | * @param mixed $column2 The SQL Column. |
| 74 | * @param string $operator The Operator. |
| 75 | * @param string $alias The table alias. |
| 76 | * |
| 77 | * @return self The current query builder. |
| 78 | */ |
| 79 | public function join( $table, $column1, $column2, $operator = '=', $alias = '' ) { // @codingStandardsIgnoreLine |
| 80 | if ( empty( $table ) || empty( $column1 ) || empty( $column2 ) ) { |
| 81 | return $this; |
| 82 | } |
| 83 | |
| 84 | if ( ! empty( $alias ) ) { |
| 85 | $table = "{$table} AS {$alias}"; |
| 86 | } |
| 87 | |
| 88 | $this->add_sql_clause( 'join', "JOIN {$table} ON {$column1} {$operator} {$column2}" ); |
| 89 | |
| 90 | return $this; |
| 91 | } |
| 92 | } |
| 93 |