LLMS_Table_Courses::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.courses.php

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

		$this->title = __( 'Courses', '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'    => array( 'publish', 'private' ),
			'post_type'      => 'course',
			'posts_per_page' => $per,
		);

		if ( 'any' !== $this->filter ) {

			$serialized_id = serialize(
				array(
					'id' => absint( $this->filter ),
				)
			);
			$serialized_id = str_replace( array( 'a:1:{', '}' ), '', $serialized_id );

			$query_args['meta_query'] = array(
				array(
					'compare' => 'LIKE',
					'key'     => '_llms_instructors',
					'value'   => $serialized_id,
				),
			);

		}

		if ( 'progress' === $this->orderby ) {
			$query_args['meta_key'] = '_llms_average_progress';
			$query_args['orderby']  = 'meta_value_num';
		} elseif ( 'grade' === $this->orderby ) {
			$query_args['meta_key'] = '_llms_average_progress';
			$query_args['orderby']  = 'meta_value_num';
		}

		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;
			}
			$query = $instructor->get_courses( $query_args, 'query' );

		} 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.15.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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