Closed (fixed)
Project:
Course
Version:
7.x-1.7
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
7 Feb 2016 at 00:33 UTC
Updated:
17 Mar 2016 at 19:59 UTC
Jump to comment: Most recent
I wonder if you could help.
Rather than just mark a course object as completed on a page view I'm trying to add a flag to a content page to allow a user to flag ("Mark as complete") the content as completed.
I have everything working but I can't work out how to test to see if the current node the user is viewing is part of a course. That way I can hide or show the flag.
I'm trying to do the check within a custom visibility rule in Panels. I have this bit working like this ... http://www.webwash.net/drupal/tutorials/create-custom-visibility-rules-p...
Any ideas would be most welcome.
Thanks
Tim
Comments
Comment #2
djdevinHi,
If your custom course object extends the CourseObjectNode class, then all you should need is
That should return the course node if the currently viewed node is a part of that course.
If you wanted to find out which course object it belonged to, you could use
Where 'module' is your custom course object's module and 'object_type' is the type defined in hook_course_handlers().
Comment #3
djdevinOr if you didn't want to use PHP you could try #2324247: Context Integration which exposes course to Context.
Comment #4
tim corkerton commentedThanks for your response, that makes sense.
I've been writing Drupal PHP for about 5 years but Classes are quite new to me. Is there any documentation on how to extend the CourseObjectNode class?
Comment #5
wwedding commentedYou might not need to worry about how to extend classes in PHP. The course_get_context() function'll work outside of class definitions, too (like page hooks, or node view code, or a custom visibility rule callback).
But if you decide to go that route, there's a page in the PHP docs that outlines how to do so (it's a language-level level bit of knowledge, not specific to Drupal): http://php.net/manual/en/language.oop5.inheritance.php
For the Course/Drupal specific bits on defining a custom course object you can look at one of the built-in sub modules like course_book (the CourseObjectBook is an extension of CourseObjectNode).
Comment #6
djdevinYou could also look at the included course_poll module, which is a very basic extension of a node-based course object.
Comment #7
djdevin