LLMS_Query_Quiz_Attempt::sql_where()
SQL “where” clause for the query.
Return Return
(string)
Source Source
File: includes/class.llms.query.quiz.attempt.php
protected function sql_where() {
global $wpdb;
$sql = 'WHERE 1';
foreach ( array( 'quiz_id', 'student_id' ) as $key ) {
$ids = $this->get( $key );
if ( $ids ) {
$prepared = implode( ',', $ids );
$sql .= " AND qa.{$key} IN ({$prepared})";
}
}
// Add attempt lookup.
$val = $this->get( 'attempt' );
if ( '' !== $val ) {
$sql .= $wpdb->prepare( ' AND qa.attempt = %d', $val );
}
// Add attempt exclude.
$exclude = $this->get( 'exclude' );
if ( $exclude ) {
$prepared = implode( ',', $exclude );
$sql .= " AND qa.id NOT IN ({$prepared})";
}
$status = $this->get( 'status' );
if ( $status ) {
$prepared = implode( ',', array_map( array( $this, 'escape_and_quote_string' ), $status ) );
$sql .= " AND qa.status IN ({$prepared})";
}
$status_exclude = $this->get( 'status_exclude' );
if ( $status_exclude ) {
$prepared = implode( ',', array_map( array( $this, 'escape_and_quote_string' ), $status_exclude ) );
$sql .= " AND qa.status NOT IN ({$prepared})";
}
$can_be_resumed = $this->get( 'can_be_resumed' );
if ( '' !== $can_be_resumed ) {
$sql .= $wpdb->prepare( ' AND qa.can_be_resumed = %d', $can_be_resumed );
}
$search = $this->get( 'search' );
if ( $search ) {
$search = $wpdb->esc_like( $search );
$sql .= $wpdb->prepare(
' AND (
u.user_login LIKE %s
OR u.user_email LIKE %s
OR u.display_name LIKE %s
OR um_first.meta_value LIKE %s
OR um_last.meta_value LIKE %s
OR p.post_title LIKE %s
)',
'%' . $search . '%',
'%' . $search . '%',
'%' . $search . '%',
'%' . $search . '%',
'%' . $search . '%',
'%' . $search . '%'
);
}
return apply_filters( $this->get_filter( 'where' ), $sql, $this );
}
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 7.8.0 | Added can_be_resumed arg logic. |
| 4.2.0 | Added exclude arg logic. |
| 3.35.0 | Better SQL preparation. |
| 3.16.0 | Introduced. |