LLMS_Query_Quiz_Attempt::sql_where()

SQL “where” clause for the query


Return Return

(string)


Top ↑

Source Source

File: includes/class.llms.query.quiz.attempt.php

164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
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 {$key} IN ({$prepared})";
        }
    }
 
    // Add attempt lookup.
    $val = $this->get( 'attempt' );
    if ( '' !== $val ) {
        $sql .= $wpdb->prepare( ' AND attempt = %d', $val );
    }
 
    // Add attempt exclude.
    $exclude = $this->get( 'exclude' );
    if ( $exclude ) {
        $prepared = implode( ',', $exclude );
        $sql     .= " AND id NOT IN ({$prepared})";
    }
 
    $status = $this->get( 'status' );
    if ( $status ) {
        $prepared = implode( ',', array_map( array( $this, 'escape_and_quote_string' ), $status ) );
        $sql     .= " AND 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 status NOT IN ({$prepared})";
    }
 
    return apply_filters( $this->get_filter( 'where' ), $sql, $this );
 
}


Top ↑

Changelog Changelog

Changelog
Version Description
4.2.0 Added exclude arg logic.
3.35.0 Better SQL preparation.
3.16.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.