Skip to content

Commit 94627f9

Browse files
committed
Merge branch '4.0.0-dev' of github.com:themeum/tutor into course-card-v4
2 parents 8235510 + 9bc1953 commit 94627f9

File tree

11 files changed

+183
-103
lines changed

11 files changed

+183
-103
lines changed

assets/src/js/frontend/dashboard/pages/discussions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ const discussionsPage = () => {
5959
return wpAjaxInstance.post(endpoints.DELETE_LESSON_COMMENT, payload);
6060
},
6161

62-
async handleReadUnreadQnA(questionId: number) {
62+
async handleReadUnreadQnA(questionId: number, context: string) {
6363
await this.readUnreadQnAMutation?.mutate({
64-
context: 'frontend-dashboard-qna-table-instructor',
64+
context: context,
6565
question_id: questionId,
6666
qna_action: 'read',
6767
});

classes/Lesson.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,12 @@ public function ajax_delete_lesson_comment() {
148148
}
149149

150150
$lesson_id = $comment->comment_post_ID;
151-
if ( ! tutor_utils()->can_user_manage( 'lesson', $lesson_id ) ) {
152-
$this->response_bad_request( tutor_utils()->error_message() );
151+
if ( get_current_user_id() === $comment->user_id || tutor_utils()->can_user_manage( 'lesson', $lesson_id ) ) {
152+
wp_delete_comment( $comment_id, true );
153+
$this->json_response( __( 'Comment deleted successfully', 'tutor' ) );
154+
} else {
155+
$this->response_bad_request( __( 'You are not allowed to delete this comment', 'tutor' ) );
153156
}
154-
155-
wp_delete_comment( $comment_id, true );
156-
$this->json_response( __( 'Comment deleted successfully', 'tutor' ) );
157157
}
158158

159159
/**

classes/User.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ class User {
4343
const PROFILE_JOB_TITLE_META = '_tutor_profile_job_title';
4444
const TUTOR_STUDENT_META = '_is_tutor_student';
4545

46+
/**
47+
* View as constants
48+
*
49+
* @since 4.0.0
50+
*/
51+
const VIEW_AS_INSTRUCTOR = 'instructor';
52+
const VIEW_AS_STUDENT = 'student';
53+
4654
/**
4755
* User model
4856
*

components/Button.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class Button extends BaseComponent {
116116
* @var string
117117
*/
118118
private const POSITION_LEFT = 'left';
119-
private const POSITION_RIGHT = 'left';
119+
private const POSITION_RIGHT = 'right';
120120

121121
/**
122122
* The icon position relative to label. Accepts 'left' or 'right'.

templates/dashboard/discussions.php

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
defined( 'ABSPATH' ) || exit;
1717

1818
$current_tab = Input::get( 'tab' );
19+
$replies = Input::get( 'replies', 0, Input::TYPE_INT );
1920
$order_filter = Input::get( 'order', 'DESC' );
2021
$current_page = max( 1, Input::get( 'current_page', 1, Input::TYPE_INT ) );
2122
$item_per_page = tutor_utils()->get_option( 'pagination_per_page', 10 );
@@ -40,18 +41,29 @@
4041
);
4142
?>
4243
<div class="tutor-dashboard-discussions tutor-surface-l1 tutor-border tutor-rounded-2xl" x-data="tutorDiscussions()">
43-
<div class="tutor-p-6 tutor-border-b">
44-
<?php Nav::make()->items( $page_nav_items )->render(); ?>
45-
</div>
46-
<div class="tutor-sm-border tutor-sm-rounded-2xl tutor-sm-mt-4">
47-
<?php
44+
<?php
45+
if ( $replies ) {
46+
$template = tutor()->path . 'templates/dashboard/discussions/qna-replies.php';
4847
if ( 'lesson-comments' === $current_tab ) {
49-
$template = tutor()->path . 'templates/dashboard/discussions/lesson-comment-list.php';
50-
} else {
51-
$template = tutor()->path . 'templates/dashboard/discussions/qna-list.php';
48+
$template = tutor()->path . 'templates/dashboard/discussions/lesson-comment-replies.php';
5249
}
53-
5450
require_once $template;
51+
} else {
5552
?>
56-
</div>
53+
<div class="tutor-p-6 tutor-border-b">
54+
<?php Nav::make()->items( $page_nav_items )->render(); ?>
55+
</div>
56+
<div class="tutor-sm-border tutor-sm-rounded-2xl tutor-sm-mt-4">
57+
<?php
58+
$template = tutor()->path . 'templates/dashboard/discussions/qna-list.php';
59+
if ( 'lesson-comments' === $current_tab ) {
60+
$template = tutor()->path . 'templates/dashboard/discussions/lesson-comment-list.php';
61+
}
62+
63+
require_once $template;
64+
?>
65+
</div>
66+
<?php
67+
}
68+
?>
5769
</div>

templates/dashboard/discussions/lesson-comment-card.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
$last_reply = $replies[0];
3232
}
3333

34-
$replies_url = UrlHelper::prepare(
34+
$replies_url = UrlHelper::add_query_params(
3535
$discussion_url,
3636
array(
3737
'tab' => 'lesson-comments',

templates/dashboard/discussions/lesson-comment-list.php

Lines changed: 22 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@
1111

1212
defined( 'ABSPATH' ) || exit;
1313

14+
use Tutor\Components\ConfirmationModal;
1415
use Tutor\Components\Pagination;
1516
use Tutor\Components\Sorting;
1617
use TUTOR\Icon;
1718
use TUTOR\Lesson;
1819

20+
$is_instructor = tutor_utils()->is_instructor( null, true );
21+
1922
$lesson_ids = get_posts(
2023
array(
2124
'post_type' => tutor()->lesson_post_type,
@@ -34,13 +37,21 @@
3437
'order' => $order_filter,
3538
);
3639

40+
if ( ! $is_instructor ) {
41+
$list_args['user_id'] = get_current_user_id();
42+
}
43+
3744
$count_args = array(
3845
'post__in' => $lesson_ids,
3946
'status' => 'approve',
4047
'parent' => 0,
4148
'count' => true,
4249
);
4350

51+
if ( ! $is_instructor ) {
52+
$count_args['user_id'] = get_current_user_id();
53+
}
54+
4455
$lesson_comments = Lesson::get_comments( $list_args );
4556
$total_items = Lesson::get_comments( $count_args );
4657
?>
@@ -74,39 +85,15 @@
7485
<?php endif; ?>
7586
</div>
7687

77-
<?php if ( ! empty( $lesson_comments ) ) : ?>
78-
<div x-data="tutorModal({ id: 'tutor-comment-delete-modal' })" x-cloak>
79-
<template x-teleport="body">
80-
<div x-bind="getModalBindings()">
81-
<div x-bind="getBackdropBindings()"></div>
82-
<div x-bind="getModalContentBindings()" style="max-width: 426px;">
83-
<button x-data="tutorIcon({ name: 'cross', width: 16, height: 16})", x-bind="getCloseButtonBindings()"></button>
84-
85-
<div class="tutor-p-7 tutor-pt-10 tutor-flex tutor-flex-column tutor-items-center">
86-
<?php tutor_utils()->render_svg_icon( Icon::BIN, 100, 100 ); ?>
87-
<h5 class="tutor-h5 tutor-font-medium tutor-mt-8">
88-
<?php esc_html_e( 'Delete This Comment?', 'tutor' ); ?>
89-
</h5>
90-
<p class="tutor-p3 tutor-text-secondary tutor-mt-2 tutor-text-center">
91-
<?php esc_html_e( 'All the replies also will be deleted.', 'tutor' ); ?>
92-
</p>
93-
</div>
88+
<?php
89+
if ( ! empty( $lesson_comments ) ) {
90+
ConfirmationModal::make()
91+
->id( 'tutor-comment-delete-modal' )
92+
->title( __( 'Delete This Comment?', 'tutor' ) )
93+
->message( __( 'Are you sure you want to delete this comment permanently? Please confirm your choice.', 'tutor' ) )
94+
->confirm_text( __( 'Yes, Delete This', 'tutor' ) )
95+
->confirm_handler( 'handleDeleteComment(payload?.commentId)' )
96+
->mutation_state( 'deleteCommentMutation' )
97+
->render();
98+
}
9499

95-
<div class="tutor-modal-footer">
96-
<button class="tutor-btn tutor-btn-ghost tutor-btn-small" @click="TutorCore.modal.closeModal('tutor-comment-delete-modal')">
97-
<?php esc_html_e( 'Cancel', 'tutor' ); ?>
98-
</button>
99-
<button
100-
class="tutor-btn tutor-btn-destructive tutor-btn-small"
101-
:class="deleteCommentMutation?.isPending ? 'tutor-btn-loading' : ''"
102-
@click="handleDeleteComment(payload?.commentId)"
103-
:disabled="deleteCommentMutation?.isPending"
104-
>
105-
<?php esc_html_e( 'Yes, Delete This', 'tutor' ); ?>
106-
</button>
107-
</div>
108-
</div>
109-
</div>
110-
</template>
111-
</div>
112-
<?php endif; ?>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
/**
3+
* Lesson comment 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+
use Tutor\Components\Button;
13+
use Tutor\Components\Constants\Size;
14+
use Tutor\Components\Constants\Variant;
15+
use TUTOR\Icon;
16+
17+
defined( 'ABSPATH' ) || exit;
18+
?>
19+
20+
<div class="tutor-p-6 tutor-border-b">
21+
<div class="tutor-flex tutor-justify-between">
22+
<div>
23+
<?php
24+
Button::make()
25+
->variant( Variant::SECONDARY )
26+
->tag( 'a' )
27+
->attr( 'href', $discussion_url )
28+
->label( __( 'Back', 'tutor' ) )
29+
->icon( Icon::BACK )
30+
->size( Size::SM )
31+
->render();
32+
?>
33+
</div>
34+
<div></div>
35+
</div>
36+
</div>
37+
38+
<div class="tutor-sm-border tutor-sm-rounded-2xl tutor-sm-mt-4">
39+
</div>

templates/dashboard/discussions/qna-card.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515
use Tutor\Components\Avatar;
1616
use Tutor\Helpers\UrlHelper;
1717

18-
$context = 'frontend-dashboard-qna-table-' . $view_as;
19-
$key_slug = 'frontend-dashboard-qna-table-student' === $context ? '_' . $current_user_id : '';
20-
$meta = $question->meta;
21-
$is_read = (int) tutor_utils()->array_get( 'tutor_qna_read' . $key_slug, $meta, 0 );
22-
$is_unread = 0 === $is_read;
23-
$text_mark_as = $is_unread ? __( 'Mark as Read', 'tutor' ) : __( 'Mark as Unread', 'tutor' );
18+
$current_user_id = get_current_user_id();
19+
$context = 'frontend-dashboard-qna-table-' . $view_as;
20+
$key_slug = 'frontend-dashboard-qna-table-student' === $context ? '_' . $current_user_id : '';
21+
$meta = $question->meta;
22+
$is_read = (int) tutor_utils()->array_get( 'tutor_qna_read' . $key_slug, $meta, 0 );
23+
$is_unread = 0 === $is_read;
24+
$text_mark_as = $is_unread ? __( 'Mark as Read', 'tutor' ) : __( 'Mark as Unread', 'tutor' );
2425

2526
$question_id = $question->comment_ID;
2627
$last_reply = null;
@@ -30,7 +31,7 @@
3031
$last_reply = $answers[0];
3132
}
3233

33-
$replies_url = UrlHelper::prepare(
34+
$replies_url = UrlHelper::add_query_params(
3435
$discussion_url,
3536
array(
3637
'tab' => 'qna',
@@ -89,7 +90,7 @@ class="tutor-btn tutor-btn-text tutor-btn-x-small tutor-btn-icon tutor-qna-card-
8990
<div class="tutor-popover-menu">
9091
<button
9192
class="tutor-popover-menu-item"
92-
@click="handleReadUnreadQnA(<?php echo esc_html( $question_id ); ?>)">
93+
@click="handleReadUnreadQnA(<?php echo esc_html( $question_id ); ?>,'<?php echo esc_html( $context ); ?>')">
9394
<?php tutor_utils()->render_svg_icon( Icon::EDIT_2 ); ?>
9495
<?php echo esc_html( $text_mark_as ); ?>
9596
</button>

templates/dashboard/discussions/qna-list.php

Lines changed: 19 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@
99
* @since 4.0.0
1010
*/
1111

12+
use Tutor\Components\ConfirmationModal;
1213
use Tutor\Components\Pagination;
1314
use Tutor\Components\Sorting;
14-
use TUTOR\Icon;
1515
use TUTOR\Input;
16+
use TUTOR\User;
1617

17-
$is_instructor = tutor_utils()->is_instructor( null, true );
18-
$view_option = get_user_meta( get_current_user_id(), 'tutor_qa_view_as', true );
18+
$user_id = get_current_user_id();
19+
$is_instructor = tutor_utils()->is_instructor( $user_id, true );
20+
$view_option = get_user_meta( $user_id, 'tutor_qa_view_as', true );
1921
$q_status = Input::get( 'data' );
20-
$view_as = $is_instructor ? ( $view_option ? $view_option : 'instructor' ) : 'student';
21-
$asker_id = 'instructor' === $view_as ? null : get_current_user_id();
22+
$view_as = $is_instructor ? ( $view_option ? $view_option : User::VIEW_AS_INSTRUCTOR ) : User::VIEW_AS_STUDENT;
23+
$asker_id = User::VIEW_AS_INSTRUCTOR === $view_as ? null : $user_id;
2224

2325
$total_items = (int) tutor_utils()->get_qa_questions( $offset, $item_per_page, '', null, null, $asker_id, $q_status, true );
2426
$questions = tutor_utils()->get_qa_questions( $offset, $item_per_page, '', null, null, $asker_id, $q_status, false, array( 'order' => $order_filter ) );
@@ -55,39 +57,15 @@
5557
<?php endif; ?>
5658
</div>
5759

58-
<?php if ( ! empty( $questions ) ) : ?>
59-
<div x-data="tutorModal({ id: 'tutor-qna-delete-modal' })" x-cloak>
60-
<template x-teleport="body">
61-
<div x-bind="getModalBindings()">
62-
<div x-bind="getBackdropBindings()"></div>
63-
<div x-bind="getModalContentBindings()" style="max-width: 426px;">
64-
<button x-data="tutorIcon({ name: 'cross', width: 16, height: 16})", x-bind="getCloseButtonBindings()"></button>
65-
66-
<div class="tutor-p-7 tutor-pt-10 tutor-flex tutor-flex-column tutor-items-center">
67-
<?php tutor_utils()->render_svg_icon( Icon::BIN, 100, 100 ); ?>
68-
<h5 class="tutor-h5 tutor-font-medium tutor-mt-8">
69-
<?php esc_html_e( 'Delete This Question?', 'tutor' ); ?>
70-
</h5>
71-
<p class="tutor-p3 tutor-text-secondary tutor-mt-2 tutor-text-center">
72-
<?php esc_html_e( 'All the replies also will be deleted.', 'tutor' ); ?>
73-
</p>
74-
</div>
75-
76-
<div class="tutor-modal-footer">
77-
<button class="tutor-btn tutor-btn-ghost tutor-btn-small" @click="TutorCore.modal.closeModal('tutor-qna-delete-modal')">
78-
<?php esc_html_e( 'Cancel', 'tutor' ); ?>
79-
</button>
80-
<button
81-
class="tutor-btn tutor-btn-destructive tutor-btn-small"
82-
:class="deleteQnAMutation?.isPending ? 'tutor-btn-loading' : ''"
83-
@click="handleDeleteQnA(payload?.questionId)"
84-
:disabled="deleteQnAMutation?.isPending"
85-
>
86-
<?php esc_html_e( 'Yes, Delete This', 'tutor' ); ?>
87-
</button>
88-
</div>
89-
</div>
90-
</div>
91-
</template>
92-
</div>
93-
<?php endif; ?>
60+
<?php
61+
if ( ! empty( $questions ) ) {
62+
ConfirmationModal::make()
63+
->id( 'tutor-qna-delete-modal' )
64+
->title( __( 'Delete This Question?', 'tutor' ) )
65+
->message( __( 'Are you sure you want to delete this question permanently? Please confirm your choice.', 'tutor' ) )
66+
->confirm_text( __( 'Yes, Delete This', 'tutor' ) )
67+
->confirm_handler( 'handleDeleteQnA(payload?.questionId)' )
68+
->mutation_state( 'deleteQnAMutation' )
69+
->render();
70+
}
71+
?>

0 commit comments

Comments
 (0)