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
24 changes: 17 additions & 7 deletions classes/Course.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,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 335 in classes/Course.php

View workflow job for this annotation

GitHub Actions / WPCS

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

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

Check failure on line 666 in classes/Course.php

View workflow job for this annotation

GitHub Actions / WPCS

If control structure block found as the only statement within an "else" 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 @@ -800,7 +800,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 803 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 @@ -2369,7 +2369,7 @@
}

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

Check failure on line 2372 in classes/Course.php

View workflow job for this annotation

GitHub Actions / WPCS

Capabilities should be used instead of roles. Found "administrator" 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 @@ -3437,7 +3437,7 @@
}

/**
* Calculate the total course duration for a set of courses.
* Calculate the total course duration for a set of courses and returns the total time in hours, minutes, and seconds.
*
* @since 4.0.0
*
Expand All @@ -3455,19 +3455,29 @@
foreach ( $course_ids as $id ) {
$duration = tutor_utils()->get_course_duration( (int) $id, true );

$total_seconds += ( (int) $duration['durationHours'] * 3600 )
+ ( (int) $duration['durationMinutes'] * 60 )
$completion_percentage = tutor_utils()->is_completed_course( $id )
? 100
: (int) tutor_utils()->get_course_completed_percent( (int) $id );

if ( 0 === $completion_percentage ) {
continue;
}

$course_duration_in_seconds = ( (int) $duration['durationHours'] * HOUR_IN_SECONDS )
+ ( (int) $duration['durationMinutes'] * MINUTE_IN_SECONDS )
+ ( (int) $duration['durationSeconds'] );

// Calculate the time spent by a user based on the course completion percentage.
$total_seconds += $course_duration_in_seconds * ( $completion_percentage / 100 );
}

$hours = floor( $total_seconds / 3600 );
$minutes = floor( $total_seconds / 60 );
$seconds = $total_seconds;
$hours = floor( $total_seconds / HOUR_IN_SECONDS );
$minutes = floor( $total_seconds / MINUTE_IN_SECONDS );

return array(
'hours' => (int) $hours,
'minutes' => (int) $minutes,
'seconds' => (int) $seconds,
'seconds' => (int) $total_seconds,
);
}

Expand Down
4 changes: 2 additions & 2 deletions classes/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -8119,10 +8119,10 @@ public function course_with_materials(): array {
* @since 2.0.0
*
* @param int $course_id course id.
* @param array $return_array return array.
* @param bool $return_array return array.
* @param array $texts texts.
*
* @return string
* @return string | array
*/
public function get_course_duration( $course_id, $return_array, $texts = array(
'h' => 'hr',
Expand Down
45 changes: 27 additions & 18 deletions templates/dashboard/student-dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,26 @@
$enrolled_course = CourseModel::get_enrolled_courses_by_user( $user_id, array( 'private', 'publish' ) );
$completed_courses = CourseModel::get_completed_courses_by_user( $user_id, 0, -1, array( 'post_status' => array( 'private', 'publish' ) ) );
$has_completed_courses = is_object( $completed_courses ) && $completed_courses->have_posts();
$completed_courses_ids = $has_completed_courses ? wp_list_pluck( $completed_courses->posts, 'ID' ) : array();
$active_courses = CourseModel::get_active_courses_by_user( $user_id, 0, -1, array( 'post_status' => array( 'private', 'publish' ) ) );

$enrolled_course_count = $enrolled_course ? $enrolled_course->post_count : 0;
$completed_course_count = $has_completed_courses ? $completed_courses->post_count : 0;
$active_course_count = is_object( $active_courses ) && $active_courses->have_posts() ? $active_courses->post_count : 0;
$enrolled_courses_ids = $enrolled_course_count ? wp_list_pluck( $enrolled_course->posts, 'ID' ) : array();

$enrolled_course_link = tutor_utils()->tutor_dashboard_url( 'courses' );
$completed_course_link = tutor_utils()->tutor_dashboard_url( 'courses/completed-courses' );
$active_course_link = tutor_utils()->tutor_dashboard_url( 'courses/active-courses' );

$time_spent = Course::get_total_course_duration( $completed_courses_ids );
$grid_col = $time_spent['hours'] > 0 ? 'tutor-grid-cols-4' : 'tutor-grid-cols-3';
// Time spent calculation.
$time_spent = Course::get_total_course_duration( $enrolled_courses_ids );
$is_hour_format = $time_spent['hours'] > 0;
$has_time_spent = $is_hour_format || $time_spent['minutes'] > 0;
$time_spent_value = $is_hour_format ? $time_spent['hours'] : $time_spent['minutes'];
$time_spent_unit = $is_hour_format ? 'h+' : 'm+';
$time_spent_unit_modal = $is_hour_format ? 'hours' : 'minutes';
?>
<div class="tutor-grid tutor-sm-grid-cols-2 tutor-gap-5 tutor-mb-7 <?php echo esc_attr( $grid_col ); ?>">
<div class="tutor-grid tutor-sm-grid-cols-2 tutor-gap-5 tutor-mb-7 tutor-grid-cols-4">
<a href="<?php echo esc_url( $enrolled_course_link ); ?>" class="tutor-stat-card tutor-stat-card-enrolled">
<div class="tutor-stat-card-header">
<h3 class="tutor-stat-card-title">
Expand Down Expand Up @@ -115,7 +120,6 @@
</div>
</div>
</a>
<?php if ( $time_spent['hours'] > 0 ) : ?>
<div
class="tutor-stat-card tutor-stat-card-time-spent"
@click="TutorCore.modal.showModal('tutor-time-spent-modal')"
Expand All @@ -132,19 +136,22 @@ class="tutor-stat-card tutor-stat-card-time-spent"
<div class="tutor-stat-card-value">
<?php
echo esc_html(
sprintf(
/* translators: 1: total hour spent */
__( '%1$d h+', 'tutor' ),
$time_spent['hours']
$has_time_spent
? sprintf(
/* translators: 1: total time spent 2: Unit. */
__( '%1$d %2$s', 'tutor' ),
$time_spent_value,
$time_spent_unit
)
: '0'
);
?>
</div>
</div>
</div>
<?php endif; ?>
</div>

<?php if ( $time_spent['minutes'] > 0 ) : ?>
<div x-data="tutorModal({ id: 'tutor-time-spent-modal' })" x-cloak>
<template x-teleport="body">
<div x-bind="getModalBindings()">
Expand All @@ -168,22 +175,23 @@ class="tutor-stat-card tutor-stat-card-time-spent"
<?php
echo esc_html(
sprintf(
/* translators: 1: total hour spent */
__( '%1$d+ hours', 'tutor' ),
$time_spent['hours']
/* translators: 1: total time spent 2: Unit. */
__( '%1$d+ %2$s', 'tutor' ),
$time_spent_value,
$time_spent_unit_modal
)
);
?>
</h2>
<p class="tutor-p2 tutor-mb-7">
<?php if ( $time_spent['minutes'] > 0 ) : ?>
<?php echo esc_html__( "That's", 'tutor' ); ?>
<?php echo esc_html__( "That's", 'tutor' ); ?>
<?php if ( $is_hour_format && $time_spent['minutes'] > 0 ) : ?>
<span class="tutor-font-medium">
<?php
echo esc_html(
sprintf(
/* translators: 1: total minutes spent */
__( '%1$d+ minutes', 'tutor' ),
__( '%1$d+ minutes, and ', 'tutor' ),
$time_spent['minutes']
)
);
Expand All @@ -197,7 +205,7 @@ class="tutor-stat-card tutor-stat-card-time-spent"
echo esc_html(
sprintf(
/* translators: 1: total seconds spent */
__( ', and %1$d+ seconds!', 'tutor' ),
__( '%1$d+ seconds!', 'tutor' ),
$time_spent['seconds']
)
);
Expand All @@ -220,6 +228,7 @@ class="tutor-btn tutor-btn-primary tutor-btn-large tutor-rounded-full tutor-btn-
</div>
</template>
</div>
<?php endif; ?>
</div>

<?php
Expand Down Expand Up @@ -307,6 +316,6 @@ class="tutor-btn tutor-btn-link tutor-btn-x-small tutor-text-brand tutor-p-none
</div>
</div>
<?php
endif;
endif;
do_action( 'tutor_after_continue_learning_section' );
?>
Loading