Skip to content

Commit

Permalink
add: fix error course API
Browse files Browse the repository at this point in the history
  • Loading branch information
daonham committed Dec 10, 2021
1 parent af5f860 commit 6537445
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions inc/jwt/rest-api/version1/class-lp-rest-courses-v1-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,18 @@ protected function get_course_data( $course, $context = 'view' ) {
}

public function get_retaken_count( $id ) {
$user = learn_press_get_current_user();
$user_id = get_current_user_id();

if ( ! $user_id ) {
return 0;
}

$user = learn_press_get_user( $user_id );

if ( ! $user ) {
return 0;
}

$user_course_data = $user->get_course_data( $id );

if ( ! $user_course_data ) {
Expand All @@ -443,7 +454,13 @@ public function get_retaken_count( $id ) {
}

public function check_can_retake( $id ) {
$user = learn_press_get_current_user();
$user_id = get_current_user_id();

if ( ! $user_id ) {
return 0;
}

$user = learn_press_get_user( $user_id );

if ( $user ) {
$can_retake_times = $user->can_retry_course( $id );
Expand All @@ -469,7 +486,13 @@ public function get_course_rating( $id ) {
}

public function check_can_finish( $course ) {
$user = learn_press_get_current_user();
$user_id = get_current_user_id();

if ( ! $user_id ) {
return false;
}

$user = learn_press_get_user( $user_id );

if ( $user && $course ) {
$check = $user->can_show_finish_course_btn( $course );
Expand Down Expand Up @@ -673,13 +696,20 @@ public function get_all_items( $course ): array {
}

public function get_course_meta( $id ) {
$user_id = get_current_user_id();

if ( ! $user_id ) {
return array();
}

if ( ! class_exists( 'LP_Meta_Box_Course' ) ) {
include_once LP_PLUGIN_PATH . 'inc/admin/views/meta-boxes/course/settings.php';
}

$metabox = new LP_Meta_Box_Course();

$output = array();

foreach ( $metabox->metabox( $id ) as $key => $tab ) {
if ( isset( $tab['content'] ) ) {
foreach ( $tab['content'] as $meta_key => $object ) {
Expand Down

0 comments on commit 6537445

Please sign in to comment.