comment-card.php
1 day ago
comment-form.php
1 day ago
comment-list.php
1 day ago
comment-replies.php
1 day ago
comment-single.php
1 day ago
qna-card.php
1 day ago
qna-form.php
1 day ago
qna-list.php
1 day ago
qna-replies.php
1 day ago
qna-single.php
1 day ago
comment-list.php
148 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Lesson comments list template. |
| 4 | * |
| 5 | * @package Tutor\Templates |
| 6 | * @subpackage Dashboard |
| 7 | * @author Themeum <support@themeum.com> |
| 8 | * @link https://themeum.com |
| 9 | * @since 4.0.0 |
| 10 | * |
| 11 | * These variables are inherited from the parent template file. |
| 12 | * template: /tutor/templates/dashboard/discussions.php |
| 13 | * |
| 14 | * @var string $discussion_url |
| 15 | * @var int $item_per_page |
| 16 | * @var int $offset |
| 17 | * @var string $order_filter |
| 18 | * @var int $current_page |
| 19 | */ |
| 20 | |
| 21 | defined( 'ABSPATH' ) || exit; |
| 22 | |
| 23 | use Tutor\Components\ConfirmationModal; |
| 24 | use Tutor\Components\EmptyState; |
| 25 | use Tutor\Components\Pagination; |
| 26 | use Tutor\Components\Sorting; |
| 27 | use TUTOR\Lesson; |
| 28 | use Tutor\Models\CourseModel; |
| 29 | use TUTOR\User; |
| 30 | |
| 31 | $current_user_id = get_current_user_id(); |
| 32 | $is_only_instructor = User::is_only_instructor( $current_user_id ); |
| 33 | |
| 34 | $list_args = array( |
| 35 | 'post_type' => tutor()->lesson_post_type, |
| 36 | 'status' => 'approve', |
| 37 | 'parent' => 0, |
| 38 | 'number' => $item_per_page, |
| 39 | 'offset' => $offset, |
| 40 | 'orderby' => 'comment_date', |
| 41 | 'order' => $order_filter, |
| 42 | ); |
| 43 | |
| 44 | $count_args = array( |
| 45 | 'post_type' => tutor()->lesson_post_type, |
| 46 | 'status' => 'approve', |
| 47 | 'parent' => 0, |
| 48 | 'count' => true, |
| 49 | ); |
| 50 | |
| 51 | if ( User::is_student_view() ) { |
| 52 | $list_args['user_id'] = $current_user_id; |
| 53 | $count_args['user_id'] = $current_user_id; |
| 54 | } elseif ( $is_only_instructor ) { |
| 55 | $courses = CourseModel::get_courses_by_instructor( $current_user_id ); |
| 56 | $course_ids = array_column( $courses, 'ID' ); |
| 57 | $lesson_ids = array(); |
| 58 | if ( count( $course_ids ) ) { |
| 59 | $lesson_ids = tutor_utils()->get_course_content_ids_by( tutor()->lesson_post_type, tutor()->course_post_type, $course_ids ); |
| 60 | } |
| 61 | |
| 62 | $list_args['tutor_instructor_comments'] = true; |
| 63 | $count_args['tutor_instructor_comments'] = true; |
| 64 | |
| 65 | $list_args['tutor_instructor_lesson_ids'] = $lesson_ids; |
| 66 | $count_args['tutor_instructor_lesson_ids'] = $lesson_ids; |
| 67 | |
| 68 | $list_args['tutor_instructor_user_id'] = $current_user_id; |
| 69 | $count_args['tutor_instructor_user_id'] = $current_user_id; |
| 70 | } |
| 71 | |
| 72 | $tutor_comments_filter = function ( $pieces, $query ) { |
| 73 | global $wpdb; |
| 74 | if ( isset( $query->query_vars['tutor_instructor_comments'] ) && $query->query_vars['tutor_instructor_comments'] ) { |
| 75 | $lesson_ids = $query->query_vars['tutor_instructor_lesson_ids']; |
| 76 | $user_id = $query->query_vars['tutor_instructor_user_id']; |
| 77 | |
| 78 | $in_lessons = '1=0'; |
| 79 | if ( is_array( $lesson_ids ) && count( $lesson_ids ) ) { |
| 80 | $in_lessons = "{$wpdb->comments}.comment_post_ID IN (" . implode( ',', array_map( 'intval', $lesson_ids ) ) . ')'; |
| 81 | } |
| 82 | |
| 83 | //phpcs:ignore -- $in_lessons is safely constructed. |
| 84 | $pieces['where'] .= $wpdb->prepare( " AND ( ($in_lessons) OR {$wpdb->comments}.user_id = %d )", $user_id ); |
| 85 | } |
| 86 | return $pieces; |
| 87 | }; |
| 88 | |
| 89 | add_filter( 'comments_clauses', $tutor_comments_filter, 10, 2 ); |
| 90 | $lesson_comments = Lesson::get_comments( $list_args ); |
| 91 | $total_items = Lesson::get_comments( $count_args ); |
| 92 | remove_filter( 'comments_clauses', $tutor_comments_filter, 10 ); |
| 93 | ?> |
| 94 | |
| 95 | <div class="tutor-flex tutor-items-center tutor-justify-between tutor-px-6 tutor-py-5 tutor-border-b"> |
| 96 | <div class="tutor-small tutor-text-secondary"> |
| 97 | <?php esc_html_e( 'Comments', 'tutor' ); ?> |
| 98 | <span class="tutor-text-primary tutor-font-medium">(<?php echo esc_html( $total_items ); ?>)</span> |
| 99 | </div> |
| 100 | <div class="tutor-discussion-filter-right"> |
| 101 | <?php Sorting::make()->order( $order_filter )->render(); ?> |
| 102 | </div> |
| 103 | </div> |
| 104 | |
| 105 | <?php if ( empty( $lesson_comments ) ) : ?> |
| 106 | <?php |
| 107 | EmptyState::make() |
| 108 | ->title( 'No Comments Found!' ) |
| 109 | ->icon( tutor_utils()->get_themed_svg( 'images/illustrations/comments-empty.svg' ) ) |
| 110 | ->render(); |
| 111 | ?> |
| 112 | <?php else : ?> |
| 113 | <div class="tutor-discussion-card-wrapper tutor-flex tutor-flex-column tutor-gap-4 tutor-sm-gap-none tutor-p-6 tutor-sm-p-none"> |
| 114 | <?php |
| 115 | foreach ( $lesson_comments as $lesson_comment ) : |
| 116 | tutor_load_template( |
| 117 | 'dashboard.discussions.comment-card', |
| 118 | array( |
| 119 | 'lesson_comment' => $lesson_comment, |
| 120 | 'discussion_url' => $discussion_url, |
| 121 | ) |
| 122 | ); |
| 123 | endforeach; |
| 124 | ?> |
| 125 | </div> |
| 126 | <?php endif; ?> |
| 127 | |
| 128 | <?php |
| 129 | Pagination::make() |
| 130 | ->current( $current_page ) |
| 131 | ->total( $total_items ) |
| 132 | ->limit( $item_per_page ) |
| 133 | ->attr( 'class', 'tutor-px-6 tutor-pb-6 tutor-sm-p-5 tutor-sm-border-t' ) |
| 134 | ->render(); |
| 135 | ?> |
| 136 | |
| 137 | <?php |
| 138 | if ( ! empty( $lesson_comments ) ) { |
| 139 | ConfirmationModal::make() |
| 140 | ->id( 'tutor-comment-delete-modal' ) |
| 141 | ->title( __( 'Delete This Comment?', 'tutor' ) ) |
| 142 | ->message( __( 'Are you sure you want to delete this comment permanently? Please confirm your choice.', 'tutor' ) ) |
| 143 | ->confirm_text( __( 'Yes, Delete This', 'tutor' ) ) |
| 144 | ->confirm_handler( 'deleteCommentMutation?.mutate({ comment_id: payload?.commentId })' ) |
| 145 | ->mutation_state( 'deleteCommentMutation' ) |
| 146 | ->render(); |
| 147 | } |
| 148 |