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

Updates to handle course, lesson & quiz flows #138

Closed
hlashbrooke opened this issue Nov 4, 2020 · 8 comments
Closed

Updates to handle course, lesson & quiz flows #138

hlashbrooke opened this issue Nov 4, 2020 · 8 comments

Comments

@hlashbrooke
Copy link
Collaborator

@hlashbrooke hlashbrooke commented Nov 4, 2020

In order to create the data structure as outlined in #133, we need to add some custom functions to get Sensei working how we need it to for this use case. None of these updates are particularly big on their own and, since they're all related, I'm creating a single issue to house all of them, but I'm happy to break this out into separate issues if that would be preferred.

For context, these are the two use flows for going through content and taking quizzes that we're working with here:

  1. User goes to course landing page, starts the course and goes through the lessons.
  2. User watches a workshop independent of a course and goes to take a quiz for that workshop without doing a full course.

Number 1 there is already possible with no extra work since that is exactly how Sensei is built to function. Number 2 requires some minor tweaks:

Auto-enrol users in courses

Quizzes on lessons can only be taken if a user is enrolled in the course that the lesson is a part of. This means that, when someone goes directly to a quiz after watching a workshop, they will need to enrol in a course in order to take the one quiz. That isn't an ideal flow for a number of reasons, so the best way to work around this would be to automatically enrol users in courses as needed. I figure this can be done whenever someone loads a single course, lesson or quiz page - that way it would only do it on demand and would make sure the user is enrolled where necessary.

This code will handle the enrolment, so it would need to be called at the top of each course, lesson and quiz page load on the frontend:

function learn_wordpress_enrol_learner( $user_id, $course_id ) {
    if( ! Sensei_Course::is_user_enrolled( $course_id, $user_id ) ) {
            $enrolment_manager = Sensei_Course_Enrolment_Manager::instance();
            $manual_enrolment  = $enrolment_manager->get_manual_enrolment_provider();
            $manual_enrolment->enrol_learner( $user_id, $course_id );
    }
}

Since much of the page content would already have been loaded by this stage (like the "enrol in this course" buttons/notifications), it might be worth running the above code and then forcing a page reload after the manual enrollment. Obviously, the page reload wouldn't need to be done if the user was already enrolled in the course.

I have checked and confirmed that no emails are sent when a learner enrols in a course, so this kind of background auto-enrollment won't trigger any confusing emails.

Prepend lesson content to the single quiz page

Since we're using workshops as the actual content for learners and those are in their own CPT, we don't really need the single lesson pages - all that will include will be a link to the relevant workshop(s) and then the button to go and take the quiz (since the quiz is actually a new CPT all on its own). The best solution that I can think of here is to link directly to the quiz and then display the content from the lesson post at the top of the quiz page above the questions. This should be relatively straight forward since there are plenty of hooks available in the frontend templates and the lesson post ID is stored in a meta field on the quiz post.

Auto-redirect lessons to quizzes

Since we would be displaying the lesson content on the quiz page itself, the single lesson view becomes redundant, so we can now auto-redirect the lesson page to the quiz page on the frontend. The quiz post ID is stored as a meta field on the lesson post, so this should also be pretty straight forward.


With all of that in place, there will likely be some minor cosmetic updates we would need to make regarding buttons and breadcrumbs, but we can sort those out once we're there.

@hlashbrooke
Copy link
Collaborator Author

@hlashbrooke hlashbrooke commented Nov 5, 2020

An additional note for the auto-enrolment:

Only registered users will be able to enrol of course, so we'll need to include an is_user_logged_in() check there and display a 'please sign up to take this quiz' type links if not. That would need to go to the standard WordPress.org registration page hopefully with an automatic redirect back to the page they came from.

@coreymckrill
Copy link
Contributor

@coreymckrill coreymckrill commented Nov 5, 2020

@hlashbrooke

Quizzes on lessons can only be taken if a user is enrolled in the course that the lesson is a part of. This means that, when someone goes directly to a quiz after watching a workshop, they will need to enrol in a course in order to take the one quiz. That isn't an ideal flow for a number of reasons, so the best way to work around this would be to automatically enrol users in courses as needed. I figure this can be done whenever someone loads a single course, lesson or quiz page - that way it would only do it on demand and would make sure the user is enrolled where necessary.

I'm worried that this will spam-enroll people in courses if they're just browsing around the site without any intention of doing them. It seems like people shouldn't be enrolled in a course just by visiting its single page, they should need to click an "Enroll in Course" button or something.

For quizzes, how will a particular workshop be linked to a particular quiz? Will the workshop content just be edited to include a button that says "Take quiz" and manually links to the correct quiz?

@hlashbrooke
Copy link
Collaborator Author

@hlashbrooke hlashbrooke commented Nov 6, 2020

I'm worried that this will spam-enroll people in courses if they're just browsing around the site without any intention of doing them. It seems like people shouldn't be enrolled in a course just by visiting its single page, they should need to click an "Enroll in Course" button or something.

The problem with a button click to do this is that if someone is just taking a quiz from a workshop and not doing a full course, they would then need to take the extra steps of enrolling in a course that they aren't going to take, which would create some UX friction and general confusion. Automatically enrolling people would remove that friction and it wouldn't really make much difference to our stats in terms of number of enrolments since we would care more about the number of people finishing quizzes rather than simply enrolling.

The other advantage of having them auto-enrolled is that if/when they do decide to take a course, then they would already be enrolled and they would have already completed one or more of the quizzes within the course so they don't need to go through the same quizzes again.

For quizzes, how will a particular workshop be linked to a particular quiz? Will the workshop content just be edited to include a button that says "Take quiz" and manually links to the correct quiz?

Yeah - that's pretty much what I'm thinking. We could maybe even include it as a meta field to standardise the display, but note that not all workshops will have quizzes.

@coreymckrill
Copy link
Contributor

@coreymckrill coreymckrill commented Nov 6, 2020

I agree that it would make sense to auto-enroll someone when they land on the quiz page itself, like this one. But what I'm saying is if someone is browsing the Learn site and they go to a course page, like this, or even a lesson page, I don't think it makes sense to auto-enroll them at that point, because there is not yet any intention to actually take the quiz.

Another question: the quiz I linked above is for a lesson that is covered by two separate workshops. It seems like it wouldn't make sense to link directly from one of those workshops to the quiz, since half of the context would be missing, so how would someone end up taking it?

@hlashbrooke
Copy link
Collaborator Author

@hlashbrooke hlashbrooke commented Nov 9, 2020

Good point - I'm happy with the auto-enrolment only happening on the quiz page itself.

Another question: the quiz I linked above is for a lesson that is covered by two separate workshops. It seems like it wouldn't make sense to link directly from one of those workshops to the quiz, since half of the context would be missing, so how would someone end up taking it?

The lesson content will link to both/all workshops relevant to the quiz, so if we prepend the lesson content to the quiz itself then the links and info will all be there.

coreymckrill added a commit that referenced this issue Nov 11, 2020
Customizations to the Sensei plugin via action/filter hooks to update how courses and quizzes work on Learn.

* Auto-enroll users in courses
* Prepend lesson content to the single quiz page
* Auto-redirect lessons to quizzes

Refs #138
@coreymckrill
Copy link
Contributor

@coreymckrill coreymckrill commented Nov 11, 2020

@hlashbrooke #141 addresses the three tweaks you outline above. I've committed and deployed these changes to production so you can try them out. Let me know if anything isn't working as expected. If there are other tweaks needed, let's open a new issue.

@hlashbrooke
Copy link
Collaborator Author

@hlashbrooke hlashbrooke commented Nov 11, 2020

This all works perfectly - thanks!

It looks like there'll be some minor cosmetic changes that will help, but I'll work all those out into a single issue.

@hlashbrooke
Copy link
Collaborator Author

@hlashbrooke hlashbrooke commented Oct 19, 2021

I'm reopening this issue because we need to revisit one of the updates.

After this issue closed we reverted the change that displayed the lesson content at the top of the quiz page, so they are now on separate pages again. We need to re-revert that now.

If possible I'd like it done a bit differently though - in the past, it was set up so that the URL was /quiz/lesson-slug (i.e. on the quiz post type page) - would it be possible to make it the other way around, so the quiz appears on the lesson post type page at /lesson/lesson-slug?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants