PluginProbe ʕ •ᴥ•ʔ
Search Regex / trunk
Search Regex vtrunk
trunk 1.4.12 1.4.13 1.4.14 1.4.15 1.4.16 2.0 2.0.1 2.1 2.2 2.2.1 2.3 2.3.1 2.3.2 2.3.3 2.4 2.4.1 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.1 3.1.1 3.1.2 3.2 3.3 3.3.0 3.3.1 3.4 3.4.1 3.4.2
search-regex / includes / sql / join / class-comment.php
search-regex / includes / sql / join Last commit date
class-comment.php 5 months ago class-join.php 4 months ago class-meta.php 5 months ago class-post.php 5 months ago class-taxonomy.php 5 months ago class-term-description.php 4 months ago class-term.php 5 months ago class-user.php 5 months ago
class-comment.php
84 lines
1 <?php
2
3 namespace SearchRegex\Sql\Join;
4
5 use SearchRegex\Sql;
6
7 /**
8 * Join on comments table
9 */
10 class Comment extends Join {
11 /**
12 * Join logic
13 *
14 * @var string|false
15 */
16 private $logic = false;
17
18 /**
19 * Join table
20 */
21 private string $join_table;
22
23 /**
24 * Constructor
25 *
26 * @param string $column Column.
27 */
28 public function __construct( $column ) {
29 global $wpdb;
30
31 $this->column = 'comment_id';
32 $this->join_table = $wpdb->commentmeta;
33 }
34
35 /**
36 * Set the logic for this join
37 *
38 * @param string $logic Logic.
39 * @return void
40 */
41 public function set_logic( $logic ) {
42 $this->logic = $logic;
43 }
44
45 public function get_select() {
46 global $wpdb;
47
48 return new Sql\Select\Select( Sql\Value::table( $wpdb->comments ), Sql\Value::column( 'comment_id' ), null, true );
49 }
50
51 public function get_from() {
52 global $wpdb;
53
54 $table = Sql\Value::table( $this->join_table );
55 $column = Sql\Value::column( $this->get_join_column() );
56
57 return new Sql\From( Sql\Value::safe_raw( sprintf( "LEFT JOIN {$wpdb->comments} ON {$wpdb->comments}.comment_id=%s.%s", $table->get_value(), $column->get_value() ) ) );
58 }
59
60 public function get_join_column() {
61 return 'comment_id';
62 }
63
64 public function get_where() {
65 global $wpdb;
66
67 if ( $this->logic ) {
68 return new Sql\Where\Where_Null( new Sql\Select\Select( Sql\Value::table( $wpdb->comments ), Sql\Value::column( 'comment_id' ) ), $this->logic );
69 }
70
71 return false;
72 }
73
74 public function get_table() {
75 global $wpdb;
76
77 return $wpdb->comments;
78 }
79
80 public function get_join_value( $value ) {
81 return "$value";
82 }
83 }
84