qna
5 days ago
reviews
5 days ago
announcements.php
5 days ago
course-info.php
5 days ago
qna.php
5 days ago
reviews.php
5 days ago
qna.php
160 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Tutor learning area Q&A. |
| 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\Components\SvgIcon; |
| 15 | use TUTOR\Input; |
| 16 | use Tutor\Components\ConfirmationModal; |
| 17 | use Tutor\Components\Constants\Size; |
| 18 | use Tutor\Components\EmptyState; |
| 19 | use Tutor\Components\Pagination; |
| 20 | use Tutor\Components\SearchFilter; |
| 21 | use Tutor\Components\Sorting; |
| 22 | use Tutor\Helpers\UrlHelper; |
| 23 | |
| 24 | $question_id = Input::get( 'question_id', 0, Input::TYPE_INT ); |
| 25 | |
| 26 | if ( $question_id ) { |
| 27 | tutor_load_template( 'learning-area.subpages.qna.single' ); |
| 28 | return; |
| 29 | } |
| 30 | |
| 31 | // Get course ID from global variable set in learning-area/index.php . |
| 32 | global $tutor_course_id; |
| 33 | |
| 34 | // Pagination setup. |
| 35 | $question_per_page = tutor_utils()->get_option( 'pagination_per_page', 10 ); |
| 36 | $current_page = max( 1, Input::get( 'current_page', 1, Input::TYPE_INT ) ); |
| 37 | $offset = ( $current_page - 1 ) * $question_per_page; |
| 38 | $search_query = Input::get( 'search', '' ); |
| 39 | $order_by = Input::get( 'order', 'DESC' ); |
| 40 | |
| 41 | // Get questions for this course. |
| 42 | $total_items = (int) tutor_utils()->get_qa_questions( |
| 43 | $offset, |
| 44 | $question_per_page, |
| 45 | $search_query, |
| 46 | null, |
| 47 | null, |
| 48 | null, |
| 49 | null, |
| 50 | true, |
| 51 | array( |
| 52 | 'course_id' => $tutor_course_id, |
| 53 | 'order' => $order_by, |
| 54 | ) |
| 55 | ); |
| 56 | $questions = tutor_utils()->get_qa_questions( |
| 57 | $offset, |
| 58 | $question_per_page, |
| 59 | $search_query, |
| 60 | null, |
| 61 | null, |
| 62 | null, |
| 63 | null, |
| 64 | false, |
| 65 | array( |
| 66 | 'course_id' => $tutor_course_id, |
| 67 | 'order' => $order_by, |
| 68 | ) |
| 69 | ); |
| 70 | |
| 71 | ?> |
| 72 | <div class="tutor-py-8"> |
| 73 | <h4 class="tutor-h4 tutor-mb-5 tutor-flex tutor-items-center tutor-gap-4"> |
| 74 | <?php SvgIcon::make()->name( Icon::QA )->size( 24 )->render(); ?> |
| 75 | <?php esc_html_e( 'Q&A', 'tutor' ); ?> |
| 76 | </h4> |
| 77 | <div class="tutor-learning-area-qna" x-data="tutorQnA()"> |
| 78 | <div class="tutor-discussion-search tutor-p-6 tutor-border-b"> |
| 79 | <?php |
| 80 | SearchFilter::make() |
| 81 | ->form_id( 'tutor-qna-search-form' ) |
| 82 | ->placeholder( 'Search questions, topics...' ) |
| 83 | ->action( UrlHelper::current() ) |
| 84 | ->hidden_inputs( array( 'subpage' => 'qna' ) ) |
| 85 | ->size( Size::LARGE ) |
| 86 | ->render(); |
| 87 | ?> |
| 88 | </div> |
| 89 | |
| 90 | <div class="tutor-p-6"> |
| 91 | <label for="answer" class="tutor-block tutor-medium tutor-font-semibold tutor-mb-4"> |
| 92 | <?php esc_html_e( 'Question & Answer', 'tutor' ); ?> |
| 93 | </label> |
| 94 | <?php |
| 95 | tutor_load_template( |
| 96 | 'learning-area.subpages.qna.form', |
| 97 | array( |
| 98 | 'form_id' => 'learning-area-qna-form', |
| 99 | 'submit_handler' => '(data) => createQnAMutation?.mutate({ ...data, course_id: ' . (int) $tutor_course_id . ' })', |
| 100 | 'cancel_handler' => 'reset(); focused = false', |
| 101 | 'is_pending' => 'createQnAMutation?.isPending', |
| 102 | 'placeholder' => __( 'Asked questions...', 'tutor' ), |
| 103 | 'submit_label' => __( 'Save', 'tutor' ), |
| 104 | ) |
| 105 | ); |
| 106 | ?> |
| 107 | </div> |
| 108 | |
| 109 | <div class="tutor-flex tutor-items-center tutor-justify-between tutor-px-6 tutor-py-5 tutor-border-b tutor-border-t"> |
| 110 | <div class="tutor-small tutor-text-secondary"> |
| 111 | <?php esc_html_e( 'Questions', 'tutor' ); ?> |
| 112 | <span class="tutor-text-primary tutor-font-medium">(<?php echo esc_html( $total_items ); ?>)</span> |
| 113 | </div> |
| 114 | <?php Sorting::make()->order( $order_by )->render(); ?> |
| 115 | </div> |
| 116 | |
| 117 | <?php if ( empty( $questions ) ) : ?> |
| 118 | <?php |
| 119 | EmptyState::make() |
| 120 | ->title( 'No Questions Found!' ) |
| 121 | ->icon( tutor_utils()->get_themed_svg( 'images/illustrations/qna-empty.svg' ) ) |
| 122 | ->render(); |
| 123 | ?> |
| 124 | <?php else : ?> |
| 125 | <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"> |
| 126 | <?php |
| 127 | foreach ( $questions as $question ) : |
| 128 | tutor_load_template( |
| 129 | 'learning-area.subpages.qna.card', |
| 130 | array( |
| 131 | 'question' => $question, |
| 132 | ) |
| 133 | ); |
| 134 | endforeach; |
| 135 | ?> |
| 136 | </div> |
| 137 | <?php endif; ?> |
| 138 | |
| 139 | <?php |
| 140 | Pagination::make() |
| 141 | ->current( $current_page ) |
| 142 | ->total( $total_items ) |
| 143 | ->limit( $question_per_page ) |
| 144 | ->attr( 'class', 'tutor-px-6 tutor-pb-6 tutor-sm-p-5 tutor-sm-border-t' ) |
| 145 | ->render(); |
| 146 | ?> |
| 147 | |
| 148 | <?php |
| 149 | ConfirmationModal::make() |
| 150 | ->id( 'tutor-qna-delete-modal' ) |
| 151 | ->title( __( 'Delete This Question?', 'tutor' ) ) |
| 152 | ->message( __( 'Are you sure you want to delete this question permanently? Please confirm your choice.', 'tutor' ) ) |
| 153 | ->confirm_text( __( 'Yes, Delete This', 'tutor' ) ) |
| 154 | ->confirm_handler( 'deleteQnAMutation?.mutate(payload)' ) |
| 155 | ->mutation_state( 'deleteQnAMutation' ) |
| 156 | ->render(); |
| 157 | ?> |
| 158 | </div> |
| 159 | </div> |
| 160 |