Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix quiz marked as passed when lesson is complete #7381

Draft
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -307,16 +307,31 @@ public function find( array $args ): array {
* @return Comments_Based_Quiz_Progress The course progress.
*/
private function create_progress_from_comment( WP_Comment $comment, ?int $quiz_id = null ): Comments_Based_Quiz_Progress {
$comment_date = new DateTime( $comment->comment_date, wp_timezone() );
$meta_start = get_comment_meta( (int) $comment->comment_ID, 'start', true );
$started_at = ! empty( $meta_start ) ? new DateTime( $meta_start, wp_timezone() ) : current_datetime();

if ( in_array( $comment->comment_approved, [ 'complete', 'passed', 'graded' ], true ) ) {
$status = $comment->comment_approved;
$comment_date = new DateTime( $comment->comment_date, wp_timezone() );
$meta_start = get_comment_meta( (int) $comment->comment_ID, 'start', true );
$started_at = ! empty( $meta_start ) ? new DateTime( $meta_start, wp_timezone() ) : current_datetime();
$grade = get_comment_meta( (int) $comment->comment_ID, 'grade', true );
$is_graded = is_numeric( $grade );
$questions_asked = get_comment_meta( (int) $comment->comment_ID, 'questions_asked', true );
$is_submitted = ! empty( $questions_asked );

if ( in_array( $status, [ 'complete', 'passed', 'graded' ], true ) ) {
$completed_at = $comment_date;
} else {
$completed_at = null;
}

if ( in_array( $status, [ 'passed' ], true ) ) {
if ( ! $is_submitted ) {
// If the lesson is completed without submitting the quiz, set the quiz status to 'in-progress'.
$status = Quiz_Progress_Interface::STATUS_IN_PROGRESS;
} elseif ( ! $is_graded ) {
// If the lesson is completed and the quiz is not graded, set the quiz status to 'ungraded'.
$status = Quiz_Progress_Interface::STATUS_UNGRADED;
}
}

if ( is_null( $quiz_id ) ) {
$quiz_id = Sensei()->lesson->lesson_quizzes( $comment->comment_post_ID );
}
Expand All @@ -325,7 +340,7 @@ private function create_progress_from_comment( WP_Comment $comment, ?int $quiz_i
(int) $comment->comment_ID,
(int) $quiz_id,
(int) $comment->user_id,
$comment->comment_approved,
$status,
$started_at,
$completed_at,
$comment_date,
Expand Down
Loading