LLMS_Student::get_completed_courses( array $args = array() )

Retrieve IDs of courses a user has completed


Description Description


Parameters Parameters

$args

(array) (Optional) query arguments @arg int $limit number of courses to return @arg string $orderby table reference and field to order results by @arg string $order result order (DESC, ASC) @arg int $skip number of results to skip for pagination purposes

Default value: array()


Top ↑

Return Return

(array) "courses" will contain an array of course ids "more" will contain a boolean determining whether or not more courses are available beyond supplied limit/skip criteria


Top ↑

Source Source

File: includes/models/model.llms.student.php

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

		global $wpdb;

		$args = array_merge( array(
			'limit'   => 20,
			'orderby' => 'upm.updated_date',
			'order'   => 'DESC',
			'skip'    => 0,
		), $args );

		// add one to the limit to see if there's pagination
		$args['limit']++;

		// the query
		$q = $wpdb->get_results( $wpdb->prepare(
			"SELECT upm.post_id AS id
			 FROM {$wpdb->prefix}lifterlms_user_postmeta AS upm
			 JOIN {$wpdb->posts} AS p ON p.ID = upm.post_id
			 WHERE p.post_type = 'course'
			   AND upm.meta_key = '_is_complete'
			   AND upm.meta_value = 'yes'
			   AND upm.user_id = %d
			 ORDER BY {$args['orderby']} {$args['order']}
			 LIMIT %d, %d;
			", array(
				$this->get_id(),
				$args['skip'],
				$args['limit'],
			)
		), 'OBJECT_K' );

		$ids = array_keys( $q );
		$more = false;

		// if we hit our limit we have too many results, pop the last one
		if ( count( $ids ) === $args['limit'] ) {
			array_pop( $ids );
			$more = true;
		}

		// reset args to pass back for pagination
		$args['limit']--;

		$r = array(
			'limit' => $args['limit'],
			'more' => $more,
			'results' => $ids,
			'skip' => $args['skip'],
		);

		return $r;

	}

Top ↑

Changelog Changelog

Changelog
Version Description
?? Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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





Permalink: