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/issue 2802 - Include private lessons in course completion count #2879

Open
wants to merge 22 commits into
base: trunk
Choose a base branch
from

Conversation

JuanchoPestana
Copy link
Contributor

Fixes #2802

Changes proposed in this Pull Request:

  • This PR includes private lessons in the course completion count/status.

Testing instructions:

  • Create a private course.
  • Create a private lesson with a quiz.
  • Enroll a learner in that course and complete the lesson/quiz. (This completes the course. We're assuming it's the only lesson.)
  • Go to Sensei LMS -> Analysis.
  • The "Completed Courses" count for that user must be correct (it must include the private course the user just finished). Also, the "Active course" count should be correct, meaning, this course should not be in the active count.
  • Go to Learner Management, to the learners section of this course.
  • The status for the user should be "Completed".

@donnapep
Copy link
Collaborator

Please see my comment. I think this fixes one small piece of a larger problem, and that we need to think holistically about it and figure out what all the issues are for private courses and lessons. We can then fix them in one go.

@JuanchoPestana
Copy link
Contributor Author

Hey @donnapep !

With these commits, I try to fix as many issues related to the private status as I could find... There are a bunch of them, so I try to be as descriptive as possible in the commit messages, but I'll also reference every commit here in this comment so that I could add extra information for each one. I hope this workflow makes it easy for you to check them, but if you'd like me to handle it in a different way, please let me know!

I'm making a few general assumptions here:

  • We are trying to integrate the "Private" status into Sensei, making Private courses and lessons work as if they were public (with the corresponding capability differences; meaning, private courses and lessons are only for users with read_private_posts capability).
  • Status (private and publish) should not be mixed in a course... If you have a public course, only include public lessons for it. Same goes for private... Throughout the comments, I explain the strange situations that we'll step into if we don't follow this rule... (This is obviously a requirements decision that is not mine to take... So, if we want to be able to mix publish and private lessons, please let me know how you'd like me to deal with those strange cases...) If I didn't make myself clear in this assumption, please read a bit further (to the first commit description) and I think it will be easier to understand... (Or let me know and I'll try to explain myself better! :) )

Regarding roles and capabilities:

  • The capability this PR uses for accessing private posts is read_private_posts. (I'm thinking of the case where someone wants to create a specific role for private courses and lessons; not only where the "Editor" role is used...)

Another important comment:

  • If the desired behavior is to "exclude private posts from Sensei", (basically the opposite of what it's done here), it should be a simple task, since I've located where each (or many) of the private/publish "conflicts" are located...

(I'll use "Frontend" to refer to the site where users take courses and "Backend" to refer to the WordPress Dashboard section...)

Ok, so here are the descriptions of the issues:

01. Course archive - fix lesson count

Located in: includes/class-sensei-course.php -> course_lesson_count() function.
Description: (Frontend) In the 'courses' page (if you have read_private_posts capability) you should see private and public courses. If the course has private lessons, the 'lesson count' (right below the course title) is wrong. The count doesn't include private lessons.
Comments: This is where I decided to make the assumption I mentioned before... If we have a course that includes private and publish lessons, then... Should the lesson number be different for each user, depending on their capability? For example: we have a course with 2 private and 2 publish lessons... If the user is a 'subscriber', should the lesson count be 2? Or 4? I opted for 2, since seeing a lesson count of 4 and then only be able to see 2 might be a bit confusing (but that's just my opinion!)...But technically, the course has 4 lessons, not 2...??? Again, I think the decision is not mine to take so please let me know what you think! :)... Building up on this confusing behavior (with this same example), should the 'subscriber' user see a progress related to the 2 lessons it's able to see? Or should the progress depend on the 4 lessons? What about the completion status?... There would be users then that complete a course doing 2 lessons, and others that need to do 4 lessons to complete the same course... (Course completion is not affected by this issue # 001, but I'm using this opportunity to explain my doubts regarding the functionality decisions.)
So, for this PR, before including the "private" status for any query, we check that the user has the read_private_posts capability... This makes sure that if you are a 'subscriber' user, you see only the number of lessons with a publish status...
I hope I made myself clear with this; and I'm sorry if it's a bit confusing, overwhelming, or if my explanation skills are not the best!

02. Single course - fix display private lessons

Located in: includes/class-sensei-course.php -> load_single_course_lessons_query() function. (non-module lessons)
includes/class-sensei-modules.php -> get_lessons_query() function. (lessons inside a module)
Description: (Frontend) Once you are inside a single course page (signed in with the proper capability), private lessons don't appear in the lessons loop. This happens for both lessons in a module and for non-module lessons, so we have to deal with the two cases.

03. Private course - fix is_enrolled() function

Located in: includes/enrolment/class-sensei-course-enrolment.php -> is_enrolled() function.
Description: (Frontend) When you click the "Take Course" button in a private course, nothing happens. (You don't see the usual progress bar that you would see normally).

04. Single course - fix lesson count

Located in: includes/class-sensei-course.php -> course_lessons() function.
Description: (Frontend) Once you are inside a course, the number of lessons in the progress section (right on top of the progress bar) doesn't include private lessons.

05. My courses - fix private lessons not appearing

Located in: includes/shortcodes/class-sensei-shortcode-user-courses.php -> setup_course_query() function.
Description: (Frontend) If you started taking a private course, it doesn't appear on the "My Courses" page.

06. Single course - fix completion status not working in private courses

Located in: includes/class-sensei-utils.php -> user_complete_course() function.
Description: (Frontend and Backend) When you finish all the lessons in a private course, the completion of the course is never achieved.

07. Grading - fix dropdown not including private lessons

Located in: includes/class-sensei-grading.php -> lessons_drop_down_html() function.
Description: (Backend) In the Grading section, in the top part of the screen, if you select a course in the left (courses) dropdown, the right (lessons) dropdown doesn't display private lessons.

08. Learners Management - fix table does not include private courses

Located in: includes/admin/class-sensei-learners-main.php -> get_courses() function.
Description: (Backend) In the Learners Management section, in the main table, private courses don't appear.

09. Learners Management - fix table does not include private lessons

Located in: includes/admin/class-sensei-learners-main.php -> get_lessons() function.
Description: (Backend) In the Learners Management section, in the courses table, click the "Manage learners" button for a course. Then click the "Lessons" button (right on top of the table). Private lessons don't appear here.

10. Dashboard - fix at a glance widget

Located in: includes/class-sensei-admin.php -> glance_items() function.
Description: (Backend) In the main WordPress Dashboard, the "At a Glance" widget shows courses and lessons counts. Private ones are not considered in those counts.

11. New Lesson - fix lesson prerequisite dropdown

Located in: includes/class-sensei-lesson.php -> lesson_prerequisite_meta_box_content() function.
Description: (Backend) When creating a new lesson, the lesson "Prerequisite" dropdown doesn't include private lessons. (We have a PR pending related to this issue btw :) )

12. New Course - fix course prerequisite dropdown

Located in: includes/class-sensei-course.php -> course_prerequisite_meta_box_content() function.
Description: (Backend) When creating a new course, the "Course Prerequisite" dropdown doesn't include private courses.

13. New Lesson - fix add lesson to course order

Located in: includes/class-sensei-lesson.php -> add_lesson_to_course_order() function.
Description: (Database) When you publish a new lesson, it's added to the post meta _lesson_order value. This doesn't work for private lessons.

14. Single course module - fix error in module progress calculation

Located in: includes/class-sensei-modules.php -> calculate_user_module_progress() function.
Description: (Frontend) In a course that has a module with private lessons, the progress bar in that module doesn't consider private lessons for the calculation (it doesn't even appear!).

15. Modules - fix table not displaying private lessons

Located in: includes/class-sensei-modules.php -> taxonomy_column_content() function.
Description: (Backend) In the Modules section, in the table, the lessons column doesn't display private lessons.

16. Authors - fix lesson count

Located in: includes/class-sensei-course.php -> course_author_lesson_count() function.
Description: (Not visible on front or backend) This function only counts lessons with a 'publish' status.

17. Teacher Notification - fix error on sending notification

Located in: includes/class-sensei-teacher.php -> notify_admin_teacher_course_creation() function.
Description: When a course is created/updated (hooked to wp_insert_post), if the old status was 'publish' no notification is sent (to avoid sending notifications on every update). Private status is not treated as the publish.
Comments: Here's another requirement issue... Should a notification be sent when a post changes from private to publish, or every time it's updated as private? I'm inclined to say no (because of latter) but, again, that's my opinion... I'm committing this functionality, but let me know if you'd like to reverse it!

Ok Donna, so basically that's it! Those were the issues I found related to the private/publish status... As I mentioned before, I hope I made myself clear, but if it's not the case, let me know and I'll try to do a better job! Also, please let me know if you find more "places" where this issue is occurring and if there's anything else I could do to help!

@donnapep donnapep removed their request for review September 2, 2022 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Private completed lessons prevent user from completing the course
2 participants