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

Tim Corkerton created an issue. See original summary.

djdevin’s picture

Hi,

If your custom course object extends the CourseObjectNode class, then all you should need is

$course_node = course_get_context();

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

$courseObject = course_get_course_object($module, $object_type, $nid);

Where 'module' is your custom course object's module and 'object_type' is the type defined in hook_course_handlers().

djdevin’s picture

Or if you didn't want to use PHP you could try #2324247: Context Integration which exposes course to Context.

tim corkerton’s picture

Thanks 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?

wwedding’s picture

You 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).

djdevin’s picture

You could also look at the included course_poll module, which is a very basic extension of a node-based course object.

djdevin’s picture

Status: Active » Closed (fixed)