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