LLMS_Table_Quizzes::get_results( array $args = array() )

Execute a query to retrieve results from the table


Parameters Parameters

$args

(array) (Optional) Array of query args.

Default value: array()


Top ↑

Return Return

(void)


Top ↑

Source Source

File: includes/admin/reporting/tables/llms.table.quizzes.php

	 */
	public function get_results( $args = array() ) {

		$this->title = __( 'Quizzes', 'lifterlms' );

		$args = $this->clean_args( $args );

		if ( isset( $args['page'] ) ) {
			$this->current_page = absint( $args['page'] );
		}

		$per = apply_filters( 'llms_reporting_' . $this->id . '_per_page', 25 );

		$this->order   = isset( $args['order'] ) ? $args['order'] : $this->order;
		$this->orderby = isset( $args['orderby'] ) ? $args['orderby'] : $this->orderby;

		$this->filter   = isset( $args['filter'] ) ? $args['filter'] : $this->get_filter();
		$this->filterby = isset( $args['filterby'] ) ? $args['filterby'] : $this->get_filterby();

		$query_args = array(
			'order'          => $this->order,
			'orderby'        => $this->orderby,
			'paged'          => $this->current_page,
			'post_status'    => 'publish',
			'post_type'      => 'llms_quiz',
			'posts_per_page' => $per,
		);

		if ( isset( $args['search'] ) ) {
			$query_args['s'] = sanitize_text_field( $args['search'] );
		}

		// if you can view others reports, make a regular query.
		if ( current_user_can( 'view_others_lifterlms_reports' ) ) {

			$query = new WP_Query( $query_args );

			// user can only see their own reports, get a list of their students.
		} elseif ( current_user_can( 'view_lifterlms_reports' ) ) {

			$instructor = llms_get_instructor();
			if ( ! $instructor ) {
				return;
			}

			$lessons = array();
			$courses = $instructor->get_courses(
				array(
					'posts_per_page' => -1,
				)
			);
			foreach ( $courses as $course ) {
				$lessons = array_merge( $lessons, $course->get_lessons( 'ids' ) );
			}

			if ( empty( $lessons ) ) {
				return;
			}

			$query_args['meta_query'] = array(  // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
				array(
					'compare' => 'IN',
					'key'     => '_llms_lesson_id',
					'value'   => $lessons,
				),
			);

			$query = new WP_Query( $query_args );

		} else {

			return;

		}

		$this->max_pages = $query->max_num_pages;

		if ( $this->max_pages > $this->current_page ) {
			$this->is_last_page = false;
		}

		$this->tbody_data = $query->posts;



Top ↑

Changelog Changelog

Changelog
Version Description
3.36.1 Fixed an issue that allow instructors, who can only see their own reports, to see all the quizzes when they had no courses or courses with no lessons.
3.16.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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