dozent_get_instructor_rating( null|int|object $user = null )
Get the rating of an instructor
Description
This function return you rating by an instructor
Example usage:
$rating = dozent_get_instructor_rating(); //Current Logged In Instructor
$rating = dozent_get_instructor_rating( $user ); //Specific Instructor
See also
Parameters
- $user
-
(null|int|object) (Optional)
Default value: null
Return
(object)
Source
File: includes/user-functions.php
function dozent_get_instructor_rating( $user = null ) { global $wpdb; $user = dozent_get_the_user( $user ); $ratings = array( 'rating_count' => 0, 'rating_sum' => 0, 'rating_avg' => 0.00, ); if ( empty( $user ) ) { return (object) $ratings; } $instructor_id = $user->ID; $rating = $wpdb->get_row( "SELECT COUNT(reviews.rating) as rating_count, SUM(reviews.rating) as rating_sum FROM {$wpdb->dozent_instructor_courses} courses INNER JOIN {$wpdb->dozent_reviews} reviews ON courses.course_id = reviews.course_id WHERE courses.instructor_id = {$instructor_id} ;" ); if ( $rating->rating_count ) { $avg_rating = number_format( ( $rating->rating_sum / $rating->rating_count ), 2 ); $ratings = array( 'rating_count' => $rating->rating_count, 'rating_sum' => $rating->rating_sum, 'rating_avg' => $avg_rating, ); } return (object) $ratings; }
Changelog
Version | Description |
---|---|
DozentLMS 1.0.0 | Introduced. |