LLMS_Student::get_completed_courses( array $args = array() )
Retrieve IDs of courses a user has completed
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()
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
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'];
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$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'
); // db call ok; no-cache ok.
// phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$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;
}
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| ?? | Introduced. |