comment-card.php
5 days ago
comment-form.php
5 days ago
comment-list.php
5 days ago
comment-replies.php
5 days ago
comment-single.php
5 days ago
qna-card.php
5 days ago
qna-form.php
5 days ago
qna-list.php
5 days ago
qna-replies.php
5 days ago
qna-single.php
5 days ago
qna-single.php
234 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\Button; |
| 16 | use Tutor\Components\ConfirmationModal; |
| 17 | use Tutor\Components\Constants\Size; |
| 18 | use Tutor\Components\PreviewTrigger; |
| 19 | use TUTOR\Icon; |
| 20 | use Tutor\Components\SvgIcon; |
| 21 | use Tutor\Components\Constants\Color; |
| 22 | use Tutor\Components\Constants\Variant; |
| 23 | use TUTOR\Input; |
| 24 | use TUTOR\User; |
| 25 | |
| 26 | $question = tutor_utils()->get_qa_question( (int) $discussion_id ); |
| 27 | if ( ! $question ) { |
| 28 | wp_safe_redirect( $discussion_url ); |
| 29 | return; |
| 30 | } |
| 31 | |
| 32 | $user_id = get_current_user_id(); |
| 33 | $is_user_asker = $user_id === (int) $question->user_id; |
| 34 | $qna_delete_modal_id = 'tutor-qna-delete-modal'; |
| 35 | |
| 36 | $replies_order = Input::get( 'order', '' ); |
| 37 | $replies = tutor_utils()->get_qa_answer_by_question( $discussion_id, $replies_order, 'frontend' ); |
| 38 | |
| 39 | $is_solved = (int) tutor_utils()->array_get( 'tutor_qna_solved', $question->meta, 0 ); |
| 40 | $is_important = (int) tutor_utils()->array_get( 'tutor_qna_important', $question->meta, 0 ); |
| 41 | $is_archived = (int) tutor_utils()->array_get( 'tutor_qna_archived', $question->meta, 0 ); |
| 42 | |
| 43 | ?> |
| 44 | <div class="tutor-discussion-single" x-init="isSolved = <?php echo $is_solved ? 'true' : 'false'; ?>; isImportant = <?php echo $is_important ? 'true' : 'false'; ?>; isArchived = <?php echo $is_archived ? 'true' : 'false'; ?>;"> |
| 45 | <div class="tutor-flex tutor-justify-between tutor-px-6 tutor-py-5 tutor-border-b"> |
| 46 | <a href="<?php echo esc_url( $discussion_url ); ?>" class="tutor-btn tutor-btn-secondary tutor-btn-small tutor-gap-2"> |
| 47 | <?php SvgIcon::make()->name( Icon::ARROW_LEFT_2 )->flip_rtl()->render(); ?> |
| 48 | <?php esc_html_e( 'Back', 'tutor' ); ?> |
| 49 | </a> |
| 50 | <?php if ( User::is_instructor_view() ) : ?> |
| 51 | <div class="tutor-flex tutor-gap-2"> |
| 52 | <button |
| 53 | class="tutor-btn tutor-btn-link tutor-btn-x-small tutor-gap-2 tutor-text-subdued" |
| 54 | @click="handleQnASingleAction(<?php echo esc_html( $question->comment_ID ); ?>, 'solved')" |
| 55 | :disabled="qnaSingleActionMutation?.isPending" |
| 56 | > |
| 57 | <template x-if="qnaSingleActionMutation?.isPending && currentAction === 'solved'"> |
| 58 | <?php SvgIcon::make()->name( Icon::SPINNER )->size( 14 )->attr( 'class', 'tutor-animate-spin' )->render(); ?> |
| 59 | </template> |
| 60 | <template x-if="!(qnaSingleActionMutation?.isPending && currentAction === 'solved')"> |
| 61 | <span class="tutor-flex"> |
| 62 | <template x-if="isSolved"> |
| 63 | <?php SvgIcon::make()->name( Icon::COMPLETED_FILL )->size( 16 )->color( Color::SUCCESS_PRIMARY )->render(); ?> |
| 64 | </template> |
| 65 | <template x-if="!isSolved"> |
| 66 | <?php SvgIcon::make()->name( Icon::COMPLETED_CIRCLE )->render(); ?> |
| 67 | </template> |
| 68 | </span> |
| 69 | </template> |
| 70 | <?php esc_html_e( 'Solved', 'tutor' ); ?> |
| 71 | </button> |
| 72 | |
| 73 | <button |
| 74 | class="tutor-btn tutor-btn-link tutor-btn-x-small tutor-gap-2 tutor-text-subdued" |
| 75 | @click="handleQnASingleAction(<?php echo esc_html( $question->comment_ID ); ?>, 'important')" |
| 76 | :disabled="qnaSingleActionMutation?.isPending" |
| 77 | > |
| 78 | <template x-if="qnaSingleActionMutation?.isPending && currentAction === 'important'"> |
| 79 | <?php SvgIcon::make()->name( Icon::SPINNER )->size( 14 )->attr( 'class', 'tutor-animate-spin' )->render(); ?> |
| 80 | </template> |
| 81 | <template x-if="!(qnaSingleActionMutation?.isPending && currentAction === 'important')"> |
| 82 | <span class="tutor-flex"> |
| 83 | <template x-if="isImportant"> |
| 84 | <?php SvgIcon::make()->name( Icon::BOOKMARK_FILL )->size( 16 )->color( Color::EXCEPTION4 )->render(); ?> |
| 85 | </template> |
| 86 | <template x-if="!isImportant"> |
| 87 | <?php SvgIcon::make()->name( Icon::BOOKMARK )->render(); ?> |
| 88 | </template> |
| 89 | </span> |
| 90 | </template> |
| 91 | <?php esc_html_e( 'Important', 'tutor' ); ?> |
| 92 | </button> |
| 93 | </div> |
| 94 | <?php endif; ?> |
| 95 | </div> |
| 96 | <div class="tutor-discussion-single-body tutor-p-6 tutor-border-b"> |
| 97 | <div class="tutor-flex tutor-gap-5 tutor-mb-5"> |
| 98 | <?php Avatar::make()->user( $question->user_id )->size( Size::SIZE_40 )->render(); ?> |
| 99 | <div class="tutor-min-w-0 tutor-flex-1"> |
| 100 | <div class="tutor-flex tutor-items-center tutor-gap-5 tutor-small"> |
| 101 | <span class="tutor-discussion-card-author tutor-flex-shrink-0"><?php echo esc_html( $question->comment_author ); ?></span> |
| 102 | <span class="tutor-text-secondary tutor-flex-shrink-0"> |
| 103 | <?php |
| 104 | /* translators: %s human-readable time difference. */ |
| 105 | echo esc_html( sprintf( __( '%s ago', 'tutor' ), human_time_diff( strtotime( $question->comment_date_gmt ) ) ) ); |
| 106 | ?> |
| 107 | </span> |
| 108 | </div> |
| 109 | <div class="tutor-tiny tutor-flex tutor-items-center tutor-gap-1 tutor-overflow-hidden"> |
| 110 | <span class="tutor-text-subdued tutor-flex-shrink-0">asked in</span> |
| 111 | <div class="tutor-min-w-0 tutor-flex-1"> |
| 112 | <?php PreviewTrigger::make()->id( $question->course_id )->render(); ?> |
| 113 | </div> |
| 114 | </div> |
| 115 | </div> |
| 116 | <div class="tutor-ml-auto"> |
| 117 | <div x-data="tutorPopover({ placement: 'bottom-end', offset: 4 })" class="tutor-quiz-item-result-more"> |
| 118 | <?php |
| 119 | Button::make() |
| 120 | ->label( __( 'More options', 'tutor' ) ) |
| 121 | ->variant( Variant::GHOST ) |
| 122 | ->size( Size::X_SMALL ) |
| 123 | ->icon( Icon::ELLIPSES, 'left', Size::SIZE_16, Color::SECONDARY ) |
| 124 | ->icon_only() |
| 125 | ->attr( 'x-ref', 'trigger' ) |
| 126 | ->attr( '@click', 'toggle()' ) |
| 127 | ->render(); |
| 128 | ?> |
| 129 | |
| 130 | <div |
| 131 | x-ref="content" |
| 132 | x-show="open" |
| 133 | x-cloak |
| 134 | @click.outside="handleClickOutside()" |
| 135 | class="tutor-popover" |
| 136 | > |
| 137 | <div class="tutor-popover-menu" style="min-width: 130px;"> |
| 138 | <?php if ( User::is_instructor_view() ) : ?> |
| 139 | <button |
| 140 | class="tutor-popover-menu-item tutor-gap-5" |
| 141 | @click="handleQnASingleAction(<?php echo esc_html( $question->comment_ID ); ?>, 'archived')" |
| 142 | :disabled="qnaSingleActionMutation?.isPending" |
| 143 | > |
| 144 | <template x-if="qnaSingleActionMutation?.isPending && currentAction === 'archived'"> |
| 145 | <?php SvgIcon::make()->name( Icon::SPINNER )->size( 20 )->color( Color::SECONDARY )->attr( 'class', 'tutor-animate-spin' )->render(); ?> |
| 146 | </template> |
| 147 | <template x-if="!(qnaSingleActionMutation?.isPending && currentAction === 'archived')"> |
| 148 | <?php SvgIcon::make()->name( Icon::ARCHIVE_2 )->size( 20 )->render(); ?> |
| 149 | </template> |
| 150 | <span x-text="isArchived ? '<?php echo esc_js( __( 'Un-Archive', 'tutor' ) ); ?>' : '<?php echo esc_js( __( 'Archive', 'tutor' ) ); ?>'"></span> |
| 151 | </button> |
| 152 | <?php endif; ?> |
| 153 | <?php if ( $is_user_asker ) : ?> |
| 154 | <button class="tutor-popover-menu-item tutor-gap-5" @click="setEditing(<?php echo (int) $question->comment_ID; ?>, 'qna'); hide()"> |
| 155 | <?php SvgIcon::make()->name( Icon::EDIT_2 )->size( 20 )->render(); ?> |
| 156 | <?php esc_html_e( 'Edit', 'tutor' ); ?> |
| 157 | </button> |
| 158 | <?php endif; ?> |
| 159 | <button |
| 160 | class="tutor-popover-menu-item tutor-gap-5" |
| 161 | @click="TutorCore.modal.showModal('<?php echo esc_js( $qna_delete_modal_id ); ?>', { question_id: <?php echo esc_html( $question->comment_ID ); ?> }); hide();" |
| 162 | > |
| 163 | <?php SvgIcon::make()->name( Icon::DELETE_2 )->size( 20 )->render(); ?> <?php esc_html_e( 'Delete', 'tutor' ); ?> |
| 164 | </button> |
| 165 | </div> |
| 166 | </div> |
| 167 | </div> |
| 168 | </div> |
| 169 | </div> |
| 170 | |
| 171 | <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"> |
| 172 | <?php echo wp_kses_post( $question->comment_content ); ?> |
| 173 | </div> |
| 174 | |
| 175 | <?php if ( $is_user_asker ) : ?> |
| 176 | <div x-show="editingId === <?php echo (int) $question->comment_ID; ?>" x-cloak class="tutor-w-full"> |
| 177 | <?php |
| 178 | tutor_load_template( |
| 179 | 'dashboard.discussions.qna-form', |
| 180 | array( |
| 181 | 'form_id' => 'qna-edit-' . (int) $question->comment_ID, |
| 182 | 'default_value' => $question->comment_content, |
| 183 | 'submit_handler' => '(data) => updateQnAMutation?.mutate({ ...data, question_id: ' . (int) $question->comment_ID . ' })', |
| 184 | 'cancel_handler' => 'setEditing(null)', |
| 185 | 'is_pending' => 'updateQnAMutation?.isPending', |
| 186 | 'keep_footer_visible' => true, |
| 187 | ) |
| 188 | ); |
| 189 | ?> |
| 190 | </div> |
| 191 | <?php endif; ?> |
| 192 | </div> |
| 193 | |
| 194 | <?php |
| 195 | tutor_load_template( |
| 196 | 'dashboard.discussions.qna-form', |
| 197 | array( |
| 198 | 'form_id' => 'qna-reply-form-' . $question->comment_ID, |
| 199 | 'submit_handler' => '(data) => replyQnAMutation?.mutate({ ...data, question_id: ' . (int) $question->comment_ID . ', course_id: ' . (int) $question->course_id . ', reply_context: "single" })', |
| 200 | 'cancel_handler' => 'reset(); focused = false', |
| 201 | 'is_pending' => 'replyQnAMutation?.isPending', |
| 202 | 'placeholder' => __( 'Just drop your response here!', 'tutor' ), |
| 203 | 'label' => __( 'Reply', 'tutor' ), |
| 204 | 'submit_label' => __( 'Save', 'tutor' ), |
| 205 | 'form_class' => 'tutor-discussion-single-reply-form tutor-p-6', |
| 206 | ) |
| 207 | ); |
| 208 | ?> |
| 209 | |
| 210 | <div id="tutor-discussion-replies-list"> |
| 211 | <?php |
| 212 | tutor_load_template( |
| 213 | 'dashboard.discussions.qna-replies', |
| 214 | array( |
| 215 | 'replies' => $replies, |
| 216 | 'replies_order' => $replies_order, |
| 217 | 'user_id' => $user_id, |
| 218 | ) |
| 219 | ); |
| 220 | ?> |
| 221 | </div> |
| 222 | |
| 223 | <?php |
| 224 | ConfirmationModal::make() |
| 225 | ->id( $qna_delete_modal_id ) |
| 226 | ->title( __( 'Delete This Question?', 'tutor' ) ) |
| 227 | ->message( __( 'Are you sure you want to delete this question permanently? Please confirm your choice.', 'tutor' ) ) |
| 228 | ->confirm_text( __( 'Yes, Delete This', 'tutor' ) ) |
| 229 | ->confirm_handler( 'deleteQnAMutation?.mutate(payload)' ) |
| 230 | ->mutation_state( 'deleteQnAMutation' ) |
| 231 | ->render(); |
| 232 | ?> |
| 233 | </div> |
| 234 |