Skip to content

Commit c00c744

Browse files
committed
Replace function from utils to course model
1 parent 2b9662d commit c00c744

File tree

2 files changed

+114
-105
lines changed

2 files changed

+114
-105
lines changed

classes/Utils.php

Lines changed: 0 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -10897,109 +10897,4 @@ public function render_template( $template, $data, $once = true ) {
1089710897

1089810898
return (string) ob_get_clean();
1089910899
}
10900-
10901-
/**
10902-
* Get topic-wise progress data for a course and a student.
10903-
*
10904-
* @since 4.0.0
10905-
*
10906-
* @param int $course_id Course ID.
10907-
* @param int $student_id Student ID.
10908-
*
10909-
* @return array[] Topic progress data.
10910-
*/
10911-
public function get_topic_progress_by_course_id( $course_id, $student_id ) {
10912-
10913-
$topics_query = $this->get_topics( $course_id );
10914-
10915-
$topic_list = array();
10916-
10917-
if ( empty( $topics_query ) || ! $topics_query->have_posts() ) {
10918-
return $topic_list;
10919-
}
10920-
10921-
foreach ( $topics_query->posts as $topic_post ) {
10922-
$topic_id = (int) $topic_post->ID;
10923-
10924-
$topic = array(
10925-
'topic_id' => $topic_id,
10926-
'topic_summary' => apply_filters( 'the_content', $topic_post->post_content ),
10927-
'topic_title' => get_the_title( $topic_id ),
10928-
'items' => array(),
10929-
'topic_completed' => true,
10930-
'topic_started' => false,
10931-
);
10932-
10933-
$contents_query = tutor_utils()->get_course_contents_by_topic( $topic_id, -1 );
10934-
10935-
if ( ! empty( $contents_query ) && $contents_query->have_posts() ) {
10936-
foreach ( $contents_query->posts as $content_post ) {
10937-
$post_id = (int) $content_post->ID;
10938-
$post_type = $content_post->post_type;
10939-
$is_completed = true;
10940-
10941-
if ( 'tutor_quiz' === $post_type ) {
10942-
10943-
$is_completed = (bool) tutor_utils()->has_attempted_quiz( $student_id, $post_id );
10944-
10945-
$topic['items'][] = array(
10946-
'type' => 'quiz',
10947-
'id' => $post_id,
10948-
'link' => esc_url( get_permalink( $post_id ) ),
10949-
'title' => $content_post->post_title,
10950-
'is_completed' => $is_completed,
10951-
'time_limit' => tutor_utils()->get_quiz_option( $post_id, 'time_limit.time_value' ),
10952-
'time_type' => tutor_utils()->get_quiz_option( $post_id, 'time_limit.time_type' ),
10953-
);
10954-
10955-
} elseif ( 'tutor_assignments' === $post_type ) {
10956-
10957-
$submitted_count = (int) tutor_utils()->get_submitted_assignment_count( $post_id, $student_id );
10958-
$is_completed = $submitted_count > 0;
10959-
10960-
$topic['items'][] = array(
10961-
'type' => 'assignment',
10962-
'id' => $post_id,
10963-
'link' => esc_url( get_permalink( $post_id ) ),
10964-
'title' => $content_post->post_title,
10965-
'is_completed' => $is_completed,
10966-
);
10967-
10968-
} elseif ( 'tutor_zoom_meeting' === $post_type ) { // @todo Need to add more information.
10969-
$topic['items'][] = array(
10970-
'type' => 'zoom_meeting',
10971-
'id' => $post_id,
10972-
'link' => esc_url( get_permalink( $post_id ) ),
10973-
);
10974-
10975-
} else {
10976-
$video = tutor_utils()->get_video_info( $post_id );
10977-
$is_completed = (bool) tutor_utils()->is_completed_lesson( $post_id, $student_id );
10978-
10979-
$topic['items'][] = array(
10980-
'type' => 'lesson',
10981-
'id' => $post_id,
10982-
'link' => esc_url( get_permalink( $post_id ) ),
10983-
'title' => $content_post->post_title,
10984-
'video' => $video,
10985-
'video_play_time' => isset( $video->playtime ) ? $video->playtime : '',
10986-
'is_completed' => $is_completed,
10987-
);
10988-
}
10989-
10990-
if ( ! $is_completed ) {
10991-
$topic['topic_completed'] = false;
10992-
} else {
10993-
$topic['topic_started'] = true;
10994-
}
10995-
}
10996-
}
10997-
10998-
$topic_list[] = $topic;
10999-
}
11000-
11001-
wp_reset_postdata();
11002-
11003-
return $topic_list;
11004-
}
1100510900
}

models/CourseModel.php

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,4 +1411,118 @@ function ( int $post_id ) use ( $start_date, $end_date ): bool {
14111411

14121412
return count( $filtered );
14131413
}
1414+
1415+
/**
1416+
* Get topic-wise progress data for a course and a student.
1417+
*
1418+
* @since 4.0.0
1419+
*
1420+
* @param int $course_id Course ID.
1421+
* @param int $student_id Student ID.
1422+
*
1423+
* @return array[] Topic progress data.
1424+
*/
1425+
public static function get_topic_progress_by_course_id( $course_id, $student_id ) {
1426+
1427+
$topics_query = tutor_utils()->get_topics( $course_id );
1428+
1429+
$topic_list = array();
1430+
1431+
if ( empty( $topics_query ) || ! $topics_query->have_posts() ) {
1432+
return $topic_list;
1433+
}
1434+
1435+
foreach ( $topics_query->posts as $topic_post ) {
1436+
$topic_id = (int) $topic_post->ID;
1437+
1438+
$topic = array(
1439+
'topic_id' => $topic_id,
1440+
'topic_summary' => apply_filters( 'the_content', $topic_post->post_content ),
1441+
'topic_title' => get_the_title( $topic_id ),
1442+
'items' => array(),
1443+
'topic_completed' => true,
1444+
'topic_started' => false,
1445+
);
1446+
1447+
$contents_query = tutor_utils()->get_course_contents_by_topic( $topic_id, -1 );
1448+
1449+
if ( ! empty( $contents_query ) && $contents_query->have_posts() ) {
1450+
foreach ( $contents_query->posts as $content_post ) {
1451+
$post_id = (int) $content_post->ID;
1452+
$post_type = $content_post->post_type;
1453+
$is_completed = true;
1454+
1455+
if ( 'tutor_quiz' === $post_type ) {
1456+
1457+
$is_completed = (bool) tutor_utils()->has_attempted_quiz( $student_id, $post_id );
1458+
1459+
$topic['items'][] = array(
1460+
'type' => 'quiz',
1461+
'id' => $post_id,
1462+
'link' => esc_url( get_permalink( $post_id ) ),
1463+
'title' => $content_post->post_title,
1464+
'is_completed' => $is_completed,
1465+
'time_limit' => tutor_utils()->get_quiz_option( $post_id, 'time_limit.time_value' ),
1466+
'time_type' => tutor_utils()->get_quiz_option( $post_id, 'time_limit.time_type' ),
1467+
);
1468+
1469+
} elseif ( 'tutor_assignments' === $post_type ) {
1470+
1471+
$submitted_count = (int) tutor_utils()->get_submitted_assignment_count( $post_id, $student_id );
1472+
$is_completed = $submitted_count > 0;
1473+
1474+
$topic['items'][] = array(
1475+
'type' => 'assignment',
1476+
'id' => $post_id,
1477+
'link' => esc_url( get_permalink( $post_id ) ),
1478+
'title' => $content_post->post_title,
1479+
'is_completed' => $is_completed,
1480+
);
1481+
1482+
} elseif ( tutor()->zoom_post_type === $post_type ) {
1483+
$topic['items'][] = array(
1484+
'type' => 'zoom_meeting',
1485+
'id' => $post_id,
1486+
'title' => $content_post->post_title,
1487+
'link' => esc_url( get_permalink( $post_id ) ),
1488+
);
1489+
1490+
} elseif ( tutor()->meet_post_type === $post_type ) {
1491+
$topic['items'][] = array(
1492+
'type' => 'google_meet',
1493+
'id' => $post_id,
1494+
'title' => $content_post->post_title,
1495+
'link' => esc_url( get_permalink( $post_id ) ),
1496+
);
1497+
1498+
} else {
1499+
$video = tutor_utils()->get_video_info( $post_id );
1500+
$is_completed = (bool) tutor_utils()->is_completed_lesson( $post_id, $student_id );
1501+
1502+
$topic['items'][] = array(
1503+
'type' => 'lesson',
1504+
'id' => $post_id,
1505+
'link' => esc_url( get_permalink( $post_id ) ),
1506+
'title' => $content_post->post_title,
1507+
'video' => $video,
1508+
'video_play_time' => isset( $video->playtime ) ? $video->playtime : '',
1509+
'is_completed' => $is_completed,
1510+
);
1511+
}
1512+
1513+
if ( ! $is_completed ) {
1514+
$topic['topic_completed'] = false;
1515+
} else {
1516+
$topic['topic_started'] = true;
1517+
}
1518+
}
1519+
}
1520+
1521+
$topic_list[] = $topic;
1522+
}
1523+
1524+
wp_reset_postdata();
1525+
1526+
return $topic_list;
1527+
}
14141528
}

0 commit comments

Comments
 (0)