contexts.php
4 years ago
qna-new.php
4 years ago
qna-single.php
4 years ago
qna-table.php
4 years ago
qna-single.php
152 lines
| 1 | <?php |
| 2 | extract( $data ); // $question_id |
| 3 | |
| 4 | // QNA data |
| 5 | $question = tutor_utils()->get_qa_question( $question_id ); |
| 6 | if (property_exists($question, 'meta')) { |
| 7 | $meta = $question->meta; |
| 8 | } |
| 9 | $answers = tutor_utils()->get_qa_answer_by_question( $question_id ); |
| 10 | $back_url = isset( $back_url ) ? $back_url : remove_query_arg( 'question_id', tutor()->current_url ); |
| 11 | |
| 12 | // Badges data |
| 13 | $_user_id = get_current_user_id(); |
| 14 | if (property_exists($question, 'user_id')) { |
| 15 | $is_user_asker = $question->user_id == $_user_id; |
| 16 | } |
| 17 | $id_slug = $is_user_asker ? '_'.$_user_id : ''; |
| 18 | $is_solved = (int) tutor_utils()->array_get( 'tutor_qna_solved'.$id_slug, $meta, 0 ); |
| 19 | $is_important = (int) tutor_utils()->array_get( 'tutor_qna_important'.$id_slug, $meta, 0 ); |
| 20 | $is_archived = (int) tutor_utils()->array_get( 'tutor_qna_archived'.$id_slug, $meta, 0 ); |
| 21 | $is_read = (int) tutor_utils()->array_get( 'tutor_qna_read'.$id_slug, $meta, 0 ); |
| 22 | |
| 23 | $modal_id = 'tutor_qna_delete_single_' . $question_id; |
| 24 | $reply_hidden = ! wp_doing_ajax() ? 'display:none;' : 0; |
| 25 | |
| 26 | // At first set this as read |
| 27 | update_comment_meta( $question_id, 'tutor_qna_read'.$id_slug, 1 ); |
| 28 | ?> |
| 29 | |
| 30 | <div class="tutor-qna-single-question<?php echo is_admin() ? ' tutor-admin-wrap' : ''; ?>" data-course_id="<?php echo $question->course_id; ?>" data-question_id="<?php echo $question_id; ?>" data-context="<?php echo $context; ?>"> |
| 31 | <?php if ( in_array( $context, array( 'backend-dashboard-qna-single', 'frontend-dashboard-qna-single' ) ) ) : ?> |
| 32 | <div class="<?php echo is_admin() ? 'tutor-wp-dashboard-header tutor-px-24 tutor-mb-24' : 'tutor-qa-sticky-bar'; ?>"> |
| 33 | <div class="tutor-row tutor-align-lg-center"> |
| 34 | <div class="tutor-col-lg"> |
| 35 | <div class="tutor-d-lg-flex tutor-align-lg-center tutor-px-12 tutor-py-16"> |
| 36 | <a class="tutor-btn tutor-btn-ghost" href="<?php echo $back_url; ?>"> |
| 37 | <span class="tutor-icon-previous tutor-mr-8" area-hidden="true"></span> |
| 38 | <?php _e('Back', 'tutor'); ?> |
| 39 | </a> |
| 40 | </div> |
| 41 | </div> |
| 42 | |
| 43 | <div class="tutor-col-lg-auto"> |
| 44 | <div class="tutor-qna-badges tutor-qna-badges-wrapper"> |
| 45 | <?php if ( ! $is_user_asker ) : ?> |
| 46 | <span class="tutor-btn tutor-btn-ghost tutor-mr-16" data-action="solved" data-state-class-selector="i" data-state-class-0="tutor-icon-circle-mark-line" data-state-class-1="tutor-icon-circle-mark tutor-color-success" role="button"> |
| 47 | <i class="<?php echo $is_solved ? 'tutor-icon-circle-mark tutor-color-success active' : 'tutor-icon-circle-mark-line'; ?> tutor-mr-8"></i> |
| 48 | <span><?php _e( 'Solved', 'tutor' ); ?></span> |
| 49 | </span> |
| 50 | |
| 51 | <span class="tutor-btn tutor-btn-ghost tutor-mr-16" data-action="important" data-state-class-selector="i" data-state-class-0="tutor-icon-important-line" data-state-class-1="tutor-icon-important-bold"> |
| 52 | <i class="<?php echo $is_important ? 'tutor-icon-important-bold active' : 'tutor-icon-important-line'; ?> tutor-mr-8"></i> |
| 53 | <span><?php _e( 'Important', 'tutor' ); ?></span> |
| 54 | </span> |
| 55 | |
| 56 | <span class="tutor-btn tutor-btn-ghost tutor-mr-16" data-action="archived" data-state-text-selector="span" data-state-text-0="<?php _e( 'Archive', 'tutor' ); ?>" data-state-text-1="<?php _e( 'Un-Archive', 'tutor' ); ?>" data-state-class-selector="i" data-state-class-0="tutor-icon-archive" data-state-class-1="tutor-icon-archive"> |
| 57 | <i class="<?php echo $is_archived ? 'tutor-icon-archive active' : 'tutor-icon-archive'; ?> tutor-mr-8"></i> |
| 58 | <span><?php $is_archived ? _e( 'Un-Archive', 'tutor' ) : _e( 'Archive', 'tutor' ); ?></span> |
| 59 | </span> |
| 60 | <?php endif; ?> |
| 61 | <span class="tutor-btn tutor-btn-ghost" data-tutor-modal-target="<?php echo $modal_id; ?>"> |
| 62 | <i class="tutor-icon-trash-can-bold tutor-mr-8" area-hidden="true"></i> |
| 63 | <?php _e( 'Delete', 'tutor' ); ?> |
| 64 | </span> |
| 65 | </div> |
| 66 | </div> |
| 67 | </div> |
| 68 | </div> |
| 69 | <?php endif; ?> |
| 70 | |
| 71 | <div class="<?php echo is_admin() ? 'tutor-admin-container' : ''; ?>"> |
| 72 | <div class="tutor-qna-course-title tutor-color-black tutor-fs-6 tutor-fw-bold tutor-mb-32<?php echo is_single_course(true) ? ' tutor-d-none' : ''; ?>"> |
| 73 | <?php echo esc_html( $question->post_title ); ?> |
| 74 | <div class="tutor-hr tutor-mt-20" area-hidden="true"></div> |
| 75 | </div> |
| 76 | <div class="tutor-qna-single-wrapper"> |
| 77 | <div class="tutor-qa-reply-wrapper tutor-mt-20"> |
| 78 | <div class="tutor-qa-chatlist"> |
| 79 | <?php |
| 80 | $current_user_id = get_current_user_id(); |
| 81 | $avatar_url = array(); |
| 82 | $is_single = in_array( $context, array( 'course-single-qna-sidebar', 'course-single-qna-single' ) ); |
| 83 | |
| 84 | if ( is_array( $answers ) && count( $answers ) ) { |
| 85 | $reply_count = count( $answers ) - 1; |
| 86 | foreach ( $answers as $answer ) { |
| 87 | if ( ! isset( $avatar_url[ $answer->user_id ] ) ) { |
| 88 | // Get avatar url if not already got |
| 89 | $avatar_url[ $answer->user_id ] = get_avatar_url( $answer->user_id ); |
| 90 | } |
| 91 | |
| 92 | $css_class = ( $current_user_id != $answer->user_id || $answer->comment_parent == 0 ) ? 'tutor-qna-left' : 'tutor-qna-right'; |
| 93 | $css_style = ( $is_single && $answer->comment_parent != 0 ) ? 'margin-left:14%;' . $reply_hidden : ''; |
| 94 | ?> |
| 95 | <div class="tutor-qna-chat <?php echo $css_class; ?> " style="<?php echo $css_style; ?>"> |
| 96 | <div class="tutor-qna-user"> |
| 97 | <div> |
| 98 | <img src="<?php echo get_avatar_url( $answer->user_id ); ?>" /> |
| 99 | </div> |
| 100 | |
| 101 | <div> |
| 102 | <div class="tutor-fs-6 tutor-fw-medium tutor-color-secondary"> |
| 103 | <?php echo $answer->display_name; ?> |
| 104 | </div> |
| 105 | <div class="tutor-fs-7 tutor-color-muted"> |
| 106 | <?php echo sprintf( __( '%s ago', 'tutor' ), human_time_diff( strtotime( $answer->comment_date ) ) ); ?> |
| 107 | </div> |
| 108 | </div> |
| 109 | </div> |
| 110 | |
| 111 | <div class="tutor-qna-text tutor-fs-7"> |
| 112 | <?php echo esc_textarea( stripslashes( $answer->comment_content ) ); ?> |
| 113 | </div> |
| 114 | |
| 115 | <?php if ( $is_single && $answer->comment_parent == 0 ) : ?> |
| 116 | <div class="tutor-toggle-reply"> |
| 117 | <span><?php _e( 'Reply', 'tutor' ); ?> <?php echo $reply_count ? '(' . $reply_count . ')' : ''; ?></span> |
| 118 | </div> |
| 119 | <?php endif; ?> |
| 120 | </div> |
| 121 | <?php |
| 122 | } |
| 123 | } |
| 124 | ?> |
| 125 | </div> |
| 126 | <div class="tutor-qa-reply tutor-mt-12 tutor-mb-24" data-context="<?php echo $context; ?>" style="<?php echo $is_single ? $reply_hidden : ''; ?>"> |
| 127 | <textarea class="tutor-form-control" placeholder="<?php _e( 'Write here...', 'tutor' ); ?>"></textarea> |
| 128 | <div class="tutor-d-flex tutor-align-center"> |
| 129 | <button data-back_url="<?php echo $back_url; ?>" type="submit" class="tutor-btn tutor-btn-primary tutor-btn-sm"> |
| 130 | <?php esc_html_e( 'Reply', 'tutor' ); ?> |
| 131 | </button> |
| 132 | </div> |
| 133 | </div> |
| 134 | </div> |
| 135 | </div> |
| 136 | </div> |
| 137 | </div> |
| 138 | |
| 139 | <?php |
| 140 | // Delete modal |
| 141 | tutor_load_template( 'modal.confirm', array( |
| 142 | 'id' => $modal_id, |
| 143 | 'image' => 'icon-trash.svg', |
| 144 | 'title' => __('Do You Want to Delete This Question?', 'tutor'), |
| 145 | 'content' => __('All the replies also will be deleted.', 'tutor'), |
| 146 | 'yes' => array( |
| 147 | 'text' => __('Yes, Delete This', 'tutor'), |
| 148 | 'class' => 'tutor-list-ajax-action', |
| 149 | 'attr' => array('data-request_data=\'{"action":"tutor_delete_dashboard_question", "question_id":"' . $question_id . '"}\'', 'data-redirect_to="' . $back_url . '"') |
| 150 | ), |
| 151 | )); |
| 152 | ?> |