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

	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.