How to get context of a course if i know contextid and component?

How to get context of a course if i know contextid and component?

by Andreas Schenkel -
Number of replies: 1
Picture of Plugin developers

I want to know to which course a file that is stored in the datebase belongs.

I have the contextid of the module where the file belongs to. How can I get the courseid or the coursecontext of this file?


Average of ratings: -
In reply to Andreas Schenkel

Re: How to get context of a course if i know contextid and component?

by Andreas Grabs -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Translators

Hi Andreas,

a course module always belong to a course even if it is on the frontpage.

So if you have the context of a course module you could just call its method "get_parent_context()".

Best regards
Andreas

Average of ratings: Useful (1)