Changeset 13184 for trunk/src/bp-core/classes/class-bp-date-query.php
- Timestamp:
- 12/12/2021 02:09:02 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/classes/class-bp-date-query.php
r10417 r13184 34 34 35 35 /** 36 * Whether to prepend the 'AND' operator to the WHERE SQL clause. 37 * 38 * @since 10.0.0 39 * 40 * @var bool 41 */ 42 public $prepend_and = false; 43 44 /** 36 45 * Constructor. 37 46 * 38 * @param array $date_query Date query arguments. 39 * @param string $column THe DB column to query against. 47 * @since 2.1.0 48 * @since 10.0.0 Added $prepend_and argument. 49 * 50 * @param array $date_query Date query arguments. 51 * @param string $column The DB column to query against. 52 * @param bool $prepend_and Whether to prepend the 'AND' operator to the WHERE SQL clause. 40 53 * 41 54 * @see WP_Date_Query::__construct() 42 55 */ 43 public function __construct( $date_query, $column = '' ) {56 public function __construct( $date_query, $column = '', $prepend_and = false ) { 44 57 if ( ! empty( $column ) ) { 45 58 $this->column = $column; 46 59 add_filter( 'date_query_valid_columns', array( $this, 'register_date_column' ) ); 60 } 61 62 if ( ! empty( $prepend_and ) ) { 63 $this->prepend_and = true; 47 64 } 48 65 … … 67 84 return $retval; 68 85 } 86 87 /** 88 * Generate SQL clauses to be appended to a main query. 89 * 90 * Since BuddyPress builds its SQL queries differently than WP_Query, we have 91 * to override the parent method to remove the leading 'AND' operator from the 92 * WHERE clause. 93 * 94 * @since 10.0.0 95 * 96 * @return array { 97 * Array containing JOIN and WHERE SQL clauses to append to the main query. 98 * 99 * @type string $join SQL fragment to append to the main JOIN clause. 100 * @type string $where SQL fragment to append to the main WHERE clause. 101 * } 102 */ 103 protected function get_sql_clauses() { 104 // If we want to have the leading 'AND' operator, just use parent method. 105 if ( $this->prepend_and ) { 106 return parent::get_sql_clauses(); 107 } 108 109 // If we're here, that means we do not want the leading 'AND' operator. 110 return $this->get_sql_for_query( $this->queries ); 111 } 112 113 /** 114 * Helper method to generate and fetch the WHERE SQL clause for a date query. 115 * 116 * See {@link BP_Date_Query::__construct()} for all argument documentation. 117 * 118 * @since 10.0.0 119 * 120 * @param array $date_query Date query arguments. 121 * @param string $column DB column to query against date. 122 * @param bool $prepend_and Whether to prepend the 'AND' operator to the WHERE clause. 123 * @return string 124 */ 125 public static function get_where_sql( $date_query = array(), $column = '', $prepend_and = false ) { 126 $sql = ''; 127 128 // Generate and fetch the WHERE clause for a date query. 129 if ( ! empty( $date_query ) && is_array( $date_query ) && ! empty( $column ) ) { 130 $date_query = new self( $date_query, $column, $prepend_and ); 131 $sql = $date_query->get_sql(); 132 } 133 134 return $sql; 135 } 69 136 } 70 137 endif;
Note: See TracChangeset
for help on using the changeset viewer.