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

Block quiz answers when the quiz is completed #4951

Merged
merged 8 commits into from
Apr 6, 2022

Conversation

gabrielcaires
Copy link
Contributor

Fixes #4889

Changes proposed in this Pull Request

This PR is blocking almost all question types to be updated after the student submits its answer.

Testing instructions

  1. Create a course
  2. Create a lesson
  3. Configure a quiz using every question type (the multi-line type is still not supported, it will be covered on issue Quiz: After the submission the Multi line question editor is not blocked as the other fields.  #4949).
  4. Enroll in the create a course as a Student.
  5. Answer all questions with wrong answers.
  6. Check the result page it is possible to edit the answers after the submission.

@gabrielcaires gabrielcaires requested a review from a team March 24, 2022 19:52
@gabrielcaires gabrielcaires self-assigned this Mar 24, 2022
@gabrielcaires gabrielcaires added this to the 4.3.0 milestone Mar 24, 2022
@gabrielcaires gabrielcaires force-pushed the fix/block-questions-when-the-quiz-is-complete branch 2 times, most recently from f0bf63f to c88940f Compare March 24, 2022 20:45
$data['quiz_grade_type'] = get_post_meta( $quiz_id, '_quiz_grade_type', true );
$data['reset_quiz_allowed'] = $reset_allowed;
$data['lesson_complete'] = $user_lesson_complete;
$data['quiz_is_completed'] = Sensei_Quiz::is_quiz_completed();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it makes sense to pass the $quiz_id variable when calling the is_quiz_completed method?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I'm not sure if I understand your question. I think you already have the $quiz_id provided to the get_template_data( $question_id, $quiz_id ) method, so you could pass that along to Sensei_Quiz::is_quiz_completed( $quiz_id ). If you don't, is_quiz_completed will use by default the post that is currently in the loop (by calling get_the_ID()).

Did that answer the question?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, my comment was in the wrong place, please ignore it.

I agree with quiz_id, I am going to update.

Comment on lines -1139 to -1145
// Check again that the lesson is complete
$user_lesson_end = Sensei_Utils::user_completed_lesson( Sensei()->quiz->get_lesson_id( $quiz_id ), get_current_user_id() );
$user_lesson_complete = false;
if ( $user_lesson_end ) {
$user_lesson_complete = true;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice refactoring! 👍

@donnapep donnapep modified the milestones: 4.3.0 - Reports v2, 4.4.0 Mar 31, 2022
We were calling some methods multiple times, instead
of reuse the returned value.  E.g quiz_id, user_id
@gabrielcaires gabrielcaires force-pushed the fix/block-questions-when-the-quiz-is-complete branch from a9135a6 to 5501ecb Compare April 1, 2022 12:27
Copy link
Member

@merkushin merkushin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works well 👍
There are a few linter issues, though.

includes/class-sensei-question.php Show resolved Hide resolved
@gabrielcaires
Copy link
Contributor Author

@merkushin I added back the $data['lesson_complete'] until we have a way to deprecate keys.
d76b439
Can you approve?

@gabrielcaires gabrielcaires requested a review from a team April 4, 2022 22:06
Copy link
Member

@merkushin merkushin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Gabriel! 👍

@gabrielcaires gabrielcaires merged commit 1f81915 into trunk Apr 6, 2022
@gabrielcaires gabrielcaires deleted the fix/block-questions-when-the-quiz-is-complete branch April 6, 2022 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Quiz responses selectors can be changed in the confirmation screen.
4 participants