← All changes
|
inc/TemplateHooks/UserItem/UserCourseTemplate.php
+392
-392
4.3.9
→
4.4.8
View file →
| @@ -1,392 +1,392 @@ | ||
| 1 | -<?php | |
| 2 | -/** | |
| 3 | - * Template hooks Single Instructor. | |
| 4 | - * | |
| 5 | - * @since 4.2.3.5 | |
| 6 | - * @version 1.0.0 | |
| 7 | - */ | |
| 8 | - | |
| 9 | -namespace LearnPress\TemplateHooks\UserItem; | |
| 10 | - | |
| 11 | -use LearnPress\Helpers\Template; | |
| 12 | -use LearnPress\Models\CourseModel; | |
| 13 | -use LearnPress\Models\QuizPostModel; | |
| 14 | -use LearnPress\Models\UserItems\UserCourseModel; | |
| 15 | -use LP_Helper; | |
| 16 | -use WP_Error; | |
| 17 | - | |
| 18 | -class UserCourseTemplate extends UserItemBaseTemplate { | |
| 19 | - public static function instance() { | |
| 20 | - static $instance = null; | |
| 21 | - if ( is_null( $instance ) ) { | |
| 22 | - $instance = new self(); | |
| 23 | - } | |
| 24 | - | |
| 25 | - return $instance; | |
| 26 | - } | |
| 27 | - | |
| 28 | - /** | |
| 29 | - * HTML button continue course. | |
| 30 | - * | |
| 31 | - * @param UserCourseModel $userCourseModel | |
| 32 | - * | |
| 33 | - * @return string | |
| 34 | - * @since 4.2.7.5 | |
| 35 | - * @version 1.0.1 | |
| 36 | - */ | |
| 37 | - public function html_btn_continue( UserCourseModel $userCourseModel ): string { | |
| 38 | - $html = ''; | |
| 39 | - | |
| 40 | - if ( $userCourseModel->can_impact_item() instanceof WP_Error ) { | |
| 41 | - return $html; | |
| 42 | - } | |
| 43 | - | |
| 44 | - $courseModel = $userCourseModel->get_course_model(); | |
| 45 | - if ( ! $courseModel ) { | |
| 46 | - return $html; | |
| 47 | - } | |
| 48 | - | |
| 49 | - $total_items = $courseModel->count_items(); | |
| 50 | - if ( empty( $total_items ) ) { | |
| 51 | - return $html; | |
| 52 | - } | |
| 53 | - | |
| 54 | - $itemModelContinue = $userCourseModel->get_item_continue(); | |
| 55 | - if ( empty( $itemModelContinue ) ) { | |
| 56 | - $link_continue = $courseModel->get_permalink(); | |
| 57 | - } else { | |
| 58 | - $link_continue = $courseModel->get_item_link( $itemModelContinue->ID ); | |
| 59 | - } | |
| 60 | - | |
| 61 | - $html = sprintf( | |
| 62 | - '<a href="%s">%s</a>', | |
| 63 | - esc_url_raw( $link_continue ), | |
| 64 | - sprintf( | |
| 65 | - '<button class="lp-button course-btn-continue">%s</button>', | |
| 66 | - esc_html__( 'Continue', 'learnpress' ) | |
| 67 | - ) | |
| 68 | - ); | |
| 69 | - | |
| 70 | - return apply_filters( 'learn-press/user/course/html-button-continue', $html, $userCourseModel ); | |
| 71 | - } | |
| 72 | - | |
| 73 | - /** | |
| 74 | - * HTML button finish course. | |
| 75 | - * | |
| 76 | - * @param UserCourseModel $userCourseModel | |
| 77 | - * | |
| 78 | - * @return string | |
| 79 | - * @since 4.2.7.5 | |
| 80 | - * @version 1.0.0 | |
| 81 | - */ | |
| 82 | - public function html_btn_finish( UserCourseModel $userCourseModel ): string { | |
| 83 | - $html = ''; | |
| 84 | - | |
| 85 | - $can_finish = $userCourseModel->can_finish(); | |
| 86 | - if ( is_wp_error( $can_finish ) ) { | |
| 87 | - return $html; | |
| 88 | - } | |
| 89 | - | |
| 90 | - $section = apply_filters( | |
| 91 | - 'learn-press/user/course/html-button-finish', | |
| 92 | - [ | |
| 93 | - 'form' => sprintf( | |
| 94 | - '<form class="lp-form form-button form-button-finish-course" method="post" data-confirm="%s">', | |
| 95 | - __( 'Do you want to finish the course?', 'learnpress' ) | |
| 96 | - ), | |
| 97 | - 'btn' => sprintf( | |
| 98 | - '<button class="lp-button btn-finish-course">%s</button>', | |
| 99 | - esc_html__( 'Finish Course', 'learnpress' ) | |
| 100 | - ), | |
| 101 | - 'input' => sprintf( | |
| 102 | - '<input type="hidden" name="course-id" value="%d"/>', | |
| 103 | - esc_attr( $userCourseModel->item_id ) | |
| 104 | - ), | |
| 105 | - 'nonce' => sprintf( | |
| 106 | - '<input type="hidden" name="finish-course-nonce" value="%s"/>', | |
| 107 | - esc_attr( | |
| 108 | - wp_create_nonce( | |
| 109 | - sprintf( 'finish-course-%d-%d', $userCourseModel->item_id, $userCourseModel->user_id ) | |
| 110 | - ) | |
| 111 | - ) | |
| 112 | - ), | |
| 113 | - 'lpajax' => '<input type="hidden" name="lp-ajax" value="finish-course"/>', | |
| 114 | - 'noajax' => '<input type="hidden" name="noajax" value="yes"/>', | |
| 115 | - 'form_end' => '</form>', | |
| 116 | - ], | |
| 117 | - $userCourseModel | |
| 118 | - ); | |
| 119 | - | |
| 120 | - return Template::combine_components( $section ); | |
| 121 | - } | |
| 122 | - | |
| 123 | - /** | |
| 124 | - * HTML button retake course | |
| 125 | - * | |
| 126 | - * @param UserCourseModel $userCourseModel | |
| 127 | - * | |
| 128 | - * @return string | |
| 129 | - * @since 4.2.7.6 | |
| 130 | - * @version 1.0.0 | |
| 131 | - */ | |
| 132 | - public function html_btn_retake( UserCourseModel $userCourseModel ): string { | |
| 133 | - $retake_remaining = $userCourseModel->can_retake(); | |
| 134 | - | |
| 135 | - if ( $retake_remaining === 0 ) { | |
| 136 | - return ''; | |
| 137 | - } | |
| 138 | - | |
| 139 | - $html_btn = sprintf( | |
| 140 | - '<button type="submit" class="lp-button button-retake-course">%s (%d)</button>', | |
| 141 | - __( 'Retake course', 'learnpress' ), | |
| 142 | - $retake_remaining | |
| 143 | - ); | |
| 144 | - | |
| 145 | - $section = apply_filters( | |
| 146 | - 'learn-press/course/html-button-retake', | |
| 147 | - [ | |
| 148 | - 'form' => sprintf( | |
| 149 | - '<form name="lp-form-retake-course" class="lp-form-retake-course" method="post" data-confirm="%s">', | |
| 150 | - esc_html__( 'Do you want to retake the course', 'learnpress' ) | |
| 151 | - ), | |
| 152 | - 'input' => sprintf( | |
| 153 | - '<input type="hidden" name="retake-course" value="%d"/>', | |
| 154 | - esc_attr( $userCourseModel->item_id ) | |
| 155 | - ), | |
| 156 | - 'btn' => $html_btn, | |
| 157 | - 'lp-ajax-mess' => '<div class="lp-ajax-message"></div>', | |
| 158 | - 'form_end' => '</form>', | |
| 159 | - ], | |
| 160 | - $userCourseModel | |
| 161 | - ); | |
| 162 | - | |
| 163 | - return Template::combine_components( $section ); | |
| 164 | - } | |
| 165 | - | |
| 166 | - /** | |
| 167 | - * HTML count items completed of Course. | |
| 168 | - * | |
| 169 | - * @return mixed|string|null | |
| 170 | - * @since 4.2.7.6 | |
| 171 | - * @version 1.0.1 | |
| 172 | - */ | |
| 173 | - public function html_count_items_completed( UserCourseModel $userCourseModel ): string { | |
| 174 | - $html = ''; | |
| 175 | - | |
| 176 | - // For case Guest user. | |
| 177 | - $userModel = $userCourseModel->get_user_model(); | |
| 178 | - if ( ! $userModel ) { | |
| 179 | - return $html; | |
| 180 | - } | |
| 181 | - | |
| 182 | - $courseModel = $userCourseModel->get_course_model(); | |
| 183 | - $item_types = CourseModel::item_types_support(); | |
| 184 | - $count_items_completed = $userCourseModel->count_items_completed(); | |
| 185 | - foreach ( $item_types as $item_type ) { | |
| 186 | - $count_item = $courseModel->count_items( $item_type ); | |
| 187 | - $count_item_completed = $count_items_completed->{$item_type . '_status_completed'} ?? ''; | |
| 188 | - if ( empty( $count_item_completed ) ) { | |
| 189 | - continue; | |
| 190 | - } | |
| 191 | - | |
| 192 | - $html .= sprintf( | |
| 193 | - '<div class="item-completed"><span>%s</span><span>%s</span></div>', | |
| 194 | - sprintf( | |
| 195 | - '%s %s: ', | |
| 196 | - LP_Helper::get_i18n_string_plural( $count_item, $item_type, false ), | |
| 197 | - __( 'completed', 'learnpress' ) | |
| 198 | - ), | |
| 199 | - sprintf( '%d/%d', $count_item_completed, $count_item ) | |
| 200 | - ); | |
| 201 | - } | |
| 202 | - | |
| 203 | - return apply_filters( 'learn-press/user/course/html-count-items-completed', $html, $userCourseModel ); | |
| 204 | - } | |
| 205 | - | |
| 206 | - /** | |
| 207 | - * HTMl progress course. | |
| 208 | - * | |
| 209 | - * @param UserCourseModel $userCourseModel | |
| 210 | - * | |
| 211 | - * @return mixed|null | |
| 212 | - * @since 4.2.7.5 | |
| 213 | - * @version 1.0.1 | |
| 214 | - */ | |
| 215 | - public function html_progress( UserCourseModel $userCourseModel ) { | |
| 216 | - $html = ''; | |
| 217 | - | |
| 218 | - // For case Guest user. | |
| 219 | - $userModel = $userCourseModel->get_user_model(); | |
| 220 | - if ( ! $userModel ) { | |
| 221 | - return $html; | |
| 222 | - } | |
| 223 | - | |
| 224 | - $courseModel = $userCourseModel->get_course_model(); | |
| 225 | - $evaluation_type = $courseModel::get_evaluation_types( $courseModel->get_evaluation_type() ); | |
| 226 | - $calculate = $userCourseModel->calculate_course_results(); | |
| 227 | - $passing_condition = $courseModel->get_passing_condition(); | |
| 228 | - if ( array_key_first( $evaluation_type ) === 'evaluate_final_quiz' ) { | |
| 229 | - $final_quiz = $courseModel->get_final_quiz(); | |
| 230 | - if ( $final_quiz ) { | |
| 231 | - $quizModel = QuizPostModel::find( $final_quiz, true ); | |
| 232 | - $passing_condition = $quizModel->get_passing_grade(); | |
| 233 | - } | |
| 234 | - } | |
| 235 | - $total_items = $courseModel->count_items(); | |
| 236 | - | |
| 237 | - $progress_items_completed_percent = round( | |
| 238 | - $total_items > 0 ? $calculate['completed_items'] * 100 / $total_items : 0, | |
| 239 | - 2 | |
| 240 | - ); | |
| 241 | - if ( $progress_items_completed_percent > 100 ) { | |
| 242 | - $progress_items_completed_percent = 100; | |
| 243 | - } | |
| 244 | - | |
| 245 | - $section = [ | |
| 246 | - 'wrapper' => '<div class="course-progress">', | |
| 247 | - 'progress' => sprintf( | |
| 248 | - '<div class="course-progress__label">%s %s</div>', | |
| 249 | - esc_html__( 'Course progress:', 'learnpress' ), | |
| 250 | - sprintf( | |
| 251 | - '<span class="course-progress__number"> | |
| 252 | - <span class="number">%s<span class="percentage">%s</span></span> | |
| 253 | - </span>', | |
| 254 | - $progress_items_completed_percent, | |
| 255 | - '%' | |
| 256 | - ) | |
| 257 | - ), | |
| 258 | - 'line-progress' => $this->html_items_completed_progress_bar( $userCourseModel ), | |
| 259 | - 'passing-progress' => sprintf( | |
| 260 | - '<div class="course-progress__label">%s %s | |
| 261 | - <span class="lp-icon-question-circle" title="%s"></span> | |
| 262 | - </div>', | |
| 263 | - esc_html__( 'Passing grade progress:', 'learnpress' ), | |
| 264 | - sprintf( | |
| 265 | - '<span class="course-progress__number"> | |
| 266 | - <span class="number">%s<span class="percentage">%s</span></span> | |
| 267 | - </span>', | |
| 268 | - $calculate['result'], | |
| 269 | - '%' | |
| 270 | - ), | |
| 271 | - sprintf( | |
| 272 | - '%s. %s', | |
| 273 | - isset( $evaluation_type['label'] ) ? esc_attr( $evaluation_type['label'] ) : '', | |
| 274 | - esc_attr( sprintf( __( 'Passing condition: %s%%', 'learnpress' ), $passing_condition ) ) | |
| 275 | - ) | |
| 276 | - ), | |
| 277 | - 'wrapper_end' => '</div>', | |
| 278 | - ]; | |
| 279 | - | |
| 280 | - $html = Template::combine_components( $section ); | |
| 281 | - | |
| 282 | - return apply_filters( 'learn-press/user/course/html-progress', $html, $userCourseModel ); | |
| 283 | - } | |
| 284 | - | |
| 285 | - /** | |
| 286 | - * HTML course items completed progress bar. | |
| 287 | - * | |
| 288 | - * @param UserCourseModel $userCourseModel | |
| 289 | - * | |
| 290 | - * @return string | |
| 291 | - * | |
| 292 | - * @since 4.3.2.6 | |
| 293 | - * @version 1.0.0 | |
| 294 | - */ | |
| 295 | - public function html_passing_grade_progress_bar( UserCourseModel $userCourseModel ): string { | |
| 296 | - $courseModel = $userCourseModel->get_course_model(); | |
| 297 | - $calculate = $userCourseModel->calculate_course_results(); | |
| 298 | - $passing_condition = $courseModel->get_passing_condition(); | |
| 299 | - | |
| 300 | - $section = [ | |
| 301 | - 'wrapper' => '<div class="course-passing-grade-progress-bar">', | |
| 302 | - 'line-passing-progress' => sprintf( | |
| 303 | - '<div class="course-progress__line"> | |
| 304 | - <div class="course-progress__line__active" style="width: %s%%"></div> | |
| 305 | - <div class="course-progress__line__point" style="left: %s%%"></div> | |
| 306 | - </div>', | |
| 307 | - $calculate['result'], | |
| 308 | - $passing_condition | |
| 309 | - ), | |
| 310 | - 'wrapper_end' => '</div>', | |
| 311 | - ]; | |
| 312 | - | |
| 313 | - return Template::combine_components( $section ); | |
| 314 | - } | |
| 315 | - | |
| 316 | - /** | |
| 317 | - * HTML course items completed progress bar. | |
| 318 | - * | |
| 319 | - * @param UserCourseModel $userCourseModel | |
| 320 | - * | |
| 321 | - * @return string | |
| 322 | - * | |
| 323 | - * @since 4.3.2.6 | |
| 324 | - * @version 1.0.0 | |
| 325 | - */ | |
| 326 | - public function html_items_completed_progress_bar( UserCourseModel $userCourseModel ): string { | |
| 327 | - $courseModel = $userCourseModel->get_course_model(); | |
| 328 | - $calculate = $userCourseModel->calculate_course_results(); | |
| 329 | - $total_items = $courseModel->count_items(); | |
| 330 | - | |
| 331 | - $progress_items_completed_percent = round( | |
| 332 | - $total_items > 0 ? $calculate['completed_items'] * 100 / $total_items : 0, | |
| 333 | - 2 | |
| 334 | - ); | |
| 335 | - if ( $progress_items_completed_percent > 100 ) { | |
| 336 | - $progress_items_completed_percent = 100; | |
| 337 | - } | |
| 338 | - | |
| 339 | - $section = [ | |
| 340 | - 'wrapper' => sprintf( | |
| 341 | - '<div class="course-items-completed-progress-bar" title="%s">', | |
| 342 | - sprintf( | |
| 343 | - esc_html__( '%1$d of %2$d items completed', 'learnpress' ), | |
| 344 | - $calculate['completed_items'], | |
| 345 | - $total_items | |
| 346 | - ) | |
| 347 | - ), | |
| 348 | - 'line-progress' => sprintf( | |
| 349 | - '<div class="course-progress__line"> | |
| 350 | - <div class="course-progress__line__active" style="width: %s%%"></div> | |
| 351 | - </div>', | |
| 352 | - $progress_items_completed_percent, | |
| 353 | - ), | |
| 354 | - 'wrapper_end' => '</div>', | |
| 355 | - ]; | |
| 356 | - | |
| 357 | - return Template::combine_components( $section ); | |
| 358 | - } | |
| 359 | - | |
| 360 | - /** | |
| 361 | - * HTMl progress course. | |
| 362 | - * | |
| 363 | - * @param UserCourseModel $userCourseModel | |
| 364 | - * | |
| 365 | - * @return mixed|null | |
| 366 | - * @since 4.2.7.6 | |
| 367 | - * @version 1.0.1 | |
| 368 | - */ | |
| 369 | - public function html_message_lock( UserCourseModel $userCourseModel ): string { | |
| 370 | - $html = ''; | |
| 371 | - | |
| 372 | - // For case Guest user. | |
| 373 | - $userModel = $userCourseModel->get_user_model(); | |
| 374 | - if ( ! $userModel ) { | |
| 375 | - return $html; | |
| 376 | - } | |
| 377 | - | |
| 378 | - $courseModel = $userCourseModel->get_course_model(); | |
| 379 | - | |
| 380 | - if ( $courseModel->enable_block_when_finished() && $userCourseModel->is_finished() ) { | |
| 381 | - $message = __( 'This course is finished.', 'learnpress' ); | |
| 382 | - } elseif ( $courseModel->enable_block_when_expire() && $userCourseModel->timestamp_remaining_duration() === 0 ) { | |
| 383 | - $message = __( 'This course is expired.', 'learnpress' ); | |
| 384 | - } else { | |
| 385 | - return $html; | |
| 386 | - } | |
| 387 | - | |
| 388 | - $html = Template::print_message( $message, 'warning', false ); | |
| 389 | - | |
| 390 | - return apply_filters( 'learn-press/user/course/html-message-lock', $html, $userCourseModel ); | |
| 391 | - } | |
| 392 | -} | |
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Template hooks Single Instructor. | |
| 4 | + * | |
| 5 | + * @since 4.2.3.5 | |
| 6 | + * @version 1.0.0 | |
| 7 | + */ | |
| 8 | + | |
| 9 | +namespace LearnPress\TemplateHooks\UserItem; | |
| 10 | + | |
| 11 | +use LearnPress\Helpers\Template; | |
| 12 | +use LearnPress\Models\CourseModel; | |
| 13 | +use LearnPress\Models\QuizPostModel; | |
| 14 | +use LearnPress\Models\UserItems\UserCourseModel; | |
| 15 | +use LP_Helper; | |
| 16 | +use WP_Error; | |
| 17 | + | |
| 18 | +class UserCourseTemplate extends UserItemBaseTemplate { | |
| 19 | + public static function instance() { | |
| 20 | + static $instance = null; | |
| 21 | + if ( is_null( $instance ) ) { | |
| 22 | + $instance = new self(); | |
| 23 | + } | |
| 24 | + | |
| 25 | + return $instance; | |
| 26 | + } | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * HTML button continue course. | |
| 30 | + * | |
| 31 | + * @param UserCourseModel $userCourseModel | |
| 32 | + * | |
| 33 | + * @return string | |
| 34 | + * @since 4.2.7.5 | |
| 35 | + * @version 1.0.1 | |
| 36 | + */ | |
| 37 | + public function html_btn_continue( UserCourseModel $userCourseModel ): string { | |
| 38 | + $html = ''; | |
| 39 | + | |
| 40 | + if ( $userCourseModel->can_impact_item() instanceof WP_Error ) { | |
| 41 | + return $html; | |
| 42 | + } | |
| 43 | + | |
| 44 | + $courseModel = $userCourseModel->get_course_model(); | |
| 45 | + if ( ! $courseModel ) { | |
| 46 | + return $html; | |
| 47 | + } | |
| 48 | + | |
| 49 | + $total_items = $courseModel->count_items(); | |
| 50 | + if ( empty( $total_items ) ) { | |
| 51 | + return $html; | |
| 52 | + } | |
| 53 | + | |
| 54 | + $itemModelContinue = $userCourseModel->get_item_continue(); | |
| 55 | + if ( empty( $itemModelContinue ) ) { | |
| 56 | + $link_continue = $courseModel->get_permalink(); | |
| 57 | + } else { | |
| 58 | + $link_continue = $courseModel->get_item_link( $itemModelContinue->ID ); | |
| 59 | + } | |
| 60 | + | |
| 61 | + $html = sprintf( | |
| 62 | + '<a href="%s">%s</a>', | |
| 63 | + esc_url_raw( $link_continue ), | |
| 64 | + sprintf( | |
| 65 | + '<button class="lp-button course-btn-continue">%s</button>', | |
| 66 | + esc_html__( 'Continue', 'learnpress' ) | |
| 67 | + ) | |
| 68 | + ); | |
| 69 | + | |
| 70 | + return apply_filters( 'learn-press/user/course/html-button-continue', $html, $userCourseModel ); | |
| 71 | + } | |
| 72 | + | |
| 73 | + /** | |
| 74 | + * HTML button finish course. | |
| 75 | + * | |
| 76 | + * @param UserCourseModel $userCourseModel | |
| 77 | + * | |
| 78 | + * @return string | |
| 79 | + * @since 4.2.7.5 | |
| 80 | + * @version 1.0.0 | |
| 81 | + */ | |
| 82 | + public function html_btn_finish( UserCourseModel $userCourseModel ): string { | |
| 83 | + $html = ''; | |
| 84 | + | |
| 85 | + $can_finish = $userCourseModel->can_finish(); | |
| 86 | + if ( is_wp_error( $can_finish ) ) { | |
| 87 | + return $html; | |
| 88 | + } | |
| 89 | + | |
| 90 | + $section = apply_filters( | |
| 91 | + 'learn-press/user/course/html-button-finish', | |
| 92 | + [ | |
| 93 | + 'form' => sprintf( | |
| 94 | + '<form class="lp-form form-button form-button-finish-course" method="post" data-confirm="%s">', | |
| 95 | + __( 'Do you want to finish the course?', 'learnpress' ) | |
| 96 | + ), | |
| 97 | + 'btn' => sprintf( | |
| 98 | + '<button class="lp-button btn-finish-course">%s</button>', | |
| 99 | + esc_html__( 'Finish Course', 'learnpress' ) | |
| 100 | + ), | |
| 101 | + 'input' => sprintf( | |
| 102 | + '<input type="hidden" name="course-id" value="%d"/>', | |
| 103 | + esc_attr( $userCourseModel->item_id ) | |
| 104 | + ), | |
| 105 | + 'nonce' => sprintf( | |
| 106 | + '<input type="hidden" name="finish-course-nonce" value="%s"/>', | |
| 107 | + esc_attr( | |
| 108 | + wp_create_nonce( | |
| 109 | + sprintf( 'finish-course-%d-%d', $userCourseModel->item_id, $userCourseModel->user_id ) | |
| 110 | + ) | |
| 111 | + ) | |
| 112 | + ), | |
| 113 | + 'lpajax' => '<input type="hidden" name="lp-ajax" value="finish-course"/>', | |
| 114 | + 'noajax' => '<input type="hidden" name="noajax" value="yes"/>', | |
| 115 | + 'form_end' => '</form>', | |
| 116 | + ], | |
| 117 | + $userCourseModel | |
| 118 | + ); | |
| 119 | + | |
| 120 | + return Template::combine_components( $section ); | |
| 121 | + } | |
| 122 | + | |
| 123 | + /** | |
| 124 | + * HTML button retake course | |
| 125 | + * | |
| 126 | + * @param UserCourseModel $userCourseModel | |
| 127 | + * | |
| 128 | + * @return string | |
| 129 | + * @since 4.2.7.6 | |
| 130 | + * @version 1.0.0 | |
| 131 | + */ | |
| 132 | + public function html_btn_retake( UserCourseModel $userCourseModel ): string { | |
| 133 | + $retake_remaining = $userCourseModel->can_retake(); | |
| 134 | + | |
| 135 | + if ( $retake_remaining === 0 ) { | |
| 136 | + return ''; | |
| 137 | + } | |
| 138 | + | |
| 139 | + $html_btn = sprintf( | |
| 140 | + '<button type="submit" class="lp-button button-retake-course">%s (%d)</button>', | |
| 141 | + __( 'Retake course', 'learnpress' ), | |
| 142 | + $retake_remaining | |
| 143 | + ); | |
| 144 | + | |
| 145 | + $section = apply_filters( | |
| 146 | + 'learn-press/course/html-button-retake', | |
| 147 | + [ | |
| 148 | + 'form' => sprintf( | |
| 149 | + '<form name="lp-form-retake-course" class="lp-form-retake-course" method="post" data-confirm="%s">', | |
| 150 | + esc_html__( 'Do you want to retake the course', 'learnpress' ) | |
| 151 | + ), | |
| 152 | + 'input' => sprintf( | |
| 153 | + '<input type="hidden" name="retake-course" value="%d"/>', | |
| 154 | + esc_attr( $userCourseModel->item_id ) | |
| 155 | + ), | |
| 156 | + 'btn' => $html_btn, | |
| 157 | + 'lp-ajax-mess' => '<div class="lp-ajax-message"></div>', | |
| 158 | + 'form_end' => '</form>', | |
| 159 | + ], | |
| 160 | + $userCourseModel | |
| 161 | + ); | |
| 162 | + | |
| 163 | + return Template::combine_components( $section ); | |
| 164 | + } | |
| 165 | + | |
| 166 | + /** | |
| 167 | + * HTML count items completed of Course. | |
| 168 | + * | |
| 169 | + * @return mixed|string|null | |
| 170 | + * @since 4.2.7.6 | |
| 171 | + * @version 1.0.1 | |
| 172 | + */ | |
| 173 | + public function html_count_items_completed( UserCourseModel $userCourseModel ): string { | |
| 174 | + $html = ''; | |
| 175 | + | |
| 176 | + // For case Guest user. | |
| 177 | + $userModel = $userCourseModel->get_user_model(); | |
| 178 | + if ( ! $userModel ) { | |
| 179 | + return $html; | |
| 180 | + } | |
| 181 | + | |
| 182 | + $courseModel = $userCourseModel->get_course_model(); | |
| 183 | + $item_types = CourseModel::item_types_support(); | |
| 184 | + $count_items_completed = $userCourseModel->count_items_completed(); | |
| 185 | + foreach ( $item_types as $item_type ) { | |
| 186 | + $count_item = $courseModel->count_items( $item_type ); | |
| 187 | + $count_item_completed = $count_items_completed->{$item_type . '_status_completed'} ?? ''; | |
| 188 | + if ( empty( $count_item_completed ) ) { | |
| 189 | + continue; | |
| 190 | + } | |
| 191 | + | |
| 192 | + $html .= sprintf( | |
| 193 | + '<div class="item-completed"><span>%s</span><span>%s</span></div>', | |
| 194 | + sprintf( | |
| 195 | + '%s %s: ', | |
| 196 | + LP_Helper::get_i18n_string_plural( $count_item, $item_type, false ), | |
| 197 | + __( 'completed', 'learnpress' ) | |
| 198 | + ), | |
| 199 | + sprintf( '%d/%d', $count_item_completed, $count_item ) | |
| 200 | + ); | |
| 201 | + } | |
| 202 | + | |
| 203 | + return apply_filters( 'learn-press/user/course/html-count-items-completed', $html, $userCourseModel ); | |
| 204 | + } | |
| 205 | + | |
| 206 | + /** | |
| 207 | + * HTMl progress course. | |
| 208 | + * | |
| 209 | + * @param UserCourseModel $userCourseModel | |
| 210 | + * | |
| 211 | + * @return mixed|null | |
| 212 | + * @since 4.2.7.5 | |
| 213 | + * @version 1.0.1 | |
| 214 | + */ | |
| 215 | + public function html_progress( UserCourseModel $userCourseModel ) { | |
| 216 | + $html = ''; | |
| 217 | + | |
| 218 | + // For case Guest user. | |
| 219 | + $userModel = $userCourseModel->get_user_model(); | |
| 220 | + if ( ! $userModel ) { | |
| 221 | + return $html; | |
| 222 | + } | |
| 223 | + | |
| 224 | + $courseModel = $userCourseModel->get_course_model(); | |
| 225 | + $evaluation_type = $courseModel::get_evaluation_types( $courseModel->get_evaluation_type() ); | |
| 226 | + $calculate = $userCourseModel->calculate_course_results(); | |
| 227 | + $passing_condition = $courseModel->get_passing_condition(); | |
| 228 | + if ( $courseModel->get_evaluation_type() === 'evaluate_final_quiz' ) { | |
| 229 | + $final_quiz = $courseModel->get_final_quiz(); | |
| 230 | + if ( $final_quiz ) { | |
| 231 | + $quizModel = QuizPostModel::find( $final_quiz, true ); | |
| 232 | + $passing_condition = $quizModel->get_passing_grade(); | |
| 233 | + } | |
| 234 | + } | |
| 235 | + $total_items = $courseModel->count_items(); | |
| 236 | + | |
| 237 | + $progress_items_completed_percent = round( | |
| 238 | + $total_items > 0 ? $calculate['completed_items'] * 100 / $total_items : 0, | |
| 239 | + 2 | |
| 240 | + ); | |
| 241 | + if ( $progress_items_completed_percent > 100 ) { | |
| 242 | + $progress_items_completed_percent = 100; | |
| 243 | + } | |
| 244 | + | |
| 245 | + $section = [ | |
| 246 | + 'wrapper' => '<div class="course-progress">', | |
| 247 | + 'progress' => sprintf( | |
| 248 | + '<div class="course-progress__label">%s %s</div>', | |
| 249 | + esc_html__( 'Course progress:', 'learnpress' ), | |
| 250 | + sprintf( | |
| 251 | + '<span class="course-progress__number"> | |
| 252 | + <span class="number">%s<span class="percentage">%s</span></span> | |
| 253 | + </span>', | |
| 254 | + $progress_items_completed_percent, | |
| 255 | + '%' | |
| 256 | + ) | |
| 257 | + ), | |
| 258 | + 'line-progress' => $this->html_items_completed_progress_bar( $userCourseModel ), | |
| 259 | + 'passing-progress' => sprintf( | |
| 260 | + '<div class="course-progress__label">%s %s | |
| 261 | + <span class="lp-icon-question-circle" title="%s"></span> | |
| 262 | + </div>', | |
| 263 | + esc_html__( 'Passing grade progress:', 'learnpress' ), | |
| 264 | + sprintf( | |
| 265 | + '<span class="course-progress__number"> | |
| 266 | + <span class="number">%s<span class="percentage">%s</span></span> | |
| 267 | + </span>', | |
| 268 | + $calculate['result'], | |
| 269 | + '%' | |
| 270 | + ), | |
| 271 | + sprintf( | |
| 272 | + '%s. %s', | |
| 273 | + isset( $evaluation_type['label'] ) ? esc_attr( $evaluation_type['label'] ) : '', | |
| 274 | + esc_attr( sprintf( __( 'Passing condition: %s%%', 'learnpress' ), $passing_condition ) ) | |
| 275 | + ) | |
| 276 | + ), | |
| 277 | + 'wrapper_end' => '</div>', | |
| 278 | + ]; | |
| 279 | + | |
| 280 | + $html = Template::combine_components( $section ); | |
| 281 | + | |
| 282 | + return apply_filters( 'learn-press/user/course/html-progress', $html, $userCourseModel ); | |
| 283 | + } | |
| 284 | + | |
| 285 | + /** | |
| 286 | + * HTML course items completed progress bar. | |
| 287 | + * | |
| 288 | + * @param UserCourseModel $userCourseModel | |
| 289 | + * | |
| 290 | + * @return string | |
| 291 | + * | |
| 292 | + * @since 4.3.2.6 | |
| 293 | + * @version 1.0.0 | |
| 294 | + */ | |
| 295 | + public function html_passing_grade_progress_bar( UserCourseModel $userCourseModel ): string { | |
| 296 | + $courseModel = $userCourseModel->get_course_model(); | |
| 297 | + $calculate = $userCourseModel->calculate_course_results(); | |
| 298 | + $passing_condition = $courseModel->get_passing_condition(); | |
| 299 | + | |
| 300 | + $section = [ | |
| 301 | + 'wrapper' => '<div class="course-passing-grade-progress-bar">', | |
| 302 | + 'line-passing-progress' => sprintf( | |
| 303 | + '<div class="course-progress__line"> | |
| 304 | + <div class="course-progress__line__active" style="width: %s%%"></div> | |
| 305 | + <div class="course-progress__line__point" style="left: %s%%"></div> | |
| 306 | + </div>', | |
| 307 | + $calculate['result'], | |
| 308 | + $passing_condition | |
| 309 | + ), | |
| 310 | + 'wrapper_end' => '</div>', | |
| 311 | + ]; | |
| 312 | + | |
| 313 | + return Template::combine_components( $section ); | |
| 314 | + } | |
| 315 | + | |
| 316 | + /** | |
| 317 | + * HTML course items completed progress bar. | |
| 318 | + * | |
| 319 | + * @param UserCourseModel $userCourseModel | |
| 320 | + * | |
| 321 | + * @return string | |
| 322 | + * | |
| 323 | + * @since 4.3.2.6 | |
| 324 | + * @version 1.0.0 | |
| 325 | + */ | |
| 326 | + public function html_items_completed_progress_bar( UserCourseModel $userCourseModel ): string { | |
| 327 | + $courseModel = $userCourseModel->get_course_model(); | |
| 328 | + $calculate = $userCourseModel->calculate_course_results(); | |
| 329 | + $total_items = $courseModel->count_items(); | |
| 330 | + | |
| 331 | + $progress_items_completed_percent = round( | |
| 332 | + $total_items > 0 ? $calculate['completed_items'] * 100 / $total_items : 0, | |
| 333 | + 2 | |
| 334 | + ); | |
| 335 | + if ( $progress_items_completed_percent > 100 ) { | |
| 336 | + $progress_items_completed_percent = 100; | |
| 337 | + } | |
| 338 | + | |
| 339 | + $section = [ | |
| 340 | + 'wrapper' => sprintf( | |
| 341 | + '<div class="course-items-completed-progress-bar" title="%s">', | |
| 342 | + sprintf( | |
| 343 | + esc_html__( '%1$d of %2$d items completed', 'learnpress' ), | |
| 344 | + $calculate['completed_items'], | |
| 345 | + $total_items | |
| 346 | + ) | |
| 347 | + ), | |
| 348 | + 'line-progress' => sprintf( | |
| 349 | + '<div class="course-progress__line"> | |
| 350 | + <div class="course-progress__line__active" style="width: %s%%"></div> | |
| 351 | + </div>', | |
| 352 | + $progress_items_completed_percent, | |
| 353 | + ), | |
| 354 | + 'wrapper_end' => '</div>', | |
| 355 | + ]; | |
| 356 | + | |
| 357 | + return Template::combine_components( $section ); | |
| 358 | + } | |
| 359 | + | |
| 360 | + /** | |
| 361 | + * HTMl progress course. | |
| 362 | + * | |
| 363 | + * @param UserCourseModel $userCourseModel | |
| 364 | + * | |
| 365 | + * @return mixed|null | |
| 366 | + * @since 4.2.7.6 | |
| 367 | + * @version 1.0.1 | |
| 368 | + */ | |
| 369 | + public function html_message_lock( UserCourseModel $userCourseModel ): string { | |
| 370 | + $html = ''; | |
| 371 | + | |
| 372 | + // For case Guest user. | |
| 373 | + $userModel = $userCourseModel->get_user_model(); | |
| 374 | + if ( ! $userModel ) { | |
| 375 | + return $html; | |
| 376 | + } | |
| 377 | + | |
| 378 | + $courseModel = $userCourseModel->get_course_model(); | |
| 379 | + | |
| 380 | + if ( $courseModel->enable_block_when_finished() && $userCourseModel->is_finished() ) { | |
| 381 | + $message = __( 'This course is finished.', 'learnpress' ); | |
| 382 | + } elseif ( $courseModel->enable_block_when_expire() && $userCourseModel->timestamp_remaining_duration() === 0 ) { | |
| 383 | + $message = __( 'This course is expired.', 'learnpress' ); | |
| 384 | + } else { | |
| 385 | + return $html; | |
| 386 | + } | |
| 387 | + | |
| 388 | + $html = Template::print_message( $message, 'warning', false ); | |
| 389 | + | |
| 390 | + return apply_filters( 'learn-press/user/course/html-message-lock', $html, $userCourseModel ); | |
| 391 | + } | |
| 392 | +} | |