2222use Tutor \Models \QuizModel ;
2323use Tutor \Helpers \HttpHelper ;
2424use Tutor \Models \CourseModel ;
25+ use Tutor \Components \Tooltip ;
2526use Tutor \Ecommerce \Ecommerce ;
2627use Tutor \Traits \JsonResponse ;
2728use Tutor \Helpers \ValidationHelper ;
@@ -2877,36 +2878,35 @@ public function remove_price_if_enrolled( $html ) {
28772878 }
28782879
28792880 /**
2880- * Check if all lessons and quizzes done before mark course complete .
2881+ * Get course completion missing requirements message .
28812882 *
2882- * @since 1.5.8
2883+ * @since 4.0.0
28832884 *
2884- * @param string $html HTML string.
2885- * @return string
2885+ * @param int $course_id Course ID.
2886+ * @param int $user_id User ID.
2887+ *
2888+ * @return string|null
28862889 */
2887- public function tutor_lms_hide_course_complete_btn ( $ html ) {
2890+ public static function get_course_completion_missing_requirements_msg ( $ course_id = 0 , $ user_id = 0 ) {
2891+ $ course_id = tutor_utils ()->get_post_id ( $ course_id );
2892+ $ user_id = tutor_utils ()->get_user_id ( $ user_id );
28882893
28892894 $ completion_mode = tutor_utils ()->get_option ( 'course_completion_process ' );
28902895 if ( 'strict ' !== $ completion_mode ) {
2891- return $ html ;
2896+ return null ;
28922897 }
28932898
2894- $ completed_lesson = tutor_utils ()->get_completed_lesson_count_by_course ();
2895- $ lesson_count = tutor_utils ()->get_lesson_count_by_course ();
2899+ $ completed_lesson = tutor_utils ()->get_completed_lesson_count_by_course ( $ course_id , $ user_id );
2900+ $ lesson_count = tutor_utils ()->get_lesson_count_by_course ( $ course_id );
28962901
28972902 if ( $ completed_lesson < $ lesson_count ) {
2898- return '<div class="tutor-alert tutor-warning tutor-mt-28">
2899- <div class="tutor-alert-text">
2900- <span class="tutor-alert-icon tutor-fs-4 tutor-icon-circle-info tutor-mr-12"></span>
2901- <span> ' . __ ( 'Complete all lessons to mark this course as complete ' , 'tutor ' ) . '</span>
2902- </div>
2903- </div> ' ;
2903+ return __ ( 'Complete all lessons to mark this course as complete ' , 'tutor ' );
29042904 }
29052905
29062906 $ quizzes = array ();
29072907 $ assignments = array ();
29082908
2909- $ course_contents = tutor_utils ()->get_course_contents_by_id ();
2909+ $ course_contents = tutor_utils ()->get_course_contents_by_id ( $ course_id );
29102910 if ( tutor_utils ()->count ( $ course_contents ) ) {
29112911 foreach ( $ course_contents as $ content ) {
29122912 if ( 'tutor_quiz ' === $ content ->post_type ) {
@@ -2919,10 +2919,8 @@ public function tutor_lms_hide_course_complete_btn( $html ) {
29192919 }
29202920
29212921 $ required_assignment_pass = 0 ;
2922-
29232922 foreach ( $ assignments as $ row ) {
2924-
2925- $ assignment_submission = tutor_utils ()->is_assignment_submitted ( $ row ->ID );
2923+ $ assignment_submission = tutor_utils ()->is_assignment_submitted ( $ row ->ID , $ user_id );
29262924 $ is_reviewed_by_instructor = ! count ( $ assignment_submission )
29272925 ? false
29282926 : get_comment_meta ( $ assignment_submission [0 ]->comment_ID , 'evaluate_time ' , true );
@@ -2950,8 +2948,7 @@ public function tutor_lms_hide_course_complete_btn( $html ) {
29502948
29512949 if ( tutor_utils ()->count ( $ quizzes ) ) {
29522950 foreach ( $ quizzes as $ quiz ) {
2953-
2954- $ attempt = tutor_utils ()->get_quiz_attempt ( $ quiz ->ID );
2951+ $ attempt = tutor_utils ()->get_quiz_attempt ( $ quiz ->ID , $ user_id );
29552952 if ( $ attempt ) {
29562953 $ passing_grade = tutor_utils ()->get_quiz_option ( $ quiz ->ID , 'passing_grade ' , 0 );
29572954 $ earned_percentage = QuizModel::calculate_attempt_earned_percentage ( $ attempt );
@@ -2973,20 +2970,33 @@ public function tutor_lms_hide_course_complete_btn( $html ) {
29732970 $ assignment_str = _n ( 'assignment ' , 'assignments ' , $ required_assignment_pass , 'tutor ' );
29742971
29752972 if ( ! $ is_quiz_pass && 0 == $ required_assignment_pass ) {
2976- /* translators: %1$s: number of quiz/assignment pass required; %2$s: quiz/assignment string */
2973+ /* translators: %1$s: number of quiz pass required; %2$s: quiz string */
29772974 $ _msg = sprintf ( __ ( 'You have to pass %1$s %2$s to complete this course. ' , 'tutor ' ), $ required_quiz_pass , $ quiz_str );
2978- }
2979-
2980- if ( $ is_quiz_pass && $ required_assignment_pass > 0 ) {
2981- //phpcs:ignore
2975+ } elseif ( $ is_quiz_pass && $ required_assignment_pass > 0 ) {
2976+ /* translators: %1$s: number of assignment pass required; %2$s: assignment string */
29822977 $ _msg = sprintf ( __ ( 'You have to pass %1$s %2$s to complete this course. ' , 'tutor ' ), $ required_assignment_pass , $ assignment_str );
2983- }
2984-
2985- if ( ! $ is_quiz_pass && $ required_assignment_pass > 0 ) {
2978+ } else {
29862979 /* translators: %1$s: number of quiz pass required; %2$s: quiz string; %3$s: number of assignment pass required; %4$s: assignment string */
29872980 $ _msg = sprintf ( __ ( 'You have to pass %1$s %2$s and %3$s %4$s to complete this course. ' , 'tutor ' ), $ required_quiz_pass , $ quiz_str , $ required_assignment_pass , $ assignment_str );
29882981 }
2982+ return $ _msg ;
2983+ }
2984+
2985+ return null ;
2986+ }
2987+
2988+ /**
2989+ * Check if all lessons and quizzes done before mark course complete.
2990+ *
2991+ * @since 1.5.8
2992+ *
2993+ * @param string $html HTML string.
2994+ * @return string
2995+ */
2996+ public function tutor_lms_hide_course_complete_btn ( $ html ) {
2997+ $ _msg = self ::get_course_completion_missing_requirements_msg ();
29892998
2999+ if ( $ _msg ) {
29903000 return '<div class="tutor-alert tutor-warning tutor-mt-28">
29913001 <div class="tutor-alert-text">
29923002 <span class="tutor-alert-icon tutor-fs-4 tutor-icon-circle-info tutor-mr-12"></span>
@@ -3502,17 +3512,24 @@ public static function get_complete_modal_content( float $course_progress = 0 ):
35023512 * @param int $course_id The ID of the course.
35033513 * @param float $course_progress The current completion percentage of the course.
35043514 * @param string $size The button size.
3515+ * @param string $tooltip Optional. Tooltip message.
3516+ * @param bool $block Optional. Whether the button is full-width.
35053517 *
35063518 * @return void
35073519 */
3508- public static function render_course_complete_btn ( string $ modal_id , int $ course_id , float $ course_progress = 0 , string $ size = Size::MEDIUM ): void {
3520+ public static function render_course_complete_btn ( string $ modal_id , int $ course_id , float $ course_progress = 0 , string $ size = Size::MEDIUM , string $ tooltip = '' , bool $ block = false ): void {
35093521 $ button = Button::make ()
35103522 ->variant ( Variant::PRIMARY_SOFT )
35113523 ->label ( __ ( 'Complete the Course ' , 'tutor ' ) )
35123524 ->icon ( Icon::TICK_MARK )
35133525 ->size ( $ size )
3526+ ->block ( $ block )
35143527 ->attr ( 'type ' , 'button ' );
35153528
3529+ if ( ! empty ( $ tooltip ) ) {
3530+ $ button ->disabled ();
3531+ }
3532+
35163533 if ( $ course_progress < 100 ) {
35173534 $ button ->attr ( '@click ' , "TutorCore.modal.showModal(' {$ modal_id }') " );
35183535 } else {
@@ -3521,7 +3538,16 @@ public static function render_course_complete_btn( string $modal_id, int $course
35213538 $ button ->attr ( ':disabled ' , 'courseCompleteMutation?.isPending ' );
35223539 }
35233540
3524- $ button ->render ();
3541+ if ( ! empty ( $ tooltip ) ) {
3542+ Tooltip::make ()
3543+ ->content ( $ tooltip )
3544+ ->placement ( Tooltip::PLACEMENT_BOTTOM )
3545+ ->arrow ( Tooltip::ARROW_CENTER )
3546+ ->trigger_element ( $ button ->get () )
3547+ ->render ();
3548+ } else {
3549+ $ button ->render ();
3550+ }
35253551 }
35263552
35273553 /**
@@ -3531,15 +3557,17 @@ public static function render_course_complete_btn( string $modal_id, int $course
35313557 *
35323558 * @param string $modal_id Modal id.
35333559 * @param string $size The button size.
3560+ * @param bool $block Optional. Whether the button is full-width.
35343561 *
35353562 * @return void
35363563 */
3537- public static function render_course_retake_btn ( string $ modal_id , string $ size = Size::MEDIUM ): void {
3564+ public static function render_course_retake_btn ( string $ modal_id , string $ size = Size::MEDIUM , bool $ block = false ): void {
35383565 Button::make ()
35393566 ->variant ( Variant::PRIMARY_SOFT )
35403567 ->label ( __ ( 'Retake this Course ' , 'tutor ' ) )
35413568 ->icon ( Icon::RELOAD_4 )
35423569 ->size ( $ size )
3570+ ->block ( $ block )
35433571 ->attr ( 'type ' , 'button ' )
35443572 ->attr ( '@click ' , "TutorCore.modal.showModal(' {$ modal_id }') " )
35453573 ->render ();
0 commit comments