← All changes
|
inc/TemplateHooks/Course/SingleCourseClassicTemplate.php
+440
-440
4.3.9
→
4.4.8
View file →
| @@ -1,440 +1,440 @@ | ||
| 1 | -<?php | |
| 2 | -/** | |
| 3 | - * Template hooks Single Course Online. | |
| 4 | - * | |
| 5 | - * @since 4.2.7 | |
| 6 | - * @version 1.0.0 | |
| 7 | - */ | |
| 8 | - | |
| 9 | -namespace LearnPress\TemplateHooks\Course; | |
| 10 | - | |
| 11 | -use LearnPress\Helpers\Singleton; | |
| 12 | -use LearnPress\Helpers\Template; | |
| 13 | -use LearnPress\Models\CourseModel; | |
| 14 | -use LearnPress\Models\UserModel; | |
| 15 | -use LearnPress\Models\UserItems\UserCourseModel; | |
| 16 | -use LearnPress\TemplateHooks\UserItem\UserCourseTemplate; | |
| 17 | -use LearnPress\TemplateHooks\Instructor\SingleInstructorTemplate; | |
| 18 | -use LearnPress\TemplateHooks\UserTemplate; | |
| 19 | - | |
| 20 | -defined( 'ABSPATH' ) || exit(); | |
| 21 | - | |
| 22 | -class SingleCourseClassicTemplate { | |
| 23 | - use Singleton; | |
| 24 | - | |
| 25 | - /** | |
| 26 | - * @var SingleCourseTemplate $singleCourseTemplate | |
| 27 | - */ | |
| 28 | - public $singleCourseTemplate; | |
| 29 | - | |
| 30 | - public function init() { | |
| 31 | - $this->singleCourseTemplate = SingleCourseTemplate::instance(); | |
| 32 | - | |
| 33 | - add_action( 'learn-press/single-course/layout/classic', [ $this, 'section' ] ); | |
| 34 | - } | |
| 35 | - | |
| 36 | - /** | |
| 37 | - * Single course layout classic | |
| 38 | - * | |
| 39 | - * @param CourseModel $course | |
| 40 | - * | |
| 41 | - * @return void | |
| 42 | - */ | |
| 43 | - public function section( CourseModel $course ) { | |
| 44 | - $user = UserModel::find( get_current_user_id(), true ); | |
| 45 | - | |
| 46 | - $content = [ | |
| 47 | - 'wrapper' => '<div class="course-content course-summary-content">', | |
| 48 | - 'section_header' => $this->header_sections( $course, $user ), | |
| 49 | - 'section_main' => $this->main_sections( $course, $user ), | |
| 50 | - 'wrapper_end' => '</div>', | |
| 51 | - ]; | |
| 52 | - | |
| 53 | - $sections = apply_filters( | |
| 54 | - 'learn-press/single-course/classic/sections', | |
| 55 | - [ | |
| 56 | - 'wrapper' => '<div class="lp-single-course lp-archive-courses">', | |
| 57 | - 'breadcrumb' => Template::html_breadcrumb(), | |
| 58 | - 'course_summary' => '<div id="learn-press-course" class="course-summary">', | |
| 59 | - 'content' => Template::combine_components( $content ), | |
| 60 | - 'course_summary_end' => '</div>', | |
| 61 | - 'wrapper_end' => '</div>', | |
| 62 | - ] | |
| 63 | - ); | |
| 64 | - | |
| 65 | - echo Template::combine_components( $sections ); | |
| 66 | - } | |
| 67 | - | |
| 68 | - public function header_sections( $course, $user ): string { | |
| 69 | - | |
| 70 | - $meta_primary = apply_filters( | |
| 71 | - 'learn-press/single-course/classic/meta-primary/sections', | |
| 72 | - [ | |
| 73 | - 'wrapper' => '<div class="course-meta course-meta-primary">', | |
| 74 | - 'instructor' => $this->html_instructor( $course ), | |
| 75 | - 'category' => $this->html_category( $course ), | |
| 76 | - 'wrapper_end' => '</div>', | |
| 77 | - ] | |
| 78 | - ); | |
| 79 | - | |
| 80 | - $meta_secondary = apply_filters( | |
| 81 | - 'learn-press/single-course/classic/meta-secondary/sections', | |
| 82 | - [ | |
| 83 | - 'wrapper' => '<div class="course-meta course-meta-secondary">', | |
| 84 | - 'duration' => sprintf( | |
| 85 | - '<div class="meta-item meta-item-duration">%s</div>', | |
| 86 | - $this->singleCourseTemplate->html_duration( $course ) | |
| 87 | - ), | |
| 88 | - 'level' => sprintf( | |
| 89 | - '<div class="meta-item meta-item-level">%s</div>', | |
| 90 | - $this->singleCourseTemplate->html_level( $course ) | |
| 91 | - ), | |
| 92 | - 'lesson' => sprintf( | |
| 93 | - '<div class="meta-item meta-item-lesson">%s</div>', | |
| 94 | - $this->singleCourseTemplate->html_count_item( $course, LP_LESSON_CPT ) | |
| 95 | - ), | |
| 96 | - 'quiz' => sprintf( | |
| 97 | - '<div class="meta-item meta-item-quiz">%s</div>', | |
| 98 | - $this->singleCourseTemplate->html_count_item( $course, LP_QUIZ_CPT ) | |
| 99 | - ), | |
| 100 | - 'student' => sprintf( | |
| 101 | - '<div class="meta-item meta-item-student">%s</div>', | |
| 102 | - $this->singleCourseTemplate->html_count_student( $course ) | |
| 103 | - ), | |
| 104 | - 'wrapper_end' => '</div>', | |
| 105 | - ] | |
| 106 | - ); | |
| 107 | - | |
| 108 | - $header_sections = apply_filters( | |
| 109 | - 'learn-press/single-course/classic/header/sections', | |
| 110 | - [ | |
| 111 | - 'wrapper' => '<div class="course-detail-info">', | |
| 112 | - 'wrapper_inner' => '<div class="course-detail-info__inner">', | |
| 113 | - 'wrapper_content' => '<div class="course-meta__pull-left">', | |
| 114 | - 'meta_primary' => Template::combine_components( $meta_primary ), | |
| 115 | - 'title' => $this->singleCourseTemplate->html_title( $course, 'h1' ), | |
| 116 | - 'meta_secondary' => Template::combine_components( $meta_secondary ), | |
| 117 | - 'wrapper_content_end' => '</div>', | |
| 118 | - 'wrapper_inner_end' => '</div>', | |
| 119 | - 'wrapper_end' => '</div>', | |
| 120 | - ] | |
| 121 | - ); | |
| 122 | - | |
| 123 | - return Template::combine_components( $header_sections ); | |
| 124 | - } | |
| 125 | - | |
| 126 | - public function main_sections( $course, $user ): string { | |
| 127 | - | |
| 128 | - $content_left = apply_filters( | |
| 129 | - 'learn-press/single-course/classic/content-left/sections', | |
| 130 | - [ | |
| 131 | - 'wrapper' => '<div class="entry-content-left">', | |
| 132 | - 'course_tabs' => $this->html_course_tabs( $course, $user ), | |
| 133 | - 'features' => $this->singleCourseTemplate->html_features( $course ), | |
| 134 | - 'target' => $this->singleCourseTemplate->html_target( $course ), | |
| 135 | - 'requirements' => $this->singleCourseTemplate->html_requirements( $course ), | |
| 136 | - 'wrapper_end' => '</div>', | |
| 137 | - ] | |
| 138 | - ); | |
| 139 | - | |
| 140 | - $userCourseModel = UserCourseModel::find( get_current_user_id(), $course->get_id(), true ); | |
| 141 | - $userCourseTemplate = UserCourseTemplate::instance(); | |
| 142 | - $btn_continue_and_finish = []; | |
| 143 | - | |
| 144 | - if ( $userCourseModel instanceof UserCourseModel ) { | |
| 145 | - $btn_continue_and_finish = [ | |
| 146 | - 'btn_continue' => $userCourseTemplate->html_btn_continue( $userCourseModel ), | |
| 147 | - 'btn_finish' => $userCourseTemplate->html_btn_finish( $userCourseModel ), | |
| 148 | - ]; | |
| 149 | - } | |
| 150 | - | |
| 151 | - $section_buttons = apply_filters( | |
| 152 | - 'learn-press/single-course/model/section-right/info-meta/buttons', | |
| 153 | - [ | |
| 154 | - 'wrapper' => '<div class="course-buttons">', | |
| 155 | - 'btn_contact' => $this->singleCourseTemplate->html_btn_external( $course, $user ), | |
| 156 | - 'btn_buy' => $this->singleCourseTemplate->html_btn_purchase_course( $course, $user ), | |
| 157 | - 'btn_enroll' => $this->singleCourseTemplate->html_btn_enroll_course( $course, $user ), | |
| 158 | - 'btn_continue_and_finish' => Template::combine_components( $btn_continue_and_finish ), | |
| 159 | - 'wrapper_end' => '</div>', | |
| 160 | - ], | |
| 161 | - $course, | |
| 162 | - $user | |
| 163 | - ); | |
| 164 | - | |
| 165 | - $summary_sidebar = apply_filters( | |
| 166 | - 'learn-press/single-course/classic/content-left/sections', | |
| 167 | - [ | |
| 168 | - 'wrapper' => '<div class="course-summary-sidebar">', | |
| 169 | - 'wrapper_inner' => '<div class="course-summary-sidebar__inner">', | |
| 170 | - 'image' => $this->singleCourseTemplate->html_image( $course ), | |
| 171 | - 'price' => $this->singleCourseTemplate->html_price( $course ), | |
| 172 | - 'buttons' => Template::combine_components( $section_buttons ), | |
| 173 | - 'featured_review' => $this->singleCourseTemplate->html_feature_review( $course, $user ), | |
| 174 | - 'sidebar' => $this->singleCourseTemplate->html_sidebar( $course ), | |
| 175 | - 'wrapper_inner_end' => '</div>', | |
| 176 | - 'wrapper_end' => '</div>', | |
| 177 | - ] | |
| 178 | - ); | |
| 179 | - | |
| 180 | - $main_sections = apply_filters( | |
| 181 | - 'learn-press/single-course/classic/main/sections', | |
| 182 | - [ | |
| 183 | - 'wrapper' => '<div class="lp-entry-content lp-content-area">', | |
| 184 | - 'content_left' => Template::combine_components( $content_left ), | |
| 185 | - 'summary_sidebar' => Template::combine_components( $summary_sidebar ), | |
| 186 | - 'wrapper_end' => '</div>', | |
| 187 | - ] | |
| 188 | - ); | |
| 189 | - | |
| 190 | - return Template::combine_components( $main_sections ); | |
| 191 | - } | |
| 192 | - | |
| 193 | - public function html_instructor( $course ): string { | |
| 194 | - $instructor = $course->get_author_model(); | |
| 195 | - if ( ! $instructor ) { | |
| 196 | - return ''; | |
| 197 | - } | |
| 198 | - | |
| 199 | - $singleInstructorTemplate = SingleInstructorTemplate::instance(); | |
| 200 | - | |
| 201 | - $html_instructor = apply_filters( | |
| 202 | - 'learn-press/course/instructor-html', | |
| 203 | - [ | |
| 204 | - 'wrapper' => '<div class="meta-item meta-item-instructor">', | |
| 205 | - 'avatar_instructor' => sprintf( '<div class="meta-item__image">%s</div>', SingleInstructorTemplate::instance()->html_avatar( $instructor, [] ) ), | |
| 206 | - 'instructor' => '<div class="meta-item__value">', | |
| 207 | - 'label' => sprintf( '<label>%s</label>', esc_html__( 'Instructor', 'learnpress' ) ), | |
| 208 | - 'name' => sprintf( | |
| 209 | - '<div><a href="%s">%s</a></div>', | |
| 210 | - $instructor->get_url_instructor(), | |
| 211 | - $singleInstructorTemplate->html_display_name( $instructor ) | |
| 212 | - ), | |
| 213 | - 'instructor_end' => '</div>', | |
| 214 | - 'wrapper_end' => '</div>', | |
| 215 | - ], | |
| 216 | - $course, | |
| 217 | - $instructor | |
| 218 | - ); | |
| 219 | - | |
| 220 | - return Template::combine_components( $html_instructor ); | |
| 221 | - } | |
| 222 | - | |
| 223 | - public function html_category( $course ): string { | |
| 224 | - $cats = $course->get_categories(); | |
| 225 | - if ( empty( $cats ) ) { | |
| 226 | - return ''; | |
| 227 | - } | |
| 228 | - | |
| 229 | - $cat_names = []; | |
| 230 | - array_map( | |
| 231 | - function ( $cat ) use ( &$cat_names ) { | |
| 232 | - $term = sprintf( '<a href="%s">%s</a>', get_term_link( $cat->term_id ), $cat->name ); | |
| 233 | - $cat_names[] = $term; | |
| 234 | - }, | |
| 235 | - $cats | |
| 236 | - ); | |
| 237 | - | |
| 238 | - $content = implode( ' | ', $cat_names ); | |
| 239 | - | |
| 240 | - $html_category = apply_filters( | |
| 241 | - 'learn-press/course/html-categories', | |
| 242 | - [ | |
| 243 | - 'wrapper' => '<div class="meta-item meta-item-categories">', | |
| 244 | - 'category' => '<div class="meta-item__value">', | |
| 245 | - 'label' => sprintf( '<label>%s</label>', esc_html__( 'Category', 'learnpress' ) ), | |
| 246 | - 'content' => sprintf( '<div>%s</div>', $content ), | |
| 247 | - 'category_end' => '</div>', | |
| 248 | - 'wrapper_end' => '</div>', | |
| 249 | - ], | |
| 250 | - $course, | |
| 251 | - $cats, | |
| 252 | - $cat_names | |
| 253 | - ); | |
| 254 | - | |
| 255 | - return Template::combine_components( $html_category ); | |
| 256 | - } | |
| 257 | - | |
| 258 | - public function html_course_tabs( $course, $user ): string { | |
| 259 | - | |
| 260 | - $tabs = apply_filters( | |
| 261 | - 'learn-press/single-course/classic/course-tabs', | |
| 262 | - [ | |
| 263 | - 'overview' => esc_html__( 'Overview', 'learnpress' ), | |
| 264 | - 'curriculum' => esc_html__( 'Curriculum', 'learnpress' ), | |
| 265 | - 'instructor' => esc_html__( 'Instructor', 'learnpress' ), | |
| 266 | - 'materials' => esc_html__( 'Materials', 'learnpress' ), | |
| 267 | - 'faqs' => esc_html__( 'FAQs', 'learnpress' ), | |
| 268 | - ] | |
| 269 | - ); | |
| 270 | - | |
| 271 | - $active_tab = 'overview'; | |
| 272 | - $lp_user = learn_press_get_current_user(); | |
| 273 | - | |
| 274 | - if ( $lp_user && ! $lp_user instanceof LP_User_Guest ) { | |
| 275 | - $can_view_course = $lp_user->can_view_content_course( get_the_ID() ); | |
| 276 | - | |
| 277 | - if ( ! $can_view_course->flag ) { | |
| 278 | - if ( LP_BLOCK_COURSE_FINISHED === $can_view_course->key ) { | |
| 279 | - learn_press_display_message( | |
| 280 | - esc_html__( 'You finished this course. This course has been blocked', 'learnpress' ), | |
| 281 | - 'warning' | |
| 282 | - ); | |
| 283 | - } elseif ( LP_BLOCK_COURSE_DURATION_EXPIRE === $can_view_course->key ) { | |
| 284 | - learn_press_display_message( | |
| 285 | - esc_html__( 'This course has been blocked for expiration', 'learnpress' ), | |
| 286 | - 'warning' | |
| 287 | - ); | |
| 288 | - } | |
| 289 | - } | |
| 290 | - } | |
| 291 | - | |
| 292 | - $html_tabs = []; | |
| 293 | - if ( $tabs ) { | |
| 294 | - ob_start(); | |
| 295 | - foreach ( $tabs as $key => $tab ) { | |
| 296 | - echo '<input type="radio" name="learn-press-course-tab-radio" id="tab-' . esc_attr( $key ) . '-input" | |
| 297 | - ' . ( $active_tab === $key ? 'checked ' : '' ) . 'value="' . esc_attr( $key ) . '"/>'; | |
| 298 | - } | |
| 299 | - $html_input = ob_get_clean(); | |
| 300 | - | |
| 301 | - ob_start(); | |
| 302 | - foreach ( $tabs as $key => $tab ) { | |
| 303 | - $classes = array( 'course-nav course-nav-tab-' . esc_attr( $key ) ); | |
| 304 | - | |
| 305 | - if ( $active_tab === $key ) { | |
| 306 | - $classes[] = 'active'; | |
| 307 | - } | |
| 308 | - | |
| 309 | - echo '<li class="' . esc_attr( implode( ' ', $classes ) ) . '">'; | |
| 310 | - echo '<label for="tab-' . esc_attr( $key ) . '-input">' . esc_html( $tab ) . '</label>'; | |
| 311 | - echo '</li>'; | |
| 312 | - } | |
| 313 | - $html_tabs_nav = ob_get_clean(); | |
| 314 | - | |
| 315 | - $tabs_nav = [ | |
| 316 | - 'wrapper' => '<div class="wrapper-course-nav-tabs TabsDragScroll">', | |
| 317 | - 'nav_tabs' => '<ul class="learn-press-nav-tabs course-nav-tabs" data-tabs="' . esc_attr( count( $tabs ) ) . '">', | |
| 318 | - 'content' => $html_tabs_nav, | |
| 319 | - 'nav_tabs_end' => '</ul>', | |
| 320 | - 'wrapper_end' => '</div>', | |
| 321 | - ]; | |
| 322 | - | |
| 323 | - ob_start(); | |
| 324 | - | |
| 325 | - foreach ( $tabs as $key => $tab ) { | |
| 326 | - echo '<div class="course-tab-panel-' . esc_attr( $key ) . ' course-tab-panel" | |
| 327 | - id="tab-' . esc_attr( $key ) . '">'; | |
| 328 | - | |
| 329 | - switch ( $key ) { | |
| 330 | - case 'overview': | |
| 331 | - echo $this->singleCourseTemplate->html_description( $course ); | |
| 332 | - break; | |
| 333 | - // case 'curriculum': | |
| 334 | - // echo $this->singleCourseTemplate->html_curriculum( $course ); | |
| 335 | - // break; | |
| 336 | - case 'instructor': | |
| 337 | - echo $this->html_instructor_main( $course, $user ); | |
| 338 | - break; | |
| 339 | - case 'faqs': | |
| 340 | - echo $this->singleCourseTemplate->html_faqs( $course ); | |
| 341 | - break; | |
| 342 | - case 'materials': | |
| 343 | - echo $this->singleCourseTemplate->html_material( $course ); | |
| 344 | - break; | |
| 345 | - } | |
| 346 | - echo '</div>'; | |
| 347 | - } | |
| 348 | - | |
| 349 | - $html_tabs_content = ob_get_clean(); | |
| 350 | - | |
| 351 | - $tabs_content = [ | |
| 352 | - 'wrapper' => '<div class="course-tab-panels">', | |
| 353 | - 'content' => $html_tabs_content, | |
| 354 | - 'wrapper_end' => '</div>', | |
| 355 | - ]; | |
| 356 | - | |
| 357 | - $html_tabs = [ | |
| 358 | - 'input' => $html_input, | |
| 359 | - 'nav' => Template::combine_components( $tabs_nav ), | |
| 360 | - 'content' => Template::combine_components( $tabs_content ), | |
| 361 | - ]; | |
| 362 | - } | |
| 363 | - | |
| 364 | - $course_tabs = apply_filters( | |
| 365 | - 'learn-press/single-course/classic/main/course-tabs', | |
| 366 | - [ | |
| 367 | - 'wrapper' => '<div id="learn-press-course-tabs" class="course-tabs">', | |
| 368 | - 'tabs' => Template::combine_components( $html_tabs ), | |
| 369 | - 'wrapper_end' => '</div>', | |
| 370 | - ] | |
| 371 | - ); | |
| 372 | - | |
| 373 | - return Template::combine_components( $course_tabs ); | |
| 374 | - } | |
| 375 | - | |
| 376 | - public function html_instructor_main( $course, $user ): string { | |
| 377 | - | |
| 378 | - $singleInstructorTemplate = SingleInstructorTemplate::instance(); | |
| 379 | - $author = $course->get_author_model(); | |
| 380 | - | |
| 381 | - // Instructor | |
| 382 | - $html_instructor = ''; | |
| 383 | - if ( $author ) { | |
| 384 | - $html_instructor_image = sprintf( | |
| 385 | - '<a href="%s" title="%s">%s</a>', | |
| 386 | - $author->get_url_instructor(), | |
| 387 | - $author->get_display_name(), | |
| 388 | - $singleInstructorTemplate->html_avatar( $author ) | |
| 389 | - ); | |
| 390 | - $section_instructor_meta = [ | |
| 391 | - 'wrapper' => '<div class="lp-instructor-meta">', | |
| 392 | - 'count_students' => sprintf( | |
| 393 | - '<div class="instructor-item-meta">%s</div>', | |
| 394 | - $singleInstructorTemplate->html_count_students( $author ) | |
| 395 | - ), | |
| 396 | - 'count_courses' => sprintf( | |
| 397 | - '<div class="instructor-item-meta">%s</div>', | |
| 398 | - $singleInstructorTemplate->html_count_courses( $author ) | |
| 399 | - ), | |
| 400 | - 'wrapper_end' => '</div>', | |
| 401 | - ]; | |
| 402 | - $html_instructor_meta = Template::combine_components( $section_instructor_meta ); | |
| 403 | - | |
| 404 | - $section_instructor_right = apply_filters( | |
| 405 | - 'learn-press/single-course/model/section-instructor/right', | |
| 406 | - [ | |
| 407 | - 'wrapper' => '<div class="lp-section-instructor">', | |
| 408 | - 'name' => sprintf( | |
| 409 | - '<a href="%s">%s</a>', | |
| 410 | - $author->get_url_instructor(), | |
| 411 | - $singleInstructorTemplate->html_display_name( $author ) | |
| 412 | - ), | |
| 413 | - 'meta' => $html_instructor_meta, | |
| 414 | - 'description' => $singleInstructorTemplate->html_description( $author ), | |
| 415 | - 'social' => $singleInstructorTemplate->html_social( $author ), | |
| 416 | - 'wrapper_end' => '</div>', | |
| 417 | - ], | |
| 418 | - $course, | |
| 419 | - $user | |
| 420 | - ); | |
| 421 | - $html_instructor_right = Template::combine_components( $section_instructor_right ); | |
| 422 | - $section_instructor = apply_filters( | |
| 423 | - 'learn-press/single-course/model/section-instructor', | |
| 424 | - [ | |
| 425 | - 'wrapper' => '<div class="lp-section-instructor">', | |
| 426 | - 'wrapper_info' => '<div class="lp-instructor-info">', | |
| 427 | - 'image' => $html_instructor_image, | |
| 428 | - 'instructor_right' => $html_instructor_right, | |
| 429 | - 'wrapper_info_end' => '</div>', | |
| 430 | - 'wrapper_end' => '</div>', | |
| 431 | - ], | |
| 432 | - $course, | |
| 433 | - $user | |
| 434 | - ); | |
| 435 | - $html_instructor = Template::combine_components( $section_instructor ); | |
| 436 | - } | |
| 437 | - | |
| 438 | - return $html_instructor; | |
| 439 | - } | |
| 440 | -} | |
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Template hooks Single Course Online. | |
| 4 | + * | |
| 5 | + * @since 4.2.7 | |
| 6 | + * @version 1.0.0 | |
| 7 | + */ | |
| 8 | + | |
| 9 | +namespace LearnPress\TemplateHooks\Course; | |
| 10 | + | |
| 11 | +use LearnPress\Helpers\Singleton; | |
| 12 | +use LearnPress\Helpers\Template; | |
| 13 | +use LearnPress\Models\CourseModel; | |
| 14 | +use LearnPress\Models\UserModel; | |
| 15 | +use LearnPress\Models\UserItems\UserCourseModel; | |
| 16 | +use LearnPress\TemplateHooks\UserItem\UserCourseTemplate; | |
| 17 | +use LearnPress\TemplateHooks\Instructor\SingleInstructorTemplate; | |
| 18 | +use LearnPress\TemplateHooks\UserTemplate; | |
| 19 | + | |
| 20 | +defined( 'ABSPATH' ) || exit(); | |
| 21 | + | |
| 22 | +class SingleCourseClassicTemplate { | |
| 23 | + use Singleton; | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * @var SingleCourseTemplate $singleCourseTemplate | |
| 27 | + */ | |
| 28 | + public $singleCourseTemplate; | |
| 29 | + | |
| 30 | + public function init() { | |
| 31 | + $this->singleCourseTemplate = SingleCourseTemplate::instance(); | |
| 32 | + | |
| 33 | + add_action( 'learn-press/single-course/layout/classic', [ $this, 'section' ] ); | |
| 34 | + } | |
| 35 | + | |
| 36 | + /** | |
| 37 | + * Single course layout classic | |
| 38 | + * | |
| 39 | + * @param CourseModel $course | |
| 40 | + * | |
| 41 | + * @return void | |
| 42 | + */ | |
| 43 | + public function section( CourseModel $course ) { | |
| 44 | + $user = UserModel::find( get_current_user_id(), true ); | |
| 45 | + | |
| 46 | + $content = [ | |
| 47 | + 'wrapper' => '<div class="course-content course-summary-content">', | |
| 48 | + 'section_header' => $this->header_sections( $course, $user ), | |
| 49 | + 'section_main' => $this->main_sections( $course, $user ), | |
| 50 | + 'wrapper_end' => '</div>', | |
| 51 | + ]; | |
| 52 | + | |
| 53 | + $sections = apply_filters( | |
| 54 | + 'learn-press/single-course/classic/sections', | |
| 55 | + [ | |
| 56 | + 'wrapper' => '<div class="lp-single-course lp-archive-courses">', | |
| 57 | + 'breadcrumb' => Template::html_breadcrumb(), | |
| 58 | + 'course_summary' => '<div id="learn-press-course" class="course-summary">', | |
| 59 | + 'content' => Template::combine_components( $content ), | |
| 60 | + 'course_summary_end' => '</div>', | |
| 61 | + 'wrapper_end' => '</div>', | |
| 62 | + ] | |
| 63 | + ); | |
| 64 | + | |
| 65 | + echo Template::combine_components( $sections ); | |
| 66 | + } | |
| 67 | + | |
| 68 | + public function header_sections( $course, $user ): string { | |
| 69 | + | |
| 70 | + $meta_primary = apply_filters( | |
| 71 | + 'learn-press/single-course/classic/meta-primary/sections', | |
| 72 | + [ | |
| 73 | + 'wrapper' => '<div class="course-meta course-meta-primary">', | |
| 74 | + 'instructor' => $this->html_instructor( $course ), | |
| 75 | + 'category' => $this->html_category( $course ), | |
| 76 | + 'wrapper_end' => '</div>', | |
| 77 | + ] | |
| 78 | + ); | |
| 79 | + | |
| 80 | + $meta_secondary = apply_filters( | |
| 81 | + 'learn-press/single-course/classic/meta-secondary/sections', | |
| 82 | + [ | |
| 83 | + 'wrapper' => '<div class="course-meta course-meta-secondary">', | |
| 84 | + 'duration' => sprintf( | |
| 85 | + '<div class="meta-item meta-item-duration">%s</div>', | |
| 86 | + $this->singleCourseTemplate->html_duration( $course ) | |
| 87 | + ), | |
| 88 | + 'level' => sprintf( | |
| 89 | + '<div class="meta-item meta-item-level">%s</div>', | |
| 90 | + $this->singleCourseTemplate->html_level( $course ) | |
| 91 | + ), | |
| 92 | + 'lesson' => sprintf( | |
| 93 | + '<div class="meta-item meta-item-lesson">%s</div>', | |
| 94 | + $this->singleCourseTemplate->html_count_item( $course, LP_LESSON_CPT ) | |
| 95 | + ), | |
| 96 | + 'quiz' => sprintf( | |
| 97 | + '<div class="meta-item meta-item-quiz">%s</div>', | |
| 98 | + $this->singleCourseTemplate->html_count_item( $course, LP_QUIZ_CPT ) | |
| 99 | + ), | |
| 100 | + 'student' => sprintf( | |
| 101 | + '<div class="meta-item meta-item-student">%s</div>', | |
| 102 | + $this->singleCourseTemplate->html_count_student( $course ) | |
| 103 | + ), | |
| 104 | + 'wrapper_end' => '</div>', | |
| 105 | + ] | |
| 106 | + ); | |
| 107 | + | |
| 108 | + $header_sections = apply_filters( | |
| 109 | + 'learn-press/single-course/classic/header/sections', | |
| 110 | + [ | |
| 111 | + 'wrapper' => '<div class="course-detail-info">', | |
| 112 | + 'wrapper_inner' => '<div class="course-detail-info__inner">', | |
| 113 | + 'wrapper_content' => '<div class="course-meta__pull-left">', | |
| 114 | + 'meta_primary' => Template::combine_components( $meta_primary ), | |
| 115 | + 'title' => $this->singleCourseTemplate->html_title( $course, 'h1' ), | |
| 116 | + 'meta_secondary' => Template::combine_components( $meta_secondary ), | |
| 117 | + 'wrapper_content_end' => '</div>', | |
| 118 | + 'wrapper_inner_end' => '</div>', | |
| 119 | + 'wrapper_end' => '</div>', | |
| 120 | + ] | |
| 121 | + ); | |
| 122 | + | |
| 123 | + return Template::combine_components( $header_sections ); | |
| 124 | + } | |
| 125 | + | |
| 126 | + public function main_sections( $course, $user ): string { | |
| 127 | + | |
| 128 | + $content_left = apply_filters( | |
| 129 | + 'learn-press/single-course/classic/content-left/sections', | |
| 130 | + [ | |
| 131 | + 'wrapper' => '<div class="entry-content-left">', | |
| 132 | + 'course_tabs' => $this->html_course_tabs( $course, $user ), | |
| 133 | + 'features' => $this->singleCourseTemplate->html_features( $course ), | |
| 134 | + 'target' => $this->singleCourseTemplate->html_target( $course ), | |
| 135 | + 'requirements' => $this->singleCourseTemplate->html_requirements( $course ), | |
| 136 | + 'wrapper_end' => '</div>', | |
| 137 | + ] | |
| 138 | + ); | |
| 139 | + | |
| 140 | + $userCourseModel = UserCourseModel::find( get_current_user_id(), $course->get_id(), true ); | |
| 141 | + $userCourseTemplate = UserCourseTemplate::instance(); | |
| 142 | + $btn_continue_and_finish = []; | |
| 143 | + | |
| 144 | + if ( $userCourseModel instanceof UserCourseModel ) { | |
| 145 | + $btn_continue_and_finish = [ | |
| 146 | + 'btn_continue' => $userCourseTemplate->html_btn_continue( $userCourseModel ), | |
| 147 | + 'btn_finish' => $userCourseTemplate->html_btn_finish( $userCourseModel ), | |
| 148 | + ]; | |
| 149 | + } | |
| 150 | + | |
| 151 | + $section_buttons = apply_filters( | |
| 152 | + 'learn-press/single-course/model/section-right/info-meta/buttons', | |
| 153 | + [ | |
| 154 | + 'wrapper' => '<div class="course-buttons">', | |
| 155 | + 'btn_contact' => $this->singleCourseTemplate->html_btn_external( $course, $user ), | |
| 156 | + 'btn_buy' => $this->singleCourseTemplate->html_btn_purchase_course( $course, $user ), | |
| 157 | + 'btn_enroll' => $this->singleCourseTemplate->html_btn_enroll_course( $course, $user ), | |
| 158 | + 'btn_continue_and_finish' => Template::combine_components( $btn_continue_and_finish ), | |
| 159 | + 'wrapper_end' => '</div>', | |
| 160 | + ], | |
| 161 | + $course, | |
| 162 | + $user | |
| 163 | + ); | |
| 164 | + | |
| 165 | + $summary_sidebar = apply_filters( | |
| 166 | + 'learn-press/single-course/classic/content-left/sections', | |
| 167 | + [ | |
| 168 | + 'wrapper' => '<div class="course-summary-sidebar">', | |
| 169 | + 'wrapper_inner' => '<div class="course-summary-sidebar__inner">', | |
| 170 | + 'image' => $this->singleCourseTemplate->html_image( $course ), | |
| 171 | + 'price' => $this->singleCourseTemplate->html_price( $course ), | |
| 172 | + 'buttons' => Template::combine_components( $section_buttons ), | |
| 173 | + 'featured_review' => $this->singleCourseTemplate->html_feature_review( $course, $user ), | |
| 174 | + 'sidebar' => $this->singleCourseTemplate->html_sidebar( $course ), | |
| 175 | + 'wrapper_inner_end' => '</div>', | |
| 176 | + 'wrapper_end' => '</div>', | |
| 177 | + ] | |
| 178 | + ); | |
| 179 | + | |
| 180 | + $main_sections = apply_filters( | |
| 181 | + 'learn-press/single-course/classic/main/sections', | |
| 182 | + [ | |
| 183 | + 'wrapper' => '<div class="lp-entry-content lp-content-area">', | |
| 184 | + 'content_left' => Template::combine_components( $content_left ), | |
| 185 | + 'summary_sidebar' => Template::combine_components( $summary_sidebar ), | |
| 186 | + 'wrapper_end' => '</div>', | |
| 187 | + ] | |
| 188 | + ); | |
| 189 | + | |
| 190 | + return Template::combine_components( $main_sections ); | |
| 191 | + } | |
| 192 | + | |
| 193 | + public function html_instructor( $course ): string { | |
| 194 | + $instructor = $course->get_author_model(); | |
| 195 | + if ( ! $instructor ) { | |
| 196 | + return ''; | |
| 197 | + } | |
| 198 | + | |
| 199 | + $singleInstructorTemplate = SingleInstructorTemplate::instance(); | |
| 200 | + | |
| 201 | + $html_instructor = apply_filters( | |
| 202 | + 'learn-press/course/instructor-html', | |
| 203 | + [ | |
| 204 | + 'wrapper' => '<div class="meta-item meta-item-instructor">', | |
| 205 | + 'avatar_instructor' => sprintf( '<div class="meta-item__image">%s</div>', SingleInstructorTemplate::instance()->html_avatar( $instructor, [] ) ), | |
| 206 | + 'instructor' => '<div class="meta-item__value">', | |
| 207 | + 'label' => sprintf( '<label>%s</label>', esc_html__( 'Instructor', 'learnpress' ) ), | |
| 208 | + 'name' => sprintf( | |
| 209 | + '<div><a href="%s">%s</a></div>', | |
| 210 | + $instructor->get_url_instructor(), | |
| 211 | + $singleInstructorTemplate->html_display_name( $instructor ) | |
| 212 | + ), | |
| 213 | + 'instructor_end' => '</div>', | |
| 214 | + 'wrapper_end' => '</div>', | |
| 215 | + ], | |
| 216 | + $course, | |
| 217 | + $instructor | |
| 218 | + ); | |
| 219 | + | |
| 220 | + return Template::combine_components( $html_instructor ); | |
| 221 | + } | |
| 222 | + | |
| 223 | + public function html_category( $course ): string { | |
| 224 | + $cats = $course->get_categories(); | |
| 225 | + if ( empty( $cats ) ) { | |
| 226 | + return ''; | |
| 227 | + } | |
| 228 | + | |
| 229 | + $cat_names = []; | |
| 230 | + array_map( | |
| 231 | + function ( $cat ) use ( &$cat_names ) { | |
| 232 | + $term = sprintf( '<a href="%s">%s</a>', get_term_link( $cat->term_id ), $cat->name ); | |
| 233 | + $cat_names[] = $term; | |
| 234 | + }, | |
| 235 | + $cats | |
| 236 | + ); | |
| 237 | + | |
| 238 | + $content = implode( ' | ', $cat_names ); | |
| 239 | + | |
| 240 | + $html_category = apply_filters( | |
| 241 | + 'learn-press/course/html-categories', | |
| 242 | + [ | |
| 243 | + 'wrapper' => '<div class="meta-item meta-item-categories">', | |
| 244 | + 'category' => '<div class="meta-item__value">', | |
| 245 | + 'label' => sprintf( '<label>%s</label>', esc_html__( 'Category', 'learnpress' ) ), | |
| 246 | + 'content' => sprintf( '<div>%s</div>', $content ), | |
| 247 | + 'category_end' => '</div>', | |
| 248 | + 'wrapper_end' => '</div>', | |
| 249 | + ], | |
| 250 | + $course, | |
| 251 | + $cats, | |
| 252 | + $cat_names | |
| 253 | + ); | |
| 254 | + | |
| 255 | + return Template::combine_components( $html_category ); | |
| 256 | + } | |
| 257 | + | |
| 258 | + public function html_course_tabs( $course, $user ): string { | |
| 259 | + | |
| 260 | + $tabs = apply_filters( | |
| 261 | + 'learn-press/single-course/classic/course-tabs', | |
| 262 | + [ | |
| 263 | + 'overview' => esc_html__( 'Overview', 'learnpress' ), | |
| 264 | + 'curriculum' => esc_html__( 'Curriculum', 'learnpress' ), | |
| 265 | + 'instructor' => esc_html__( 'Instructor', 'learnpress' ), | |
| 266 | + 'materials' => esc_html__( 'Materials', 'learnpress' ), | |
| 267 | + 'faqs' => esc_html__( 'FAQs', 'learnpress' ), | |
| 268 | + ] | |
| 269 | + ); | |
| 270 | + | |
| 271 | + $active_tab = 'overview'; | |
| 272 | + $lp_user = learn_press_get_current_user(); | |
| 273 | + | |
| 274 | + if ( $lp_user && ! $lp_user instanceof LP_User_Guest ) { | |
| 275 | + $can_view_course = $lp_user->can_view_content_course( get_the_ID() ); | |
| 276 | + | |
| 277 | + if ( ! $can_view_course->flag ) { | |
| 278 | + if ( LP_BLOCK_COURSE_FINISHED === $can_view_course->key ) { | |
| 279 | + learn_press_display_message( | |
| 280 | + esc_html__( 'You finished this course. This course has been blocked', 'learnpress' ), | |
| 281 | + 'warning' | |
| 282 | + ); | |
| 283 | + } elseif ( LP_BLOCK_COURSE_DURATION_EXPIRE === $can_view_course->key ) { | |
| 284 | + learn_press_display_message( | |
| 285 | + esc_html__( 'This course has been blocked for expiration', 'learnpress' ), | |
| 286 | + 'warning' | |
| 287 | + ); | |
| 288 | + } | |
| 289 | + } | |
| 290 | + } | |
| 291 | + | |
| 292 | + $html_tabs = []; | |
| 293 | + if ( $tabs ) { | |
| 294 | + ob_start(); | |
| 295 | + foreach ( $tabs as $key => $tab ) { | |
| 296 | + echo '<input type="radio" name="learn-press-course-tab-radio" id="tab-' . esc_attr( $key ) . '-input" | |
| 297 | + ' . ( $active_tab === $key ? 'checked ' : '' ) . 'value="' . esc_attr( $key ) . '"/>'; | |
| 298 | + } | |
| 299 | + $html_input = ob_get_clean(); | |
| 300 | + | |
| 301 | + ob_start(); | |
| 302 | + foreach ( $tabs as $key => $tab ) { | |
| 303 | + $classes = array( 'course-nav course-nav-tab-' . esc_attr( $key ) ); | |
| 304 | + | |
| 305 | + if ( $active_tab === $key ) { | |
| 306 | + $classes[] = 'active'; | |
| 307 | + } | |
| 308 | + | |
| 309 | + echo '<li class="' . esc_attr( implode( ' ', $classes ) ) . '">'; | |
| 310 | + echo '<label for="tab-' . esc_attr( $key ) . '-input">' . esc_html( $tab ) . '</label>'; | |
| 311 | + echo '</li>'; | |
| 312 | + } | |
| 313 | + $html_tabs_nav = ob_get_clean(); | |
| 314 | + | |
| 315 | + $tabs_nav = [ | |
| 316 | + 'wrapper' => '<div class="wrapper-course-nav-tabs TabsDragScroll">', | |
| 317 | + 'nav_tabs' => '<ul class="learn-press-nav-tabs course-nav-tabs" data-tabs="' . esc_attr( count( $tabs ) ) . '">', | |
| 318 | + 'content' => $html_tabs_nav, | |
| 319 | + 'nav_tabs_end' => '</ul>', | |
| 320 | + 'wrapper_end' => '</div>', | |
| 321 | + ]; | |
| 322 | + | |
| 323 | + ob_start(); | |
| 324 | + | |
| 325 | + foreach ( $tabs as $key => $tab ) { | |
| 326 | + echo '<div class="course-tab-panel-' . esc_attr( $key ) . ' course-tab-panel" | |
| 327 | + id="tab-' . esc_attr( $key ) . '">'; | |
| 328 | + | |
| 329 | + switch ( $key ) { | |
| 330 | + case 'overview': | |
| 331 | + echo $this->singleCourseTemplate->html_description( $course ); | |
| 332 | + break; | |
| 333 | + // case 'curriculum': | |
| 334 | + // echo $this->singleCourseTemplate->html_curriculum( $course ); | |
| 335 | + // break; | |
| 336 | + case 'instructor': | |
| 337 | + echo $this->html_instructor_main( $course, $user ); | |
| 338 | + break; | |
| 339 | + case 'faqs': | |
| 340 | + echo $this->singleCourseTemplate->html_faqs( $course ); | |
| 341 | + break; | |
| 342 | + case 'materials': | |
| 343 | + echo $this->singleCourseTemplate->html_material( $course ); | |
| 344 | + break; | |
| 345 | + } | |
| 346 | + echo '</div>'; | |
| 347 | + } | |
| 348 | + | |
| 349 | + $html_tabs_content = ob_get_clean(); | |
| 350 | + | |
| 351 | + $tabs_content = [ | |
| 352 | + 'wrapper' => '<div class="course-tab-panels">', | |
| 353 | + 'content' => $html_tabs_content, | |
| 354 | + 'wrapper_end' => '</div>', | |
| 355 | + ]; | |
| 356 | + | |
| 357 | + $html_tabs = [ | |
| 358 | + 'input' => $html_input, | |
| 359 | + 'nav' => Template::combine_components( $tabs_nav ), | |
| 360 | + 'content' => Template::combine_components( $tabs_content ), | |
| 361 | + ]; | |
| 362 | + } | |
| 363 | + | |
| 364 | + $course_tabs = apply_filters( | |
| 365 | + 'learn-press/single-course/classic/main/course-tabs', | |
| 366 | + [ | |
| 367 | + 'wrapper' => '<div id="learn-press-course-tabs" class="course-tabs">', | |
| 368 | + 'tabs' => Template::combine_components( $html_tabs ), | |
| 369 | + 'wrapper_end' => '</div>', | |
| 370 | + ] | |
| 371 | + ); | |
| 372 | + | |
| 373 | + return Template::combine_components( $course_tabs ); | |
| 374 | + } | |
| 375 | + | |
| 376 | + public function html_instructor_main( $course, $user ): string { | |
| 377 | + | |
| 378 | + $singleInstructorTemplate = SingleInstructorTemplate::instance(); | |
| 379 | + $author = $course->get_author_model(); | |
| 380 | + | |
| 381 | + // Instructor | |
| 382 | + $html_instructor = ''; | |
| 383 | + if ( $author ) { | |
| 384 | + $html_instructor_image = sprintf( | |
| 385 | + '<a href="%s" title="%s">%s</a>', | |
| 386 | + $author->get_url_instructor(), | |
| 387 | + $author->get_display_name(), | |
| 388 | + $singleInstructorTemplate->html_avatar( $author ) | |
| 389 | + ); | |
| 390 | + $section_instructor_meta = [ | |
| 391 | + 'wrapper' => '<div class="lp-instructor-meta">', | |
| 392 | + 'count_students' => sprintf( | |
| 393 | + '<div class="instructor-item-meta">%s</div>', | |
| 394 | + $singleInstructorTemplate->html_count_students( $author ) | |
| 395 | + ), | |
| 396 | + 'count_courses' => sprintf( | |
| 397 | + '<div class="instructor-item-meta">%s</div>', | |
| 398 | + $singleInstructorTemplate->html_count_courses( $author ) | |
| 399 | + ), | |
| 400 | + 'wrapper_end' => '</div>', | |
| 401 | + ]; | |
| 402 | + $html_instructor_meta = Template::combine_components( $section_instructor_meta ); | |
| 403 | + | |
| 404 | + $section_instructor_right = apply_filters( | |
| 405 | + 'learn-press/single-course/model/section-instructor/right', | |
| 406 | + [ | |
| 407 | + 'wrapper' => '<div class="lp-section-instructor">', | |
| 408 | + 'name' => sprintf( | |
| 409 | + '<a href="%s">%s</a>', | |
| 410 | + $author->get_url_instructor(), | |
| 411 | + $singleInstructorTemplate->html_display_name( $author ) | |
| 412 | + ), | |
| 413 | + 'meta' => $html_instructor_meta, | |
| 414 | + 'description' => $singleInstructorTemplate->html_description( $author ), | |
| 415 | + 'social' => $singleInstructorTemplate->html_social( $author ), | |
| 416 | + 'wrapper_end' => '</div>', | |
| 417 | + ], | |
| 418 | + $course, | |
| 419 | + $user | |
| 420 | + ); | |
| 421 | + $html_instructor_right = Template::combine_components( $section_instructor_right ); | |
| 422 | + $section_instructor = apply_filters( | |
| 423 | + 'learn-press/single-course/model/section-instructor', | |
| 424 | + [ | |
| 425 | + 'wrapper' => '<div class="lp-section-instructor">', | |
| 426 | + 'wrapper_info' => '<div class="lp-instructor-info">', | |
| 427 | + 'image' => $html_instructor_image, | |
| 428 | + 'instructor_right' => $html_instructor_right, | |
| 429 | + 'wrapper_info_end' => '</div>', | |
| 430 | + 'wrapper_end' => '</div>', | |
| 431 | + ], | |
| 432 | + $course, | |
| 433 | + $user | |
| 434 | + ); | |
| 435 | + $html_instructor = Template::combine_components( $section_instructor ); | |
| 436 | + } | |
| 437 | + | |
| 438 | + return $html_instructor; | |
| 439 | + } | |
| 440 | +} | |