How do I require that a user be a logged in as a student in some course

How do I require that a user be a logged in as a student in some course

by Nathaniel Titterton -
Number of replies: 1
I know this should be relatively simple, but I'm not seeing the answer in accesslib or elsewhere. I want a simple script that will return system-wide resources (html docs, say, stored outside of particular courses) if the current user has some basic capability as a student in any course.

I'm not sure how to build the context for require_capability, for instance.

(I was hoping there was a mod/resource:view, but I could use mod/book:read, perhaps. I need to differentiate between guests and students, so I'll need to change default permissions perhaps)

Average of ratings: -
In reply to Nathaniel Titterton

Re: How do I require that a user be a logged in as a student in some course

by Olav Jordan -
you want to have something along the lines of

$context = get_context_instance(CONTEXT_COURSE, $course->id)
require_capability('mod/resource:view', $context);

or

$context = get_context_instance(CONTEXT_SYSTEM);
require_capability('mod/resource:view', $context);

but if what you're looking for is a completely new capability here's a walk through of the whole process http://docs.moodle.org/en/Development:NEWMODULE_Adding_capabilities