Problem/Motivation
While creating or browsing a Book node that has been added to a Course, PHP warnings will appear if the content is being viewed before the user has enrolled in a course containing that book.
Warning: array_filter() expects parameter 1 to be array, null given in CourseObjectBook->grade() (line 88 of PATH_TO_COURSE\modules\course_book\course_book.classes.inc).
Warning: array_keys() expects parameter 1 to be array, null given in CourseObjectBook->grade() (line 88 of PATH_TO_COURSE\modules\course_book\course_book.classes.inc).
Warning: array_diff(): Argument #2 is not an array in CourseObjectBook->grade() (line 89 of PATH_TO_COURSE\modules\course_book\course_book.classes.inc).
This is because the Course Book will try to grade and save or update course fulfillment when a book page is viewed, even if the viewer isn't enrolled in a course related to this object. The grading and fulfillment fail to save, as you'd expect, but the grading does it noisily.
Comments
Comment #2
wwedding commentedComment #3
wwedding commentedComment #4
wwedding commentedFixed the local problem, specific to the grade() function, but it feels like it shouldn't even get to that point. If I'm not enrolled, it seems like all that work going into trying to save, set options, make a fulfillment object, shouldn't be happening to begin with. Perhaps there should be a check right at the top of a node_view that checks if someone is even in a course.
I tried to take that approach, initially, but I couldn't figure out how to walk backwards from node to a list of courses that a node might be a part of using existing module functionality.
Comment #5
wwedding commentedComment #7
wwedding commentedWhat's up with the testing? Seems like 5.6 is broken or something.
Comment #9
djdevinLooks fine. Thanks!