single.php
154 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Q&A replies 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 | |
| 12 | defined( 'ABSPATH' ) || exit; |
| 13 | |
| 14 | use Tutor\Components\Avatar; |
| 15 | use Tutor\Components\ConfirmationModal; |
| 16 | use Tutor\Components\Constants\Size; |
| 17 | use TUTOR\Icon; |
| 18 | use Tutor\Components\SvgIcon; |
| 19 | use Tutor\Components\Constants\Color; |
| 20 | use TUTOR\Input; |
| 21 | |
| 22 | $question_id = Input::get( 'question_id', 0, Input::TYPE_INT ); |
| 23 | $replies_order = Input::get( 'order', '' ); |
| 24 | |
| 25 | $back_url = remove_query_arg( 'question_id' ); |
| 26 | |
| 27 | $question = tutor_utils()->get_qa_question( $question_id ); |
| 28 | if ( ! $question ) { |
| 29 | wp_safe_redirect( $back_url ); |
| 30 | return; |
| 31 | } |
| 32 | |
| 33 | $user_id = get_current_user_id(); |
| 34 | $is_user_asker = $user_id === (int) $question->user_id; |
| 35 | $qna_delete_modal_id = 'tutor-qna-delete-modal'; |
| 36 | |
| 37 | $replies = tutor_utils()->get_qa_answer_by_question( $question_id, $replies_order, 'frontend' ); |
| 38 | ?> |
| 39 | <div class="tutor-pt-4 tutor-pb-6"> |
| 40 | <div class="tutor-discussion-single" x-data="tutorQnA()"> |
| 41 | <div class="tutor-flex tutor-justify-between tutor-px-6 tutor-py-5 tutor-border-b"> |
| 42 | <a href="<?php echo esc_url( $back_url ); ?>" class="tutor-btn tutor-btn-secondary tutor-btn-small tutor-gap-2"> |
| 43 | <?php SvgIcon::make()->name( Icon::ARROW_LEFT_2 )->flip_rtl()->render(); ?> |
| 44 | <?php esc_html_e( 'Back', 'tutor' ); ?> |
| 45 | </a> |
| 46 | </div> |
| 47 | <div class="tutor-discussion-single-body tutor-p-6 tutor-border-b"> |
| 48 | <div class="tutor-flex tutor-gap-5 tutor-mb-5"> |
| 49 | <?php Avatar::make()->user( $question->user_id )->size( Size::SIZE_40 )->render(); ?> |
| 50 | <div class="tutor-flex tutor-items-center tutor-gap-5 tutor-small"> |
| 51 | <span class="tutor-discussion-card-author"><?php echo esc_html( $question->comment_author ); ?></span> |
| 52 | <span class="tutor-text-secondary"> |
| 53 | <?php |
| 54 | /* translators: %s human-readable time difference. */ |
| 55 | echo esc_html( sprintf( __( '%s ago', 'tutor' ), human_time_diff( strtotime( $question->comment_date_gmt ) ) ) ); |
| 56 | ?> |
| 57 | </span> |
| 58 | </div> |
| 59 | <?php if ( $is_user_asker ) : ?> |
| 60 | <div class="tutor-ml-auto"> |
| 61 | <div x-data="tutorPopover({ placement: 'bottom-end', offset: 4 })"> |
| 62 | <button class="tutor-btn tutor-btn-ghost tutor-btn-icon tutor-btn-x-small" x-ref="trigger" @click="toggle()" aria-label="<?php esc_attr_e( 'More options', 'tutor' ); ?>"> |
| 63 | <?php SvgIcon::make()->name( Icon::ELLIPSES )->size( 16 )->color( Color::SECONDARY )->render(); ?> |
| 64 | </button> |
| 65 | <div |
| 66 | x-ref="content" |
| 67 | x-show="open" |
| 68 | x-cloak |
| 69 | @click.outside="handleClickOutside()" |
| 70 | class="tutor-popover" |
| 71 | > |
| 72 | <div class="tutor-popover-menu" style="min-width: 130px;"> |
| 73 | <button class="tutor-popover-menu-item tutor-gap-5" @click="setEditing(<?php echo (int) $question->comment_ID; ?>); hide()"> |
| 74 | <?php SvgIcon::make()->name( Icon::EDIT_2 )->size( 20 )->render(); ?> |
| 75 | <?php esc_html_e( 'Edit', 'tutor' ); ?> |
| 76 | </button> |
| 77 | <button |
| 78 | class="tutor-popover-menu-item tutor-gap-5" |
| 79 | @click="TutorCore.modal.showModal('<?php echo esc_js( $qna_delete_modal_id ); ?>', { question_id: <?php echo esc_html( $question->comment_ID ); ?> }); hide();" |
| 80 | > |
| 81 | <?php SvgIcon::make()->name( Icon::DELETE_2 )->size( 20 )->render(); ?> <?php esc_html_e( 'Delete', 'tutor' ); ?> |
| 82 | </button> |
| 83 | </div> |
| 84 | </div> |
| 85 | </div> |
| 86 | </div> |
| 87 | <?php endif; ?> |
| 88 | </div> |
| 89 | |
| 90 | <div x-show="editingId !== <?php echo (int) $question->comment_ID; ?>" id="tutor-qna-text-<?php echo esc_attr( $question->comment_ID ); ?>" class="tutor-p1 tutor-font-medium tutor-text-secondary"> |
| 91 | <?php echo wp_kses_post( $question->comment_content ); ?> |
| 92 | </div> |
| 93 | |
| 94 | <?php if ( $is_user_asker ) : ?> |
| 95 | <div x-show="editingId === <?php echo (int) $question->comment_ID; ?>" x-cloak class="tutor-w-full"> |
| 96 | <?php |
| 97 | tutor_load_template( |
| 98 | 'learning-area.subpages.qna.form', |
| 99 | array( |
| 100 | 'form_id' => 'qna-edit-' . (int) $question->comment_ID, |
| 101 | 'default_value' => $question->comment_content, |
| 102 | 'submit_handler' => '(data) => updateQnAMutation?.mutate({ ...data, question_id: ' . (int) $question->comment_ID . ' })', |
| 103 | 'cancel_handler' => 'reset(); setEditing(null)', |
| 104 | 'is_pending' => 'updateQnAMutation?.isPending', |
| 105 | 'keep_footer_visible' => true, |
| 106 | ) |
| 107 | ); |
| 108 | ?> |
| 109 | </div> |
| 110 | <?php endif; ?> |
| 111 | </div> |
| 112 | |
| 113 | <?php |
| 114 | tutor_load_template( |
| 115 | 'learning-area.subpages.qna.form', |
| 116 | array( |
| 117 | 'form_id' => 'qna-reply-form-' . $question->comment_ID, |
| 118 | 'submit_handler' => '(data) => replyQnAMutation?.mutate({ ...data, question_id: ' . (int) $question->comment_ID . ', course_id: ' . (int) $question->course_id . ', reply_context: "single" })', |
| 119 | 'cancel_handler' => 'reset(); focused = false', |
| 120 | 'is_pending' => 'replyQnAMutation?.isPending', |
| 121 | 'placeholder' => __( 'Just drop your response here!', 'tutor' ), |
| 122 | 'label' => __( 'Reply', 'tutor' ), |
| 123 | 'submit_label' => __( 'Save', 'tutor' ), |
| 124 | 'form_class' => 'tutor-discussion-single-reply-form tutor-p-6', |
| 125 | ) |
| 126 | ); |
| 127 | ?> |
| 128 | |
| 129 | <div id="tutor-discussion-replies-list"> |
| 130 | <?php |
| 131 | tutor_load_template( |
| 132 | 'learning-area.subpages.qna.replies', |
| 133 | array( |
| 134 | 'replies' => $replies, |
| 135 | 'replies_order' => $replies_order, |
| 136 | 'user_id' => $user_id, |
| 137 | ) |
| 138 | ); |
| 139 | ?> |
| 140 | </div> |
| 141 | |
| 142 | <?php |
| 143 | ConfirmationModal::make() |
| 144 | ->id( $qna_delete_modal_id ) |
| 145 | ->title( __( 'Delete This Question?', 'tutor' ) ) |
| 146 | ->message( __( 'Are you sure you want to delete this question permanently? Please confirm your choice.', 'tutor' ) ) |
| 147 | ->confirm_text( __( 'Yes, Delete This', 'tutor' ) ) |
| 148 | ->confirm_handler( 'deleteQnAMutation?.mutate(payload)' ) |
| 149 | ->mutation_state( 'deleteQnAMutation' ) |
| 150 | ->render(); |
| 151 | ?> |
| 152 | </div> |
| 153 | </div> |
| 154 |