<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://docs.moodle.org/dev/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Abhijit13</id>
	<title>MoodleDocs - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://docs.moodle.org/dev/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Abhijit13"/>
	<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/Special:Contributions/Abhijit13"/>
	<updated>2026-07-20T21:39:05Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Talk:New_permissions_evaluation_in_2.0&amp;diff=49746</id>
		<title>Talk:New permissions evaluation in 2.0</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Talk:New_permissions_evaluation_in_2.0&amp;diff=49746"/>
		<updated>2016-03-31T10:12:50Z</updated>

		<summary type="html">&lt;p&gt;Abhijit13: Created page with &amp;quot;In the file Allowed_roles.png   the third table has entry &amp;quot;Non Editing Teacher&amp;quot; in Column &amp;quot;Assignments&amp;quot;, and row &amp;quot;Forum&amp;quot;. What does it mean?&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In the file Allowed_roles.png &lt;br /&gt;
&lt;br /&gt;
the third table has entry &amp;quot;Non Editing Teacher&amp;quot; in Column &amp;quot;Assignments&amp;quot;, and row &amp;quot;Forum&amp;quot;. What does it mean?&lt;/div&gt;</summary>
		<author><name>Abhijit13</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Role_archetypes&amp;diff=49738</id>
		<title>Role archetypes</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Role_archetypes&amp;diff=49738"/>
		<updated>2016-03-30T06:13:08Z</updated>

		<summary type="html">&lt;p&gt;Abhijit13: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Infobox Project&lt;br /&gt;
|name = Role archetypes&lt;br /&gt;
|state = Implemented&lt;br /&gt;
|tracker = MDL-21772&lt;br /&gt;
|discussion = n/a&lt;br /&gt;
|assignee = [[User:Petr Škoda (škoďák)|Petr Škoda (škoďák)]]&lt;br /&gt;
}}&lt;br /&gt;
{{Moodle 2.0}}&lt;br /&gt;
&lt;br /&gt;
=Goals=&lt;br /&gt;
* Remove all roles legacy stuff&lt;br /&gt;
* Cleanup guest access&lt;br /&gt;
* Prevent accidental breaking of admin roles&lt;br /&gt;
* Improve performance&lt;br /&gt;
* Simplify coding style&lt;br /&gt;
* Fix some other long standing design problems&lt;br /&gt;
&lt;br /&gt;
=Legacy capabilities=&lt;br /&gt;
Since 1.7 roles could be marked by setting legacy capabilities. Originally this was intended as a temporary solution for replacing of isteacher(), isstudent(), but we soon realised we need it also for upgrades when adding new capabilities and also for role resetting. Later the legacy capabilities were used for role related default settings.&lt;br /&gt;
&lt;br /&gt;
Legacy guest capability was used for different purposes - course guest access and preventing students from posting.&lt;br /&gt;
&lt;br /&gt;
=Role archetypes=&lt;br /&gt;
Role archetype can be specified in a new field in role table. The difference is that the code is significantly simplified and it is not possible to use the legacy capability checks at all (we have to finally solve all legacy problems).&lt;br /&gt;
&lt;br /&gt;
=Redefined guest access=&lt;br /&gt;
Originally guests had both moodle/course:view and moodle/legacy:guest, this lead to many problems because the moodle/course:view was not used exclusively for enrolments. The guest access can be fully implemented in require_login() without any giving any capability.&lt;br /&gt;
&lt;br /&gt;
=Redefined moodle/course:view capability=&lt;br /&gt;
The hidden role assignments were implemented to work around the single moodle/course:view capability that was used both for enrolled users and managers or admins. Unfortunately this was very hacky solution that required hacks all over the place and was never completely implemented. Now the moodle/course:view is allowing users to enter the course without actually participating in course. They are mostly invisible to other users.&lt;br /&gt;
&lt;br /&gt;
The old course:view is now replaced by records in user_enrolments table.&lt;br /&gt;
&lt;br /&gt;
=Admins without a role=&lt;br /&gt;
Since 1.7 we just kept adding hacks for hiding of administrators over and over again, we had to implement various hacks in order to protect the admin users. Solution is very simple - do not create any admin role and instead just keep the list of admins only in $CFG-&amp;gt;siteadmins. moodle/course:view capability grants admins the right to enter any course.&lt;br /&gt;
&lt;br /&gt;
Benefits:&lt;br /&gt;
* admins are not returned from get_users_by_capability() - no need for $doanything there&lt;br /&gt;
* has_capability() - the only place where $doanything makes sense&lt;br /&gt;
* is_siteadmin() is extremely fast because it does not need any DB access&lt;br /&gt;
* much safer - nobody may get doanything capability&lt;br /&gt;
* no admin my_courses() exceptions needed&lt;br /&gt;
* nobody may &amp;quot;break&amp;quot; admins anymore&lt;br /&gt;
&lt;br /&gt;
=New Manager role=&lt;br /&gt;
Manager role is supposed to replace original &amp;quot;small administrators&amp;quot; that were assigned at a course category level. moodle/course:view capability grants admins the right to enter managed course. Admins assigned in lower levels can be automatically migrated to manager role assignments. Managers are by default not enrolled in courses, they can enter them and manage them only.&lt;br /&gt;
&lt;br /&gt;
Benefits:&lt;br /&gt;
* better control&lt;br /&gt;
* much easier to setup manager of course categories&lt;br /&gt;
&lt;br /&gt;
Potential problems:&lt;br /&gt;
* we already have &amp;quot;course manager&amp;quot; admin setting which marks roles responsible for course enrolment&lt;br /&gt;
&lt;br /&gt;
=See also=&lt;br /&gt;
* [[Enrolment usage overview]]&lt;br /&gt;
* [[Enrolment rewrite and role tweaks proposal]]&lt;br /&gt;
* [[New permissions evaluation in 2.0]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Enrolment]]&lt;br /&gt;
[[Category:Roles]]&lt;/div&gt;</summary>
		<author><name>Abhijit13</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Roles&amp;diff=49735</id>
		<title>Roles</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Roles&amp;diff=49735"/>
		<updated>2016-03-30T04:11:17Z</updated>

		<summary type="html">&lt;p&gt;Abhijit13: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Definitions==&lt;br /&gt;
&lt;br /&gt;
* A &#039;&#039;&#039;role&#039;&#039;&#039; is an identifier of the user&#039;s status in some context. For example: Teacher, Student and Forum moderator are examples of roles.&lt;br /&gt;
&lt;br /&gt;
* A &#039;&#039;&#039;capability&#039;&#039;&#039; is a description of some particular Moodle feature. Capabilities are associated with roles. For example, &#039;&#039;mod/forum:replypost&#039;&#039; is a capability.&lt;br /&gt;
&lt;br /&gt;
* A &#039;&#039;&#039;permission&#039;&#039;&#039; is some value that is assigned for a capability for a particular role.  For example, allow or prevent.&lt;br /&gt;
&lt;br /&gt;
* A &#039;&#039;&#039;context&#039;&#039;&#039; is a &amp;quot;space&amp;quot; in the Moodle, such as courses, activity modules, blocks etc.&lt;br /&gt;
&lt;br /&gt;
==The system prior to v1.7==&lt;br /&gt;
&lt;br /&gt;
In versions prior to v1.7, Moodle uses a fixed set of roles i.e. primary admin, admins, course creators, editing teachers, non-editing teachers, students, and guests. For each role, the capability or actions that they can perform are fixed. For example, the role student allows the user to submit an assignment, but doesn&#039;t allow the user to browse/edit other users&#039; work. By using this setup we limit ourselves to a rather rigid set of capabilities for each role. If we want, say a particular student or group to be able to mark assignments in a particular course, we can&#039;t do that without giving these users teacher privileges.&lt;br /&gt;
&lt;br /&gt;
==The new roles and capability system==&lt;br /&gt;
&lt;br /&gt;
With v1.7 and greater, Moodle introduces a roles and capabilities system.&lt;br /&gt;
&lt;br /&gt;
=== Roles ===&lt;br /&gt;
Role has two primary functions:&lt;br /&gt;
# define list of permissions - role definition is global for all contexts, but can be changed by local context overrides&lt;br /&gt;
# replace old course enrolments in Moodle 1.7-1.9 - role assignment in course context is similar to the old enrolment process&lt;br /&gt;
&lt;br /&gt;
The new system will allow authorized users to define an arbitrary number of roles (eg a teacher) &lt;br /&gt;
&lt;br /&gt;
A role consists of a list of permissions for different possible actions within Moodle (eg delete discussions, add activities etc)&lt;br /&gt;
&lt;br /&gt;
Roles can be applied to users in a &#039;&#039;context&#039;&#039; (eg assign Fred as a teacher in a particular course)&lt;br /&gt;
&lt;br /&gt;
=== Context ===&lt;br /&gt;
Here are the possible contexts, listed from the most general to the most specific. &lt;br /&gt;
&lt;br /&gt;
[[Image:Moodle-contexts-1.8.png|right|thumbnail|200px|A diagram of the contexts in Moodle. Click on the diagram to see a more detailed view of it.]]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! CONTEXT NAME&lt;br /&gt;
! CONTEXT AREA&lt;br /&gt;
! CONTEXTLEVEL&lt;br /&gt;
|-&lt;br /&gt;
| CONTEXT_SYSTEM&lt;br /&gt;
| the whole site&lt;br /&gt;
| 10&lt;br /&gt;
|-&lt;br /&gt;
| CONTEXT_USER&lt;br /&gt;
| another user&lt;br /&gt;
| 30&lt;br /&gt;
|-&lt;br /&gt;
| CONTEXT_COURSECAT&lt;br /&gt;
| a course category&lt;br /&gt;
| 40&lt;br /&gt;
|-&lt;br /&gt;
| CONTEXT_COURSE&lt;br /&gt;
| a course&lt;br /&gt;
| 50&lt;br /&gt;
|-&lt;br /&gt;
| CONTEXT_MODULE&lt;br /&gt;
| an activity module&lt;br /&gt;
| 70&lt;br /&gt;
|-&lt;br /&gt;
| CONTEXT_BLOCK&lt;br /&gt;
| a block&lt;br /&gt;
| 80&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Please note that CONTEXT_PERSONAL (present in 1.7-1.8) was never implemented and was removed in 1.9. CONTEXT_GROUP is also not implemented and can not be used.&lt;br /&gt;
&lt;br /&gt;
An authorized user will be able to assign an arbitrary number of roles to each user in any context.&lt;br /&gt;
&lt;br /&gt;
(See [[Roles and modules#Context]] for more information.)&lt;br /&gt;
&lt;br /&gt;
=== Capabilities ===&lt;br /&gt;
Capabilities can have the following permissions:&lt;br /&gt;
&lt;br /&gt;
#CAP_INHERIT&lt;br /&gt;
#CAP_ALLOW&lt;br /&gt;
#CAP_PREVENT&lt;br /&gt;
#CAP_PROHIBIT&lt;br /&gt;
&lt;br /&gt;
If no permission is defined, then the capability permission is inherited from a context that is more general than the current context. If we define different permission values for the same capability in different contexts, we say that we are overriding the capability in the more specific context.&lt;br /&gt;
&lt;br /&gt;
=== Checking for capabilities ===&lt;br /&gt;
You can use the [[Roles_and_modules#has_capability_.28.24capability.2C_.24contextid.2C_.24kill.29|has_capability ()]] function for checking for capabilities in your code. &lt;br /&gt;
&lt;br /&gt;
=== Capability conflicts ===&lt;br /&gt;
Since the capabilities in each role could be different, there could be conflict in capabilities. This is resolved using different methods in versions below Moodle 2.0.&lt;br /&gt;
&lt;br /&gt;
If we set a PROHIBIT on a capability, it means that the capability cannot be overridden and will ALWAYS  have a permission of prevent (deny). Prohibit always wins.   For example, Jeff has a naughty student role that prohibits him from postings in any forums (for the whole site), but he&#039;s also assigned a facilitator role in &amp;quot;Science forum&amp;quot; in the course Science and Math 101. Since prohibit always wins, Jeff is unable to post in &amp;quot;Science forum&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Capability-locality changes in v1.9===&lt;br /&gt;
&lt;br /&gt;
When resolving conflicts between &amp;quot;allow&amp;quot; and &amp;quot;prevent&amp;quot; in v1.7 and v1.8 the locality of the capability is taken into account, although with less weight than the locality of the role assignment. In v1.9 the process has been reworked, we consider locality of the role assignment when dealing with allow/prevent conflicts, but ignore where the capability has been defined (as long as it applies to the context).&lt;br /&gt;
&lt;br /&gt;
Allow and prevent will cancel each other out if set for the same capability at the same context level. If this happens, we refer to the previous context level to determine the permission for the capability. This may sound more complex than it really is in practice.  The upshot is that the system can be flexible enough to allow pretty much any combination of permissions.&lt;br /&gt;
&lt;br /&gt;
For example - for the situation where there is&lt;br /&gt;
&lt;br /&gt;
* two roles assigned to one user in a context (eg student role and teacher role)&lt;br /&gt;
* one override on one of those roles ( eg student role), at the same context&lt;br /&gt;
 &lt;br /&gt;
then&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;1.7/1.8&#039;&#039;&#039; The override used to &#039;&#039;always&#039;&#039; win over the settings from the combined roles.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;1.9&#039;&#039;&#039; The override is combined with the student role first. and then the roles are combined. This is more logical, as the override is acting like a modification to the student role.&lt;br /&gt;
&lt;br /&gt;
For more details, see [http://tracker.moodle.org/browse/MDL-11218 MDL-11218]&lt;br /&gt;
&lt;br /&gt;
===New permissions evaluation in 2.0===&lt;br /&gt;
&lt;br /&gt;
The permission evaluation changes introduced in 1.9 were too complex for majority of uses, the permission evaluation was finally simplified in Moodle 2.0 - see [[New permissions evaluation in 2.0]].&lt;br /&gt;
&lt;br /&gt;
==Upgrading from 1.6==&lt;br /&gt;
&lt;br /&gt;
A smooth upgrade will be provided with 1.7. The existing roles (admin, teacher, student, etc), and the existing capabilities will be automatically retained.  This is done by creating default roles at site/course levels, and assigning the current users to these roles accordingly. The default roles will have default capabilities associated with them, mirroring what we have  in 1.6.   With no modifications, Moodle will operate exactly the same before and after the upgrade.&lt;br /&gt;
&lt;br /&gt;
===Admins===&lt;br /&gt;
&lt;br /&gt;
Admin users will be assigned the default legacy admin role in the system (site) context in Moodle 1.7-1.9. In Moodle 2.0 admins do not have any role assigned at all, this role was replaced by Manager role.&lt;br /&gt;
&lt;br /&gt;
===Course Creators===&lt;br /&gt;
&lt;br /&gt;
Course Creators will be assigned the default legacy course creator role in the system (site) context. Course creators are intended to create course only, nothing else! Once the creator creates a new course they are usually enrolled into course with default creator role.&lt;br /&gt;
&lt;br /&gt;
===Teachers===&lt;br /&gt;
&lt;br /&gt;
Users who were teachers will be assigned the default legacy teacher role (or non-editing teacher role) in all courses they were teacher.&lt;br /&gt;
&lt;br /&gt;
===Students===&lt;br /&gt;
&lt;br /&gt;
Users who were students will be assigned the default student role in all courses they were student.&lt;br /&gt;
&lt;br /&gt;
===Guests===&lt;br /&gt;
&lt;br /&gt;
There will still be a single guest user with no default role at site level.   For each course that allows guest access, the guest role will be assigned to the guest user for that course context.   The guest control for the course will be modified from three to two options (guests always need to enter enrolment key - on/off).  This setting is checked as now to force guests to enter key.&lt;br /&gt;
&lt;br /&gt;
==Capabilities==&lt;br /&gt;
&lt;br /&gt;
This will be a comprehensive list of capabilities (it&#039;s not complete yet). It is important that capability names are unique.&lt;br /&gt;
&lt;br /&gt;
===Core-level Capabilities===&lt;br /&gt;
&lt;br /&gt;
Moodle core capability names start with &#039;moodle/&#039;.  The next word indicates what type of core capability it is, and the last word is the actual capability itself.  The capabilities for the Moodle core are defined in lib/db/access.php&lt;br /&gt;
&lt;br /&gt;
#moodle/legacy:guest - legacy capabilities are used to transition existing users to the new roles system during the upgrade to Moodle 1.7&lt;br /&gt;
#moodle/legacy:student&lt;br /&gt;
#moodle/legacy:teacher&lt;br /&gt;
#moodle/legacy:editingteacher&lt;br /&gt;
#moodle/legacy:coursecreator&lt;br /&gt;
#moodle/legacy:admin&lt;br /&gt;
#moodle/site:doanything - special capability, meant for admins, if is set, overrides all other capability settings&lt;br /&gt;
#moodle/site:config - applicable in admin/index.php and config.php (might break down later) : 1)admin/config.php 2)admin/configure.php 3)blocks/admin/block_admin.php load_content_for_site()&lt;br /&gt;
#moodle/site:readallmessages - reads all messages and history&lt;br /&gt;
#moodle/site:approvecourse - approves a pending course&lt;br /&gt;
#moodle/site:manageblocks - adding/removing/editing blocks (site, course contexts only for now) : 1)_add_edit_controls moodleblock.class.php &lt;br /&gt;
#moodle/site:backup - can create a course backup : 1)course/category.php 2)block_admin.php&lt;br /&gt;
#moodle/site:restore - can restore into this context : 1)course/category.php 2)block_admin.php&lt;br /&gt;
#moodle/site:import - can import other courses into this context : 1)block_admin.php&lt;br /&gt;
#moodle/site:accessallgroups - able to access all groups irrespective of what group the user is in&lt;br /&gt;
#moodle/site:accessdb - directly accessing db (phpmyadmin)&lt;br /&gt;
#moodle/site:viewfullnames - able to see fullnames of other users&lt;br /&gt;
#moodle/site:viewparticipants - able to view participants&lt;br /&gt;
#moodle/site:viewreports - able to view site/course reports&lt;br /&gt;
#moodle/site:trustcontent - ability to use trusttext feature and bypass cleaning in specific areas&lt;br /&gt;
#moodle/site:uploadusers - ability to upload/update users from text file; moodle/role:assign capability is needed for course enrolling&lt;br /&gt;
#moodle/blog:view - read blogs (usable in system or course context)&lt;br /&gt;
#moodle/blog:create - write new blog posts (usable in system context only)&lt;br /&gt;
#moodle/blog:manageofficialtags - create/delete official blog tags that others can use (usable in system context only)&lt;br /&gt;
#moodle/blog:managepersonaltags - delete personal blog tags that others can use (usable in system context only) Note: users can always add own personal tags. This setting should be off for students by default.&lt;br /&gt;
#moodle/blog:manageentries - edit/delete all blog entries (usable in system context only)&lt;br /&gt;
#moodle/course:setcurrentsection - mark course section&lt;br /&gt;
#moodle/course:create - create courses : 1)course/edit.php 2)course/category.php 3)course/index.php&lt;br /&gt;
#moodle/course:delete - create courses : 1)course/category.php&lt;br /&gt;
#moodle/course:update - update course settings&lt;br /&gt;
#moodle/course:view - can use this to find participants&lt;br /&gt;
#moodle/course:viewparticipants - allows a user to view participant list&lt;br /&gt;
#moodle/course:viewscales - view scales (i.e. in a help window?) : 1)course/scales.php&lt;br /&gt;
#moodle/course:manageactivities - adding/removing/editing activities and resources (don&#039;t think it makes any sense to split these)&lt;br /&gt;
#moodle/course:managescales - add, delete, edit scales, move scales up and down : 1)blocks/block_admin.php 2)course/scales.php&lt;br /&gt;
#moodle/course:managegroups - managing groups, add, edit, delete : 1)course/groups.php 2)course/group.php&lt;br /&gt;
#moodle/course:managefiles - manage course files and folders&lt;br /&gt;
#moodle/course:managequestions - manage course questions&lt;br /&gt;
#moodle/course:managemetacourse - manage child courses in metacourse&lt;br /&gt;
#moodle/course:reset - able to reset the course&lt;br /&gt;
#moodle/course:useremail - Can use the enable/disable email stuff&lt;br /&gt;
#moodle/course:visibility - hide/show courses : 1)course/category.php&lt;br /&gt;
#moodle/course:viewhiddencourses - see hidden courses&lt;br /&gt;
#moodle/course:activityvisibility - hide/show activities within a course&lt;br /&gt;
#moodle/course:viewhiddenactivities - able to see activities that have been hidden&lt;br /&gt;
#moodle/course:sectionvisibility - hide/show sections&lt;br /&gt;
#moodle/course:viewhiddensections - view hidden sections&lt;br /&gt;
#moodle/course:viewcoursegrades - views all grades in course&lt;br /&gt;
#moodle/course:viewhiddenuserfields - view all hidden user fields&lt;br /&gt;
#moodle/course:managegrades - manages grades settings in course&lt;br /&gt;
#moodle/category:create - create category : 1)course/index.php&lt;br /&gt;
#moodle/category:delete - delete category : 1)course/index.php&lt;br /&gt;
#moodle/category:update - update category settings (sort and rename) this is currently an admin capability : 1)course/category.php&lt;br /&gt;
#moodle/category:visibility - hide/show categories : 1)course/index.php&lt;br /&gt;
#moodle/user:viewusergrades - view your own, or other user&#039;s grades (with specified context)&lt;br /&gt;
#moodle/user:create - create user : 1) user/edit.php&lt;br /&gt;
#moodle/user:delete - delete user : 1) admin/user.php&lt;br /&gt;
#moodle/user:readuserblogs - read blog entries&lt;br /&gt;
#moodle/user:update - update user settings : 1) user/edit.php&lt;br /&gt;
#moodle/user:viewdetails - view personally-identifying user details (e.g. name, photo).&lt;br /&gt;
#moodle/user:viewhiddendetails - view user details marked as &amp;quot;hidden&amp;quot;&lt;br /&gt;
#moodle/calendar:manageownentries - create/edit/delete &lt;br /&gt;
#moodle/calendar:manageentries - create/edit/delete&lt;br /&gt;
#moodle/role:assign - assign roles to users&lt;br /&gt;
#moodle/role:override - can override role capabilities (depending on context)&lt;br /&gt;
#moodle/role:manage - create/edit/delete roles, set capability permissions for each role&lt;br /&gt;
#moodle/role:unassignself - unassign yourself from your own roles&lt;br /&gt;
#moodle/role:viewhiddenassigns - view role assignments that have been marked as hidden&lt;br /&gt;
#moodle/question:import - imports questions (course level?) - Yes, question permissions currently need to be course-level.--[[User:Tim Hunt|Tim Hunt]]&lt;br /&gt;
#moodle/question:export - exports questions (course level?)&lt;br /&gt;
#moodle/question:managecategory - add/delete/edit question categories (course level?)&lt;br /&gt;
#moodle/question:manage - add/edit/delete a question (course level)&lt;br /&gt;
&lt;br /&gt;
===User-level Capabilities===&lt;br /&gt;
# moodle/user:readuserposts -read individual user posts on profile page (parent?)&lt;br /&gt;
# moodle/user:readuserblogs -read individual user blogs on profile page (parent?)&lt;br /&gt;
# moodle/user:viewuseractivitiesreport-read individual activity report on profile page (parent?)&lt;br /&gt;
# moodle/user:editprofile - edit profile (normally used in CONTEXT_USERID and CONTEXT_SYSTEM)&lt;br /&gt;
&lt;br /&gt;
===Module-level Capabilities===&lt;br /&gt;
The capabilities are cached into a database table when a module is installed or updated. Whenever the capability definitions are updated, the module version number should be bumped up so that the database table can be updated.&lt;br /&gt;
&lt;br /&gt;
The naming convention for capabilities that are specific to modules and blocks is &#039;mod/mod_name:capability&#039;.  The part before the colon is the full path to the module in the Moodle code.  The module capabilities are defined in mod/mod_name/db/access.php.&lt;br /&gt;
&lt;br /&gt;
#Assignment&lt;br /&gt;
##mod/assignment:view- reading the assignment description&lt;br /&gt;
##mod/assignment:submit - turn assignment in&lt;br /&gt;
##mod/assignment:grade - grading, viewing of list of submitted assignments&lt;br /&gt;
#Chat&lt;br /&gt;
##mod/chat:chat - allows a user to participate in this chat&lt;br /&gt;
##mod/chat:readlog - allows a user to read past chat session logs&lt;br /&gt;
##mod/chat:deletelog - allows a user to delete past chat logs&lt;br /&gt;
#Choice&lt;br /&gt;
##mod/choice:choose - make a choice&lt;br /&gt;
##mod/choice:readresponses - read all responses&lt;br /&gt;
##mod/choice:deleteresponses - deletes all responses&lt;br /&gt;
##mod/choice:downloadresponses - download responses&lt;br /&gt;
#Database&lt;br /&gt;
##mod/data:viewentry - reads other people&#039;s entry&lt;br /&gt;
##mod/data:writeentry - add / edit and delete (own) entries&lt;br /&gt;
##mod/data:managetemplates - add, delete, edit fields and templates&lt;br /&gt;
##mod/data:manageentries - edit/delete all entries&lt;br /&gt;
##mod/data:comment - comment&lt;br /&gt;
##mod/data:managecomments - edit/delete all comments&lt;br /&gt;
##mod/data:rate - rate an entry&lt;br /&gt;
##mod/data:viewrating&lt;br /&gt;
##mod/data:approve - approves an entry&lt;br /&gt;
##mod/data:uploadentries - batch upload of entries&lt;br /&gt;
#Exercise&lt;br /&gt;
##mod/exercise:assess&lt;br /&gt;
#Forum&lt;br /&gt;
##mod/forum:viewdiscussion&lt;br /&gt;
##mod/forum:viewdiscussionsfromallgroups&lt;br /&gt;
##mod/forum:viewhiddentimedposts&lt;br /&gt;
##mod/forum:startdiscussion&lt;br /&gt;
##mod/forum:replypost&lt;br /&gt;
##mod/forum:viewrating&lt;br /&gt;
##mod/forum:viewanyrating&lt;br /&gt;
##mod/forum:rate&lt;br /&gt;
##mod/forum:createattachment&lt;br /&gt;
##mod/forum:deleteownpost&lt;br /&gt;
##mod/forum:deleteanypost&lt;br /&gt;
##mod/forum:splitdiscussions&lt;br /&gt;
##mod/forum:movediscussions&lt;br /&gt;
##mod/forum:editanypost&lt;br /&gt;
##mod/forum:viewqandawithoutposting&lt;br /&gt;
##mod/forum:viewsubscribers&lt;br /&gt;
##mod/forum:managesubscriptions&lt;br /&gt;
##mod/forum:throttlingapplies&lt;br /&gt;
#Glossary&lt;br /&gt;
##mod/glossary:write - add entries&lt;br /&gt;
##mod/glossary:manageentries - add, edit, delete entries&lt;br /&gt;
##mod/glossary:managecategories - create, delete, edit categories&lt;br /&gt;
##mod/glossary:comment - comment on an entry&lt;br /&gt;
##mod/glossary:managecomments - edit, delete comments&lt;br /&gt;
##mod/glossary:import - import glossaries&lt;br /&gt;
##mod/glossary:export - export glossaries&lt;br /&gt;
##mod/glossary:approve - approve glossaries&lt;br /&gt;
##mod/glossary:rate - rates glossary&lt;br /&gt;
##mod/glossary:viewrating - view ratings&lt;br /&gt;
#Hotpot&lt;br /&gt;
##mod/hotpot:attempt - attempt a hotpot&lt;br /&gt;
##mod/hotpot:viewreport - review and view reports&lt;br /&gt;
##mod/hotpot:grade - (grade? and) regrade&lt;br /&gt;
##mod/hotpot:deleteattempt - deletes attempts&lt;br /&gt;
#Label&lt;br /&gt;
##none&lt;br /&gt;
#Lams&lt;br /&gt;
##mod/lams:participate - original student&lt;br /&gt;
##mod/lams:manage - original teacher&lt;br /&gt;
#Lesson&lt;br /&gt;
##mod/lesson:edit - add and edit pages&lt;br /&gt;
##mod/lesson:manage - view student attempts&lt;br /&gt;
#Quiz&lt;br /&gt;
##mod/quiz:grade - comment, override grade, manual grade&lt;br /&gt;
##mod/quiz:preview - previews the quiz&lt;br /&gt;
##mod/quiz:viewreports - view quiz result reports&lt;br /&gt;
##mod/quiz:manage - add/delete/move (up or down) questions for a quiz&lt;br /&gt;
##mod/quiz:attempt - attempt the quiz--[[User:Tim Hunt|Tim Hunt]]&lt;br /&gt;
#Resource&lt;br /&gt;
#Scorm&lt;br /&gt;
##mod/scorm:viewgrades&lt;br /&gt;
#Survey&lt;br /&gt;
##mod/survey:download - downloads survery result&lt;br /&gt;
##mod/survey:participate - participate/ do survey&lt;br /&gt;
##mod/survey:readresponses - read all user&#039;s responese&lt;br /&gt;
#Wiki&lt;br /&gt;
##mod/wiki:participate - original student, meaning depends of type and course setting&lt;br /&gt;
##mod/wiki:manage - original teacher, manages assigned group; moodle/site:accessallgroups is needed to manage all groups &lt;br /&gt;
##(Waiting on new wiki)&lt;br /&gt;
#Workshop&lt;br /&gt;
##mod/workshop:participate - original student, allows user to submit and assess&lt;br /&gt;
##mod/workshop:manage - original teacher, user can manage others&lt;br /&gt;
##(Waiting on new Workshop)&lt;br /&gt;
&lt;br /&gt;
===Enrolment-level Capabilities===&lt;br /&gt;
&lt;br /&gt;
The naming convention for capabilities that are specific to enrolment is &#039;enrol/enrol_name:capability&#039;. The enrolment capabilities are defined in enrol/enrol_name/db/access.php.&lt;br /&gt;
&lt;br /&gt;
#Authorize.net Payment Gateway &lt;br /&gt;
##enrol/authorize:managepayments - manage user payments, capture, void, refund, delete etc.&lt;br /&gt;
&lt;br /&gt;
===Blocks===&lt;br /&gt;
#activity_modules&lt;br /&gt;
##None&lt;br /&gt;
#admin&lt;br /&gt;
#admin_2&lt;br /&gt;
#admin_bookmarks&lt;br /&gt;
#blog_menu&lt;br /&gt;
#blog_tags&lt;br /&gt;
#calendar_month&lt;br /&gt;
#calendar_upcoming&lt;br /&gt;
#course_list&lt;br /&gt;
#course_summary&lt;br /&gt;
#glossary_random&lt;br /&gt;
#html&lt;br /&gt;
#loancalc&lt;br /&gt;
#login&lt;br /&gt;
#messages&lt;br /&gt;
#news_items&lt;br /&gt;
#online_users&lt;br /&gt;
#participants&lt;br /&gt;
#quiz_results&lt;br /&gt;
#recent_activity&lt;br /&gt;
#rss_client&lt;br /&gt;
##block/rss_client:createprivatefeeds&lt;br /&gt;
##block/rss_client:createsharedfeeds&lt;br /&gt;
##block/rss_client:manageownfeeds&lt;br /&gt;
##block/rss_client:manageanyfeeds&lt;br /&gt;
#search&lt;br /&gt;
#search_forums&lt;br /&gt;
#section_links&lt;br /&gt;
#site_main_menu&lt;br /&gt;
#social_activities&lt;br /&gt;
&lt;br /&gt;
===Questions===&lt;br /&gt;
I am adding question categories here because they seem to have been forgotten in the whole scheme of things since having been removed from the quiz module itself. I&#039;ve made a suggestion on how these could be handled in MDL-6118.&lt;br /&gt;
&lt;br /&gt;
: See [http://moodle.org/mod/forum/discuss.php?d=51143 this forum thread] for a discussion about the current problems wth publishing question categories.[[User:Tim Hunt|Tim Hunt]] 18:50, 8 August 2006 (WST)&lt;br /&gt;
&lt;br /&gt;
==Programming Interface==&lt;br /&gt;
&lt;br /&gt;
Although the Roles system may look complicated at first glance, implementing it in Moodle code is fairly simple.&lt;br /&gt;
&lt;br /&gt;
* You need to define each capability once, so that Moodle can upgrade existing roles to take advantage of it.  You do this in an &#039;&#039;&#039;access.php&#039;&#039;&#039; inside the &#039;&#039;db folder&#039;&#039; of any module (eg see mod/forum/db/access.php). The array contains entries like this (note the descriptions for the legacy roles which provides forward compatibility):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&#039;mod/forum:viewforum&#039; =&amp;gt; array(&lt;br /&gt;
  &#039;captype&#039;      =&amp;gt; &#039;read&#039;,&lt;br /&gt;
  &#039;contextlevel&#039; =&amp;gt; CONTEXT_MODULE,&lt;br /&gt;
      &#039;archetypes&#039; =&amp;gt; array(&lt;br /&gt;
        &#039;guest&#039;          =&amp;gt; CAP_PREVENT,&lt;br /&gt;
        &#039;student&#039;        =&amp;gt; CAP_ALLOW,&lt;br /&gt;
        &#039;teacher&#039;        =&amp;gt; CAP_ALLOW,&lt;br /&gt;
        &#039;editingteacher&#039; =&amp;gt; CAP_ALLOW,&lt;br /&gt;
        &#039;coursecreator&#039;  =&amp;gt; CAP_ALLOW,&lt;br /&gt;
        &#039;manager&#039;        =&amp;gt; CAP_ALLOW&lt;br /&gt;
      )&lt;br /&gt;
  ),&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To load/change these capabilities you need to bump the module version.   There&#039;s no need to provide changes or differences as Moodle will scan the whole array and sort it out.&lt;br /&gt;
* On each page you need to find the context the user is working in, using the &#039;&#039;&#039;get_context_instance()&#039;&#039;&#039; function.  For example, in the forum module:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$context = get_context_instance(CONTEXT_MODULE, $cm-&amp;gt;id);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* or at the course level:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$context = get_context_instance(CONTEXT_COURSE, $id);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Then, whenever you want to check that the current user has rights to do something, call &#039;&#039;&#039;has_capability()&#039;&#039;&#039; like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
if (!has_capability(&#039;mod/forum:viewforum&#039;, $context)) {&lt;br /&gt;
  print_error(&#039;nopermissiontoviewforum&#039;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* If you just want to assert a capability and then finish with an error message if it&#039;s not met (as we did above), then a shorter way it to use &#039;&#039;&#039;require_capability()&#039;&#039;&#039; like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
require_capability(&#039;mod/forum:viewforum&#039;, $context);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Note that there are extra parameters you can specify to get a custom error message, otherwise users get an automated &amp;quot;No permissions&amp;quot; message that lists the permission they were missing.&lt;br /&gt;
&lt;br /&gt;
As a result of the new Roles System, all calls to isadmin(), iscoursecreator, isteacheredit(), isteacher(), isstudent(), and isguest() will have to be replaced with calls to has_capability() or require_capability().   However, these functions will be retained for some backward compatibility with old code, using the legacy capabilities to try and work out what to do.&lt;br /&gt;
&lt;br /&gt;
==Problem areas we are working on ==&lt;br /&gt;
&lt;br /&gt;
===Student view===&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;Student view&amp;quot; button has been removed completely.&lt;br /&gt;
&lt;br /&gt;
If there is time and a secure way can be found, it will be replaced by a menu to let the user assume a temporary role in the context of that course.&lt;br /&gt;
&lt;br /&gt;
===Teacher forum===&lt;br /&gt;
&lt;br /&gt;
Teacher forums were always a curious exception to normal forums, as they were not part of a course as such, and were not backed up.&lt;br /&gt;
&lt;br /&gt;
We&#039;re taking the opportunity to rectify this.   The upgrade converts teacher forums with content to normal forums in section 0 of the course, and ensures that only teachers can access them.  If the teacher forum had not been used in the course then it&#039;s not converted and will just dissappear.&lt;br /&gt;
&lt;br /&gt;
===Enrolment plugins===&lt;br /&gt;
&lt;br /&gt;
====Process of logging in====&lt;br /&gt;
&lt;br /&gt;
# load_user_capability() is called to load all the capabilities&lt;br /&gt;
# check_enrolment_plugins() is called at the top of load_user_capability() to check all the enrolment plugins.&lt;br /&gt;
# For each active plugin:&lt;br /&gt;
##Check for setup_enrolments($user) and run it.  This function will do all the processing needed to assign or unassign roles from the current user.&lt;br /&gt;
# load_user_capability() continues and loads up all the roles&lt;br /&gt;
# load_defaultuser_role() is called to add default site permissions (all users)&lt;br /&gt;
&lt;br /&gt;
====Process of checking access to a course====&lt;br /&gt;
&lt;br /&gt;
require_login($course-&amp;gt;id) is called by the script and has logic like this:&lt;br /&gt;
&lt;br /&gt;
# Is the user a guest at site level?&lt;br /&gt;
## Yes: Does the course allow guests?&lt;br /&gt;
### Yes: return true (and further capabilities are checked by the script)&lt;br /&gt;
### No:  send the user to course/enrol.php for enrolment&lt;br /&gt;
## No: continue below&lt;br /&gt;
&lt;br /&gt;
# Does the user have moodle/course:view in that (course) context?&lt;br /&gt;
## Yes: then they can enter (and further capabilities are checked by the script)&lt;br /&gt;
##  No: is guest access allowed on the course?&lt;br /&gt;
### Yes: assign temporary guest role to that user for that context (in session cache).&lt;br /&gt;
### No: send the user to course/enrol.php for enrolment.&lt;br /&gt;
&lt;br /&gt;
====Process of enrolling====&lt;br /&gt;
&lt;br /&gt;
(more soon)&lt;br /&gt;
&lt;br /&gt;
==Scenario brainstorming==&lt;br /&gt;
&lt;br /&gt;
This section is for brainstorming some example roles that we would like to support.  Note some of these *may* not be possible in 1.7.&lt;br /&gt;
&lt;br /&gt;
===Student===&lt;br /&gt;
Obviously.&lt;br /&gt;
&lt;br /&gt;
===Site Designers===&lt;br /&gt;
Is there a role for people involved in how the site looks but not full administrators? Thinking here of online control of themes rather than FTP theme uploading. But in either case they caneditlogos, caneditcss, candeditlevelatwhichthemeapplies.&lt;br /&gt;
&lt;br /&gt;
===Educational Authority Adviser===&lt;br /&gt;
Someone who would want to browse the site and may be asked to comment or contribute to particular discussions or developments in school. Access for this role would be controlled by the school in the case of school level moodles but may be different if there were to be a Local Authority wide Moodle.&lt;br /&gt;
&lt;br /&gt;
===Educational Inspector===&lt;br /&gt;
Someone who will visit the site to verify the school&#039;s self review that comments on home school relationships, extending the classroom etc. They may want to see summaries of usage and reports from surveys garnering parent and pupil views.&lt;br /&gt;
&lt;br /&gt;
===Second Marker / Moderator===&lt;br /&gt;
A teacher within ths site that has access to assignments and quizzes from another teacher&#039;s course for second marking purposes. This may need additional functionality adding to the assignment module so that two sets of grades/feedback can be given to one set of assignments.&lt;br /&gt;
&lt;br /&gt;
===Peer observer of teaching===&lt;br /&gt;
Many institutions encourage peer observation of teaching, to encourage reflection on practice. In online environments this will be similar to moderation or inspection. The peer observer would need to be able to experience the course &amp;quot;as a student&amp;quot;, but also to be able to view summaries of usage, transcripts of interactions (forums/surveys/polls etc), grades assigned (e.g. in assignments).&lt;br /&gt;
&lt;br /&gt;
===External Examiner===&lt;br /&gt;
Has all the rights of inspectors, but would also need to be able to review assignments and feedback, view forums, glossaries etc. However, would not want to post, feedback onto the site at all.&lt;br /&gt;
&lt;br /&gt;
===Parent===&lt;br /&gt;
A parent will have one or more children in one or more institutions which could be using one or more moodle instances or a mixture of Learning Platforms. A parent&#039;s role will vary depending on the age of their children and whether they are contributing as a parent or a school supporter.&lt;br /&gt;
&lt;br /&gt;
In Early Years (EY=3+4 yr olds) and Key Stage 1 (KS1=5+6 yr olds) they may play/learn on an activity or write for the child. Parents often interpret homework tasks and read to their children perhaps filling in a joint reading diary. In Key Stage 2 (KS2=7-11 yr olds) parents would be more monitoring but may join in as well.&lt;br /&gt;
&lt;br /&gt;
In Key stages 3 (KS3=12-14 yr olds) and 4 (KS4=15+16 yr olds) this changes to more of a monitoring/awareness role where a parent would expect to have a summary report of attendance, attainment and general achievement on a weekly/monthly/termly or annual basis. Parents will often be asked to sign and write back comments about this review report.&lt;br /&gt;
&lt;br /&gt;
In all Key Stages there is a great need for parents to receive communication from the school which they can confirm they have received by signing a form. In some cases this may also involve making choices from a list. It may also involve payment for a trip or disco being returned so there could be the possibility of electronic payments. Also in all Key Satges there may be a home-school agreement which may be signed up to. Could this form part of a site policy system that incorporates a tickable list of activities the parent agrees to the child using (blogs/wikis/forums etc.)?&lt;br /&gt;
&lt;br /&gt;
Parent&#039;s evenings often involve complex booking systems that attempt to get parent&#039;s and teachers together. Easy for EY/KS1/KS2 very difficult for KS3/KS4. Wow would this help if it was built into the Learning Platform.&lt;br /&gt;
&lt;br /&gt;
In some cases there needs to be confidential communication between the parent and the teacher without the child being party to this. It may involve teaching and learning but could also involve a behaviour or medical issue. Often this may be done via a sealed letter or face to face. &lt;br /&gt;
&lt;br /&gt;
The latest incarnation of OfSTED with the Self Review Framework (SEF) there is a greater emphasis on schools gathering parent voice via surveys and discussion. There is a clear match here with parents have access to parental votes, questionnaires and discussions and for schools to be able to publish news, results and reports back to parents.&lt;br /&gt;
&lt;br /&gt;
In the UK the LP framework and agenda as being pushed by the DfES via Becta emphasises that within the mandatory groups and roles functionality the parent role is likely to be required to meet the LP Framework procurement standard.&lt;br /&gt;
&lt;br /&gt;
Again in the UK, parents have their own independent right of access to a child&#039;s educational records. Obviously, children&#039;s records must not be made available to other parties, including the parents of other children in the same class. Thus it would be necessary to associate parent accounts with their own child&#039;s accounts in such a way that they could, if so desired, have read access to their child&#039;s grades, answers and contributions, but generally not those of other children - this may be problematic in the case of wiki activities or forum posts.&lt;br /&gt;
&lt;br /&gt;
There is some concern that children&#039;s forum contributions etc may be constrained if their parents are able to read all that they write; this may be particularly problematic in areas such as Personal, Social and Health Education (PSHE), where some schools may choose to use obfuscated usernames.&lt;br /&gt;
&lt;br /&gt;
===Manager===&lt;br /&gt;
&#039;&#039;Typically, for a manager in a business environment, they will want to be able to view reports, view grades for Quizzes, and view results from Surveys/Questionnaires for specific courses. They will also want to be able to view the list of enrolled students.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Note  that in Moodle 2.0, there is a manager role, but that is manager like a lesser admin. It is not manager like a manager in a business environment.&lt;br /&gt;
&lt;br /&gt;
===Weekly Seminar Leader===&lt;br /&gt;
&#039;&#039;In a university seminar, typically 8-15 students in their 3rd/4th year, each student is responsible for leading one topic in a study series.  I ask each student to research 5-10 resources, then give a powerpoint presentation to the other students.  This is followed by an in-class discussion and then online homework.  The homework involves some fun quiz questions and then some reflective journal questions.  I ask each seminar leader to prepare the quiz questions and journal questions as well as their presentation.  To do that, I would like to assign activity-making/authoring roles to the student--either for a short period, or for duration of the whole course.  Thus &amp;quot;Allow Quiz Authoring Role&amp;quot; or &amp;quot;Allow Assignment Authoring Role&amp;quot; at the course level or, if possible, even the Topic level (in a topic or week format course) would be important.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===Mentor/Mentee===&lt;br /&gt;
&#039;&#039;Please add text here...&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===Community-Designed Rating Criteria===&lt;br /&gt;
&#039;&#039;The gradebook tends to be the domain of the teacher.  What if community/peer ratings/marks could also be entered there? What if peer assessment criteria could be designed by the students, not just the teacher?&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===Visitor===&lt;br /&gt;
&lt;br /&gt;
This would be a role whereby one could allow a visitor to visit one&#039;s classroom. This might be a colleague interested in seeing your course, or a journalist who might be writing an article about one&#039;s site. They should not be able to see the names of any students anywhere (eg recent activity, forum posts) for privacy reasons. They should be able to try out things like quizzes, and lessons but no grades would be recorded (like in teacher preview mode). They would not be able to participate in choices and forums but could view them. It would be read only in a way like former-student role below but without access to a particular student&#039;s records that former student role would grant.&lt;br /&gt;
&lt;br /&gt;
===Guest Speaker===&lt;br /&gt;
&lt;br /&gt;
This role would be similar to the Visitor role above, but would allow seeing student names, and also allow both reading and posting to a specific forum or forums. We often have &amp;quot;guest speakers&amp;quot; who read and respond to student forum posts. Right now we have to add them as students, which isn&#039;t ideal.&lt;br /&gt;
&lt;br /&gt;
===Former Student===&lt;br /&gt;
This role would be of particular use for courses with rolling enrollments. This role would be one where a student had completed all of the requirements of a course (ie. assignments, quizzes etc.) but wished to have continued access to the course material for review or consultation. The key factor is that one would give access to the completed student to the notes he read, his work and the teacher&#039;s comments on it, but he would not be allowed to do anything that would take up the teacher&#039;s time. In other words, a sort-of read-only access to the course. How forums, which might contain pertinent information and would continue to grow, would be handled is a question. Perhaps the student would be shown only what was in the forums at the time he completed the course. He would not be allowed to see any new posts or add any himself. Same thing for database and glossary entries. In other words, a snapshot of the course at the time his regular enrollment ended. He shouldn&#039;t be able to see the names or profiles of any newly enrolled students for privacy reasons-hence the restrictions on forum access. One issue that would have to be dealt with would be changes to existing modules-such as resources. Does the student get access to the module as it was or as it is? We have no versioning of resources in Moodle so this would be a problem. What about a teacher changing a quiz question so that the answer is different? What would a former student see?&lt;br /&gt;
&lt;br /&gt;
===Alumnus=== &lt;br /&gt;
An ALUMNUS should be able to search for all other ALUMNI of the school, interact with them and be enrolled in a separate course - which is like a META course with all the content of his learning and interaction - as well as capabilities to be a part of this ALUMNI only course.  All the teachers of courses during school years should automatically be a part of the ALUMNI course .. which means when an ALUMNUS is enrolled in a course, the original teachers of all his courses get enrolled ?  --[[User:Anil Sharma|Anil Sharma]] 20:54, 15 July 2006 (WST)&lt;br /&gt;
&lt;br /&gt;
===Librarian===&lt;br /&gt;
&lt;br /&gt;
Reference Librarians have an active role in most of the courses taught at some schools such as Earlham College (with Bibliographic Instruction). The Librarian role within Moodle could encompass default read access to all courses (unless prohibited by course teacher) and read access to all components of the course unless access is barred (again by teacher). The Librarians would also perhaps have a block called perhaps Reference Services or Reference Desk with write access where they could deposit resources. Also this block might have a chat applet whereby enrolled students could chat to the Reference Librarian on duty about their bibliographic research needs.&lt;br /&gt;
&lt;br /&gt;
In schools there is often a book review system. This may be covered by the lending system database but may not in which case a librarian may neeed to have a course area they can create a database template to handle the reviews in which case they may have a normal teacher style role? Off topic but course an integration with common schools database systems would be great.&lt;br /&gt;
&lt;br /&gt;
===Teacher===&lt;br /&gt;
&lt;br /&gt;
Teachers should have read access to other Teacher&#039;s courses unless explictly prohibited. They should be able to set parts of their own course to be totally private (perhaps even to admin?). Just as each activity can currently be set to have group access, each activity could have a permissions field. Teachers could set default permissions for all activities on their course (eg they might disallow Librarian access for example) and then change the access permission for an individual activity. &lt;br /&gt;
&lt;br /&gt;
I think that what is needed is a simple heirarchy of permissions and levels of granularity.&lt;br /&gt;
&lt;br /&gt;
I would take issue with &amp;quot;teachers should have read access to other teacher&#039;s courses unless explicitly prohibited.&amp;quot; This is a violation of the students&#039; privacy as how they perform and what they do in one class isn&#039;t the business of another teacher. Moreover, in the real world a teacher wouldn&#039;t suddenly go sit in on a colleague&#039;s class without asking permission first. I would not have appreciated such an invasion of privacy as either a teacher or a student. It could be an option, but shouldn&#039;t be default.--[[User:N Hansen|N Hansen]] 19:54, 12 June 2006 (WST)&lt;br /&gt;
&lt;br /&gt;
===Community Education Tutors/Trainers===&lt;br /&gt;
Teachers may be community adult education trainers making use of a school moodle so must only have access to their courses unless given access elsewhere. They would not necessarily get the default teacher privileges.&lt;br /&gt;
&lt;br /&gt;
===Secretary/Student Worker===&lt;br /&gt;
&lt;br /&gt;
We often have faculty who want their departmental secretary or student worker to scan and upload files and perhaps create resources. Currently they have to be given teacher access to the course. This is dangerous from a FERPA standpoint since they could easily get access to grades.&lt;br /&gt;
&lt;br /&gt;
===Teaching Assistant===&lt;br /&gt;
&lt;br /&gt;
Our Faculty frequently have undergraduate students acting as Teaching Assistants. These students need to be able to add resources, create assignments, and possibly grade assignments. However, due to FERPA they cannot have access to other students&#039; overall grade information. I think the requirements here are slightly different than those of Secretary/Student Worker&lt;br /&gt;
&lt;br /&gt;
===Student - FERPA rights===&lt;br /&gt;
&lt;br /&gt;
A student that has asserted their FERPA rights to non-disclosure.  Typically includes not publishing their name&lt;br /&gt;
in any public place.  Could include this student only being seen with an &amp;quot;alias&amp;quot; within course spaces.  Is this an attribute rather&lt;br /&gt;
than a role?&lt;br /&gt;
&lt;br /&gt;
===Help Desk===&lt;br /&gt;
&lt;br /&gt;
Help desk agents that have read access for the purposes of trouble shooting.  Some care in placing this role within a hierarchy&lt;br /&gt;
of inheritance is needed, full access will be problematic with FERPA.&lt;br /&gt;
&lt;br /&gt;
===Admin - Catgory based===&lt;br /&gt;
&lt;br /&gt;
Basically a person in between full Admin and Creator that has the permissions of an Admin but only with respect to courses and students. Currently a Creator has permissions site-wide which does not always meet the requirements of a given organisation (e.g. Department A may not be happy that a person from Department B can create/modify courses within Department A&#039;s area). The ability to designate a Creator within a specific category would allow areas to be set up for a faculty/department/organisation and allow the Admin for that area to create/delete courses, upload users, add site-wide entries to the calendar etc.&lt;br /&gt;
&lt;br /&gt;
===Process Roles===&lt;br /&gt;
&lt;br /&gt;
organising the learning process for a group you wish to have the choice to place students in differnt roles: examples of this are:&lt;br /&gt;
* Give a student the role of forum-moderator with edit and chunk-rights&lt;br /&gt;
* Give students different roles &amp;amp; rights in a Webquest design (and change these roles next week&lt;br /&gt;
* Give students different resources, depending of their roles in a rolegame/simulation&lt;br /&gt;
* Give a student the rights to create the section content of next week (and only that week..)&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
*[[Hardening new Roles system]]&lt;br /&gt;
*[[Roles and modules]]&lt;br /&gt;
*Using Moodle course:&lt;br /&gt;
**[http://moodle.org/mod/forum/view.php?f=941 Roles and Capabilities forum]&lt;br /&gt;
**Key discussions at Using Moodle forums:&lt;br /&gt;
***[http://moodle.org/mod/forum/discuss.php?d=38788 Roles and Permissions architecture]&lt;br /&gt;
***[http://moodle.org/mod/forum/discuss.php?d=56302#256313 An example of admin roles as set in the database]&lt;br /&gt;
*** A short description by Tim Hunt of some new role related features in Moodle 2.0: [http://moodle.org/mod/forum/discuss.php?d=139641&amp;amp;parent=610871 Adding new roles as part of a module]&lt;br /&gt;
&lt;br /&gt;
[[Category:Roles]]&lt;br /&gt;
[[Category:Interfaces]]&lt;/div&gt;</summary>
		<author><name>Abhijit13</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=User:Abhijit_m&amp;diff=49731</id>
		<title>User:Abhijit m</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=User:Abhijit_m&amp;diff=49731"/>
		<updated>2016-03-27T08:21:18Z</updated>

		<summary type="html">&lt;p&gt;Abhijit13: Created page with &amp;quot;Abhijit A.M. http://github.com/abhijit13/&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Abhijit A.M.&lt;br /&gt;
http://github.com/abhijit13/&lt;/div&gt;</summary>
		<author><name>Abhijit13</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Output_API&amp;diff=49730</id>
		<title>Output API</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Output_API&amp;diff=49730"/>
		<updated>2016-03-27T08:19:18Z</updated>

		<summary type="html">&lt;p&gt;Abhijit13: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:Work in progress}}&lt;br /&gt;
&lt;br /&gt;
{{ Moodle 2.9 }}&lt;br /&gt;
&lt;br /&gt;
See [[ Output Components ]] for (much) older information on the using output components in previous versions of Moodle. &lt;br /&gt;
&lt;br /&gt;
This page is a fresh attempt to explain how renderers, renderables, themes and templates all work together for Moodle 2.9. &lt;br /&gt;
&lt;br /&gt;
Lets start with building a page that is part of an admin tool.&lt;br /&gt;
&lt;br /&gt;
E.g. &lt;br /&gt;
/admin/tool/demo/index.php&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
// Standard GPL and phpdocs&lt;br /&gt;
require_once(__DIR__ . &#039;/../../../config.php&#039;);&lt;br /&gt;
require_once($CFG-&amp;gt;libdir.&#039;/adminlib.php&#039;);&lt;br /&gt;
&lt;br /&gt;
admin_externalpage_setup(&#039;tooldemo&#039;);&lt;br /&gt;
&lt;br /&gt;
// Set up the page.&lt;br /&gt;
$title = get_string(&#039;pluginname&#039;, &#039;tool_demo&#039;);&lt;br /&gt;
$pagetitle = $title;&lt;br /&gt;
$url = new moodle_url(&amp;quot;/admin/tool/demo/index.php&amp;quot;);&lt;br /&gt;
$PAGE-&amp;gt;set_url($url);&lt;br /&gt;
$PAGE-&amp;gt;set_title($title);&lt;br /&gt;
$PAGE-&amp;gt;set_heading($title);&lt;br /&gt;
&lt;br /&gt;
$output = $PAGE-&amp;gt;get_renderer(&#039;tool_demo&#039;);&lt;br /&gt;
&lt;br /&gt;
echo $output-&amp;gt;header();&lt;br /&gt;
echo $output-&amp;gt;heading($pagetitle);&lt;br /&gt;
&lt;br /&gt;
$renderable = new \tool_demo\output\index_page(&#039;Some text&#039;);&lt;br /&gt;
echo $output-&amp;gt;render($renderable);&lt;br /&gt;
&lt;br /&gt;
echo $output-&amp;gt;footer();&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Explaining this demo step by step we have firstly the standard config and includes, plus the admin_externalpage_setup(&#039;tooldemo&#039;) which calls require_login and performs permissions checks for admin pages.&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&lt;br /&gt;
// Standard GPL and phpdocs&lt;br /&gt;
require_once(__DIR__ . &#039;/../../../config.php&#039;);&lt;br /&gt;
require_once($CFG-&amp;gt;libdir.&#039;/adminlib.php&#039;);&lt;br /&gt;
&lt;br /&gt;
admin_externalpage_setup(&#039;tooldemo&#039;);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then we load the title of the page from a lang string (see [[String_API]] ). We use this string to set some $PAGE properties (url title and heading). &lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
// Set up the page.&lt;br /&gt;
$title = get_string(&#039;pluginname&#039;, &#039;tool_demo&#039;);&lt;br /&gt;
$pagetitle = $title;&lt;br /&gt;
$url = new moodle_url(&amp;quot;/admin/tool/demo/index.php&amp;quot;);&lt;br /&gt;
$PAGE-&amp;gt;set_url($url);&lt;br /&gt;
$PAGE-&amp;gt;set_title($title);&lt;br /&gt;
$PAGE-&amp;gt;set_heading($title);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What is $PAGE and where did it come from ?&lt;br /&gt;
&lt;br /&gt;
$PAGE is a global variable used to track the state of the page that is being returned. It is an instance of the moodle_page class defined in lib/pagelib.php. See [[Page_API]] for more information on the $PAGE variable.&lt;br /&gt;
&lt;br /&gt;
The most important properties stored in $PAGE are the page context, the url, the layout, title and headings. $PAGE also gives access to some other important classes such as $PAGE-&amp;gt;requires, which is an instance of the page_requirements_manager (lib/outputrequirementslib.php). The page_requirements_manager class lets us set dependencies on e.g. javascript and css to be inserted in the correct place in the page (The order things are inserted in the page is hugely important for performance). &lt;br /&gt;
&lt;br /&gt;
$PAGE also lets us load specific renderers for a plugin, or plugin and subtype. We will cover renderers in more detail next.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$output = $PAGE-&amp;gt;get_renderer(&#039;tool_demo&#039;);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This gets an instance of the plugin_renderer_base class that we use to create all output for our page. Themers can subclass this renderer to override specific render methods in order to customise Moodle&#039;s output. See [[Output_renderers]] for more information, and [[Overriding_a_renderer]] for information about how themers can customise a renderer. &lt;br /&gt;
&lt;br /&gt;
Note - some pages use the global variable $OUTPUT to generate their output. This is a generic renderer used for core pages etc, but plugins should always use a more specific plugin renderer. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
echo $output-&amp;gt;header();&lt;br /&gt;
echo $output-&amp;gt;heading($pagetitle);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This code prints the header of the page and adds one heading to the page at the top of the content region. Page headings are very important in Moodle and should be applied consistently. See [[HTML_Guidelines]] for more information on how and where to use  headings.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$renderable = new \tool_demo\output\index_page(&#039;Some text&#039;);&lt;br /&gt;
echo $output-&amp;gt;render($renderable);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is the most interesting part of our page. We are creating a renderable and telling our renderer to render it. The renderable is usually more complex than this, it should hold all the data required for the renderer to display the page. This means we should perform all our logic such as database queries, page parameters and access checks in advance and the results should be passed as data to the renderable. The renderable then just takes that data and returns a HTML representation of it. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
echo $output-&amp;gt;footer();&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This prints the HTML for the bottom of the page. It is very important because it also prints out things that were added to the page_requirements_manager and need to be printed in the footer. Things like javascript includes, navigation tree setup, closing open containers tags etc. The reason all javascripts are added to the footer of the page is for performance. If you add javascript includes to the top of the page, or inline with the content the browser must stop and execute the javascript before it can render the page. See https://developers.google.com/speed/docs/insights/BlockingJS for more information.&lt;br /&gt;
&lt;br /&gt;
In the code above, we created a renderable. This is a class that you have to add to your plugin. It holds all the data required to display something on the page. Here is the renderable for this example:&lt;br /&gt;
&lt;br /&gt;
/admin/tool/demo/classes/output/index_page.php&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
// Standard GPL and phpdocs&lt;br /&gt;
namespace tool_demo\output;                                                                                                         &lt;br /&gt;
                                                                                                                                    &lt;br /&gt;
use renderable;                                                                                                                     &lt;br /&gt;
use renderer_base;                                                                                                                  &lt;br /&gt;
use templatable;                                                                                                                    &lt;br /&gt;
use stdClass;                                                                                                                       &lt;br /&gt;
             &lt;br /&gt;
class index_page implements renderable, templatable {                                                                               &lt;br /&gt;
    /** @var string $sometext Some text to show how to pass data to a template. */                                                  &lt;br /&gt;
    var $sometext = null;                                                                                                           &lt;br /&gt;
            &lt;br /&gt;
    public function __construct($sometext) {                                                                                        &lt;br /&gt;
        $this-&amp;gt;sometext = $sometext;                                                                                                &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    /**                                                                                                                             &lt;br /&gt;
     * Export this data so it can be used as the context for a mustache template.                                                   &lt;br /&gt;
     *                                                                                                                              &lt;br /&gt;
     * @return stdClass                                                                                                             &lt;br /&gt;
     */                                                                                                                             &lt;br /&gt;
    public function export_for_template(renderer_base $output) {                                                                    &lt;br /&gt;
        $data = new stdClass();                                                                                                     &lt;br /&gt;
        $data-&amp;gt;sometext = $this-&amp;gt;sometext;                                                                                          &lt;br /&gt;
        return $data;                                                                                                               &lt;br /&gt;
    }&lt;br /&gt;
}         &lt;br /&gt;
?&amp;gt;                      &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This class implements the renderable interface, which has no methods, and the templatable interface, which means that this class could be rendered with a template, so it must implement the &amp;quot;export_for_template&amp;quot; method. So in this example, the class accepts data via it&#039;s constructor, and stores that data in class variables. It does nothing else fancy with the data in this example (but it could). Note that the export_for_template function should only return simple types (arrays, stdClass, bool, int, float, string).&lt;br /&gt;
&lt;br /&gt;
Now lets look at the renderer for this plugin.&lt;br /&gt;
&lt;br /&gt;
tool/admin/demo/classes/output/renderer.php&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
// Standard GPL and phpdocs&lt;br /&gt;
namespace tool_demo\output;                                                                                                         &lt;br /&gt;
                                                                                                                                    &lt;br /&gt;
defined(&#039;MOODLE_INTERNAL&#039;) || die;                                                                                                  &lt;br /&gt;
                                                                                                                                    &lt;br /&gt;
use plugin_renderer_base;  &lt;br /&gt;
&lt;br /&gt;
class renderer extends plugin_renderer_base {&lt;br /&gt;
    /**                                                                                                                             &lt;br /&gt;
     * Defer to template.                                                                                                           &lt;br /&gt;
     *                                                                                                                              &lt;br /&gt;
     * @param index_page $page                                                                                                      &lt;br /&gt;
     *                                                                                                                              &lt;br /&gt;
     * @return string html for the page                                                                                             &lt;br /&gt;
     */                                                                                                                             &lt;br /&gt;
    public function render_index_page($page) {                                                                                      &lt;br /&gt;
        $data = $page-&amp;gt;export_for_template($this);                                                                                  &lt;br /&gt;
        return parent::render_from_template(&#039;tool_demo/index_page&#039;, $data);                                                         &lt;br /&gt;
    }           &lt;br /&gt;
}&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The renderer exists to provide render_x methods for all renderables used in the plugin. A theme designer can provide a custom version of this renderer that changes the behaviour of any of the render methods and so to customize their theme. In this example, the render method for the index page (render_index_page) does 2 things. It asks the renderable to export it&#039;s data so that it is suitable for passing as the context to a template, and then renders a specific template with this context. A themer could either manipulate the data in the render method (e.g. removing menu entries), or change the template (change the generated html) to customize the output. &lt;br /&gt;
&lt;br /&gt;
The template used in this plugin is located in the plugins templates folder. The template can also be overridden by a themer. &lt;br /&gt;
&lt;br /&gt;
admin/tool/demo/templates/index_page.mustache&lt;br /&gt;
&amp;lt;code xml&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;hero-unit&amp;quot;&amp;gt;                                                                                                             &lt;br /&gt;
  &amp;lt;h1&amp;gt;Heading&amp;lt;/h1&amp;gt;                                                                                                                  &lt;br /&gt;
  &amp;lt;p&amp;gt;{{sometext}}&amp;lt;/p&amp;gt;                                                                                                               &lt;br /&gt;
&amp;lt;/div&amp;gt; &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is the mustache template for this demo. It uses some bootstrap classes directly to position and style the content on the page. {{sometext}} is replaced with the variable from the context when this template is rendered. For more information on templates see [[Templates]].&lt;/div&gt;</summary>
		<author><name>Abhijit13</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Output_API&amp;diff=49729</id>
		<title>Output API</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Output_API&amp;diff=49729"/>
		<updated>2016-03-27T08:17:10Z</updated>

		<summary type="html">&lt;p&gt;Abhijit13: added &amp;lt;?php ?&amp;gt; so that the page code can be directed copy-pasted in a file&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:Work in progress}}&lt;br /&gt;
&lt;br /&gt;
{{ Moodle 2.9 }}&lt;br /&gt;
&lt;br /&gt;
See [[ Output Components ]] for (much) older information on the using output components in previous versions of Moodle. &lt;br /&gt;
&lt;br /&gt;
This page is a fresh attempt to explain how renderers, renderables, themes and templates all work together for Moodle 2.9. &lt;br /&gt;
&lt;br /&gt;
Lets start with building a page that is part of an admin tool.&lt;br /&gt;
&lt;br /&gt;
E.g. &lt;br /&gt;
/admin/tool/demo/index.php&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
// Standard GPL and phpdocs&lt;br /&gt;
require_once(__DIR__ . &#039;/../../../config.php&#039;);&lt;br /&gt;
require_once($CFG-&amp;gt;libdir.&#039;/adminlib.php&#039;);&lt;br /&gt;
&lt;br /&gt;
admin_externalpage_setup(&#039;tooldemo&#039;);&lt;br /&gt;
&lt;br /&gt;
// Set up the page.&lt;br /&gt;
$title = get_string(&#039;pluginname&#039;, &#039;tool_demo&#039;);&lt;br /&gt;
$pagetitle = $title;&lt;br /&gt;
$url = new moodle_url(&amp;quot;/admin/tool/demo/index.php&amp;quot;);&lt;br /&gt;
$PAGE-&amp;gt;set_url($url);&lt;br /&gt;
$PAGE-&amp;gt;set_title($title);&lt;br /&gt;
$PAGE-&amp;gt;set_heading($title);&lt;br /&gt;
&lt;br /&gt;
$output = $PAGE-&amp;gt;get_renderer(&#039;tool_demo&#039;);&lt;br /&gt;
&lt;br /&gt;
echo $output-&amp;gt;header();&lt;br /&gt;
echo $output-&amp;gt;heading($pagetitle);&lt;br /&gt;
&lt;br /&gt;
$renderable = new \tool_demo\output\index_page(&#039;Some text&#039;);&lt;br /&gt;
echo $output-&amp;gt;render($renderable);&lt;br /&gt;
&lt;br /&gt;
echo $output-&amp;gt;footer();&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Explaining this demo step by step we have firstly the standard config and includes, plus the admin_externalpage_setup(&#039;tooldemo&#039;) which calls require_login and performs permissions checks for admin pages.&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&lt;br /&gt;
// Standard GPL and phpdocs&lt;br /&gt;
require_once(__DIR__ . &#039;/../../../config.php&#039;);&lt;br /&gt;
require_once($CFG-&amp;gt;libdir.&#039;/adminlib.php&#039;);&lt;br /&gt;
&lt;br /&gt;
admin_externalpage_setup(&#039;tooldemo&#039;);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then we load the title of the page from a lang string (see [[String_API]] ). We use this string to set some $PAGE properties (url title and heading). &lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
// Set up the page.&lt;br /&gt;
$title = get_string(&#039;pluginname&#039;, &#039;tool_demo&#039;);&lt;br /&gt;
$pagetitle = $title;&lt;br /&gt;
$url = new moodle_url(&amp;quot;/admin/tool/demo/index.php&amp;quot;);&lt;br /&gt;
$PAGE-&amp;gt;set_url($url);&lt;br /&gt;
$PAGE-&amp;gt;set_title($title);&lt;br /&gt;
$PAGE-&amp;gt;set_heading($title);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What is $PAGE and where did it come from ?&lt;br /&gt;
&lt;br /&gt;
$PAGE is a global variable used to track the state of the page that is being returned. It is an instance of the moodle_page class defined in lib/pagelib.php. See [[Page_API]] for more information on the $PAGE variable.&lt;br /&gt;
&lt;br /&gt;
The most important properties stored in $PAGE are the page context, the url, the layout, title and headings. $PAGE also gives access to some other important classes such as $PAGE-&amp;gt;requires, which is an instance of the page_requirements_manager (lib/outputrequirementslib.php). The page_requirements_manager class lets us set dependencies on e.g. javascript and css to be inserted in the correct place in the page (The order things are inserted in the page is hugely important for performance). &lt;br /&gt;
&lt;br /&gt;
$PAGE also lets us load specific renderers for a plugin, or plugin and subtype. We will cover renderers in more detail next.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$output = $PAGE-&amp;gt;get_renderer(&#039;tool_demo&#039;);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This gets an instance of the plugin_renderer_base class that we use to create all output for our page. Themers can subclass this renderer to override specific render methods in order to customise Moodle&#039;s output. See [[Output_renderers]] for more information, and [[Overriding_a_renderer]] for information about how themers can customise a renderer. &lt;br /&gt;
&lt;br /&gt;
Note - some pages use the global variable $OUTPUT to generate their output. This is a generic renderer used for core pages etc, but plugins should always use a more specific plugin renderer. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
echo $output-&amp;gt;header();&lt;br /&gt;
echo $output-&amp;gt;heading($pagetitle);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This code prints the header of the page and adds one heading to the page at the top of the content region. Page headings are very important in Moodle and should be applied consistently. See [[HTML_Guidelines]] for more information on how and where to use  headings.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$renderable = new \tool_demo\output\index_page(&#039;Some text&#039;);&lt;br /&gt;
echo $output-&amp;gt;render($renderable);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is the most interesting part of our page. We are creating a renderable and telling our renderer to render it. The renderable is usually more complex than this, it should hold all the data required for the renderer to display the page. This means we should perform all our logic such as database queries, page parameters and access checks in advance and the results should be passed as data to the renderable. The renderable then just takes that data and returns a HTML representation of it. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
echo $output-&amp;gt;footer();&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This prints the HTML for the bottom of the page. It is very important because it also prints out things that were added to the page_requirements_manager and need to be printed in the footer. Things like javascript includes, navigation tree setup, closing open containers tags etc. The reason all javascripts are added to the footer of the page is for performance. If you add javascript includes to the top of the page, or inline with the content the browser must stop and execute the javascript before it can render the page. See https://developers.google.com/speed/docs/insights/BlockingJS for more information.&lt;br /&gt;
&lt;br /&gt;
In the code above, we created a renderable. This is a class that you have to add to your plugin. It holds all the data required to display something on the page. Here is the renderable for this example:&lt;br /&gt;
&lt;br /&gt;
/admin/tool/demo/classes/output/index_page.php&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
// Standard GPL and phpdocs&lt;br /&gt;
namespace tool_demo\output;                                                                                                         &lt;br /&gt;
                                                                                                                                    &lt;br /&gt;
use renderable;                                                                                                                     &lt;br /&gt;
use renderer_base;                                                                                                                  &lt;br /&gt;
use templatable;                                                                                                                    &lt;br /&gt;
use stdClass;                                                                                                                       &lt;br /&gt;
             &lt;br /&gt;
class index_page implements renderable, templatable {                                                                               &lt;br /&gt;
    /** @var string $sometext Some text to show how to pass data to a template. */                                                  &lt;br /&gt;
    var $sometext = null;                                                                                                           &lt;br /&gt;
            &lt;br /&gt;
    public function __construct($sometext) {                                                                                        &lt;br /&gt;
        $this-&amp;gt;sometext = $sometext;                                                                                                &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    /**                                                                                                                             &lt;br /&gt;
     * Export this data so it can be used as the context for a mustache template.                                                   &lt;br /&gt;
     *                                                                                                                              &lt;br /&gt;
     * @return stdClass                                                                                                             &lt;br /&gt;
     */                                                                                                                             &lt;br /&gt;
    public function export_for_template(renderer_base $output) {                                                                    &lt;br /&gt;
        $data = new stdClass();                                                                                                     &lt;br /&gt;
        $data-&amp;gt;sometext = $this-&amp;gt;sometext;                                                                                          &lt;br /&gt;
        return $data;                                                                                                               &lt;br /&gt;
    }&lt;br /&gt;
}                               &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This class implements the renderable interface, which has no methods, and the templatable interface, which means that this class could be rendered with a template, so it must implement the &amp;quot;export_for_template&amp;quot; method. So in this example, the class accepts data via it&#039;s constructor, and stores that data in class variables. It does nothing else fancy with the data in this example (but it could). Note that the export_for_template function should only return simple types (arrays, stdClass, bool, int, float, string).&lt;br /&gt;
&lt;br /&gt;
Now lets look at the renderer for this plugin.&lt;br /&gt;
&lt;br /&gt;
tool/admin/demo/classes/output/renderer.php&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
// Standard GPL and phpdocs&lt;br /&gt;
namespace tool_demo\output;                                                                                                         &lt;br /&gt;
                                                                                                                                    &lt;br /&gt;
defined(&#039;MOODLE_INTERNAL&#039;) || die;                                                                                                  &lt;br /&gt;
                                                                                                                                    &lt;br /&gt;
use plugin_renderer_base;  &lt;br /&gt;
&lt;br /&gt;
class renderer extends plugin_renderer_base {&lt;br /&gt;
    /**                                                                                                                             &lt;br /&gt;
     * Defer to template.                                                                                                           &lt;br /&gt;
     *                                                                                                                              &lt;br /&gt;
     * @param index_page $page                                                                                                      &lt;br /&gt;
     *                                                                                                                              &lt;br /&gt;
     * @return string html for the page                                                                                             &lt;br /&gt;
     */                                                                                                                             &lt;br /&gt;
    public function render_index_page($page) {                                                                                      &lt;br /&gt;
        $data = $page-&amp;gt;export_for_template($this);                                                                                  &lt;br /&gt;
        return parent::render_from_template(&#039;tool_demo/index_page&#039;, $data);                                                         &lt;br /&gt;
    }           &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The renderer exists to provide render_x methods for all renderables used in the plugin. A theme designer can provide a custom version of this renderer that changes the behaviour of any of the render methods and so to customize their theme. In this example, the render method for the index page (render_index_page) does 2 things. It asks the renderable to export it&#039;s data so that it is suitable for passing as the context to a template, and then renders a specific template with this context. A themer could either manipulate the data in the render method (e.g. removing menu entries), or change the template (change the generated html) to customize the output. &lt;br /&gt;
&lt;br /&gt;
The template used in this plugin is located in the plugins templates folder. The template can also be overridden by a themer. &lt;br /&gt;
&lt;br /&gt;
admin/tool/demo/templates/index_page.mustache&lt;br /&gt;
&amp;lt;code xml&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;hero-unit&amp;quot;&amp;gt;                                                                                                             &lt;br /&gt;
  &amp;lt;h1&amp;gt;Heading&amp;lt;/h1&amp;gt;                                                                                                                  &lt;br /&gt;
  &amp;lt;p&amp;gt;{{sometext}}&amp;lt;/p&amp;gt;                                                                                                               &lt;br /&gt;
&amp;lt;/div&amp;gt; &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is the mustache template for this demo. It uses some bootstrap classes directly to position and style the content on the page. {{sometext}} is replaced with the variable from the context when this template is rendered. For more information on templates see [[Templates]].&lt;/div&gt;</summary>
		<author><name>Abhijit13</name></author>
	</entry>
</feed>