index.php
213 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Learning area main file |
| 4 | * |
| 5 | * @package Tutor\Templates |
| 6 | * @subpackage LearningArea |
| 7 | * @author Themeum <support@themeum.com> |
| 8 | * @link https://themeum.com |
| 9 | * @since 4.0.0 |
| 10 | */ |
| 11 | |
| 12 | defined( 'ABSPATH' ) || exit; |
| 13 | |
| 14 | use Tutor\Components\ConfirmationModal; |
| 15 | use TUTOR\Course_List; |
| 16 | use TUTOR\Icon; |
| 17 | use Tutor\Components\SvgIcon; |
| 18 | use TUTOR\Course; |
| 19 | use TUTOR\Dashboard; |
| 20 | use TUTOR\Input; |
| 21 | use Tutor\Models\CourseModel; |
| 22 | use Tutor\Models\EnrollmentModel; |
| 23 | use TUTOR\Quiz; |
| 24 | use TUTOR\Template; |
| 25 | use TUTOR\User; |
| 26 | |
| 27 | $current_user_id = get_current_user_id(); |
| 28 | $tutor_current_post = get_post(); |
| 29 | $tutor_current_post_type = get_post_type(); |
| 30 | $tutor_current_content_id = get_the_ID(); |
| 31 | $tutor_course_id = tutor()->course_post_type === $tutor_current_post_type ? $tutor_current_content_id : tutor_utils()->get_course_id_by_subcontent( $tutor_current_content_id ); |
| 32 | |
| 33 | do_action( 'tutor/course/single/content/before/all', $tutor_course_id, $tutor_current_content_id ); |
| 34 | |
| 35 | $tutor_course_list_url = tutor_utils()->course_archive_page_url(); |
| 36 | $tutor_is_enrolled = EnrollmentModel::is_enrolled( $tutor_course_id ); |
| 37 | $tutor_is_public_course = Course_List::is_public( $tutor_course_id ); |
| 38 | $tutor_is_course_instructor = tutor_utils()->is_instructor_of_this_course( $current_user_id, $tutor_course_id, true ); |
| 39 | $tutor_is_course_completed = tutor_utils()->is_completed_course( $tutor_course_id, $current_user_id ); |
| 40 | $tutor_can_complete_course = CourseModel::can_complete_course( $tutor_course_id, $current_user_id ) && ! $tutor_is_course_completed; |
| 41 | $is_tour_completed = get_user_meta( $current_user_id, User::TOUR_COMPLETED_META, true ); |
| 42 | |
| 43 | $tutor_course_progress = tutor_utils()->get_course_completed_percent( $tutor_course_id, $current_user_id ); |
| 44 | $tutor_completion_mode = tutor_utils()->get_option( 'course_completion_process' ); |
| 45 | $tutor_retake_course = tutor_utils()->get_option( 'course_retake_feature', false ) && ( $tutor_is_course_completed || $tutor_course_progress >= 100 ); |
| 46 | $tutor_can_retake_course = $tutor_retake_course && ( CourseModel::MODE_FLEXIBLE === $tutor_completion_mode || $tutor_is_course_completed ); |
| 47 | |
| 48 | // Global variables defined above are used by the 'make_learning_area_sub_page_nav_items' function. |
| 49 | $subpages = Template::make_learning_area_sub_page_nav_items(); |
| 50 | $subpage = Input::get( 'subpage' ); |
| 51 | $attempt_id = Input::get( 'attempt_id', 0, Input::TYPE_INT ); |
| 52 | $user_action = Input::get( 'action' ); |
| 53 | $tutor_course = get_post( $tutor_course_id ); |
| 54 | $course_title = $tutor_course ? get_the_title( $tutor_course ) : ''; |
| 55 | $content_title = $tutor_current_post ? get_the_title( $tutor_current_post ) : $course_title; |
| 56 | $learning_meta_title = $content_title ? $content_title : __( 'Learning area', 'tutor' ); |
| 57 | $site_name = get_bloginfo( 'name' ); |
| 58 | |
| 59 | if ( $subpage && ! empty( $subpages[ $subpage ]['title'] ) ) { |
| 60 | $learning_meta_title = $subpages[ $subpage ]['title']; |
| 61 | } elseif ( Quiz::ACTION_VIEW_DETAILS === $user_action ) { |
| 62 | if ( $content_title ) { |
| 63 | /* translators: %s: quiz attempt details. */ |
| 64 | $learning_meta_title = sprintf( __( 'Quiz Attempt Details: %s', 'tutor' ), $content_title ); |
| 65 | } |
| 66 | } elseif ( tutor()->quiz_post_type === $tutor_current_post_type && $content_title ) { |
| 67 | /* translators: %s: quiz attempt title. */ |
| 68 | $learning_meta_title = sprintf( __( 'Quiz: %s', 'tutor' ), $content_title ); |
| 69 | } |
| 70 | |
| 71 | /* translators: %s: learning area meta title. */ |
| 72 | $page_meta_title = sprintf( __( '%1$s - %2$s', 'tutor' ), $learning_meta_title, $site_name ); |
| 73 | |
| 74 | Dashboard::set_document_title( $page_meta_title ); |
| 75 | ?> |
| 76 | <!DOCTYPE html> |
| 77 | <html <?php language_attributes(); ?>> |
| 78 | <head> |
| 79 | <meta charset="UTF-8"> |
| 80 | <meta name="viewport" content="width=device-width, initial-scale=1" /> |
| 81 | <?php wp_head(); ?> |
| 82 | </head> |
| 83 | <body <?php body_class( '' ); ?> x-data="tutorCourseCompleteHandler()"> |
| 84 | <?php wp_body_open(); ?> |
| 85 | <?php |
| 86 | |
| 87 | // Auto complete course. |
| 88 | if ( CourseModel::can_autocomplete_course( $tutor_course_id, $current_user_id ) ) { |
| 89 | $mark_completed = CourseModel::mark_course_as_completed( $tutor_course_id, $current_user_id ); |
| 90 | if ( $mark_completed ) { |
| 91 | Course::set_review_popup_data( $current_user_id, $tutor_course_id ); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | $course_complete_modal_id = 'tutor-course-complete-modal'; |
| 96 | $course_retake_modal_id = 'tutor-course-retake-modal'; |
| 97 | |
| 98 | $args = array( |
| 99 | 'current_post_type' => $tutor_current_post_type, |
| 100 | 'current_post_id' => $tutor_current_content_id, |
| 101 | 'course_id' => $tutor_course_id, |
| 102 | 'is_public' => $tutor_is_public_course, |
| 103 | 'is_enrolled' => $tutor_is_enrolled, |
| 104 | ); |
| 105 | |
| 106 | $tutor_course_content_access = CourseModel::has_course_content_access( $args ); |
| 107 | if ( ! $tutor_course_content_access ) { |
| 108 | if ( $current_user_id ) { |
| 109 | tutor_load_template( 'single.lesson.required-enroll' ); |
| 110 | } else { |
| 111 | tutor_load_template( 'login' ); |
| 112 | } |
| 113 | return; |
| 114 | } |
| 115 | |
| 116 | $tutor_is_started_quiz = false; |
| 117 | if ( tutor()->quiz_post_type === $tutor_current_post_type ) { |
| 118 | $tutor_is_started_quiz = tutor_utils()->is_started_quiz( $tutor_current_content_id ); |
| 119 | |
| 120 | if ( $tutor_is_started_quiz ) { |
| 121 | tutor_load_template( 'learning-area.quiz.attempt' ); |
| 122 | wp_footer(); |
| 123 | exit; |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | $attempt_id = Input::get( 'attempt_id', 0, Input::TYPE_INT ); |
| 128 | $user_action = Input::get( 'action' ); |
| 129 | |
| 130 | if ( Quiz::ACTION_VIEW_DETAILS === $user_action && $attempt_id ) { |
| 131 | tutor_load_template( 'learning-area.quiz.attempt-details' ); |
| 132 | wp_footer(); |
| 133 | exit; |
| 134 | } |
| 135 | |
| 136 | ?> |
| 137 | <div |
| 138 | class="tutor-learning-area<?php echo esc_attr( is_admin_bar_showing() ? ' tutor-has-admin-bar' : '' ); ?>" |
| 139 | x-data="{ sidebarOpen: false, isFullScreen: false }" |
| 140 | :class="{ 'is-fullscreen': isFullScreen }" |
| 141 | > |
| 142 | <?php tutor_load_template( 'learning-area.components.header' ); ?> |
| 143 | <div class="tutor-learning-area-body"> |
| 144 | <?php tutor_load_template( 'learning-area.components.sidebar' ); ?> |
| 145 | <div class="tutor-learning-area-content" role="main"> |
| 146 | <div class="tutor-learning-area-container"> |
| 147 | <?php |
| 148 | if ( $subpage ) { |
| 149 | $template = $subpages[ $subpage ]['template'] ?? ''; |
| 150 | if ( file_exists( $template ) ) { |
| 151 | tutor_load_template_from_custom_path( $template ); |
| 152 | } else { |
| 153 | do_action( 'tutor_single_content_' . $tutor_current_post_type ); |
| 154 | } |
| 155 | } else { |
| 156 | do_action( 'tutor_single_content_' . $tutor_current_post_type, $tutor_current_post ); |
| 157 | } |
| 158 | ?> |
| 159 | </div> |
| 160 | </div> |
| 161 | <button |
| 162 | class="tutor-btn tutor-btn-outline tutor-btn-small tutor-btn-icon tutor-expand-btn" |
| 163 | @click="isFullScreen = !isFullScreen" |
| 164 | :aria-label="isFullScreen ? '<?php echo esc_attr__( 'Exit fullscreen', 'tutor' ); ?>' : '<?php echo esc_attr__( 'Enter fullscreen', 'tutor' ); ?>'" |
| 165 | > |
| 166 | <template x-if="!isFullScreen"> |
| 167 | <?php SvgIcon::make()->name( Icon::EXPAND )->flip_rtl()->render(); ?> |
| 168 | </template> |
| 169 | |
| 170 | <template x-if="isFullScreen"> |
| 171 | <?php SvgIcon::make()->name( Icon::COLLAPSED )->flip_rtl()->render(); ?> |
| 172 | </template> |
| 173 | </button> |
| 174 | </div> |
| 175 | </div> |
| 176 | <?php |
| 177 | if ( is_user_logged_in() && ! $is_tour_completed ) { |
| 178 | tutor_load_template( 'shared.tour' ); |
| 179 | } |
| 180 | ?> |
| 181 | <?php wp_footer(); ?> |
| 182 | |
| 183 | <?php |
| 184 | if ( $tutor_can_complete_course ) { |
| 185 | $progress = $tutor_course_progress['completed_percent'] ?? 0; |
| 186 | if ( $progress < 100 ) { |
| 187 | ConfirmationModal::make() |
| 188 | ->id( $course_complete_modal_id ) |
| 189 | ->title( __( 'Finish Course Early?', 'tutor' ) ) |
| 190 | ->message( Course::get_complete_modal_content( $tutor_course_progress ), wp_kses_allowed_html( 'post' ) ) |
| 191 | ->cancel_text( __( 'Go Back to Course', 'tutor' ) ) |
| 192 | ->confirm_text( __( 'Complete Anyway', 'tutor' ) ) |
| 193 | ->icon( tutor_utils()->get_themed_svg( 'images/illustrations/warning.svg' ), 80, 80, ConfirmationModal::ICON_TYPE_HTML ) |
| 194 | ->confirm_handler( "handleCourseComplete($tutor_course_id)" ) |
| 195 | ->mutation_state( 'courseCompleteMutation' ) |
| 196 | ->render(); |
| 197 | } |
| 198 | } |
| 199 | if ( $tutor_can_retake_course ) { |
| 200 | ConfirmationModal::make() |
| 201 | ->id( $course_retake_modal_id ) |
| 202 | ->title( __( 'Start the Course Again?', 'tutor' ) ) |
| 203 | ->message( __( 'Retaking the course will reset your progress and start everything from the beginning.', 'tutor' ) ) |
| 204 | ->icon( tutor_utils()->get_themed_svg( 'images/illustrations/retake-course.svg' ), 80, 80, ConfirmationModal::ICON_TYPE_HTML ) |
| 205 | ->cancel_text( __( 'Cancel', 'tutor' ) ) |
| 206 | ->confirm_text( __( 'Start Retake', 'tutor' ) ) |
| 207 | ->confirm_handler( "handleCourseRetake($tutor_course_id)" ) |
| 208 | ->mutation_state( 'courseRetakeMutation' ) |
| 209 | ->render(); |
| 210 | } |
| 211 | ?> |
| 212 | </body> |
| 213 | </html> |