Cheatography
https://cheatography.com
Common functions userful for developers working in Moodle
Capabilities
Has capabilitity |
has_capability() |
User is admin |
is_admin() |
Require Capability |
require_capability() |
Context Levels
System Context |
CONTEXT_SYSTEM |
10 |
User Context |
CONTEXT_USER |
30 |
Course Category Context |
CONTEXT_COURSECAT |
40 |
Module Context |
CONTEXT_MODULE |
70 |
Block Context |
CONTEXT_BLOCK |
80 |
Course Context |
CONTEXT_COURSE |
50 |
Access API
System Context |
context_system::instance(); |
User Context |
context_user::instance($user->id); |
Category Context |
context_coursecat::instance($category->id); |
Course Context |
context_course::instance($course->id); |
Module Context |
context_module::instance($cm->id); |
Get context by ID |
context::instance_by_id($contextid); |
|
|
Enrolment API
Is user enrolled |
is_enrolled(context $context, $user = null, $withcapability = '', $onlyactive = false) |
Get all enrolled users |
get_enrolled_sql(context $context, $withcapability = '', $groupid = 0, $onlyactive = false) |
|
count_enrolled_users(context $context, $withcapability = '', $groupid = 0) |
|
get_enrolled_users(context $context, $withcapability = '', $groupid = 0, $userfields = 'u.*', $orderby = '', $limitfrom = 0, $limitnum = 0) |
Login API
Require to login |
require_login() |
Require login to course |
require_course_login() |
Get users by capability |
get_users_by_capability() |
Is guest user ? |
isguestuser($user) |
Is user logged in ? |
isloggedin() |
Is site admin |
is_siteadmin() |
Is guest ( by context) |
is_guest($context,$user=null) |
Is viewing ? |
is_viewing(context $context, $user = null, $withcapability = '') |
|
|
Output API
Header |
echo $output->header() |
Footer |
echo $output->footer |
Heading title |
echo $output->heading($pagetitle); |
|
Created By
Metadata
Comments
No comments yet. Add yours below!
Add a Comment
Related Cheat Sheets