Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions assets/src/js/frontend/dashboard/pages/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ interface PreferencesFormProps {
auto_play_next: boolean;
theme: string;
font_scale: number;
formId?: string;
}

interface UpdateNotificationProps {
[key: string]: boolean | string;
}

const settings = () => {
Expand Down Expand Up @@ -100,7 +105,8 @@ const settings = () => {
this.handleResetPassword = this.handleResetPassword.bind(this);

this.handleUpdateNotification = this.query.useMutation(this.updateNotification, {
onSuccess: (data: TutorMutationResponse<string>) => {
onSuccess: (data: TutorMutationResponse<string>, payload: UpdateNotificationProps) => {
this.form.reset(payload?.formId as string, payload as unknown as Record<string, unknown>);
this.toast.success(data?.message ?? __('Notification settings updated', 'tutor'));
},
onError: (error: Error) => {
Expand Down Expand Up @@ -168,7 +174,8 @@ const settings = () => {
});

this.savePreferencesMutation = this.query.useMutation(this.updatePreferences, {
onSuccess: (data: TutorMutationResponse<PreferencesFormProps>) => {
onSuccess: (data: TutorMutationResponse<PreferencesFormProps>, payload: PreferencesFormProps) => {
this.form.reset(payload?.formId || '', payload as unknown as Record<string, unknown>);
this.toast.success(data?.message ?? __('Preferences saved successfully', 'tutor'));
},
onError: (error: Error) => {
Expand All @@ -177,16 +184,22 @@ const settings = () => {
});
},

async updatePreferences(payload: Record<string, unknown>) {
async updatePreferences(payload: PreferencesFormProps) {
return wpAjaxInstance.post(endpoints.UPDATE_USER_PREFERENCES, payload) as unknown as Promise<
TutorMutationResponse<PreferencesFormProps>
>;
},

async updateNotification(payload: Record<string, boolean>) {
async updateNotification(payload: UpdateNotificationProps) {
const transformedPayload = Object.keys(payload).reduce(
(formattedPayload, key) => {
const value = payload[key];

if (typeof value !== 'boolean') {
formattedPayload[`${key}`] = value;
return formattedPayload;
}

const stringValue = typeof value === 'boolean' ? (value ? 'on' : 'off') : value;

if (!key.includes('__')) {
Expand Down
11 changes: 7 additions & 4 deletions assets/src/scss/frontend/dashboard/_progress-card.scss
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,15 @@
}

&-actions {
display: none;
}

&-footer {
position: static;
display: block;
visibility: visible;
opacity: 1;
padding: $tutor-spacing-6 $tutor-spacing-4 0;

.tutor-btn {
width: 100%;
}
}
}
}
8 changes: 0 additions & 8 deletions assets/src/scss/frontend/dashboard/settings/_profile.scss
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,6 @@ body:has(#wpadminbar) {
}
}

.tutor-profile-notification-content {
border-top: 1px solid $tutor-border-idle;
}

.tutor-profile-notification-toggle {
display: flex;
align-items: center;
Expand Down Expand Up @@ -142,8 +138,4 @@ body:has(#wpadminbar) {
.tutor-input-field {
margin-bottom: 0px;
}

.tutor-profile-notification-content {
border-top: 1px solid $tutor-border-idle;
}
}
39 changes: 37 additions & 2 deletions classes/Course.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
exit;
}

use stdClass;
use TUTOR\Input;
use Tutor\Ecommerce\Tax;
use Tutor\Models\QuizModel;
Expand All @@ -23,7 +22,6 @@
use Tutor\Ecommerce\Ecommerce;
use Tutor\Traits\JsonResponse;
use Tutor\Helpers\ValidationHelper;
use TutorPro\CourseBundle\Models\BundleModel;

/**
* Course Class
Expand Down Expand Up @@ -300,6 +298,8 @@
add_filter( 'template_include', array( $this, 'handle_password_protected' ) );
add_action( 'login_form_postpass', array( $this, 'handle_password_submit' ) );
add_filter( 'the_preview', array( $this, 'handle_schedule_courses' ) );

add_action( 'tutor_course_action_btn', array( $this, 'render_course_action_btn' ) );
}

/**
Expand All @@ -315,7 +315,7 @@
global $wp_query;
$course_coming_soon_enabled = (int) get_post_meta( $content->ID, '_tutor_course_enable_coming_soon', true );
$is_instructor = tutor_utils()->is_instructor_of_this_course( get_current_user_id(), $content->ID, true );
if ( ! CourseModel::get_post_types( $content ) || current_user_can( 'administrator' ) || $is_instructor || $course_coming_soon_enabled ) {

Check failure on line 318 in classes/Course.php

View workflow job for this annotation

GitHub Actions / WPCS

Capabilities should be used instead of roles. Found &quot;administrator&quot; in function call to current_user_can()
return $content;
}

Expand Down Expand Up @@ -623,7 +623,7 @@
} else {
$errors['pricing'] = __( 'Invalid product', 'tutor' );
}
} else {

Check failure on line 626 in classes/Course.php

View workflow job for this annotation

GitHub Actions / WPCS

If control structure block found as the only statement within an &quot;else&quot; block. Use elseif instead.
/**
* If user does not select WC product
* Then automatic WC product will be create name with course title.
Expand Down Expand Up @@ -760,7 +760,7 @@
update_post_meta( $post_id, self::COURSE_PRICE_TYPE_META, $params['pricing']['type'] );
}
} catch ( \Throwable $th ) {
throw new \Exception( $th->getMessage() );

Check failure on line 763 in classes/Course.php

View workflow job for this annotation

GitHub Actions / WPCS

All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '$th'.
}
}

Expand Down Expand Up @@ -2242,7 +2242,7 @@
}

// Check if user is only an instructor.
if ( ! current_user_can( 'administrator' ) ) {

Check failure on line 2245 in classes/Course.php

View workflow job for this annotation

GitHub Actions / WPCS

Capabilities should be used instead of roles. Found &quot;administrator&quot; in function call to current_user_can()
// Check if instructor can trash course.
$can_trash_post = tutor_utils()->get_option( 'instructor_can_delete_course' );

Expand Down Expand Up @@ -2286,7 +2286,7 @@
/**
* Only admin can change main author
*/
if ( $courses_post_type === $post_type && ! current_user_can( 'administrator' ) ) {

Check failure on line 2289 in classes/Course.php

View workflow job for this annotation

GitHub Actions / WPCS

Capabilities should be used instead of roles. Found &quot;administrator&quot; in function call to current_user_can()
global $wpdb;
$post_ID = (int) tutor_utils()->avalue_dot( 'ID', $postarr );
$post_author = (int) $wpdb->get_var( $wpdb->prepare( "SELECT post_author FROM {$wpdb->posts} WHERE ID = %d ", $post_ID ) );
Expand Down Expand Up @@ -3244,4 +3244,39 @@
update_post_meta( $post_ID, self::COURSE_PRICE_META, $regular_price );
update_post_meta( $post_ID, self::COURSE_SALE_PRICE_META, $sale_price );
}

/**
* Render start/resume button in enrolled course action btn.
*
* @since 4.0.0
*
* @param int $course_id course id.
*
* @return void
*/
public function render_course_action_btn( int $course_id ) {
$is_completed = tutor_utils()->is_completed_course( $course_id );
if ( $is_completed ) {
return;
}

$course_progress = tutor_utils()->get_course_completed_percent( $course_id, 0, true );

$button_text = $course_progress['completed_percent'] > 0 ? __( 'Resume', 'tutor' ) : __( 'Start', 'tutor' );
$button_url = tutor_utils()->get_course_first_lesson( $course_id );

if ( ! $button_url ) {
$button_url = get_the_permalink( $course_id );
}

ob_start();
?>
<a href="<?php echo esc_url( $button_url ); ?>" class="tutor-btn tutor-btn-primary tutor-btn-x-small">
<?php echo esc_html( $button_text ); ?>
</a>
<?php
$button = ob_get_clean();

echo wp_kses_post( $button );
}
}
3 changes: 1 addition & 2 deletions templates/dashboard/account/settings/preferences.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@
shouldFocusError: true,
defaultValues: <?php echo wp_json_encode( $default_values ); ?>
})'

x-bind="getFormBindings()"
@submit="handleSubmit((data) => { savePreferencesMutation?.mutate(data); })($event)"
@submit="handleSubmit((data) => { savePreferencesMutation?.mutate({...data, formId: '<?php echo esc_attr( $form_id ); ?>'}); })($event)"
>
<!-- Course Content Section -->
<h5 class="tutor-preferences-section-header tutor-h5">
Expand Down
120 changes: 62 additions & 58 deletions templates/dashboard/courses/course-card.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,73 +20,77 @@
$category_names = is_array( $course_categories ) ? wp_list_pluck( $course_categories, 'name' ) : array();
$category = implode( ', ', $category_names );

$course_learning_url = tutor_utils()->get_course_first_lesson();
if ( get_post_type() !== tutor()->course_post_type ) {
$course_learning_url = get_permalink();
}

?>

<a href="<?php echo esc_url( $course_permalink ); ?>">
<div class="tutor-card tutor-progress-card">

<div class="tutor-progress-card-thumbnail">
<?php do_action( 'tutor_my_courses_before_thumbnail', $course_id ); ?>
<?php if ( ! empty( $tutor_course_img ) ) : ?>
<img src="<?php echo esc_url( $tutor_course_img ); ?>" alt="<?php the_title(); ?>" />
<div class="tutor-card tutor-progress-card" onclick="window.location.href = '<?php echo esc_url( $course_learning_url ); ?>';">
<div class="tutor-progress-card-thumbnail">
<?php do_action( 'tutor_my_courses_before_thumbnail', $course_id ); ?>
<?php if ( ! empty( $tutor_course_img ) ) : ?>
<img src="<?php echo esc_url( $tutor_course_img ); ?>" alt="<?php the_title(); ?>" />
<?php endif; ?>
</div>

<div class="tutor-progress-card-content">
<!-- course header -->
<div class="tutor-progress-card-header">
<?php if ( ! empty( $category ) ) : ?>
<div class="tutor-progress-card-category">
<?php echo esc_html( $category ); ?>
</div>
<?php endif; ?>
<h3 class="tutor-progress-card-title tutor-line-clamp-2">
<?php the_title(); ?>
</h3>
</div>

<div class="tutor-progress-card-content">

<!-- course header -->
<div class="tutor-progress-card-header">
<?php if ( ! empty( $category ) ) : ?>
<div class="tutor-progress-card-category">
<?php echo esc_html( $category ); ?>
</div>
<?php endif; ?>
<h3 class="tutor-progress-card-title tutor-line-clamp-2">
<?php the_title(); ?>
</h3>
</div>
<!-- course progress -->
<?php if ( $course_progress['completed_count'] > 0 || $course_progress['total_count'] > 0 ) : ?>
<div class="tutor-progress-card-progress">
<?php if ( $course_progress['total_count'] > 0 ) : ?>
<div class="tutor-progress-card-details">
<?php
printf(
esc_html(
_n(
'%1$s of %2$s lesson',
'%1$s of %2$s lessons',
(int) $course_progress['total_count'],
'tutor'
)
),
esc_html( $course_progress['completed_percent'] ),
esc_html( $course_progress['total_count'] )
);

<!-- course progress -->
<?php if ( $course_progress['completed_count'] > 0 || $course_progress['total_count'] > 0 ) : ?>
<div class="tutor-progress-card-progress">
<?php if ( $course_progress['total_count'] > 0 ) : ?>
<div class="tutor-progress-card-details">
<?php
?>
<span class="tutor-progress-card-separator">•</span>
<?php
printf(
esc_html(
_n(
'%1$s of %2$s lesson',
'%1$s of %2$s lessons',
(int) $course_progress['total_count'],
'tutor'
)
),
esc_html( $course_progress['completed_percent'] ),
esc_html( $course_progress['total_count'] )
esc_html__( '%1$s%% Complete', 'tutor' ),
esc_html( $course_progress['completed_percent'] )
);

?>
<span class="tutor-progress-card-separator">•</span>
<?php
printf(
esc_html__( '%1$s%% Complete', 'tutor' ),
esc_html( $course_progress['completed_percent'] )
);
?>
</div>
<?php endif; ?>
<?php if ( $course_progress['completed_percent'] >= 0 ) : ?>
<div class="tutor-progress-card-bar">
<div class="tutor-progress-bar" data-tutor-animated>
<div class="tutor-progress-bar-fill"
style="--tutor-progress-width: <?php echo esc_attr( $course_progress['completed_percent'] ); ?>%;">
</div>
?>
</div>
<?php endif; ?>
<?php if ( $course_progress['completed_percent'] >= 0 ) : ?>
<div class="tutor-progress-card-bar">
<div class="tutor-progress-bar" data-tutor-animated>
<div class="tutor-progress-bar-fill"
style="--tutor-progress-width: <?php echo esc_attr( $course_progress['completed_percent'] ); ?>%;">
</div>
</div>
<?php endif; ?>
</div>
<?php endif; ?>
</div>
<?php endif; ?>
</div>
<?php endif; ?>
</div>

</div>
<div class="tutor-progress-card-actions">
<?php do_action( 'tutor_course_action_btn', $course_id ); ?>
</div>
</a>
</div>
9 changes: 1 addition & 8 deletions templates/dashboard/student-dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,7 @@ class="tutor-btn tutor-btn-link tutor-btn-x-small tutor-text-brand tutor-p-none
</div>
</div>
<div class="tutor-progress-card-actions">
<a href="<?php the_permalink(); ?>" class="tutor-btn tutor-btn-primary tutor-btn-small">
<?php esc_html_e( 'Resume', 'tutor' ); ?>
</a>
</div>
<div class="tutor-progress-card-footer">
<a href="<?php the_permalink(); ?>" class="tutor-btn tutor-btn-primary tutor-btn-block">
<?php esc_html_e( 'Resume', 'tutor' ); ?>
</a>
<?php do_action( 'tutor_course_action_btn', get_the_ID() ); ?>
</div>
</div>
<?php endwhile; ?>
Expand Down
Loading