| @@ -1,10 +1,14 @@ | ||
| 1 | 1 | <?php |
| 2 | + | |
| 3 | +use LearnPress\Filters\UserItemsFilter; | |
| 4 | +use LearnPress\Models\UserItems\UserCourseModel; | |
| 5 | + | |
| 2 | 6 | /** |
| 3 | 7 | * Class LP_User_Item_Course |
| 4 | 8 | */ |
| 5 | 9 | |
| 6 | -class LP_User_Item_Course extends LP_User_Item implements ArrayAccess { | |
| 10 | +class LP_User_Item_Course extends LP_User_Item { | |
| 7 | 11 | public $_item_type = LP_COURSE_CPT; |
| 8 | 12 | public $_ref_type = LP_ORDER_CPT; |
| 9 | 13 | |
| 10 | 14 | /** |
| @@ -153,10 +157,14 @@ | ||
| 153 | 157 | public function get_course_id() { |
| 154 | 158 | return $this->get_data( 'item_id' ); |
| 155 | 159 | } |
| 156 | 160 | |
| 161 | + /** | |
| 162 | + * @deprecated 4.1.7.3 | |
| 163 | + */ | |
| 157 | 164 | public function get_finishing_type() { |
| 158 | - $type = $this->get_meta( 'finishing_type' ); | |
| 165 | + _deprecated_function( __METHOD__, '4.1.7.3' ); | |
| 166 | + /*$type = $this->get_meta( 'finishing_type' ); | |
| 159 | 167 | |
| 160 | 168 | if ( ! $type ) { |
| 161 | 169 | $type = $this->is_exceeded() <= 0 ? 'exceeded' : 'click'; |
| 162 | 170 | |
| @@ -164,9 +172,9 @@ | ||
| 164 | 172 | |
| 165 | 173 | $this->set_meta( 'finishing_type', $type ); |
| 166 | 174 | } |
| 167 | 175 | |
| 168 | - return $type; | |
| 176 | + return $type;*/ | |
| 169 | 177 | } |
| 170 | 178 | |
| 171 | 179 | public function offsetSet( $offset, $value ) { |
| 172 | 180 | // $this->set_data( $offset, $value ); |
| @@ -190,10 +198,11 @@ | ||
| 190 | 198 | } |
| 191 | 199 | |
| 192 | 200 | /** |
| 193 | 201 | * @return LP_User_Item|bool |
| 202 | + * @deprecated 4.1.6.9.2 | |
| 194 | 203 | */ |
| 195 | - public function get_viewing_item() { | |
| 204 | + /*public function get_viewing_item() { | |
| 196 | 205 | $item = LP_Global::course_item(); |
| 197 | 206 | if ( $item ) { |
| 198 | 207 | return $this[ $item->get_id() ]; |
| 199 | 208 | } |
| @@ -198,17 +207,24 @@ | ||
| 198 | 207 | return $this[ $item->get_id() ]; |
| 199 | 208 | } |
| 200 | 209 | |
| 201 | 210 | return false; |
| 202 | - } | |
| 211 | + }*/ | |
| 203 | 212 | |
| 204 | - public function get_course( $return = '' ) { | |
| 205 | - $cid = $this->get_data( 'item_id' ); | |
| 213 | + /** | |
| 214 | + * Get course. | |
| 215 | + * | |
| 216 | + * @param string $return | |
| 217 | + * | |
| 218 | + * @return bool|LP_Course|int|mixed | |
| 219 | + */ | |
| 220 | + public function get_course( string $return = '' ) { | |
| 221 | + $course_id = $this->get_data( 'item_id', 0 ); | |
| 206 | 222 | if ( $return == '' ) { |
| 207 | - return $cid ? learn_press_get_course( $cid ) : false; | |
| 223 | + return $course_id ? learn_press_get_course( $course_id ) : false; | |
| 208 | 224 | } |
| 209 | 225 | |
| 210 | - return $cid; | |
| 226 | + return $course_id; | |
| 211 | 227 | } |
| 212 | 228 | |
| 213 | 229 | /** |
| 214 | 230 | * Get result/processing course |
| @@ -256,15 +272,9 @@ | ||
| 256 | 272 | 'course-results' |
| 257 | 273 | ); |
| 258 | 274 | |
| 259 | 275 | if ( $results === false ) { |
| 260 | - // $course_result = $course->get_evaluation_results_method(); | |
| 261 | - | |
| 262 | - // $results = LP_User_Items_Result_DB::instance()->get_result( $this->get_user_item_id() ); | |
| 263 | - | |
| 264 | - // if ( is_array( $results ) && array_key_exists( 'result', $results ) ) { | |
| 265 | 276 | $results = $this->calculate_course_results(); |
| 266 | - // } | |
| 267 | 277 | |
| 268 | 278 | LP_Object_Cache::set( |
| 269 | 279 | 'course-' . $this->get_item_id() . '-' . $this->get_user_id(), |
| 270 | 280 | $results, |
| @@ -278,8 +288,31 @@ | ||
| 278 | 288 | /** |
| 279 | 289 | * Calculate course result |
| 280 | 290 | */ |
| 281 | 291 | public function calculate_course_results( bool $force_cache = false ) { |
| 292 | + $results = array( | |
| 293 | + 'count_items' => 0, | |
| 294 | + 'completed_items' => 0, | |
| 295 | + 'items' => array(), | |
| 296 | + 'evaluate_type' => '', | |
| 297 | + 'pass' => 0, | |
| 298 | + 'result' => 0, | |
| 299 | + ); | |
| 300 | + | |
| 301 | + try { | |
| 302 | + $userCourseModel = UserCourseModel::find( $this->get_user_id(), $this->get_course_id(), true ); | |
| 303 | + if ( ! $userCourseModel instanceof UserCourseModel ) { | |
| 304 | + return $results; | |
| 305 | + } | |
| 306 | + | |
| 307 | + $results = $userCourseModel->calculate_course_results(); | |
| 308 | + } catch ( Throwable $e ) { | |
| 309 | + LP_Debug::error_log( $e ); | |
| 310 | + } | |
| 311 | + | |
| 312 | + return $results; | |
| 313 | + | |
| 314 | + // Code old | |
| 282 | 315 | $items = array(); |
| 283 | 316 | $results = array( |
| 284 | 317 | 'count_items' => 0, |
| 285 | 318 | 'completed_items' => 0, |
| @@ -285,8 +318,9 @@ | ||
| 285 | 318 | 'completed_items' => 0, |
| 286 | 319 | 'items' => array(), |
| 287 | 320 | 'evaluate_type' => '', |
| 288 | 321 | 'pass' => 0, |
| 322 | + 'result' => 0, | |
| 289 | 323 | ); |
| 290 | 324 | |
| 291 | 325 | try { |
| 292 | 326 | $course = learn_press_get_course( $this->get_course_id() ); |
| @@ -308,12 +342,19 @@ | ||
| 308 | 342 | // Todo: tungnx - set cache |
| 309 | 343 | return LP_User_Items_Result_DB::instance()->get_result( $this->get_user_item_id() ); |
| 310 | 344 | } |
| 311 | 345 | |
| 346 | + if ( $this->get_status() !== LP_COURSE_ENROLLED ) { | |
| 347 | + return $results; | |
| 348 | + } | |
| 349 | + | |
| 312 | 350 | $count_items = $course->count_items(); |
| 313 | 351 | $count_items_completed = $this->count_items_completed(); |
| 314 | 352 | |
| 315 | - $evaluate_type = $course->get_data( 'course_result', 'evaluate_lesson' ); | |
| 353 | + $evaluate_type = get_post_meta( $course->get_id(), '_lp_course_result', true ); | |
| 354 | + if ( ! $evaluate_type ) { | |
| 355 | + $evaluate_type = 'evaluate_lesson'; | |
| 356 | + } | |
| 316 | 357 | switch ( $evaluate_type ) { |
| 317 | 358 | case 'evaluate_lesson': |
| 318 | 359 | $results_evaluate = $this->evaluate_course_by_lesson( $count_items_completed, $course->count_items( LP_LESSON_CPT ) ); |
| 319 | 360 | break; |
| @@ -328,8 +369,9 @@ | ||
| 328 | 369 | $results_evaluate = $this->evaluate_course_by_question( $evaluate_type ); |
| 329 | 370 | break; |
| 330 | 371 | default: |
| 331 | 372 | $results_evaluate = apply_filters( 'learn-press/evaluate_passed_conditions', $results, $evaluate_type, $this ); |
| 373 | + break; | |
| 332 | 374 | } |
| 333 | 375 | |
| 334 | 376 | if ( ! is_array( $results_evaluate ) ) { |
| 335 | 377 | $results_evaluate = array( |
| @@ -357,15 +399,8 @@ | ||
| 357 | 399 | $results_evaluate, |
| 358 | 400 | compact( 'count_items', 'completed_items', 'items', 'evaluate_type' ) |
| 359 | 401 | ); |
| 360 | 402 | |
| 361 | - /* | |
| 362 | - $graduation = ''; | |
| 363 | - | |
| 364 | - if ( ! $this->is_purchased() ) { | |
| 365 | - $graduation = $this->is_finished() ? $this->_is_passed( $results['result'] ) : 'in-progress'; | |
| 366 | - }*/ | |
| 367 | - | |
| 368 | 403 | $results = apply_filters( |
| 369 | 404 | 'learn-press/update-course-results', |
| 370 | 405 | $results, |
| 371 | 406 | $this->get_item_id(), |
| @@ -374,9 +409,9 @@ | ||
| 374 | 409 | ); |
| 375 | 410 | |
| 376 | 411 | LP_Cache::cache_load_first( 'set', $key_first_cache, $results ); |
| 377 | 412 | } catch ( Throwable $e ) { |
| 378 | - | |
| 413 | + error_log( __METHOD__ . ': ' . $e->getMessage() ); | |
| 379 | 414 | } |
| 380 | 415 | |
| 381 | 416 | return $results; |
| 382 | 417 | } |
| @@ -381,232 +416,16 @@ | ||
| 381 | 416 | return $results; |
| 382 | 417 | } |
| 383 | 418 | |
| 384 | 419 | /** |
| 385 | - * @editor tungnx | |
| 386 | - * @modify 4.1.4.1 - comment - not use | |
| 387 | - */ | |
| 388 | - /* | |
| 389 | - public function count_items() { | |
| 390 | - global $wpdb; | |
| 391 | - $t = microtime( true ); | |
| 392 | - $course = $this->get_course(); | |
| 393 | - $item_ids = $course->get_items(); | |
| 394 | - $item_ids_format = LP_Helper::db_format_array( $item_ids, '%d' ); | |
| 395 | - | |
| 396 | - $query = LP_Helper::prepare( | |
| 397 | - " | |
| 398 | - SELECT MAX(user_item_id) user_item_id | |
| 399 | - FROM {$wpdb->learnpress_user_items} | |
| 400 | - WHERE user_id = %d | |
| 401 | - AND item_id IN (" . $item_ids_format . ') | |
| 402 | - GROUP BY item_id | |
| 403 | - ', | |
| 404 | - $this->get_user_id(), | |
| 405 | - $item_ids | |
| 406 | - ); | |
| 407 | - | |
| 408 | - if ( $user_item_ids = $wpdb->get_col( $query ) ) { | |
| 409 | - | |
| 410 | - $item_types = learn_press_get_course_item_types(); | |
| 411 | - $item_types_format = LP_Helper::db_format_array( $item_types, '%s' ); | |
| 412 | - | |
| 413 | - $query = LP_Helper::prepare( | |
| 414 | - " | |
| 415 | - SELECT ui.*, p.post_type AS item_type, grade.meta_value as grade, data.meta_value as data, results.meta_value as results, version.meta_value as version | |
| 416 | - FROM {$wpdb->learnpress_user_items} ui | |
| 417 | - LEFT JOIN {$wpdb->learnpress_user_itemmeta} grade ON ui.user_item_id = grade.learnpress_user_item_id AND grade.meta_key = '%s' | |
| 418 | - LEFT JOIN {$wpdb->learnpress_user_itemmeta} data ON ui.user_item_id = data.learnpress_user_item_id AND data.meta_key = '%s' | |
| 419 | - LEFT JOIN {$wpdb->learnpress_user_itemmeta} results ON ui.user_item_id = results.learnpress_user_item_id AND results.meta_key = '%s' | |
| 420 | - LEFT JOIN {$wpdb->learnpress_user_itemmeta} version ON ui.user_item_id = version.learnpress_user_item_id AND version.meta_key = '%s' | |
| 421 | - INNER JOIN {$wpdb->posts} p ON p.ID = ui.item_id | |
| 422 | - WHERE user_item_id IN(" . LP_Helper::db_format_array( $user_item_ids ) . ') | |
| 423 | - AND p.post_type IN(' . $item_types_format . ') | |
| 424 | - ', | |
| 425 | - 'grade', | |
| 426 | - 'data', | |
| 427 | - 'results', | |
| 428 | - 'version', | |
| 429 | - $user_item_ids, | |
| 430 | - $item_types | |
| 431 | - ); | |
| 432 | - | |
| 433 | - $user_items = $wpdb->get_results( $query ); | |
| 434 | - $user_items_by_types = array(); | |
| 435 | - | |
| 436 | - if ( $user_items ) { | |
| 437 | - foreach ( $user_items as $k => $user_item ) { | |
| 438 | - $user_items[ $k ]->data = maybe_unserialize( $user_item->data ); | |
| 439 | - $user_items[ $k ]->results = maybe_unserialize( $user_item->results ); | |
| 440 | - | |
| 441 | - if ( empty( $user_items_by_types[ $user_item->item_type ] ) ) { | |
| 442 | - $user_items_by_types[ $user_item->item_type ] = array(); | |
| 443 | - } | |
| 444 | - $user_items_by_types[ $user_item->item_type ][] = $user_item->item_id; | |
| 445 | - } | |
| 446 | - } | |
| 447 | - | |
| 448 | - learn_press_debug( $user_items, $user_items_by_types ); | |
| 449 | - | |
| 450 | - } | |
| 451 | - | |
| 452 | - }*/ | |
| 453 | - | |
| 454 | - /** | |
| 455 | - * Evaluate course results by count quizzes passed/all quizzes. | |
| 456 | - * | |
| 457 | - * @param bool $hard - Optional. TRUE will re-calculate results instead of get from cache | |
| 458 | - * | |
| 459 | - * @return array|mixed | |
| 460 | - * @since 4.0.0 | |
| 461 | - * @author Nhamdv <[email protected]> | |
| 462 | - */ | |
| 463 | - protected function _evaluate_results_by_passed_per_all_quizzes( $hard = false ) { | |
| 464 | - $cache_key = 'user-course-' . $this->get_user_id() . '-' . $this->get_id(); | |
| 465 | - $cache_sub_key = 'passed-per-all-quizzes'; | |
| 466 | - $cached_data = LP_Object_Cache::get( $cache_key, 'learn-press/course-results' ); | |
| 467 | - | |
| 468 | - if ( $hard || false === $cached_data || ! array_key_exists( $cache_sub_key, $cached_data ) ) { | |
| 469 | - $data = array( | |
| 470 | - 'items_completed' => 0, | |
| 471 | - 'items_count' => 0, | |
| 472 | - 'result' => 0, | |
| 473 | - 'status' => $this->get_status(), | |
| 474 | - ); | |
| 475 | - | |
| 476 | - $items = $this->get_items( true ); | |
| 477 | - if ( $items ) { | |
| 478 | - foreach ( $items as $item ) { | |
| 479 | - if ( $item->get_type() !== LP_QUIZ_CPT ) { | |
| 480 | - continue; | |
| 481 | - } | |
| 482 | - | |
| 483 | - $data['items_completed'] += $item->get_status( 'graduation' ) == 'passed' ? 1 : 0; | |
| 484 | - $data['items_count'] ++; | |
| 485 | - } | |
| 486 | - | |
| 487 | - $data['result'] = $data['items_count'] ? ( $data['items_completed'] / $data['items_count'] ) * 100 : 0; | |
| 488 | - } | |
| 489 | - | |
| 490 | - if ( $cached_data ) { | |
| 491 | - $cached_data[ $cache_sub_key ] = $data; | |
| 492 | - } else { | |
| 493 | - $cached_data = array( $cache_sub_key => $data ); | |
| 494 | - } | |
| 495 | - | |
| 496 | - LP_Object_Cache::set( $cache_key, $cached_data, 'learn-press/course-results' ); | |
| 497 | - } | |
| 498 | - | |
| 499 | - return isset( $cached_data[ $cache_sub_key ] ) ? $cached_data[ $cache_sub_key ] : array(); | |
| 500 | - } | |
| 501 | - | |
| 502 | - protected function _evaluate_course_by_question( $hard = false ) { | |
| 503 | - $cache_key = 'user-course-' . $this->get_user_id() . '-' . $this->get_id(); | |
| 504 | - $cached_data = LP_Object_Cache::get( $cache_key, 'learn-press/course-results' ); | |
| 505 | - | |
| 506 | - if ( $hard || false === $cached_data || ! array_key_exists( 'questions', $cached_data ) ) { | |
| 507 | - $data = array( | |
| 508 | - 'result' => 0, | |
| 509 | - 'status' => $this->get_status(), | |
| 510 | - ); | |
| 511 | - | |
| 512 | - $result = 0; | |
| 513 | - $result_of_items = 0; | |
| 514 | - | |
| 515 | - $items = $this->get_items(); | |
| 516 | - | |
| 517 | - if ( $items ) { | |
| 518 | - foreach ( $items as $item ) { | |
| 519 | - if ( $item->get_type() !== LP_QUIZ_CPT ) { | |
| 520 | - continue; | |
| 521 | - } | |
| 522 | - | |
| 523 | - $quiz_result = $item->get_results( '' ); | |
| 524 | - | |
| 525 | - if ( $quiz_result ) { | |
| 526 | - if ( $quiz_result['question_correct'] ) { | |
| 527 | - $result += absint( $quiz_result['question_correct'] ); | |
| 528 | - } | |
| 529 | - } | |
| 530 | - | |
| 531 | - $result_of_items += ! empty( $item->get_questions() ) ? count( $item->get_questions() ) : 0; | |
| 532 | - } | |
| 533 | - | |
| 534 | - $result = $result_of_items ? ( $result * 100 ) / $result_of_items : 0; | |
| 535 | - $data['result'] = $result; | |
| 536 | - } | |
| 537 | - | |
| 538 | - settype( $cached_data, 'array' ); | |
| 539 | - $cached_data['questions'] = $data; | |
| 540 | - | |
| 541 | - LP_Object_Cache::set( $cache_key, $cached_data, 'learn-press/course-results' ); | |
| 542 | - } | |
| 543 | - | |
| 544 | - return isset( $cached_data['questions'] ) ? $cached_data['questions'] : array(); | |
| 545 | - } | |
| 546 | - | |
| 547 | - protected function _evaluate_course_by_mark() { | |
| 548 | - $cache_key = 'user-course-' . $this->get_user_id() . '-' . $this->get_id(); | |
| 549 | - $cached_data = LP_Object_Cache::get( $cache_key, 'learn-press/course-results' ); | |
| 550 | - | |
| 551 | - if ( false === $cached_data || ! array_key_exists( 'marks', $cached_data ) ) { | |
| 552 | - $data = array( | |
| 553 | - 'result' => 0, | |
| 554 | - 'status' => $this->get_status(), | |
| 555 | - ); | |
| 556 | - | |
| 557 | - $result = 0; | |
| 558 | - $result_of_items = 0; | |
| 559 | - | |
| 560 | - $items = $this->get_items(); | |
| 561 | - | |
| 562 | - if ( $items ) { | |
| 563 | - foreach ( $items as $item ) { | |
| 564 | - if ( $item->get_type() !== LP_QUIZ_CPT ) { | |
| 565 | - continue; | |
| 566 | - } | |
| 567 | - | |
| 568 | - $questions = $item->get_questions(); | |
| 569 | - $quiz_result = $item->get_results( '' ); | |
| 570 | - | |
| 571 | - if ( $questions ) { | |
| 572 | - foreach ( $questions as $question_id ) { | |
| 573 | - $question = LP_Question::get_question( $question_id ); | |
| 574 | - | |
| 575 | - if ( $question ) { | |
| 576 | - $result_of_items += absint( $question->get_mark() ); | |
| 577 | - } | |
| 578 | - } | |
| 579 | - } | |
| 580 | - | |
| 581 | - if ( $quiz_result ) { | |
| 582 | - if ( $quiz_result['user_mark'] ) { | |
| 583 | - $result += $quiz_result['user_mark']; | |
| 584 | - } | |
| 585 | - } | |
| 586 | - } | |
| 587 | - | |
| 588 | - $result = $result_of_items ? ( $result * 100 ) / $result_of_items : 0; | |
| 589 | - $data['result'] = $result; | |
| 590 | - } | |
| 591 | - | |
| 592 | - settype( $cached_data, 'array' ); | |
| 593 | - $cached_data['marks'] = $data; | |
| 594 | - | |
| 595 | - LP_Object_Cache::set( $cache_key, $cached_data, 'learn-press/course-results' ); | |
| 596 | - } | |
| 597 | - | |
| 598 | - return isset( $cached_data['marks'] ) ? $cached_data['marks'] : array(); | |
| 599 | - } | |
| 600 | - | |
| 601 | - /** | |
| 602 | 420 | * Get graduation |
| 603 | 421 | * |
| 604 | 422 | * @param string $context |
| 605 | 423 | * |
| 606 | 424 | * @return string |
| 425 | + * @deprecated 4.1.6.9.3 | |
| 607 | 426 | */ |
| 608 | - public function get_grade( string $context = 'display' ): string { | |
| 427 | + public function get_grade( string $context = '' ): string { | |
| 609 | 428 | $grade = $this->get_graduation() ?? ''; |
| 610 | 429 | |
| 611 | 430 | return $context == 'display' ? learn_press_course_grade_html( $grade, false ) : $grade; |
| 612 | 431 | } |
| @@ -611,72 +430,19 @@ | ||
| 611 | 430 | return $context == 'display' ? learn_press_course_grade_html( $grade, false ) : $grade; |
| 612 | 431 | } |
| 613 | 432 | |
| 614 | 433 | /** |
| 615 | - * @return bool | |
| 616 | - */ | |
| 617 | - public function is_passed() { | |
| 618 | - return $this->get_grade() == 'passed'; | |
| 619 | - } | |
| 620 | - | |
| 621 | - /** | |
| 622 | 434 | * @param int $decimal |
| 623 | 435 | * |
| 624 | 436 | * @return int|string |
| 625 | 437 | */ |
| 626 | 438 | public function get_percent_result( $decimal = 1 ) { |
| 627 | - return apply_filters( | |
| 628 | - 'learn-press/user/course-percent-result', | |
| 629 | - sprintf( | |
| 630 | - '%s%%', | |
| 631 | - round( $this->get_results( 'result' ), $decimal ), | |
| 632 | - $this->get_user_id(), | |
| 633 | - $this->get_item_id() | |
| 634 | - ) | |
| 635 | - ); | |
| 439 | + return round( $this->get_result( 'result' ), $decimal ); | |
| 636 | 440 | } |
| 637 | 441 | |
| 638 | 442 | /** |
| 639 | 443 | * Evaluate course result by lessons. |
| 640 | 444 | * |
| 641 | - * @param bool $hard | |
| 642 | - * | |
| 643 | - * @return array | |
| 644 | - */ | |
| 645 | - protected function _evaluate_course_by_lesson( $hard = false ) { | |
| 646 | - $cache_key = 'user-course-' . $this->get_user_id() . '-' . $this->get_id(); | |
| 647 | - $cached_data = LP_Object_Cache::get( $cache_key, 'learn-press/course-results' ); | |
| 648 | - | |
| 649 | - if ( $hard || false === $cached_data || ! array_key_exists( 'lessons', $cached_data ) ) { | |
| 650 | - $completing = $this->get_completed_items( LP_LESSON_CPT, true ); | |
| 651 | - | |
| 652 | - if ( $completing[1] ) { | |
| 653 | - $result = $completing[0] / $completing[1]; | |
| 654 | - } else { | |
| 655 | - $result = 0; | |
| 656 | - } | |
| 657 | - | |
| 658 | - $result *= 100; | |
| 659 | - $data = array( | |
| 660 | - 'result' => $result, | |
| 661 | - 'status' => $this->get_status(), | |
| 662 | - ); | |
| 663 | - | |
| 664 | - if ( $cached_data ) { | |
| 665 | - $cached_data['lessons'] = $data; | |
| 666 | - } else { | |
| 667 | - $cached_data = array( 'lessons' => $data ); | |
| 668 | - } | |
| 669 | - | |
| 670 | - LP_Object_Cache::set( $cache_key, $cached_data, 'learn-press/course-results' ); | |
| 671 | - } | |
| 672 | - | |
| 673 | - return isset( $cached_data['lessons'] ) ? $cached_data['lessons'] : array(); | |
| 674 | - } | |
| 675 | - | |
| 676 | - /** | |
| 677 | - * Evaluate course result by lessons. | |
| 678 | - * | |
| 679 | 445 | * @param $count_items_completed |
| 680 | 446 | * @param int $total_item_lesson |
| 681 | 447 | * |
| 682 | 448 | * @return array |
| @@ -901,9 +667,9 @@ | ||
| 901 | 667 | continue; |
| 902 | 668 | } |
| 903 | 669 | |
| 904 | 670 | if ( $item->type == LP_QUIZ_CPT ) { |
| 905 | - $total_questions += count( $itemObj->get_questions() ); | |
| 671 | + $total_questions += count( $itemObj->get_question_ids() ); | |
| 906 | 672 | $total_mark_question += $itemObj->get_mark(); |
| 907 | 673 | } |
| 908 | 674 | } |
| 909 | 675 | } |
| @@ -928,31 +694,9 @@ | ||
| 928 | 694 | return $evaluate; |
| 929 | 695 | } |
| 930 | 696 | |
| 931 | 697 | /** |
| 932 | - * Finish course for user | |
| 933 | - * | |
| 934 | - * @return int | |
| 935 | - * @depecated 4.1.6.9 | |
| 936 | - */ | |
| 937 | - /*public function finish() { | |
| 938 | - $status = apply_filters( | |
| 939 | - 'learn-press/finish-course-status', | |
| 940 | - 'finished', | |
| 941 | - $this->get_course_id(), | |
| 942 | - $this->get_user(), | |
| 943 | - $this | |
| 944 | - ); | |
| 945 | - | |
| 946 | - // $results = $this->calculate_course_results(); | |
| 947 | - | |
| 948 | - return parent::complete( $status ); | |
| 949 | - }*/ | |
| 950 | - | |
| 951 | - /** | |
| 952 | 698 | * Check course of use has enrolled |
| 953 | - * | |
| 954 | - * @throws Exception | |
| 955 | 699 | */ |
| 956 | 700 | public function is_enrolled(): bool { |
| 957 | 701 | return $this->get_status() == LP_COURSE_ENROLLED; |
| 958 | 702 | } |
| @@ -958,10 +702,8 @@ | ||
| 958 | 702 | } |
| 959 | 703 | |
| 960 | 704 | /** |
| 961 | 705 | * Check course of use has purchased |
| 962 | - * | |
| 963 | - * @throws Exception | |
| 964 | 706 | * @author tungnx |
| 965 | 707 | * @since 4.1.3 |
| 966 | 708 | * @version 1.0.0 |
| 967 | 709 | */ |
| @@ -989,90 +731,11 @@ | ||
| 989 | 731 | return $level; |
| 990 | 732 | } |
| 991 | 733 | |
| 992 | 734 | /** |
| 993 | - * Evaluate course result by final quiz. | |
| 994 | - * | |
| 995 | - * @return array | |
| 735 | + * @deprecated 4.1.6.9.2 | |
| 996 | 736 | */ |
| 997 | - protected function _evaluate_course_by_final_quiz() { | |
| 998 | - $cache_key = 'user-course-' . $this->get_user_id() . '-' . $this->get_id(); | |
| 999 | - $cached_data = LP_Object_Cache::get( $cache_key, 'learn-press/course-results' ); | |
| 1000 | - | |
| 1001 | - if ( false === $cached_data || ! array_key_exists( 'final-quiz', $cached_data ) ) { | |
| 1002 | - $course = $this->get_course(); | |
| 1003 | - $final_quiz = $course->get_final_quiz(); | |
| 1004 | - $user_quiz = $this->get_item( $final_quiz ); | |
| 1005 | - $result = false; | |
| 1006 | - | |
| 1007 | - if ( $user_quiz ) { | |
| 1008 | - $result = $user_quiz->get_results( false ); | |
| 1009 | - } | |
| 1010 | - | |
| 1011 | - $percent = $result ? $result['result'] : 0; | |
| 1012 | - $data = array( | |
| 1013 | - 'result' => $percent, | |
| 1014 | - 'status' => $this->get_status(), | |
| 1015 | - ); | |
| 1016 | - | |
| 1017 | - settype( $cached_data, 'array' ); | |
| 1018 | - $cached_data['final-quiz'] = $data; | |
| 1019 | - | |
| 1020 | - LP_Object_Cache::set( $cache_key, $cached_data, 'learn-press/course-results' ); | |
| 1021 | - } | |
| 1022 | - | |
| 1023 | - return isset( $cached_data['final-quiz'] ) ? $cached_data['final-quiz'] : array(); | |
| 1024 | - } | |
| 1025 | - | |
| 1026 | - /** | |
| 1027 | - * Evaluate course result by point of quizzes doing/done per total quizzes. | |
| 1028 | - * | |
| 1029 | - * @return array | |
| 1030 | - * @editor tungnx | |
| 1031 | - * @modify 4.1.3 - comment - not use | |
| 1032 | - */ | |
| 1033 | - /* | |
| 1034 | - protected function _evaluate_course_by_quizzes() { | |
| 1035 | - $cache_key = 'user-course-' . $this->get_user_id() . '-' . $this->get_id(); | |
| 1036 | - $cached_data = LP_Object_Cache::get( $cache_key, 'learn-press/course-results' ); | |
| 1037 | - | |
| 1038 | - if ( ( false === $cached_data ) || ! array_key_exists( 'quizzes', $cached_data ) ) { | |
| 1039 | - $data = array( | |
| 1040 | - 'result' => 0, | |
| 1041 | - 'status' => $this->get_status(), | |
| 1042 | - ); | |
| 1043 | - | |
| 1044 | - $result = 0; | |
| 1045 | - $result_of_items = 0; | |
| 1046 | - | |
| 1047 | - $items = $this->get_items(); | |
| 1048 | - | |
| 1049 | - if ( $items ) { | |
| 1050 | - foreach ( $items as $item ) { | |
| 1051 | - if ( $item->get_type() !== LP_QUIZ_CPT ) { | |
| 1052 | - continue; | |
| 1053 | - } | |
| 1054 | - | |
| 1055 | - if ( $item->get_quiz()->get_data( 'passing_grade' ) ) { | |
| 1056 | - $result += $item->get_results( 'result' ); | |
| 1057 | - $result_of_items ++; | |
| 1058 | - } | |
| 1059 | - } | |
| 1060 | - | |
| 1061 | - $result = $result_of_items ? $result / $result_of_items : 0; | |
| 1062 | - $data['result'] = $result; | |
| 1063 | - } | |
| 1064 | - | |
| 1065 | - settype( $cached_data, 'array' ); | |
| 1066 | - $cached_data['quizzes'] = $data; | |
| 1067 | - | |
| 1068 | - LP_Object_Cache::set( $cache_key, $cached_data, 'learn-press/course-results' ); | |
| 1069 | - } | |
| 1070 | - | |
| 1071 | - return isset( $cached_data['quizzes'] ) ? $cached_data['quizzes'] : array(); | |
| 1072 | - }*/ | |
| 1073 | - | |
| 1074 | - protected function _is_passed( $result ) { | |
| 737 | + /*protected function _is_passed( $result ) { | |
| 1075 | 738 | $is_passed = LP_COURSE_GRADUATION_FAILED; |
| 1076 | 739 | $result = round( $result, 2 ); |
| 1077 | 740 | |
| 1078 | 741 | if ( $result >= $this->get_passing_condition() ) { |
| @@ -1079,9 +742,9 @@ | ||
| 1079 | 742 | $is_passed = LP_COURSE_GRADUATION_PASSED; |
| 1080 | 743 | } |
| 1081 | 744 | |
| 1082 | 745 | return apply_filters( 'learnpress/user/course/is-passed', $is_passed, $result ); |
| 1083 | - } | |
| 746 | + }*/ | |
| 1084 | 747 | |
| 1085 | 748 | /** |
| 1086 | 749 | * Get completed items. |
| 1087 | 750 | * |
| @@ -1099,9 +762,9 @@ | ||
| 1099 | 762 | // $completed_items = array(0,100); |
| 1100 | 763 | // return $with_total ? $completed_items : $completed_items[0]; |
| 1101 | 764 | |
| 1102 | 765 | if ( ! $this->_course ) { |
| 1103 | - return; | |
| 766 | + return 0; | |
| 1104 | 767 | } |
| 1105 | 768 | |
| 1106 | 769 | $key = sprintf( |
| 1107 | 770 | '%d-%d-%s', |
| @@ -1144,9 +807,9 @@ | ||
| 1144 | 807 | } |
| 1145 | 808 | |
| 1146 | 809 | if ( $type === $item_type ) { |
| 1147 | 810 | if ( $item->get_status() == 'completed' ) { |
| 1148 | - $completed ++; | |
| 811 | + ++$completed; | |
| 1149 | 812 | } |
| 1150 | 813 | $completed = apply_filters( |
| 1151 | 814 | 'learn-press/course-item/completed', |
| 1152 | 815 | $completed, |
| @@ -1153,9 +816,9 @@ | ||
| 1153 | 816 | $item, |
| 1154 | 817 | $item->get_status() |
| 1155 | 818 | ); |
| 1156 | 819 | // if ( ! $item->is_preview() ) { |
| 1157 | - $total ++; | |
| 820 | + ++$total; | |
| 1158 | 821 | // } |
| 1159 | 822 | } |
| 1160 | 823 | } |
| 1161 | 824 | } |
| @@ -1180,17 +843,15 @@ | ||
| 1180 | 843 | $count_items_completed = new stdClass(); |
| 1181 | 844 | |
| 1182 | 845 | try { |
| 1183 | 846 | $course = learn_press_get_course( $this->get_course_id() ); |
| 1184 | - | |
| 1185 | 847 | if ( ! $course ) { |
| 1186 | - throw new Exception( __FUNCTION__ . ': Course is invalid!' ); | |
| 848 | + throw new Exception( 'Course is invalid!' ); | |
| 1187 | 849 | } |
| 1188 | 850 | |
| 1189 | 851 | $user_course = $this->get_last_user_course(); |
| 1190 | - | |
| 1191 | 852 | if ( ! $user_course ) { |
| 1192 | - throw new Exception(); | |
| 853 | + throw new Exception( 'User course is invalid!' ); | |
| 1193 | 854 | } |
| 1194 | 855 | |
| 1195 | 856 | $filter_count = new LP_User_Items_Filter(); |
| 1196 | 857 | $filter_count->parent_id = $user_course->user_item_id; |
| @@ -1199,9 +860,9 @@ | ||
| 1199 | 860 | $filter_count->status = 'completed'; |
| 1200 | 861 | $filter_count->graduation = LP_COURSE_GRADUATION_PASSED; |
| 1201 | 862 | $count_items_completed = $lp_user_items_db->count_items_of_course_with_status( $filter_count ); |
| 1202 | 863 | } catch ( Throwable $e ) { |
| 1203 | - | |
| 864 | + error_log( __METHOD__ . ': ' . $e->getMessage() ); | |
| 1204 | 865 | } |
| 1205 | 866 | |
| 1206 | 867 | return $count_items_completed; |
| 1207 | 868 | } |
| @@ -1252,9 +913,8 @@ | ||
| 1252 | 913 | /** |
| 1253 | 914 | * Check course is completed or not. |
| 1254 | 915 | * |
| 1255 | 916 | * @return bool |
| 1256 | - * @throws Exception | |
| 1257 | 917 | * @editor tungnx |
| 1258 | 918 | * @modify 4.1.3 |
| 1259 | 919 | */ |
| 1260 | 920 | public function is_finished(): bool { |
| @@ -1271,12 +931,13 @@ | ||
| 1271 | 931 | } |
| 1272 | 932 | |
| 1273 | 933 | /** |
| 1274 | 934 | * @return bool |
| 935 | + * @deprecated 4.1.6.9.2 | |
| 1275 | 936 | */ |
| 1276 | - public function can_graduated() { | |
| 937 | + /*public function can_graduated() { | |
| 1277 | 938 | return $this->get_results( 'result' ) >= $this->get_passing_condition(); |
| 1278 | - } | |
| 939 | + }*/ | |
| 1279 | 940 | |
| 1280 | 941 | function __destruct() { |
| 1281 | 942 | // TODO: Implement __unset() method. |
| 1282 | 943 | } |
| @@ -1281,47 +942,10 @@ | ||
| 1281 | 942 | // TODO: Implement __unset() method. |
| 1282 | 943 | } |
| 1283 | 944 | |
| 1284 | 945 | /** |
| 1285 | - * @depecated 4.1.6.9 | |
| 1286 | - */ | |
| 1287 | - /*public function count_history_items( $item_id ) { | |
| 1288 | - | |
| 1289 | - if ( false === ( $history = LP_Object_Cache::get( | |
| 1290 | - 'course-' . $this->get_item_id() . '-' . $this->get_user_id(), | |
| 1291 | - 'learn-press/items-history' | |
| 1292 | - ) ) ) { | |
| 1293 | - global $wpdb; | |
| 1294 | - $query = $wpdb->prepare( | |
| 1295 | - " | |
| 1296 | - SELECT item_id, COUNT(user_item_id) `count` | |
| 1297 | - FROM {$wpdb->learnpress_user_items} | |
| 1298 | - WHERE user_id = %d | |
| 1299 | - AND parent_id = %d | |
| 1300 | - GROUP BY item_id | |
| 1301 | - ", | |
| 1302 | - $this->get_user_id(), | |
| 1303 | - $this->get_user_item_id() | |
| 1304 | - ); | |
| 1305 | - | |
| 1306 | - $history = array(); | |
| 1307 | - if ( $results = $wpdb->get_results( $query ) ) { | |
| 1308 | - foreach ( $results as $result ) { | |
| 1309 | - $history[ $result->item_id ] = $result->count; | |
| 1310 | - } | |
| 1311 | - } | |
| 1312 | - | |
| 1313 | - LP_Object_Cache::set( | |
| 1314 | - 'course-' . $this->get_item_id() . '-' . $this->get_user_id(), | |
| 1315 | - $history, | |
| 1316 | - 'learn-press/items-history' | |
| 1317 | - ); | |
| 1318 | - } | |
| 1319 | - | |
| 1320 | - return isset( $history[ $item_id ] ) ? $history[ $item_id ] : 0; | |
| 1321 | - }*/ | |
| 1322 | - | |
| 1323 | - /** | |
| 946 | + * Get item user attend on course by item_id. | |
| 947 | + * | |
| 1324 | 948 | * @param int $item_id |
| 1325 | 949 | * |
| 1326 | 950 | * @return bool|LP_User_Item |
| 1327 | 951 | * @editor tungnx |
| @@ -1350,67 +974,8 @@ | ||
| 1350 | 974 | return $item; |
| 1351 | 975 | } |
| 1352 | 976 | |
| 1353 | 977 | /** |
| 1354 | - * @param int $user_item_id | |
| 1355 | - * | |
| 1356 | - * @return LP_User_Item|LP_User_Item_Quiz|bool | |
| 1357 | - */ | |
| 1358 | - /* | |
| 1359 | - public function get_item_by_user_item_id( $user_item_id ) { | |
| 1360 | - $this->read_items(); | |
| 1361 | - | |
| 1362 | - if ( ! empty( $this->_items_by_item_ids[ $user_item_id ] ) ) { | |
| 1363 | - $item_id = $this->_items_by_item_ids[ $user_item_id ]; | |
| 1364 | - | |
| 1365 | - return $this->get_item( $item_id ); | |
| 1366 | - } | |
| 1367 | - | |
| 1368 | - return false; | |
| 1369 | - }*/ | |
| 1370 | - | |
| 1371 | - /** | |
| 1372 | - * @param $item | |
| 1373 | - * | |
| 1374 | - * @return bool|LP_User_Item | |
| 1375 | - * @depecated 4.1.6.9 | |
| 1376 | - */ | |
| 1377 | - /*public function set_item( $item ) { | |
| 1378 | - if ( $item = LP_User_Item::get_item_object( $item ) ) { | |
| 1379 | - $this->cache_set_item( $item ); | |
| 1380 | - } | |
| 1381 | - | |
| 1382 | - return $item; | |
| 1383 | - }*/ | |
| 1384 | - | |
| 1385 | - /** | |
| 1386 | - * @param LP_User_Item $item | |
| 1387 | - * @depecated 4.1.6.9 | |
| 1388 | - */ | |
| 1389 | - /*public function cache_set_item( $item ) { | |
| 1390 | - $items = $this->read_items(); | |
| 1391 | - if ( ! $items ) { | |
| 1392 | - $items = array(); | |
| 1393 | - } | |
| 1394 | - $items[ $item->get_item_id() ] = $item; | |
| 1395 | - LP_Object_Cache::set( | |
| 1396 | - $this->get_user_id() . '-' . $this->get_id(), | |
| 1397 | - $items, | |
| 1398 | - 'learn-press/user-course-item-objects' | |
| 1399 | - ); | |
| 1400 | - }*/ | |
| 1401 | - | |
| 1402 | - /** | |
| 1403 | - * @depecated 4.1.6.9 | |
| 1404 | - */ | |
| 1405 | - /*public function cache_get_items() { | |
| 1406 | - return LP_Object_Cache::get( | |
| 1407 | - $this->get_user_id() . '-' . $this->get_id(), | |
| 1408 | - 'learn-press/user-course-item-objects' | |
| 1409 | - ); | |
| 1410 | - }*/ | |
| 1411 | - | |
| 1412 | - /** | |
| 1413 | 978 | * @param $item_id |
| 1414 | 979 | * @param string $prop |
| 1415 | 980 | * |
| 1416 | 981 | * @return bool|float|int |
| @@ -1431,27 +996,8 @@ | ||
| 1431 | 996 | return false; |
| 1432 | 997 | } |
| 1433 | 998 | |
| 1434 | 999 | /** |
| 1435 | - * @param int $at | |
| 1436 | - * | |
| 1437 | - * @return LP_User_Item_Course | |
| 1438 | - * @editor tungnx | |
| 1439 | - * @modify 4.1.3 - comment - not use | |
| 1440 | - */ | |
| 1441 | - /* | |
| 1442 | - public function get_item_at( $at = 0 ) { | |
| 1443 | - $items = $this->read_items(); | |
| 1444 | - $item_id = ! empty( $this->_items_by_order[ $at ] ) ? $this->_items_by_order[ $at ] : 0; | |
| 1445 | - if ( ! $item_id && $items ) { | |
| 1446 | - $items = array_values( $items ); | |
| 1447 | - $item_id = $items[ $at ]->get_id(); | |
| 1448 | - } | |
| 1449 | - | |
| 1450 | - return $this->offsetGet( $item_id ); | |
| 1451 | - }*/ | |
| 1452 | - | |
| 1453 | - /** | |
| 1454 | 1000 | * @param $id |
| 1455 | 1001 | * |
| 1456 | 1002 | * @return LP_User_Item_Quiz|bool |
| 1457 | 1003 | */ |
| @@ -1460,64 +1006,8 @@ | ||
| 1460 | 1006 | return $this->get_item( $id ); |
| 1461 | 1007 | } |
| 1462 | 1008 | |
| 1463 | 1009 | /** |
| 1464 | - * Get js settings of course. | |
| 1465 | - * | |
| 1466 | - * @return array | |
| 1467 | - * @depecated 4.1.6.9 | |
| 1468 | - */ | |
| 1469 | - /*public function get_js_args() { | |
| 1470 | - $js_args = false; | |
| 1471 | - $course = $this->get_course(); | |
| 1472 | - | |
| 1473 | - if ( $course ) { | |
| 1474 | - $item = false; | |
| 1475 | - $js_args = array( | |
| 1476 | - 'root_url' => trailingslashit( get_home_url() ), | |
| 1477 | - 'id' => $course->get_id(), | |
| 1478 | - 'url' => $course->get_permalink(), | |
| 1479 | - 'result' => $this->get_results(), | |
| 1480 | - 'current_item' => $item ? $item->get_id() : false, | |
| 1481 | - //'items' => $this->get_items_for_js(), | |
| 1482 | - ); | |
| 1483 | - } | |
| 1484 | - | |
| 1485 | - return apply_filters( 'learn-press/course/single-params', $js_args, $this->get_id() ); | |
| 1486 | - }*/ | |
| 1487 | - | |
| 1488 | - /** | |
| 1489 | - * @depecated 4.1.6.9 | |
| 1490 | - */ | |
| 1491 | - /*public function update_item_retaken_count( $item_id, $count = 0 ) { | |
| 1492 | - $items = $this->get_meta( '_retaken_items' ); | |
| 1493 | - if ( is_string( $count ) && preg_match( '#^(\+|\-)([0-9]+)#', $count, $m ) ) { | |
| 1494 | - $last_count = ! empty( $items[ $item_id ] ) ? $items[ $item_id ] : 0; | |
| 1495 | - $count = $m[1] == '+' ? ( $last_count + $m[2] ) : ( $last_count - $m[2] ); | |
| 1496 | - } | |
| 1497 | - | |
| 1498 | - $items[ $item_id ] = $count; | |
| 1499 | - | |
| 1500 | - learn_press_update_user_item_meta( $this->get_user_item_id(), '_retaken_items', $items ); | |
| 1501 | - | |
| 1502 | - return $count; | |
| 1503 | - }*/ | |
| 1504 | - | |
| 1505 | - /** | |
| 1506 | - * @depecated 4.1.6.9 | |
| 1507 | - */ | |
| 1508 | - /*public function get_item_retaken_count( $item_id ) { | |
| 1509 | - $items = $this->get_meta( '_retaken_items' ); | |
| 1510 | - $count = false; | |
| 1511 | - | |
| 1512 | - if ( is_array( $items ) && array_key_exists( $item_id, $items ) ) { | |
| 1513 | - $count = absint( $items[ $item_id ] ); | |
| 1514 | - } | |
| 1515 | - | |
| 1516 | - return $count; | |
| 1517 | - }*/ | |
| 1518 | - | |
| 1519 | - /** | |
| 1520 | 1010 | * Get number of retaken times for user course. |
| 1521 | 1011 | * |
| 1522 | 1012 | * @return int |
| 1523 | 1013 | */ |
| @@ -1531,43 +1021,21 @@ | ||
| 1531 | 1021 | * @return bool|int |
| 1532 | 1022 | */ |
| 1533 | 1023 | public function increase_retake_count() { |
| 1534 | 1024 | $count = $this->get_retaken_count(); |
| 1535 | - $count ++; | |
| 1025 | + ++$count; | |
| 1536 | 1026 | |
| 1537 | 1027 | return $this->update_meta( '_lp_retaken_count', $count ); |
| 1538 | 1028 | } |
| 1539 | 1029 | |
| 1540 | 1030 | /** |
| 1541 | - * Get js settings of course items. | |
| 1542 | - * | |
| 1543 | - * @return array | |
| 1544 | - * @editor tungnx | |
| 1545 | - * @modify 4.1.4.1 - comment - not use | |
| 1546 | - */ | |
| 1547 | - // public function get_items_for_js() { | |
| 1548 | - // | |
| 1549 | - // *** TEST CACHE */ | |
| 1550 | - // return false; | |
| 1551 | - // $args = array(); | |
| 1552 | - // if ( $items = $this->get_items() ) { | |
| 1553 | - // $user = $this->get_user(); | |
| 1554 | - // $course = $this->get_course(); | |
| 1555 | - // foreach ( $items as $item ) { | |
| 1556 | - // | |
| 1557 | - // $args[ $item->get_id() ] = $item->get_js_args();// $item_js; | |
| 1558 | - // } | |
| 1559 | - // } | |
| 1560 | - // | |
| 1561 | - // return apply_filters( 'learn-press/course/items-for-js', $args, $this->get_id(), $this->get_user_id() ); | |
| 1562 | - // } | |
| 1563 | - | |
| 1564 | - /** | |
| 1565 | 1031 | * Update course item and it's child. |
| 1566 | 1032 | * |
| 1567 | 1033 | * @TODO: tungnx - review to modify |
| 1034 | + * @deprecated 4.1.7.3 | |
| 1568 | 1035 | */ |
| 1569 | 1036 | public function save() { |
| 1037 | + _deprecated_function( __METHOD__, '4.1.7.3' ); | |
| 1570 | 1038 | /** |
| 1571 | 1039 | * @var LP_User_Item $item |
| 1572 | 1040 | */ |
| 1573 | 1041 | $this->update(); |
| @@ -1576,18 +1044,16 @@ | ||
| 1576 | 1044 | return false; |
| 1577 | 1045 | } |
| 1578 | 1046 | |
| 1579 | 1047 | foreach ( $items as $item_id => $item ) { |
| 1580 | - | |
| 1581 | 1048 | if ( ! $item->get_status() ) { |
| 1582 | 1049 | continue; |
| 1583 | 1050 | } |
| 1584 | 1051 | |
| 1585 | 1052 | /** |
| 1586 | - * Auto fill the end-time if it isn't already set | |
| 1053 | + * Autofill the end-time if it isn't already set | |
| 1587 | 1054 | */ |
| 1588 | 1055 | if ( in_array( $item->get_status(), array( 'completed', 'finished' ) ) ) { |
| 1589 | - | |
| 1590 | 1056 | if ( ! $item->get_end_time() || $item->get_end_time()->is_null() ) { |
| 1591 | 1057 | $item->set_end_time( current_time( 'mysql', 1 ) ); |
| 1592 | 1058 | } |
| 1593 | 1059 | } |
| @@ -1605,9 +1071,9 @@ | ||
| 1605 | 1071 | * @param bool $with_total - Optional. Include total if TRUE |
| 1606 | 1072 | * @param int $section_id - Optional. Get in specific section |
| 1607 | 1073 | * |
| 1608 | 1074 | * @return array|bool|mixed |
| 1609 | - * @depecated 4.1.6.9 | |
| 1075 | + * @deprecated 4.1.6.9 | |
| 1610 | 1076 | */ |
| 1611 | 1077 | public function get_passed_items( $type = '', $with_total = false, $section_id = 0 ) { |
| 1612 | 1078 | _deprecated_function( __FUNCTION__, '4.1.6.9' ); |
| 1613 | 1079 | $this->read_items(); |
| @@ -1651,9 +1117,9 @@ | ||
| 1651 | 1117 | } |
| 1652 | 1118 | |
| 1653 | 1119 | if ( $type === $item_type ) { |
| 1654 | 1120 | if ( $item->get_status( 'graduation' ) == 'passed' ) { |
| 1655 | - $passed ++; | |
| 1121 | + ++$passed; | |
| 1656 | 1122 | } |
| 1657 | 1123 | $passed = apply_filters( |
| 1658 | 1124 | 'learn-press/course-item/passed', |
| 1659 | 1125 | $passed, |
| @@ -1660,9 +1126,9 @@ | ||
| 1660 | 1126 | $item, |
| 1661 | 1127 | $item->get_status() |
| 1662 | 1128 | ); |
| 1663 | 1129 | // if ( ! $item->is_preview() ) { |
| 1664 | - $total ++; | |
| 1130 | + ++$total; | |
| 1665 | 1131 | // } |
| 1666 | 1132 | } |
| 1667 | 1133 | } |
| 1668 | 1134 | } |
| @@ -1726,14 +1192,14 @@ | ||
| 1726 | 1192 | |
| 1727 | 1193 | /** |
| 1728 | 1194 | * Get courses only by course's user are learning |
| 1729 | 1195 | * |
| 1730 | - * @param LP_User_Items_Filter $filter | |
| 1196 | + * @param LP_User_Items_Filter|UserItemsFilter $filter | |
| 1731 | 1197 | * @param int $total_rows return total row query |
| 1732 | 1198 | * |
| 1733 | 1199 | * @return array|null|int|string |
| 1734 | 1200 | */ |
| 1735 | - public static function get_user_courses( LP_User_Items_Filter $filter, int &$total_rows = 0 ) { | |
| 1201 | + public static function get_user_courses( $filter, int &$total_rows = 0 ) { | |
| 1736 | 1202 | try { |
| 1737 | 1203 | /*$key_cache = md5( json_encode( $filter ) ); |
| 1738 | 1204 | $courses_cache = LP_Cache::instance()->get_cache( $key_cache ); |
| 1739 | 1205 | |
| @@ -1748,10 +1214,6 @@ | ||
| 1748 | 1214 | error_log( __FUNCTION__ . ': ' . $e->getMessage() ); |
| 1749 | 1215 | } |
| 1750 | 1216 | |
| 1751 | 1217 | return $courses; |
| 1752 | - } | |
| 1753 | - | |
| 1754 | - public function get_total_users_learn_course( LP_User_Items_Filter $filter ) { | |
| 1755 | - | |
| 1756 | 1218 | } |
| 1757 | 1219 | } |