qna
4 days ago
reviews
4 days ago
announcements.php
4 days ago
course-info.php
4 days ago
qna.php
4 days ago
reviews.php
4 days ago
reviews.php
185 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Tutor learning area reviews. |
| 4 | * |
| 5 | * @package Tutor\Templates |
| 6 | * @author Themeum <support@themeum.com> |
| 7 | * @link https://themeum.com |
| 8 | * @since 4.0.0 |
| 9 | */ |
| 10 | |
| 11 | defined( 'ABSPATH' ) || exit; |
| 12 | |
| 13 | use TUTOR\Icon; |
| 14 | use TUTOR\Input; |
| 15 | use Tutor\Components\Button; |
| 16 | use Tutor\Components\ConfirmationModal; |
| 17 | use Tutor\Components\Constants\Size; |
| 18 | use Tutor\Components\Constants\Variant; |
| 19 | use Tutor\Components\EmptyState; |
| 20 | use Tutor\Components\Modal; |
| 21 | use Tutor\Components\Pagination; |
| 22 | use Tutor\Components\Progress; |
| 23 | use Tutor\Components\StarRating; |
| 24 | use Tutor\Components\SvgIcon; |
| 25 | |
| 26 | // Get course ID from global variable set in learning-area/index.php . |
| 27 | global $tutor_course_id, |
| 28 | $current_user_id, |
| 29 | $tutor_is_enrolled; |
| 30 | |
| 31 | // Pagination setup. |
| 32 | $review_per_page = tutor_utils()->get_option( 'pagination_per_page', 10 ); |
| 33 | $current_page = max( 1, Input::get( 'current_page', 1, Input::TYPE_INT ) ); |
| 34 | $offset = ( $current_page - 1 ) * $review_per_page; |
| 35 | |
| 36 | $course_rating = tutor_utils()->get_course_rating( $tutor_course_id ); |
| 37 | $total_items = (int) tutor_utils()->get_course_reviews( $tutor_course_id, null, null, true, array( 'approved' ), $current_user_id ); |
| 38 | $reviews = tutor_utils()->get_course_reviews( $tutor_course_id, $offset, $review_per_page, false, array( 'approved' ), $current_user_id ); |
| 39 | $my_rating = tutor_utils()->get_reviews_by_user( 0, 0, null, false, $tutor_course_id, array( 'approved', 'hold' ) ); |
| 40 | |
| 41 | if ( ! empty( $my_rating ) ) { |
| 42 | $my_rating = is_array( $my_rating ) ? $my_rating[0] : $my_rating; |
| 43 | $my_rating_id = $my_rating->comment_ID; |
| 44 | |
| 45 | $reviews = array_filter( |
| 46 | $reviews, |
| 47 | function ( $review ) use ( $my_rating_id ) { |
| 48 | return $review->comment_ID !== $my_rating_id; |
| 49 | } |
| 50 | ); |
| 51 | |
| 52 | $reviews = array_values( $reviews ); |
| 53 | array_unshift( $reviews, $my_rating ); |
| 54 | } |
| 55 | |
| 56 | ?> |
| 57 | |
| 58 | <div class="tutor-py-8 tutor-learning-area-reviews"> |
| 59 | <div class="tutor-flex tutor-items-center tutor-justify-between tutor-mb-5"> |
| 60 | <h4 class="tutor-h4 tutor-flex tutor-items-center tutor-gap-4"> |
| 61 | <?php SvgIcon::make()->name( Icon::RATINGS )->size( 24 )->render(); ?> |
| 62 | <?php esc_html_e( 'Reviews', 'tutor' ); ?> |
| 63 | </h4> |
| 64 | <?php |
| 65 | if ( $tutor_is_enrolled && empty( $my_rating ) ) { |
| 66 | ?> |
| 67 | <div> |
| 68 | <?php |
| 69 | Button::make() |
| 70 | ->label( __( 'Write a Review', 'tutor' ) ) |
| 71 | ->size( Size::SMALL ) |
| 72 | ->attr( 'x-on:click', 'TutorCore.modal.showModal("create-review-modal")' ) |
| 73 | ->render(); |
| 74 | |
| 75 | $modal_template = tutor_get_template( 'learning-area.subpages.reviews.create-review-modal' ); |
| 76 | Modal::make() |
| 77 | ->id( 'create-review-modal' ) |
| 78 | ->title( __( 'How Was Your Experience?', 'tutor' ) ) |
| 79 | ->subtitle( __( 'Your feedback helps others find the right course.', 'tutor' ) ) |
| 80 | ->width( '452px' ) |
| 81 | ->template( $modal_template ) |
| 82 | ->render(); |
| 83 | ?> |
| 84 | </div> |
| 85 | <?php |
| 86 | } |
| 87 | ?> |
| 88 | </div> |
| 89 | |
| 90 | <div class="tutor-card tutor-card-rounded-2xl tutor-p-none"> |
| 91 | <?php if ( empty( $reviews ) ) : ?> |
| 92 | <?php |
| 93 | EmptyState::make() |
| 94 | ->title( __( 'No Reviews Found!', 'tutor' ) ) |
| 95 | ->icon( tutor_utils()->get_themed_svg( 'images/illustrations/reviews-empty.svg' ) ) |
| 96 | ->render(); |
| 97 | ?> |
| 98 | <?php else : ?> |
| 99 | <div class="tutor-grid tutor-grid-cols-2 tutor-sm-grid-cols-1 tutor-gap-4 tutor-sm-gap-6 tutor-p-6"> |
| 100 | <div class="tutor-flex tutor-flex-column tutor-gap-4 tutor-justify-between"> |
| 101 | <div class="tutor-medium tutor-font-medium" style="max-width: 172px;"> |
| 102 | <?php esc_html_e( 'Student Ratings & Reviews', 'tutor' ); ?> |
| 103 | </div> |
| 104 | <div class="tutor-average-rating tutor-surface-l1-hover tutor-rounded-sm tutor-py-3 tutor-px-5 tutor-flex tutor-flex-column tutor-gap-1 tutor-w-fit"> |
| 105 | <div class="tutor-flex tutor-items-center tutor-gap-5"> |
| 106 | <div class="tutor-h4 tutor-font-bold"> |
| 107 | <?php echo esc_html( number_format_i18n( (float) $course_rating->rating_avg, 1 ) ); ?> |
| 108 | </div> |
| 109 | <?php |
| 110 | StarRating::make() |
| 111 | ->rating( $course_rating->rating_avg ) |
| 112 | ->show_average( false ) |
| 113 | ->render(); |
| 114 | ?> |
| 115 | </div> |
| 116 | <div class="tutor-tiny tutor-text-secondary"> |
| 117 | <?php |
| 118 | printf( |
| 119 | /* translators: %s is total rating count */ |
| 120 | esc_html( _n( 'Based on %s rating', 'Based on %s ratings', $total_items, 'tutor' ) ), |
| 121 | esc_html( number_format_i18n( $total_items ) ) |
| 122 | ); |
| 123 | ?> |
| 124 | </div> |
| 125 | </div> |
| 126 | </div> |
| 127 | <div class="tutor-flex tutor-flex-column tutor-gap-3"> |
| 128 | <?php for ( $i = 5; $i >= 1; $i-- ) : ?> |
| 129 | <?php |
| 130 | $count = (int) ( $course_rating->count_by_value[ $i ] ?? 0 ); |
| 131 | $percent = $course_rating->rating_count > 0 ? ( $count * 100 ) / $course_rating->rating_count : 0; |
| 132 | ?> |
| 133 | <div class="tutor-flex tutor-items-center tutor-gap-5"> |
| 134 | <div class="tutor-flex tutor-items-center tutor-gap-3"> |
| 135 | <?php SvgIcon::make()->name( Icon::STAR_FILL )->size( 12 )->attr( 'class', 'tutor-icon-exception4' )->render(); ?> |
| 136 | <span class="tutor-small" style="font-variant-numeric: tabular-nums;"><?php echo esc_html( $i ); ?></span> |
| 137 | </div> |
| 138 | <?php Progress::make()->variant( Variant::WARNING )->value( $percent )->animated()->render(); ?> |
| 139 | <div class="tutor-small tutor-flex-shrink-0" style="min-width: 80px;"> |
| 140 | <?php |
| 141 | printf( |
| 142 | /* translators: %s is rating count */ |
| 143 | esc_html( _n( '%s rating', '%s ratings', $count, 'tutor' ) ), |
| 144 | esc_html( number_format_i18n( $count ) ) |
| 145 | ); |
| 146 | ?> |
| 147 | </div> |
| 148 | </div> |
| 149 | <?php endfor; ?> |
| 150 | </div> |
| 151 | </div> |
| 152 | |
| 153 | <div> |
| 154 | <?php foreach ( $reviews as $review ) : ?> |
| 155 | <?php tutor_load_template( 'learning-area.subpages.reviews.review-card', array( 'review' => $review ) ); ?> |
| 156 | <?php endforeach; ?> |
| 157 | </div> |
| 158 | |
| 159 | <div x-data="tutorReviewDeleteModal()" x-cloak> |
| 160 | <?php |
| 161 | ConfirmationModal::make() |
| 162 | ->id( 'review-delete-modal' ) |
| 163 | ->title( __( 'Delete your Review?', 'tutor' ) ) |
| 164 | ->message( __( 'Are you sure you want to delete this review? This action cannot be undone.', 'tutor' ) ) |
| 165 | ->icon( tutor_utils()->get_themed_svg( 'images/illustrations/delete-reviews.svg' ), 80, 80, ConfirmationModal::ICON_TYPE_HTML ) |
| 166 | ->confirm_handler( 'handleDeleteReview(payload?.id)' ) |
| 167 | ->mutation_state( 'deleteReviewMutation' ) |
| 168 | ->confirm_text( __( 'Yes, Delete This', 'tutor' ) ) |
| 169 | ->cancel_text( __( 'Cancel', 'tutor' ) ) |
| 170 | ->render(); |
| 171 | ?> |
| 172 | </div> |
| 173 | <?php endif; ?> |
| 174 | </div> |
| 175 | |
| 176 | <?php |
| 177 | Pagination::make() |
| 178 | ->current( $current_page ) |
| 179 | ->total( $total_items ) |
| 180 | ->limit( $review_per_page ) |
| 181 | ->attr( 'class', 'tutor-mt-6' ) |
| 182 | ->render(); |
| 183 | ?> |
| 184 | </div> |
| 185 |