<?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=Vf</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=Vf"/>
	<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/Special:Contributions/Vf"/>
	<updated>2026-04-25T16:38:09Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=User:Valery_Fremaux&amp;diff=37905</id>
		<title>User:Valery Fremaux</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=User:Valery_Fremaux&amp;diff=37905"/>
		<updated>2013-02-21T12:46:07Z</updated>

		<summary type="html">&lt;p&gt;Vf: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Hi&lt;br /&gt;
&lt;br /&gt;
I am now full time independant architect for Moodle Integrations in France.&lt;br /&gt;
&lt;br /&gt;
I was originally graduated in Electronics Engineering but leaved quite a long time ago the Dark Side of the force...&lt;br /&gt;
I got a further master degree in Ethnomethodology related to Computer Sciences topics, and a master degree in Hypermedia and Sociologic Issues. &lt;br /&gt;
&lt;br /&gt;
I was working as ICT teacher in EISTI where i developped my Applied Research Lab in Web technologies and Web app based architectures.&lt;br /&gt;
&lt;br /&gt;
I now work on Moodle quite full time (even twice time) for 10 years, starting with a Moodle evaluation in 2003 for a European funded project.&lt;br /&gt;
&lt;br /&gt;
==My Key topics==&lt;br /&gt;
&lt;br /&gt;
===Technical architecture===&lt;br /&gt;
* Moodle MNET working in consistant Moodle arrays or constellations&lt;br /&gt;
* Distributes Moodle service architectures&lt;br /&gt;
&lt;br /&gt;
===Top level usages===&lt;br /&gt;
* Hi level content editorialization in Moodle&lt;br /&gt;
* Course management, publishing cycle management&lt;br /&gt;
&lt;br /&gt;
===Pedagogic Items===&lt;br /&gt;
* Cognitive engines&lt;br /&gt;
* Coordination and cooperation activities&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==My major contribs==&lt;br /&gt;
* Techproject Module&lt;br /&gt;
* Customlabel Module&lt;br /&gt;
* Magtest Module&lt;br /&gt;
* Coursehop block&lt;br /&gt;
&lt;br /&gt;
In total more than 50 contributions packaged in of plugin types...&lt;/div&gt;</summary>
		<author><name>Vf</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Developer_documentation&amp;diff=649</id>
		<title>Developer documentation</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Developer_documentation&amp;diff=649"/>
		<updated>2010-01-04T21:44:59Z</updated>

		<summary type="html">&lt;p&gt;Vf: /* Resources */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This [[:Category:Developer|Developer]] section of Moodle Docs is aimed at developers who contribute to the Moodle code, plugins, themes, and so on.&lt;br /&gt;
* If you manage a Moodle site, [[Administrator documentation]] may suit your needs better. &lt;br /&gt;
* If you teach using Moodle, try [[Teacher documentation]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p class=&amp;quot;note&amp;quot;&amp;gt;&#039;&#039;&#039;Note:&#039;&#039;&#039; New developer documentation pages should be added to the &#039;&#039;Development namespace&#039;&#039; by typing &amp;lt;code&amp;gt;Development:&amp;lt;/code&amp;gt; before the new page name i.e. &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;[[New page name]]&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;. If you are a developer, you probably want to change your [[Special:Preferences|preferences]] to include the Development namespace in searches.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A page may be added to the Developer category by adding the template &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{CategoryDeveloper}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; to the bottom of the page. - If required, you can use &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;[[Category:Sort key]]&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; to provide a sort key other than the default page name.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==How Moodle development works==&lt;br /&gt;
&lt;br /&gt;
The [[Overview|overview of the Moodle development process]] explains how Moodle development occurs and how people become Moodle developers. Current plans are listed on the [[Roadmap]].&lt;br /&gt;
&lt;br /&gt;
You can also enrol in one of the [http://dev.moodle.org Moodle Developer Courses].&lt;br /&gt;
&lt;br /&gt;
==Guidelines==&lt;br /&gt;
&lt;br /&gt;
The following guidelines are crucial reading for anyone wanting to contribute to the Moodle code base:&lt;br /&gt;
*[[Coding|Coding guidelines]] have to be followed by all Moodle developers&lt;br /&gt;
*[[Moodle design goals]] spells out the basic design goals behind Moodle&lt;br /&gt;
*[[Interface guidelines]] aim to provide a common feel to the Moodle user interface&lt;br /&gt;
*[[CVS (developer)|Moodle CVS for developers]] explains how to work with the Moodle code in CVS&lt;br /&gt;
*[[Tracker]] explains the Moodle Tracker for keeping track of bugs, issues, feature requests etc&lt;br /&gt;
*[[Working with the Community|Working with the Community]] explains how to engage with the dev community and discuss changes&lt;br /&gt;
*[[Unit tests|Unit tests]] explains how to run the unit tests, and how to write new test cases.&lt;br /&gt;
*[[Fast portable SQL]] shows SQL techniques that are fast, efficient, and known to work on all supported DBs.&lt;br /&gt;
&lt;br /&gt;
==Documentation for core components==&lt;br /&gt;
&lt;br /&gt;
This section is for documentation of specific components of the existing core Moodle code. Discussion of components that are under discussion or in development can be found in the [[Developer notes|developer notes]] or on the [[Roadmap|roadmap]].&lt;br /&gt;
&lt;br /&gt;
The documents below give a general overview. For detailed function-by-function documentation, see the [http://phpdocs.moodle.org/ phpDocumentor] documentation that is automatically generated from the comments in the code. &lt;br /&gt;
&lt;br /&gt;
And don&#039;t forget that the most up-to-date and detailed description of how the code works is the code itself, and you can [http://xref.moodle.org/nav.html?index.html browse the code online] using [[PHPXref|PHPXref]].&lt;br /&gt;
&lt;br /&gt;
===Core components that affect everything===&lt;br /&gt;
&lt;br /&gt;
*[[Database schema introduction|The database schema]]&lt;br /&gt;
*[[What happens when you require config.php|What happens when you require config.php]]&lt;br /&gt;
*lib/moodlelib.php &lt;br /&gt;
*[[lib/weblib.php|lib/weblib.php]] for outputting stuff&lt;br /&gt;
*[[JavaScript_functions|JavaScript function available on the client side]]&lt;br /&gt;
*[[XMLDB_Documentation|Database abstraction layer]] @ v[[1.7]]&lt;br /&gt;
*[[Roles|Roles and Capabilities system]] @ v[[1.7]] for controlling who can do what&lt;br /&gt;
*[[lib/formslib.php|Forms library]] @ v[[1.8]] for creating accessible and secure HTML forms that let users edit things&lt;br /&gt;
*[[Using_the_file_API|File API]] @ v[[2.0]] for managing files stored by Moodle&lt;br /&gt;
&lt;br /&gt;
===Core libraries with a more specific uses===&lt;br /&gt;
&lt;br /&gt;
*[[Authentication API]]&lt;br /&gt;
*[[Cookieless Sessions]]&lt;br /&gt;
*[[Email processing]]&lt;br /&gt;
*[[Environment checking|Environment checking]] before install, check the user&#039;s server to ensure Moodle will work there.&lt;br /&gt;
*[[Groups|Groups system]]&lt;br /&gt;
*[[Grades|Gradebook]]&lt;br /&gt;
*[[Moodle Network|Moodle Network]]&lt;br /&gt;
*[[Question engine]]&lt;br /&gt;
*[[Stats package]]&lt;br /&gt;
*[[UTF-8 migration|Migration to UTF-8]] @ v[[:Category:Moodle 1.6|1.6]]&lt;br /&gt;
*[http://developer.yahoo.com/yui YUI JavaScript library] - YUI was selected as the official AJAX library for Moodle.&lt;br /&gt;
*[[lib/graphlib|lib/graphlib]]&lt;br /&gt;
*[[Admin settings|Admin settings]]&lt;br /&gt;
&lt;br /&gt;
===Modules included in the standard distribution===&lt;br /&gt;
&lt;br /&gt;
*[[Lesson Specification|Lesson Specification]]&lt;br /&gt;
*[[Quiz developer docs|Quiz module]]&lt;br /&gt;
*[[SCORM schema|SCORM module 1.5 schema]]&lt;br /&gt;
&lt;br /&gt;
==How you can contribute==&lt;br /&gt;
&lt;br /&gt;
===Make a new plugin===&lt;br /&gt;
&lt;br /&gt;
The M in Moodle stands for modular, and the easiest, most maintainable way to add new functionality to Moodle is by using one of the many plugin APIs. There are many types of plugin you can write:&lt;br /&gt;
*[[Modules|Activity modules]], see also [[NEWMODULE Documentation]] (work in progress)&lt;br /&gt;
*[[Admin reports|Admin reports]]&lt;br /&gt;
*[[Assignment types|Assignment types]]&lt;br /&gt;
*[[Authentication plugins|Authentication plugins]]&lt;br /&gt;
*[[Blocks|Blocks]]&lt;br /&gt;
*[[Course formats]]&lt;br /&gt;
*[[Course Report Plugins|Course reports]]&lt;br /&gt;
*[[Database fields|Database fields]]&lt;br /&gt;
*[[Database presets|Database presets]]&lt;br /&gt;
*[[Enrolment plugins|Enrolment plugins]]&lt;br /&gt;
*[[Filters|Filters]]&lt;br /&gt;
*[[Gradebook plugins|Gradebook plugins]] (1.9 onwards)&lt;br /&gt;
**[[Gradebook_Report_Tutorial|Gradebook report]]&lt;br /&gt;
**[[Gradebook export|Gradebook export]]&lt;br /&gt;
**[[Gradebook import|Gradebook import]]&lt;br /&gt;
*[[Writing_a_Portfolio_Plugin|Portfolio plugins]] (2.0 onwards)&lt;br /&gt;
*[[Question_type_plugin_how_to|Question types]]&lt;br /&gt;
*[[Question import/export formats|Question import/export formats]]&lt;br /&gt;
*[[How to write a quiz report plugin|Quiz reports]]&lt;br /&gt;
*[[Repository plugins|Repository plugins]] (2.0 onwards)&lt;br /&gt;
*[[Resource types|Resource types]]&lt;br /&gt;
*[[Search engine adapters|Search engine adapters]]&lt;br /&gt;
&lt;br /&gt;
General information that applies to all types of plugins&lt;br /&gt;
*[[Places to search for lang strings|Where to put language strings for your plugin]]&lt;br /&gt;
*[[Installing and upgrading plugin database tables|Defining the database tables for your plugin]]&lt;br /&gt;
&lt;br /&gt;
Please see the [[Guidelines for contributed code|Guidelines for contributed code]] for an overview of how to contribute to the Moodle code.&lt;br /&gt;
&lt;br /&gt;
Sometimes it is not possible to write a proper plugin for what you want to do, in which case you may have to resort to using the [[Local_customisation|local customisations]] hook.&lt;br /&gt;
&lt;br /&gt;
===Change core code===&lt;br /&gt;
&lt;br /&gt;
Some types of change can only be made by editing the core Moodle code. Such changes are much harder to maintain than plugins. If you want your core change to be considered for inclusion in the official Moodle release, you need to create an issue in the [[Tracker|tracker]], and attach your change as a [[How_to_create_a_patch|patch]]. It is also a good idea to discuss your ideas in the forums first.  See [[Overview#Major_Development]] for more details.&lt;br /&gt;
&lt;br /&gt;
===Ways to contribute that do not involve PHP programming===&lt;br /&gt;
&lt;br /&gt;
*[[Themes|Create Moodle themes]]&lt;br /&gt;
*[[Translation|Translate Moodle into other languages]]&lt;br /&gt;
*[[MoodleDocs:Guidelines for contributors|Help document Moodle]]&lt;br /&gt;
*[[Tests|Join the testing effort]], which involves [[Tracker|participating in the bug tracker]]&lt;br /&gt;
&lt;br /&gt;
==Plans for the future==&lt;br /&gt;
&lt;br /&gt;
Ideas for and details of planned future features of Moodle are initially discussed on the forums in the [http://moodle.org/course/view.php?id=5 Using Moodle] course at moodle.org. That developer discussions are intermixed with user discussions in the same forums may seem strange at first but is one of the reasons for the success of Moodle. It is important that both end-users and developers discuss the future features together.&lt;br /&gt;
&lt;br /&gt;
Once ideas begin to crystallize on the forums they can be summarized in this wiki, either as part of the [[Roadmap|roadmap]] or in the form of [[Developer notes|developer notes]]. These pages then form the basis for further discussion in the forums.&lt;br /&gt;
&lt;br /&gt;
*[[Roadmap]]&lt;br /&gt;
*[[Developer notes|Developer notes]]&lt;br /&gt;
*[[Student projects]]&lt;br /&gt;
*[[Developer meetings]]&lt;br /&gt;
&lt;br /&gt;
== Resources ==&lt;br /&gt;
&lt;br /&gt;
*[[Developer FAQ]] - frequently asked questions, especially useful for newcomers to Moodle&lt;br /&gt;
*[[Finding_your_way_into_the_Moodle_code|Finding your way into the Moodle code]] - also aimed at newcomers&lt;br /&gt;
*[http://tracker.moodle.org/ Moodle tracker] - bug reports, feature requests and other tracked issues&lt;br /&gt;
**[[Firefox tracker search]] - How to setup a firefox quicksearch to easily navigate to moodle bugs&lt;br /&gt;
**[[Firefox tracker search#Firefox Search Plugins|Firefox Search Plugins]] - Find tracked issues even more easily&lt;br /&gt;
*[[Unmerged files]] - changes on the stable branch in CVS that have not been merged to [[HEAD]]&lt;br /&gt;
*Browse the code online:&lt;br /&gt;
**[http://cvs.moodle.org/moodle/ the code with a complete change history from CVS]&lt;br /&gt;
**[http://xref.moodle.org/index.html the code, with links generated by PHPXref]&lt;br /&gt;
*[http://phpdocs.moodle.org/ Moodle PHP doc reference] - compiled nightly from the comment attached to each class and function in the code.  &lt;br /&gt;
*[[Database Schema|Database Schema]] - for recent releases&lt;br /&gt;
*[http://moodle.org/course/view.php?id=5#4 Development news and discussion] section of Using Moodle course&lt;br /&gt;
**especially the [http://moodle.org/mod/forum/view.php?id=55 General developer forum]&lt;br /&gt;
**[[Filters used on the Moodle.org forums|cool tricks you can use in the moodle.org forums]]&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
Some tools people use when working on Moodle code:&lt;br /&gt;
&lt;br /&gt;
=== IDEs ===&lt;br /&gt;
&lt;br /&gt;
* [[Setting_up_Netbeans|Setting up NetBeans for Moodle development]] - NetBeans for PHP is a great out-of-the-box editor.&lt;br /&gt;
* [[Setting_up_Eclipse|Setting up Eclipse for Moodle development]] - Eclipse is a great editor to use for php development, if you can work out how to set it up.&lt;br /&gt;
* [[vim|Setting up Vim for Moodle development]]&lt;br /&gt;
&lt;br /&gt;
=== Browser add-ons ===&lt;br /&gt;
*[http://getfirebug.com Firebug], see [[Firebug]].&lt;br /&gt;
* [[Web developer extension]]&lt;br /&gt;
* [https://addons.mozilla.org/en-US/firefox/addon/394 ViewSourceWith] - The main goal is to view page source with external applications, but you can do a lot of other things as well.&lt;br /&gt;
&lt;br /&gt;
=== Miscellaneous === &lt;br /&gt;
*[[ctags|Ctags]] - Using a tags file to navigate code&lt;br /&gt;
*[[W3C_validation|W3C HTML validator]] - Moodle has built in support to make using it easier.&lt;br /&gt;
*[[Windows Installer|Windows Installer]] - Windows Installer documentation for developer.&lt;br /&gt;
&lt;br /&gt;
See also: [http://dev.moodle.org/mod/forum/view.php?id=18 Useful Development Tools forum]in the [http://dev.moodle.org/course/view.php?id=2 Introduction to Moodle Programming course]&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
*[http://moodle.org/security/ Moodle Security Announcements]&lt;br /&gt;
*[http://moodle.com/partners/ Moodle Partners] - providers of custom Moodle development services&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer tools]]&lt;br /&gt;
&lt;br /&gt;
[[ru:Development:Краткий обзор]]&lt;/div&gt;</summary>
		<author><name>Vf</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Developer_documentation&amp;diff=648</id>
		<title>Developer documentation</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Developer_documentation&amp;diff=648"/>
		<updated>2009-12-21T16:03:43Z</updated>

		<summary type="html">&lt;p&gt;Vf: /* Resources */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This [[:Category:Developer|Developer]] section of Moodle Docs is aimed at developers who contribute to the Moodle code, plugins, themes, and so on.&lt;br /&gt;
* If you manage a Moodle site, [[Administrator documentation]] may suit your needs better. &lt;br /&gt;
* If you teach using Moodle, try [[Teacher documentation]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p class=&amp;quot;note&amp;quot;&amp;gt;&#039;&#039;&#039;Note:&#039;&#039;&#039; New developer documentation pages should be added to the &#039;&#039;Development namespace&#039;&#039; by typing &amp;lt;code&amp;gt;Development:&amp;lt;/code&amp;gt; before the new page name i.e. &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;[[New page name]]&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;. If you are a developer, you probably want to change your [[Special:Preferences|preferences]] to include the Development namespace in searches.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A page may be added to the Developer category by adding the template &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{CategoryDeveloper}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; to the bottom of the page. - If required, you can use &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;[[Category:Sort key]]&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; to provide a sort key other than the default page name.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==How Moodle development works==&lt;br /&gt;
&lt;br /&gt;
The [[Overview|overview of the Moodle development process]] explains how Moodle development occurs and how people become Moodle developers. Current plans are listed on the [[Roadmap]].&lt;br /&gt;
&lt;br /&gt;
You can also enrol in one of the [http://dev.moodle.org Moodle Developer Courses].&lt;br /&gt;
&lt;br /&gt;
==Guidelines==&lt;br /&gt;
&lt;br /&gt;
The following guidelines are crucial reading for anyone wanting to contribute to the Moodle code base:&lt;br /&gt;
*[[Coding|Coding guidelines]] have to be followed by all Moodle developers&lt;br /&gt;
*[[Moodle design goals]] spells out the basic design goals behind Moodle&lt;br /&gt;
*[[Interface guidelines]] aim to provide a common feel to the Moodle user interface&lt;br /&gt;
*[[CVS (developer)|Moodle CVS for developers]] explains how to work with the Moodle code in CVS&lt;br /&gt;
*[[Tracker]] explains the Moodle Tracker for keeping track of bugs, issues, feature requests etc&lt;br /&gt;
*[[Working with the Community|Working with the Community]] explains how to engage with the dev community and discuss changes&lt;br /&gt;
*[[Unit tests|Unit tests]] explains how to run the unit tests, and how to write new test cases.&lt;br /&gt;
*[[Fast portable SQL]] shows SQL techniques that are fast, efficient, and known to work on all supported DBs.&lt;br /&gt;
&lt;br /&gt;
==Documentation for core components==&lt;br /&gt;
&lt;br /&gt;
This section is for documentation of specific components of the existing core Moodle code. Discussion of components that are under discussion or in development can be found in the [[Developer notes|developer notes]] or on the [[Roadmap|roadmap]].&lt;br /&gt;
&lt;br /&gt;
The documents below give a general overview. For detailed function-by-function documentation, see the [http://phpdocs.moodle.org/ phpDocumentor] documentation that is automatically generated from the comments in the code. &lt;br /&gt;
&lt;br /&gt;
And don&#039;t forget that the most up-to-date and detailed description of how the code works is the code itself, and you can [http://xref.moodle.org/nav.html?index.html browse the code online] using [[PHPXref|PHPXref]].&lt;br /&gt;
&lt;br /&gt;
===Core components that affect everything===&lt;br /&gt;
&lt;br /&gt;
*[[Database schema introduction|The database schema]]&lt;br /&gt;
*[[What happens when you require config.php|What happens when you require config.php]]&lt;br /&gt;
*lib/moodlelib.php &lt;br /&gt;
*[[lib/weblib.php|lib/weblib.php]] for outputting stuff&lt;br /&gt;
*[[JavaScript_functions|JavaScript function available on the client side]]&lt;br /&gt;
*[[XMLDB_Documentation|Database abstraction layer]] @ v[[1.7]]&lt;br /&gt;
*[[Roles|Roles and Capabilities system]] @ v[[1.7]] for controlling who can do what&lt;br /&gt;
*[[lib/formslib.php|Forms library]] @ v[[1.8]] for creating accessible and secure HTML forms that let users edit things&lt;br /&gt;
*[[Using_the_file_API|File API]] @ v[[2.0]] for managing files stored by Moodle&lt;br /&gt;
&lt;br /&gt;
===Core libraries with a more specific uses===&lt;br /&gt;
&lt;br /&gt;
*[[Authentication API]]&lt;br /&gt;
*[[Cookieless Sessions]]&lt;br /&gt;
*[[Email processing]]&lt;br /&gt;
*[[Environment checking|Environment checking]] before install, check the user&#039;s server to ensure Moodle will work there.&lt;br /&gt;
*[[Groups|Groups system]]&lt;br /&gt;
*[[Grades|Gradebook]]&lt;br /&gt;
*[[Moodle Network|Moodle Network]]&lt;br /&gt;
*[[Question engine]]&lt;br /&gt;
*[[Stats package]]&lt;br /&gt;
*[[UTF-8 migration|Migration to UTF-8]] @ v[[:Category:Moodle 1.6|1.6]]&lt;br /&gt;
*[http://developer.yahoo.com/yui YUI JavaScript library] - YUI was selected as the official AJAX library for Moodle.&lt;br /&gt;
*[[lib/graphlib|lib/graphlib]]&lt;br /&gt;
*[[Admin settings|Admin settings]]&lt;br /&gt;
&lt;br /&gt;
===Modules included in the standard distribution===&lt;br /&gt;
&lt;br /&gt;
*[[Lesson Specification|Lesson Specification]]&lt;br /&gt;
*[[Quiz developer docs|Quiz module]]&lt;br /&gt;
*[[SCORM schema|SCORM module 1.5 schema]]&lt;br /&gt;
&lt;br /&gt;
==How you can contribute==&lt;br /&gt;
&lt;br /&gt;
===Make a new plugin===&lt;br /&gt;
&lt;br /&gt;
The M in Moodle stands for modular, and the easiest, most maintainable way to add new functionality to Moodle is by using one of the many plugin APIs. There are many types of plugin you can write:&lt;br /&gt;
*[[Modules|Activity modules]], see also [[NEWMODULE Documentation]] (work in progress)&lt;br /&gt;
*[[Admin reports|Admin reports]]&lt;br /&gt;
*[[Assignment types|Assignment types]]&lt;br /&gt;
*[[Authentication plugins|Authentication plugins]]&lt;br /&gt;
*[[Blocks|Blocks]]&lt;br /&gt;
*[[Course formats]]&lt;br /&gt;
*[[Course Report Plugins|Course reports]]&lt;br /&gt;
*[[Database fields|Database fields]]&lt;br /&gt;
*[[Database presets|Database presets]]&lt;br /&gt;
*[[Enrolment plugins|Enrolment plugins]]&lt;br /&gt;
*[[Filters|Filters]]&lt;br /&gt;
*[[Gradebook plugins|Gradebook plugins]] (1.9 onwards)&lt;br /&gt;
**[[Gradebook_Report_Tutorial|Gradebook report]]&lt;br /&gt;
**[[Gradebook export|Gradebook export]]&lt;br /&gt;
**[[Gradebook import|Gradebook import]]&lt;br /&gt;
*[[Writing_a_Portfolio_Plugin|Portfolio plugins]] (2.0 onwards)&lt;br /&gt;
*[[Question_type_plugin_how_to|Question types]]&lt;br /&gt;
*[[Question import/export formats|Question import/export formats]]&lt;br /&gt;
*[[How to write a quiz report plugin|Quiz reports]]&lt;br /&gt;
*[[Repository plugins|Repository plugins]] (2.0 onwards)&lt;br /&gt;
*[[Resource types|Resource types]]&lt;br /&gt;
*[[Search engine adapters|Search engine adapters]]&lt;br /&gt;
&lt;br /&gt;
General information that applies to all types of plugins&lt;br /&gt;
*[[Places to search for lang strings|Where to put language strings for your plugin]]&lt;br /&gt;
*[[Installing and upgrading plugin database tables|Defining the database tables for your plugin]]&lt;br /&gt;
&lt;br /&gt;
Please see the [[Guidelines for contributed code|Guidelines for contributed code]] for an overview of how to contribute to the Moodle code.&lt;br /&gt;
&lt;br /&gt;
Sometimes it is not possible to write a proper plugin for what you want to do, in which case you may have to resort to using the [[Local_customisation|local customisations]] hook.&lt;br /&gt;
&lt;br /&gt;
===Change core code===&lt;br /&gt;
&lt;br /&gt;
Some types of change can only be made by editing the core Moodle code. Such changes are much harder to maintain than plugins. If you want your core change to be considered for inclusion in the official Moodle release, you need to create an issue in the [[Tracker|tracker]], and attach your change as a [[How_to_create_a_patch|patch]]. It is also a good idea to discuss your ideas in the forums first.  See [[Overview#Major_Development]] for more details.&lt;br /&gt;
&lt;br /&gt;
===Ways to contribute that do not involve PHP programming===&lt;br /&gt;
&lt;br /&gt;
*[[Themes|Create Moodle themes]]&lt;br /&gt;
*[[Translation|Translate Moodle into other languages]]&lt;br /&gt;
*[[MoodleDocs:Guidelines for contributors|Help document Moodle]]&lt;br /&gt;
*[[Tests|Join the testing effort]], which involves [[Tracker|participating in the bug tracker]]&lt;br /&gt;
&lt;br /&gt;
==Plans for the future==&lt;br /&gt;
&lt;br /&gt;
Ideas for and details of planned future features of Moodle are initially discussed on the forums in the [http://moodle.org/course/view.php?id=5 Using Moodle] course at moodle.org. That developer discussions are intermixed with user discussions in the same forums may seem strange at first but is one of the reasons for the success of Moodle. It is important that both end-users and developers discuss the future features together.&lt;br /&gt;
&lt;br /&gt;
Once ideas begin to crystallize on the forums they can be summarized in this wiki, either as part of the [[Roadmap|roadmap]] or in the form of [[Developer notes|developer notes]]. These pages then form the basis for further discussion in the forums.&lt;br /&gt;
&lt;br /&gt;
*[[Roadmap]]&lt;br /&gt;
*[[Developer notes|Developer notes]]&lt;br /&gt;
*[[Student projects]]&lt;br /&gt;
*[[Developer meetings]]&lt;br /&gt;
&lt;br /&gt;
== Resources ==&lt;br /&gt;
&lt;br /&gt;
*[[Developer FAQ]] - frequently asked questions, especially useful for newcomers to Moodle&lt;br /&gt;
*[[Finding_your_way_into_the_Moodle_code|Finding your way into the Moodle code]] - also aimed at newcomers&lt;br /&gt;
*[http://tracker.moodle.org/ Moodle tracker] - bug reports, feature requests and other tracked issues&lt;br /&gt;
**[[Firefox tracker search]] - How to setup a firefox quicksearch to easily navigate to moodle bugs&lt;br /&gt;
**[[Firefox tracker search#Firefox Search Plugins|Firefox Search Plugins]] - Find tracked issues even more easily&lt;br /&gt;
*[[Unmerged files]] - changes on the stable branch in CVS that have not been merged to [[HEAD]]&lt;br /&gt;
*Browse the code online:&lt;br /&gt;
**[http://cvs.moodle.org/moodle/ the code with a complete change history from CVS]&lt;br /&gt;
**[http://xref.moodle.org/index.html the code, with links generated by PHPXref]&lt;br /&gt;
*[http://phpdocs.moodle.org/ Moodle PHP doc reference] - compiled nightly from the comment attached to each class and function in the code. &#039;&#039;&#039;Attention : Due to physical migration of the whole data center at EISTI (France), the phpdoc volumes WILL NOT BE available till the end of the year. We hope migration will allow us to feed back the community with the PHPDoc generated code documentation as soon as possible.&#039;&#039;&#039;  &lt;br /&gt;
*[[Database Schema|Database Schema]] - for recent releases&lt;br /&gt;
*[http://moodle.org/course/view.php?id=5#4 Development news and discussion] section of Using Moodle course&lt;br /&gt;
**especially the [http://moodle.org/mod/forum/view.php?id=55 General developer forum]&lt;br /&gt;
**[[Filters used on the Moodle.org forums|cool tricks you can use in the moodle.org forums]]&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
Some tools people use when working on Moodle code:&lt;br /&gt;
&lt;br /&gt;
=== IDEs ===&lt;br /&gt;
&lt;br /&gt;
* [[Setting_up_Netbeans|Setting up NetBeans for Moodle development]] - NetBeans for PHP is a great out-of-the-box editor.&lt;br /&gt;
* [[Setting_up_Eclipse|Setting up Eclipse for Moodle development]] - Eclipse is a great editor to use for php development, if you can work out how to set it up.&lt;br /&gt;
* [[vim|Setting up Vim for Moodle development]]&lt;br /&gt;
&lt;br /&gt;
=== Browser add-ons ===&lt;br /&gt;
*[http://getfirebug.com Firebug], see [[Firebug]].&lt;br /&gt;
* [[Web developer extension]]&lt;br /&gt;
* [https://addons.mozilla.org/en-US/firefox/addon/394 ViewSourceWith] - The main goal is to view page source with external applications, but you can do a lot of other things as well.&lt;br /&gt;
&lt;br /&gt;
=== Miscellaneous === &lt;br /&gt;
*[[ctags|Ctags]] - Using a tags file to navigate code&lt;br /&gt;
*[[W3C_validation|W3C HTML validator]] - Moodle has built in support to make using it easier.&lt;br /&gt;
*[[Windows Installer|Windows Installer]] - Windows Installer documentation for developer.&lt;br /&gt;
&lt;br /&gt;
See also: [http://dev.moodle.org/mod/forum/view.php?id=18 Useful Development Tools forum]in the [http://dev.moodle.org/course/view.php?id=2 Introduction to Moodle Programming course]&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
*[http://moodle.org/security/ Moodle Security Announcements]&lt;br /&gt;
*[http://moodle.com/partners/ Moodle Partners] - providers of custom Moodle development services&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer tools]]&lt;br /&gt;
&lt;br /&gt;
[[ru:Development:Краткий обзор]]&lt;/div&gt;</summary>
		<author><name>Vf</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Developer_documentation&amp;diff=647</id>
		<title>Developer documentation</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Developer_documentation&amp;diff=647"/>
		<updated>2009-10-12T10:33:37Z</updated>

		<summary type="html">&lt;p&gt;Vf: /* Documentation for core components */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This [[:Category:Developer|Developer]] section of Moodle Docs is aimed at developers who contribute to the Moodle code, plugins, themes, and so on.&lt;br /&gt;
* If you manage a Moodle site, [[Administrator documentation]] may suit your needs better. &lt;br /&gt;
* If you teach using Moodle, try [[Teacher documentation]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p class=&amp;quot;note&amp;quot;&amp;gt;&#039;&#039;&#039;Note:&#039;&#039;&#039; New developer documentation pages should be added to the &#039;&#039;Development namespace&#039;&#039; by typing &amp;lt;code&amp;gt;Development:&amp;lt;/code&amp;gt; before the new page name i.e. &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;[[New page name]]&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;. If you are a developer, you probably want to change your [[Special:Preferences|preferences]] to include the Development namespace in searches.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A page may be added to the Developer category by adding the template &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{CategoryDeveloper}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; to the bottom of the page. - If required, you can use &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;[[Category:Sort key]]&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; to provide a sort key other than the default page name.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==How Moodle development works==&lt;br /&gt;
&lt;br /&gt;
The [[Overview|overview of the Moodle development process]] explains how Moodle development occurs and how people become Moodle developers. Current plans are listed on the [[Roadmap]].&lt;br /&gt;
&lt;br /&gt;
You can also enrol in one of the [http://dev.moodle.org Moodle Developer Courses].&lt;br /&gt;
&lt;br /&gt;
==Guidelines==&lt;br /&gt;
&lt;br /&gt;
The following guidelines are crucial reading for anyone wanting to contribute to the Moodle code base:&lt;br /&gt;
*[[Coding|Coding guidelines]] have to be followed by all Moodle developers&lt;br /&gt;
*[[Moodle design goals]] spells out the basic design goals behind Moodle&lt;br /&gt;
*[[Interface guidelines]] aim to provide a common feel to the Moodle user interface&lt;br /&gt;
*[[CVS (developer)|Moodle CVS for developers]] explains how to work with the Moodle code in CVS&lt;br /&gt;
*[[Tracker]] explains the Moodle Tracker for keeping track of bugs, issues, feature requests etc&lt;br /&gt;
*[[Working with the Community|Working with the Community]] explains how to engage with the dev community and discuss changes&lt;br /&gt;
*[[Unit tests|Unit tests]] explains how to run the unit tests, and how to write new test cases.&lt;br /&gt;
*[[Fast portable SQL]] shows SQL techniques that are fast, efficient, and known to work on all supported DBs.&lt;br /&gt;
&lt;br /&gt;
==Documentation for core components==&lt;br /&gt;
&lt;br /&gt;
This section is for documentation of specific components of the existing core Moodle code. Discussion of components that are under discussion or in development can be found in the [[Developer notes|developer notes]] or on the [[Roadmap|roadmap]].&lt;br /&gt;
&lt;br /&gt;
The documents below give a general overview. For detailed function-by-function documentation, see the [http://phpdocs.moodle.org/ phpDocumentor] documentation that is automatically generated from the comments in the code. &lt;br /&gt;
&lt;br /&gt;
And don&#039;t forget that the most up-to-date and detailed description of how the code works is the code itself, and you can [http://xref.moodle.org/nav.html?index.html browse the code online] using [[PHPXref|PHPXref]].&lt;br /&gt;
&lt;br /&gt;
===Core components that affect everything===&lt;br /&gt;
&lt;br /&gt;
*[[Database schema introduction|The database schema]]&lt;br /&gt;
*[[What happens when you require config.php|What happens when you require config.php]]&lt;br /&gt;
*lib/moodlelib.php &lt;br /&gt;
*[[lib/weblib.php|lib/weblib.php]] for outputting stuff&lt;br /&gt;
*[[JavaScript_functions|JavaScript function available on the client side]]&lt;br /&gt;
*[[XMLDB_Documentation|Database abstraction layer]] @ v[[1.7]]&lt;br /&gt;
*[[Roles|Roles and Capabilities system]] @ v[[1.7]] for controlling who can do what&lt;br /&gt;
*[[lib/formslib.php|Forms library]] @ v[[1.8]] for creating accessible and secure HTML forms that let users edit things&lt;br /&gt;
*[[Using_the_file_API|File API]] @ v[[2.0]] for managing files stored by Moodle&lt;br /&gt;
&lt;br /&gt;
===Core libraries with a more specific uses===&lt;br /&gt;
&lt;br /&gt;
*[[Authentication API]]&lt;br /&gt;
*[[Cookieless Sessions]]&lt;br /&gt;
*[[Email processing]]&lt;br /&gt;
*[[Environment checking|Environment checking]] before install, check the user&#039;s server to ensure Moodle will work there.&lt;br /&gt;
*[[Groups|Groups system]]&lt;br /&gt;
*[[Grades|Gradebook]]&lt;br /&gt;
*[[Moodle Network|Moodle Network]]&lt;br /&gt;
*[[Question engine]]&lt;br /&gt;
*[[Stats package]]&lt;br /&gt;
*[[UTF-8 migration|Migration to UTF-8]] @ v[[:Category:Moodle 1.6|1.6]]&lt;br /&gt;
*[http://developer.yahoo.com/yui YUI JavaScript library] - YUI was selected as the official AJAX library for Moodle.&lt;br /&gt;
*[[lib/graphlib|lib/graphlib]]&lt;br /&gt;
*[[Admin settings|Admin settings]]&lt;br /&gt;
&lt;br /&gt;
===Modules included in the standard distribution===&lt;br /&gt;
&lt;br /&gt;
*[[Lesson Specification|Lesson Specification]]&lt;br /&gt;
*[[Quiz developer docs|Quiz module]]&lt;br /&gt;
*[[SCORM schema|SCORM module 1.5 schema]]&lt;br /&gt;
&lt;br /&gt;
==How you can contribute==&lt;br /&gt;
&lt;br /&gt;
===Make a new plugin===&lt;br /&gt;
&lt;br /&gt;
The M in Moodle stands for modular, and the easiest, most maintainable way to add new functionality to Moodle is by using one of the many plugin APIs. There are many types of plugin you can write:&lt;br /&gt;
*[[Modules|Activity modules]], see also [[NEWMODULE Documentation]] (work in progress)&lt;br /&gt;
*[[Admin reports|Admin reports]]&lt;br /&gt;
*[[Assignment types|Assignment types]]&lt;br /&gt;
*[[Authentication plugins|Authentication plugins]]&lt;br /&gt;
*[[Blocks|Blocks]]&lt;br /&gt;
*[[Course formats]]&lt;br /&gt;
*[[Course Report Plugins|Course reports]]&lt;br /&gt;
*[[Database fields|Database fields]]&lt;br /&gt;
*[[Database presets|Database presets]]&lt;br /&gt;
*[[Enrolment plugins|Enrolment plugins]]&lt;br /&gt;
*[[Filters|Filters]]&lt;br /&gt;
*[[Gradebook plugins|Gradebook plugins]] (1.9 onwards)&lt;br /&gt;
**[[Gradebook_Report_Tutorial|Gradebook report]]&lt;br /&gt;
**[[Gradebook export|Gradebook export]]&lt;br /&gt;
**[[Gradebook import|Gradebook import]]&lt;br /&gt;
*[[Writing_a_Portfolio_Plugin|Portfolio plugins]] (2.0 onwards)&lt;br /&gt;
*[[Question_type_plugin_how_to|Question types]]&lt;br /&gt;
*[[Question import/export formats|Question import/export formats]]&lt;br /&gt;
*[[How to write a quiz report plugin|Quiz reports]]&lt;br /&gt;
*[[Repository plugins|Repository plugins]] (2.0 onwards)&lt;br /&gt;
*[[Resource types|Resource types]]&lt;br /&gt;
*[[Search engine adapters|Search engine adapters]]&lt;br /&gt;
&lt;br /&gt;
General information that applies to all types of plugins&lt;br /&gt;
*[[Places to search for lang strings|Where to put language strings for your plugin]]&lt;br /&gt;
*[[Installing and upgrading plugin database tables|Defining the database tables for your plugin]]&lt;br /&gt;
&lt;br /&gt;
Please see the [[Guidelines for contributed code|Guidelines for contributed code]] for an overview of how to contribute to the Moodle code.&lt;br /&gt;
&lt;br /&gt;
Sometimes it is not possible to write a proper plugin for what you want to do, in which case you may have to resort to using the [[Local_customisation|local customisations]] hook.&lt;br /&gt;
&lt;br /&gt;
===Change core code===&lt;br /&gt;
&lt;br /&gt;
Some types of change can only be made by editing the core Moodle code. Such changes are much harder to maintain than plugins. If you want your core change to be considered for inclusion in the official Moodle release, you need to create an issue in the [[Tracker|tracker]], and attach your change as a [[How_to_create_a_patch|patch]]. It is also a good idea to discuss your ideas in the forums first.  See [[Overview#Major_Development]] for more details.&lt;br /&gt;
&lt;br /&gt;
===Ways to contribute that do not involve PHP programming===&lt;br /&gt;
&lt;br /&gt;
*[[Themes|Create Moodle themes]]&lt;br /&gt;
*[[Translation|Translate Moodle into other languages]]&lt;br /&gt;
*[[MoodleDocs:Guidelines for contributors|Help document Moodle]]&lt;br /&gt;
*[[Tests|Join the testing effort]], which involves [[Tracker|participating in the bug tracker]]&lt;br /&gt;
&lt;br /&gt;
==Plans for the future==&lt;br /&gt;
&lt;br /&gt;
Ideas for and details of planned future features of Moodle are initially discussed on the forums in the [http://moodle.org/course/view.php?id=5 Using Moodle] course at moodle.org. That developer discussions are intermixed with user discussions in the same forums may seem strange at first but is one of the reasons for the success of Moodle. It is important that both end-users and developers discuss the future features together.&lt;br /&gt;
&lt;br /&gt;
Once ideas begin to crystallize on the forums they can be summarized in this wiki, either as part of the [[Roadmap|roadmap]] or in the form of [[Developer notes|developer notes]]. These pages then form the basis for further discussion in the forums.&lt;br /&gt;
&lt;br /&gt;
*[[Roadmap]]&lt;br /&gt;
*[[Developer notes|Developer notes]]&lt;br /&gt;
*[[Student projects]]&lt;br /&gt;
*[[Developer meetings]]&lt;br /&gt;
&lt;br /&gt;
== Resources ==&lt;br /&gt;
&lt;br /&gt;
*[[Developer FAQ]] - frequently asked questions, especially useful for newcomers to Moodle&lt;br /&gt;
*[[Finding_your_way_into_the_Moodle_code|Finding your way into the Moodle code]] - also aimed at newcomers&lt;br /&gt;
*[http://tracker.moodle.org/ Moodle tracker] - bug reports, feature requests and other tracked issues&lt;br /&gt;
**[[Firefox tracker search]] - How to setup a firefox quicksearch to easily navigate to moodle bugs&lt;br /&gt;
**[[Firefox tracker search#Firefox Search Plugins|Firefox Search Plugins]] - Find tracked issues even more easily&lt;br /&gt;
*[[Unmerged files]] - changes on the stable branch in CVS that have not been merged to [[HEAD]]&lt;br /&gt;
*Browse the code online:&lt;br /&gt;
**[http://cvs.moodle.org/moodle/ the code with a complete change history from CVS]&lt;br /&gt;
**[http://xref.moodle.org/index.html the code, with links generated by PHPXref]&lt;br /&gt;
*[http://phpdocs.moodle.org/ Moodle PHP doc reference] - compiled from the comment attached to each class and function in the code&lt;br /&gt;
*[[Database Schema|Database Schema]] - for recent releases&lt;br /&gt;
*[http://moodle.org/course/view.php?id=5#4 Development news and discussion] section of Using Moodle course&lt;br /&gt;
**especially the [http://moodle.org/mod/forum/view.php?id=55 General developer forum]&lt;br /&gt;
**[[Filters used on the Moodle.org forums|cool tricks you can use in the moodle.org forums]]&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
Some tools people use when working on Moodle code:&lt;br /&gt;
&lt;br /&gt;
=== IDEs ===&lt;br /&gt;
&lt;br /&gt;
* [[Setting_up_Netbeans|Setting up NetBeans for Moodle development]] - NetBeans for PHP is a great out-of-the-box editor.&lt;br /&gt;
* [[Setting_up_Eclipse|Setting up Eclipse for Moodle development]] - Eclipse is a great editor to use for php development, if you can work out how to set it up.&lt;br /&gt;
* [[vim|Setting up Vim for Moodle development]]&lt;br /&gt;
&lt;br /&gt;
=== Browser add-ons ===&lt;br /&gt;
*[http://getfirebug.com Firebug], see [[Firebug]].&lt;br /&gt;
* [[Web developer extension]]&lt;br /&gt;
* [https://addons.mozilla.org/en-US/firefox/addon/394 ViewSourceWith] - The main goal is to view page source with external applications, but you can do a lot of other things as well.&lt;br /&gt;
&lt;br /&gt;
=== Miscellaneous === &lt;br /&gt;
*[[ctags|Ctags]] - Using a tags file to navigate code&lt;br /&gt;
*[[W3C_validation|W3C HTML validator]] - Moodle has built in support to make using it easier.&lt;br /&gt;
*[[Windows Installer|Windows Installer]] - Windows Installer documentation for developer.&lt;br /&gt;
&lt;br /&gt;
See also: [http://dev.moodle.org/mod/forum/view.php?id=18 Useful Development Tools forum]in the [http://dev.moodle.org/course/view.php?id=2 Introduction to Moodle Programming course]&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
*[http://moodle.org/security/ Moodle Security Announcements]&lt;br /&gt;
*[http://moodle.com/partners/ Moodle Partners] - providers of custom Moodle development services&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer tools]]&lt;br /&gt;
&lt;br /&gt;
[[ru:Development:Краткий обзор]]&lt;/div&gt;</summary>
		<author><name>Vf</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Developer_documentation&amp;diff=646</id>
		<title>Developer documentation</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Developer_documentation&amp;diff=646"/>
		<updated>2009-10-10T21:44:19Z</updated>

		<summary type="html">&lt;p&gt;Vf: /* Documentation for core components */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This [[:Category:Developer|Developer]] section of Moodle Docs is aimed at developers who contribute to the Moodle code, plugins, themes, and so on.&lt;br /&gt;
* If you manage a Moodle site, [[Administrator documentation]] may suit your needs better. &lt;br /&gt;
* If you teach using Moodle, try [[Teacher documentation]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p class=&amp;quot;note&amp;quot;&amp;gt;&#039;&#039;&#039;Note:&#039;&#039;&#039; New developer documentation pages should be added to the &#039;&#039;Development namespace&#039;&#039; by typing &amp;lt;code&amp;gt;Development:&amp;lt;/code&amp;gt; before the new page name i.e. &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;[[New page name]]&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;. If you are a developer, you probably want to change your [[Special:Preferences|preferences]] to include the Development namespace in searches.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A page may be added to the Developer category by adding the template &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{CategoryDeveloper}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; to the bottom of the page. - If required, you can use &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;[[Category:Sort key]]&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; to provide a sort key other than the default page name.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==How Moodle development works==&lt;br /&gt;
&lt;br /&gt;
The [[Overview|overview of the Moodle development process]] explains how Moodle development occurs and how people become Moodle developers. Current plans are listed on the [[Roadmap]].&lt;br /&gt;
&lt;br /&gt;
You can also enrol in one of the [http://dev.moodle.org Moodle Developer Courses].&lt;br /&gt;
&lt;br /&gt;
==Guidelines==&lt;br /&gt;
&lt;br /&gt;
The following guidelines are crucial reading for anyone wanting to contribute to the Moodle code base:&lt;br /&gt;
*[[Coding|Coding guidelines]] have to be followed by all Moodle developers&lt;br /&gt;
*[[Moodle design goals]] spells out the basic design goals behind Moodle&lt;br /&gt;
*[[Interface guidelines]] aim to provide a common feel to the Moodle user interface&lt;br /&gt;
*[[CVS (developer)|Moodle CVS for developers]] explains how to work with the Moodle code in CVS&lt;br /&gt;
*[[Tracker]] explains the Moodle Tracker for keeping track of bugs, issues, feature requests etc&lt;br /&gt;
*[[Working with the Community|Working with the Community]] explains how to engage with the dev community and discuss changes&lt;br /&gt;
*[[Unit tests|Unit tests]] explains how to run the unit tests, and how to write new test cases.&lt;br /&gt;
*[[Fast portable SQL]] shows SQL techniques that are fast, efficient, and known to work on all supported DBs.&lt;br /&gt;
&lt;br /&gt;
==Documentation for core components==&lt;br /&gt;
&lt;br /&gt;
This section is for documentation of specific components of the existing core Moodle code. Discussion of components that are under discussion or in development can be found in the [[Developer notes|developer notes]] or on the [[Roadmap|roadmap]].&lt;br /&gt;
&lt;br /&gt;
The documents below give a general overview. For detailed function-by-function documentation, see the [http://phpdocs.moodle.org/ phpDocumentor] documentation that is automatically generated from the comments in the code. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;(For technical plant cooling desease reasons, the phpdoc servers might be unavailable or unstable for some days. Please appologize - Valery)&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
And don&#039;t forget that the most up-to-date and detailed description of how the code works is the code itself, and you can [http://xref.moodle.org/nav.html?index.html browse the code online] using [[PHPXref|PHPXref]].&lt;br /&gt;
&lt;br /&gt;
===Core components that affect everything===&lt;br /&gt;
&lt;br /&gt;
*[[Database schema introduction|The database schema]]&lt;br /&gt;
*[[What happens when you require config.php|What happens when you require config.php]]&lt;br /&gt;
*lib/moodlelib.php &lt;br /&gt;
*[[lib/weblib.php|lib/weblib.php]] for outputting stuff&lt;br /&gt;
*[[JavaScript_functions|JavaScript function available on the client side]]&lt;br /&gt;
*[[XMLDB_Documentation|Database abstraction layer]] @ v[[1.7]]&lt;br /&gt;
*[[Roles|Roles and Capabilities system]] @ v[[1.7]] for controlling who can do what&lt;br /&gt;
*[[lib/formslib.php|Forms library]] @ v[[1.8]] for creating accessible and secure HTML forms that let users edit things&lt;br /&gt;
*[[Using_the_file_API|File API]] @ v[[2.0]] for managing files stored by Moodle&lt;br /&gt;
&lt;br /&gt;
===Core libraries with a more specific uses===&lt;br /&gt;
&lt;br /&gt;
*[[Authentication API]]&lt;br /&gt;
*[[Cookieless Sessions]]&lt;br /&gt;
*[[Email processing]]&lt;br /&gt;
*[[Environment checking|Environment checking]] before install, check the user&#039;s server to ensure Moodle will work there.&lt;br /&gt;
*[[Groups|Groups system]]&lt;br /&gt;
*[[Grades|Gradebook]]&lt;br /&gt;
*[[Moodle Network|Moodle Network]]&lt;br /&gt;
*[[Question engine]]&lt;br /&gt;
*[[Stats package]]&lt;br /&gt;
*[[UTF-8 migration|Migration to UTF-8]] @ v[[:Category:Moodle 1.6|1.6]]&lt;br /&gt;
*[http://developer.yahoo.com/yui YUI JavaScript library] - YUI was selected as the official AJAX library for Moodle.&lt;br /&gt;
*[[lib/graphlib|lib/graphlib]]&lt;br /&gt;
*[[Admin settings|Admin settings]]&lt;br /&gt;
&lt;br /&gt;
===Modules included in the standard distribution===&lt;br /&gt;
&lt;br /&gt;
*[[Lesson Specification|Lesson Specification]]&lt;br /&gt;
*[[Quiz developer docs|Quiz module]]&lt;br /&gt;
*[[SCORM schema|SCORM module 1.5 schema]]&lt;br /&gt;
&lt;br /&gt;
==How you can contribute==&lt;br /&gt;
&lt;br /&gt;
===Make a new plugin===&lt;br /&gt;
&lt;br /&gt;
The M in Moodle stands for modular, and the easiest, most maintainable way to add new functionality to Moodle is by using one of the many plugin APIs. There are many types of plugin you can write:&lt;br /&gt;
*[[Modules|Activity modules]], see also [[NEWMODULE Documentation]] (work in progress)&lt;br /&gt;
*[[Admin reports|Admin reports]]&lt;br /&gt;
*[[Assignment types|Assignment types]]&lt;br /&gt;
*[[Authentication plugins|Authentication plugins]]&lt;br /&gt;
*[[Blocks|Blocks]]&lt;br /&gt;
*[[Course formats]]&lt;br /&gt;
*[[Course Report Plugins|Course reports]]&lt;br /&gt;
*[[Database fields|Database fields]]&lt;br /&gt;
*[[Database presets|Database presets]]&lt;br /&gt;
*[[Enrolment plugins|Enrolment plugins]]&lt;br /&gt;
*[[Filters|Filters]]&lt;br /&gt;
*[[Gradebook plugins|Gradebook plugins]] (1.9 onwards)&lt;br /&gt;
**[[Gradebook_Report_Tutorial|Gradebook report]]&lt;br /&gt;
**[[Gradebook export|Gradebook export]]&lt;br /&gt;
**[[Gradebook import|Gradebook import]]&lt;br /&gt;
*[[Writing_a_Portfolio_Plugin|Portfolio plugins]] (2.0 onwards)&lt;br /&gt;
*[[Question_type_plugin_how_to|Question types]]&lt;br /&gt;
*[[Question import/export formats|Question import/export formats]]&lt;br /&gt;
*[[How to write a quiz report plugin|Quiz reports]]&lt;br /&gt;
*[[Repository plugins|Repository plugins]] (2.0 onwards)&lt;br /&gt;
*[[Resource types|Resource types]]&lt;br /&gt;
*[[Search engine adapters|Search engine adapters]]&lt;br /&gt;
&lt;br /&gt;
General information that applies to all types of plugins&lt;br /&gt;
*[[Places to search for lang strings|Where to put language strings for your plugin]]&lt;br /&gt;
*[[Installing and upgrading plugin database tables|Defining the database tables for your plugin]]&lt;br /&gt;
&lt;br /&gt;
Please see the [[Guidelines for contributed code|Guidelines for contributed code]] for an overview of how to contribute to the Moodle code.&lt;br /&gt;
&lt;br /&gt;
Sometimes it is not possible to write a proper plugin for what you want to do, in which case you may have to resort to using the [[Local_customisation|local customisations]] hook.&lt;br /&gt;
&lt;br /&gt;
===Change core code===&lt;br /&gt;
&lt;br /&gt;
Some types of change can only be made by editing the core Moodle code. Such changes are much harder to maintain than plugins. If you want your core change to be considered for inclusion in the official Moodle release, you need to create an issue in the [[Tracker|tracker]], and attach your change as a [[How_to_create_a_patch|patch]]. It is also a good idea to discuss your ideas in the forums first.  See [[Overview#Major_Development]] for more details.&lt;br /&gt;
&lt;br /&gt;
===Ways to contribute that do not involve PHP programming===&lt;br /&gt;
&lt;br /&gt;
*[[Themes|Create Moodle themes]]&lt;br /&gt;
*[[Translation|Translate Moodle into other languages]]&lt;br /&gt;
*[[MoodleDocs:Guidelines for contributors|Help document Moodle]]&lt;br /&gt;
*[[Tests|Join the testing effort]], which involves [[Tracker|participating in the bug tracker]]&lt;br /&gt;
&lt;br /&gt;
==Plans for the future==&lt;br /&gt;
&lt;br /&gt;
Ideas for and details of planned future features of Moodle are initially discussed on the forums in the [http://moodle.org/course/view.php?id=5 Using Moodle] course at moodle.org. That developer discussions are intermixed with user discussions in the same forums may seem strange at first but is one of the reasons for the success of Moodle. It is important that both end-users and developers discuss the future features together.&lt;br /&gt;
&lt;br /&gt;
Once ideas begin to crystallize on the forums they can be summarized in this wiki, either as part of the [[Roadmap|roadmap]] or in the form of [[Developer notes|developer notes]]. These pages then form the basis for further discussion in the forums.&lt;br /&gt;
&lt;br /&gt;
*[[Roadmap]]&lt;br /&gt;
*[[Developer notes|Developer notes]]&lt;br /&gt;
*[[Student projects]]&lt;br /&gt;
*[[Developer meetings]]&lt;br /&gt;
&lt;br /&gt;
== Resources ==&lt;br /&gt;
&lt;br /&gt;
*[[Developer FAQ]] - frequently asked questions, especially useful for newcomers to Moodle&lt;br /&gt;
*[[Finding_your_way_into_the_Moodle_code|Finding your way into the Moodle code]] - also aimed at newcomers&lt;br /&gt;
*[http://tracker.moodle.org/ Moodle tracker] - bug reports, feature requests and other tracked issues&lt;br /&gt;
**[[Firefox tracker search]] - How to setup a firefox quicksearch to easily navigate to moodle bugs&lt;br /&gt;
**[[Firefox tracker search#Firefox Search Plugins|Firefox Search Plugins]] - Find tracked issues even more easily&lt;br /&gt;
*[[Unmerged files]] - changes on the stable branch in CVS that have not been merged to [[HEAD]]&lt;br /&gt;
*Browse the code online:&lt;br /&gt;
**[http://cvs.moodle.org/moodle/ the code with a complete change history from CVS]&lt;br /&gt;
**[http://xref.moodle.org/index.html the code, with links generated by PHPXref]&lt;br /&gt;
*[http://phpdocs.moodle.org/ Moodle PHP doc reference] - compiled from the comment attached to each class and function in the code&lt;br /&gt;
*[[Database Schema|Database Schema]] - for recent releases&lt;br /&gt;
*[http://moodle.org/course/view.php?id=5#4 Development news and discussion] section of Using Moodle course&lt;br /&gt;
**especially the [http://moodle.org/mod/forum/view.php?id=55 General developer forum]&lt;br /&gt;
**[[Filters used on the Moodle.org forums|cool tricks you can use in the moodle.org forums]]&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
Some tools people use when working on Moodle code:&lt;br /&gt;
&lt;br /&gt;
=== IDEs ===&lt;br /&gt;
&lt;br /&gt;
* [[Setting_up_Netbeans|Setting up NetBeans for Moodle development]] - NetBeans for PHP is a great out-of-the-box editor.&lt;br /&gt;
* [[Setting_up_Eclipse|Setting up Eclipse for Moodle development]] - Eclipse is a great editor to use for php development, if you can work out how to set it up.&lt;br /&gt;
* [[vim|Setting up Vim for Moodle development]]&lt;br /&gt;
&lt;br /&gt;
=== Browser add-ons ===&lt;br /&gt;
*[http://getfirebug.com Firebug], see [[Firebug]].&lt;br /&gt;
* [[Web developer extension]]&lt;br /&gt;
* [https://addons.mozilla.org/en-US/firefox/addon/394 ViewSourceWith] - The main goal is to view page source with external applications, but you can do a lot of other things as well.&lt;br /&gt;
&lt;br /&gt;
=== Miscellaneous === &lt;br /&gt;
*[[ctags|Ctags]] - Using a tags file to navigate code&lt;br /&gt;
*[[W3C_validation|W3C HTML validator]] - Moodle has built in support to make using it easier.&lt;br /&gt;
*[[Windows Installer|Windows Installer]] - Windows Installer documentation for developer.&lt;br /&gt;
&lt;br /&gt;
See also: [http://dev.moodle.org/mod/forum/view.php?id=18 Useful Development Tools forum]in the [http://dev.moodle.org/course/view.php?id=2 Introduction to Moodle Programming course]&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
*[http://moodle.org/security/ Moodle Security Announcements]&lt;br /&gt;
*[http://moodle.com/partners/ Moodle Partners] - providers of custom Moodle development services&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer tools]]&lt;br /&gt;
&lt;br /&gt;
[[ru:Development:Краткий обзор]]&lt;/div&gt;</summary>
		<author><name>Vf</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Authentication_plugins&amp;diff=10525</id>
		<title>Authentication plugins</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Authentication_plugins&amp;diff=10525"/>
		<updated>2009-04-28T11:36:10Z</updated>

		<summary type="html">&lt;p&gt;Vf: /* See also */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview of Moodle authentication process ==&lt;br /&gt;
The authentication use case in Moodle starts when a user clicks on the Login link in the UI. Then the following happens (skipping some minor details and rarer scenarios):&lt;br /&gt;
&lt;br /&gt;
# If using the default login page, the page /login/index.php is displayed, asking for the user&#039;s credentials. OR, if a system administrator has set the Alternate Login URL on the &amp;quot;Manage authentication&amp;quot; page, that URL will be displayed.&lt;br /&gt;
# User enters their credentials and submits the form.&lt;br /&gt;
# The handler code in /login/index.php runs:&lt;br /&gt;
## It gets a list of enabled authentication plugins.&lt;br /&gt;
## It runs loginpage_hook() for each plugin, in case any of them needs to intercept the login request.&lt;br /&gt;
## It checks to make sure that the username meets Moodle&#039;s criteria (alphanumeric, with periods and hyphens allowed).&lt;br /&gt;
## It calls authenticate_user_login() in /lib/moodlelib.php, which returns a $user object. (Details of this code follow this main outline.)&lt;br /&gt;
## It determines whether authentication was successful (by checking whether $user is a valid object) and, if not, sends them back to the login page with an error message. Otherwise, it figures out where to send the user based on their original page request, whether their password is expired, etc., and redirects them there.&lt;br /&gt;
&lt;br /&gt;
That&#039;s the main outline, but a lot of interesting stuff happens in authenticate_user_login():&lt;br /&gt;
&lt;br /&gt;
# It gets a list of enabled authentication plugins.&lt;br /&gt;
# It looks up the username in the mdl_user table to see if they are allowed to log in, and which authentication plugin handles their login requests. (This will be the plugin that handled their first-ever login request.)&lt;br /&gt;
# It creates a user object, which will contain the data from mdl_user if the username is known; if not, it will be an empty object.&lt;br /&gt;
# It does the following with the authentication plugin (note that for a username unknown to Moodle, it will do these steps for each authenticated plugin until one succeeds or it has tried them all):&lt;br /&gt;
## Calls the user_login() function provided by that plugin, which returns a boolean value based on whether the credentials authenticate or not. If the result is false (not authenticated), skips the rest of the steps below and continues to the next plugin.&lt;br /&gt;
## If the plugin authenticates against an external system (not Moodle&#039;s user database), its update_user_record() function is called to get the user&#039;s name, contact info, etc.&lt;br /&gt;
## Creates the Moodle user record if it doesn&#039;t already exist.&lt;br /&gt;
## Calls the plugin&#039;s sync_roles() function (I am not clear what this is exactly supposed to do).&lt;br /&gt;
## Notifies each enabled authentication plugin that the user successfully authenticated, by calling each one&#039;s user_authenticated_hook() function.&lt;br /&gt;
# It returns the user object if everything was successful, or false if no plugin was able to successfully authenticate the credentials.&lt;br /&gt;
&lt;br /&gt;
== Creating and enabling an authentication plugin ==&lt;br /&gt;
To create and register an authentication plugin, do the following:&lt;br /&gt;
&lt;br /&gt;
# Choose a name for your plugin.  We&#039;ll use &#039;sentry&#039; as an example below; change it to whatever name you have chosen.&lt;br /&gt;
# Under your Moodle installation root, create the directory /auth/sentry.  It should be sibling to existing auth plugin directories: &#039;db&#039;, &#039;nologin&#039;, &#039;none&#039;, etc.&lt;br /&gt;
# Create the file /auth/sentry/auth.php.  Within the file, create a class auth_plugin_sentry that extends auth_plugin_base from /lib/authlib.php.  (You will need to require_once the authlib file.)&lt;br /&gt;
# Implement the user_login() function in your auth.php file, and create or override additional functions based on your plugin&#039;s requirements.&lt;br /&gt;
# Log in to your Moodle installation as a site administrator and find, in the site administrator block, the page &amp;quot;Users -&amp;gt; Authentication -&amp;gt; Manage authentication&amp;quot;.  You will see your plugin in the list, appearing as &amp;lt;nowiki&amp;gt;[[auth_sentrytitle]]&amp;lt;/nowiki&amp;gt;.  You can enable it and move it up and down in the order.  &#039;&#039;&#039;At this point, with the plugin enabled, your plugin is registered and will be used by Moodle in its authentication process.&#039;&#039;&#039;&lt;br /&gt;
# If you don&#039;t like seeing &amp;lt;nowiki&amp;gt;[[auth_sentrytitle]]&amp;lt;/nowiki&amp;gt; as the name of your plugin in the Moodle UI, you&#039;ll need to create language files for your plugin.  Do this by creating the directory /auth/sentry/lang, and under it, a directory for each language that your installation needs to support.  (Example: /auth/sentry/lang/en_us_utf8.)  Within each of these language directories, create a file called auth_sentry.php.  That file should set the desired value for $string[&#039;auth_sentrytitle&#039;] for that language.  You can also set the plugin description by setting $string[&#039;auth_sentrydescription&#039;], and you can also assign other translatable strings that your plugin uses, in these files.&lt;br /&gt;
# If you want to configure your plugin through the Moodle UI, implement config_form() and process_config() in the plugin class.  You might find it convenient to use the &#039;db&#039; plugin as a model for this.  The plugin&#039;s config settings can then be managed through the Manage authentication page by clicking on the Settings link for that plugin, and the values will be stored in the mdl_config_pluginstable in the database.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
*Using Moodle [http://moodle.org/mod/forum/discuss.php?d=102070 Overview of entire authentication code flow] forum discussion&lt;br /&gt;
&lt;br /&gt;
[[Category:Authentication]]&lt;br /&gt;
&lt;br /&gt;
[[fr:Méthodes_d&#039;authentification]]&lt;/div&gt;</summary>
		<author><name>Vf</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Development:Developer_FAQ&amp;diff=29768</id>
		<title>Development:Developer FAQ</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Development:Developer_FAQ&amp;diff=29768"/>
		<updated>2008-05-12T07:39:50Z</updated>

		<summary type="html">&lt;p&gt;Vf: /* How do I insert/retrieve records in the database, without creating my own database connections? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{FAQ}}&lt;br /&gt;
&lt;br /&gt;
==Help for new coders==&lt;br /&gt;
&lt;br /&gt;
===Where can &amp;quot;newbies&amp;quot; to Moodle get help?===&lt;br /&gt;
&lt;br /&gt;
The [http://moodle.org/mod/forum/view.php?f=33 General developer forum]! Feel free to ask any question, no matter how basic or advanced. Many people ask different levels of question every day, and the community is generally welcoming and quick to respond.&lt;br /&gt;
&lt;br /&gt;
==Moodle&#039;s database==&lt;br /&gt;
&lt;br /&gt;
===Where can I see a schema for the structure of the Moodle database?===&lt;br /&gt;
&lt;br /&gt;
When installing Moodle, the database tables are generated and updated by various db-handling scripts located in various places. There is no canonical schema representation, although the [[Coding#Database_structures | coding guidelines for database structure]] give an outline of the general approach.&lt;br /&gt;
&lt;br /&gt;
The reason that the database information isn&#039;t stored in one place is because of Moodle&#039;s &#039;&#039;&#039;modular structure&#039;&#039;&#039;. Each activity module, for example, comes as a folder with script files inside. If the module needs to store information in the database, it must include scripts in a &amp;quot;db&amp;quot; subfolder which define and update the database structure.&lt;br /&gt;
&lt;br /&gt;
==How to get/set information when writing new Moodle code==&lt;br /&gt;
&lt;br /&gt;
===How do I find out the currently-logged-on user?===&lt;br /&gt;
&lt;br /&gt;
The global object $USER, which contains the numeric $USER-&amp;gt;id among other things.&lt;br /&gt;
&lt;br /&gt;
===How do I find out the current course?===&lt;br /&gt;
The global object $COURSE, which contains the numeric $COURSE-&amp;gt;id&lt;br /&gt;
&lt;br /&gt;
===How do I insert/retrieve records in the database, without creating my own database connections?===&lt;br /&gt;
&lt;br /&gt;
Always use the &amp;quot;datalib&amp;quot; functions, such as insert_record() or get_record(). Since Moodle 1.7 these are found in lib/dmllib.php. Using these functions helps with database abstraction (e.g. running on either MySQL or Postgres) as well as maintaining a single database connection. Moodle uses ADODB for database abstraction.&lt;br /&gt;
&lt;br /&gt;
Look at [http://phpdocs.moodle.org/19/moodlecore/_lib---datalib.php.html  the documentation for datalib.php] for the list of functions and details of use.&lt;br /&gt;
&lt;br /&gt;
===How do I get/set configuration settings?===&lt;br /&gt;
&lt;br /&gt;
To get config values you would typically access the global $CFG object directly, which is automatically created by the core Moodle scripts. To set these &amp;quot;main&amp;quot; config values use set_config($name, $value). The values are stored in the Moodle &amp;quot;config&amp;quot; database table, but these functions take care of cacheing on your behalf, so you should always use these rather than fetching the records directly.&lt;br /&gt;
&lt;br /&gt;
There is also a second table of config settings specifically for plugins (&amp;quot;config_plugin&amp;quot;). These are not automatically loaded into the $CFG object, so to fetch these you would use get_config($plugin, $name). To set them use set_config($name, $value, $plugin).&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
*Using Moodle [http://moodle.org/mod/forum/discuss.php?d=55719 How does date / time in DB convert to real Date / Time?] forum discussion&lt;br /&gt;
&lt;br /&gt;
[[Category: Developer]]&lt;br /&gt;
[[Category: FAQ]]&lt;br /&gt;
&lt;br /&gt;
[[es:FAQ Desarrollador]]&lt;br /&gt;
[[fr:FAQ de développement]]&lt;br /&gt;
[[pl:Developer FAQ]]&lt;/div&gt;</summary>
		<author><name>Vf</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Developer_FAQ&amp;diff=3355</id>
		<title>Developer FAQ</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Developer_FAQ&amp;diff=3355"/>
		<updated>2008-05-12T07:39:50Z</updated>

		<summary type="html">&lt;p&gt;Vf: /* How do I insert/retrieve records in the database, without creating my own database connections? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{FAQ}}&lt;br /&gt;
&lt;br /&gt;
==Help for new coders==&lt;br /&gt;
&lt;br /&gt;
===Where can &amp;quot;newbies&amp;quot; to Moodle get help?===&lt;br /&gt;
&lt;br /&gt;
The [http://moodle.org/mod/forum/view.php?f=33 General developer forum]! Feel free to ask any question, no matter how basic or advanced. Many people ask different levels of question every day, and the community is generally welcoming and quick to respond.&lt;br /&gt;
&lt;br /&gt;
==Moodle&#039;s database==&lt;br /&gt;
&lt;br /&gt;
===Where can I see a schema for the structure of the Moodle database?===&lt;br /&gt;
&lt;br /&gt;
When installing Moodle, the database tables are generated and updated by various db-handling scripts located in various places. There is no canonical schema representation, although the [[Coding#Database_structures | coding guidelines for database structure]] give an outline of the general approach.&lt;br /&gt;
&lt;br /&gt;
The reason that the database information isn&#039;t stored in one place is because of Moodle&#039;s &#039;&#039;&#039;modular structure&#039;&#039;&#039;. Each activity module, for example, comes as a folder with script files inside. If the module needs to store information in the database, it must include scripts in a &amp;quot;db&amp;quot; subfolder which define and update the database structure.&lt;br /&gt;
&lt;br /&gt;
==How to get/set information when writing new Moodle code==&lt;br /&gt;
&lt;br /&gt;
===How do I find out the currently-logged-on user?===&lt;br /&gt;
&lt;br /&gt;
The global object $USER, which contains the numeric $USER-&amp;gt;id among other things.&lt;br /&gt;
&lt;br /&gt;
===How do I find out the current course?===&lt;br /&gt;
The global object $COURSE, which contains the numeric $COURSE-&amp;gt;id&lt;br /&gt;
&lt;br /&gt;
===How do I insert/retrieve records in the database, without creating my own database connections?===&lt;br /&gt;
&lt;br /&gt;
Always use the &amp;quot;datalib&amp;quot; functions, such as insert_record() or get_record(). Since Moodle 1.7 these are found in lib/dmllib.php. Using these functions helps with database abstraction (e.g. running on either MySQL or Postgres) as well as maintaining a single database connection. Moodle uses ADODB for database abstraction.&lt;br /&gt;
&lt;br /&gt;
Look at [http://phpdocs.moodle.org/19/moodlecore/_lib---datalib.php.html  the documentation for datalib.php] for the list of functions and details of use.&lt;br /&gt;
&lt;br /&gt;
===How do I get/set configuration settings?===&lt;br /&gt;
&lt;br /&gt;
To get config values you would typically access the global $CFG object directly, which is automatically created by the core Moodle scripts. To set these &amp;quot;main&amp;quot; config values use set_config($name, $value). The values are stored in the Moodle &amp;quot;config&amp;quot; database table, but these functions take care of cacheing on your behalf, so you should always use these rather than fetching the records directly.&lt;br /&gt;
&lt;br /&gt;
There is also a second table of config settings specifically for plugins (&amp;quot;config_plugin&amp;quot;). These are not automatically loaded into the $CFG object, so to fetch these you would use get_config($plugin, $name). To set them use set_config($name, $value, $plugin).&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
*Using Moodle [http://moodle.org/mod/forum/discuss.php?d=55719 How does date / time in DB convert to real Date / Time?] forum discussion&lt;br /&gt;
&lt;br /&gt;
[[Category: Developer]]&lt;br /&gt;
[[Category: FAQ]]&lt;br /&gt;
&lt;br /&gt;
[[es:FAQ Desarrollador]]&lt;br /&gt;
[[fr:FAQ de développement]]&lt;br /&gt;
[[pl:Developer FAQ]]&lt;/div&gt;</summary>
		<author><name>Vf</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Development:Developer_FAQ&amp;diff=29767</id>
		<title>Development:Developer FAQ</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Development:Developer_FAQ&amp;diff=29767"/>
		<updated>2008-05-12T07:39:17Z</updated>

		<summary type="html">&lt;p&gt;Vf: /* How do I insert/retrieve records in the database, without creating my own database connections? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{FAQ}}&lt;br /&gt;
&lt;br /&gt;
==Help for new coders==&lt;br /&gt;
&lt;br /&gt;
===Where can &amp;quot;newbies&amp;quot; to Moodle get help?===&lt;br /&gt;
&lt;br /&gt;
The [http://moodle.org/mod/forum/view.php?f=33 General developer forum]! Feel free to ask any question, no matter how basic or advanced. Many people ask different levels of question every day, and the community is generally welcoming and quick to respond.&lt;br /&gt;
&lt;br /&gt;
==Moodle&#039;s database==&lt;br /&gt;
&lt;br /&gt;
===Where can I see a schema for the structure of the Moodle database?===&lt;br /&gt;
&lt;br /&gt;
When installing Moodle, the database tables are generated and updated by various db-handling scripts located in various places. There is no canonical schema representation, although the [[Coding#Database_structures | coding guidelines for database structure]] give an outline of the general approach.&lt;br /&gt;
&lt;br /&gt;
The reason that the database information isn&#039;t stored in one place is because of Moodle&#039;s &#039;&#039;&#039;modular structure&#039;&#039;&#039;. Each activity module, for example, comes as a folder with script files inside. If the module needs to store information in the database, it must include scripts in a &amp;quot;db&amp;quot; subfolder which define and update the database structure.&lt;br /&gt;
&lt;br /&gt;
==How to get/set information when writing new Moodle code==&lt;br /&gt;
&lt;br /&gt;
===How do I find out the currently-logged-on user?===&lt;br /&gt;
&lt;br /&gt;
The global object $USER, which contains the numeric $USER-&amp;gt;id among other things.&lt;br /&gt;
&lt;br /&gt;
===How do I find out the current course?===&lt;br /&gt;
The global object $COURSE, which contains the numeric $COURSE-&amp;gt;id&lt;br /&gt;
&lt;br /&gt;
===How do I insert/retrieve records in the database, without creating my own database connections?===&lt;br /&gt;
&lt;br /&gt;
Always use the &amp;quot;datalib&amp;quot; functions, such as insert_record() or get_record(). Since Moodle 1.7 these are found in lib/dmllib.php. Using these functions helps with database abstraction (e.g. running on either MySQL or Postgres) as well as maintaining a single database connection. Moodle uses ADODB for database abstraction.&lt;br /&gt;
&lt;br /&gt;
Look at [http://phpdocs.moodle.org/19/moodlecore/_lib---datalib.php.html  the documentation for datalib.php - Broken Link] for the list of functions and details of use.&lt;br /&gt;
&lt;br /&gt;
===How do I get/set configuration settings?===&lt;br /&gt;
&lt;br /&gt;
To get config values you would typically access the global $CFG object directly, which is automatically created by the core Moodle scripts. To set these &amp;quot;main&amp;quot; config values use set_config($name, $value). The values are stored in the Moodle &amp;quot;config&amp;quot; database table, but these functions take care of cacheing on your behalf, so you should always use these rather than fetching the records directly.&lt;br /&gt;
&lt;br /&gt;
There is also a second table of config settings specifically for plugins (&amp;quot;config_plugin&amp;quot;). These are not automatically loaded into the $CFG object, so to fetch these you would use get_config($plugin, $name). To set them use set_config($name, $value, $plugin).&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
*Using Moodle [http://moodle.org/mod/forum/discuss.php?d=55719 How does date / time in DB convert to real Date / Time?] forum discussion&lt;br /&gt;
&lt;br /&gt;
[[Category: Developer]]&lt;br /&gt;
[[Category: FAQ]]&lt;br /&gt;
&lt;br /&gt;
[[es:FAQ Desarrollador]]&lt;br /&gt;
[[fr:FAQ de développement]]&lt;br /&gt;
[[pl:Developer FAQ]]&lt;/div&gt;</summary>
		<author><name>Vf</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Developer_FAQ&amp;diff=3354</id>
		<title>Developer FAQ</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Developer_FAQ&amp;diff=3354"/>
		<updated>2008-05-12T07:39:17Z</updated>

		<summary type="html">&lt;p&gt;Vf: /* How do I insert/retrieve records in the database, without creating my own database connections? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{FAQ}}&lt;br /&gt;
&lt;br /&gt;
==Help for new coders==&lt;br /&gt;
&lt;br /&gt;
===Where can &amp;quot;newbies&amp;quot; to Moodle get help?===&lt;br /&gt;
&lt;br /&gt;
The [http://moodle.org/mod/forum/view.php?f=33 General developer forum]! Feel free to ask any question, no matter how basic or advanced. Many people ask different levels of question every day, and the community is generally welcoming and quick to respond.&lt;br /&gt;
&lt;br /&gt;
==Moodle&#039;s database==&lt;br /&gt;
&lt;br /&gt;
===Where can I see a schema for the structure of the Moodle database?===&lt;br /&gt;
&lt;br /&gt;
When installing Moodle, the database tables are generated and updated by various db-handling scripts located in various places. There is no canonical schema representation, although the [[Coding#Database_structures | coding guidelines for database structure]] give an outline of the general approach.&lt;br /&gt;
&lt;br /&gt;
The reason that the database information isn&#039;t stored in one place is because of Moodle&#039;s &#039;&#039;&#039;modular structure&#039;&#039;&#039;. Each activity module, for example, comes as a folder with script files inside. If the module needs to store information in the database, it must include scripts in a &amp;quot;db&amp;quot; subfolder which define and update the database structure.&lt;br /&gt;
&lt;br /&gt;
==How to get/set information when writing new Moodle code==&lt;br /&gt;
&lt;br /&gt;
===How do I find out the currently-logged-on user?===&lt;br /&gt;
&lt;br /&gt;
The global object $USER, which contains the numeric $USER-&amp;gt;id among other things.&lt;br /&gt;
&lt;br /&gt;
===How do I find out the current course?===&lt;br /&gt;
The global object $COURSE, which contains the numeric $COURSE-&amp;gt;id&lt;br /&gt;
&lt;br /&gt;
===How do I insert/retrieve records in the database, without creating my own database connections?===&lt;br /&gt;
&lt;br /&gt;
Always use the &amp;quot;datalib&amp;quot; functions, such as insert_record() or get_record(). Since Moodle 1.7 these are found in lib/dmllib.php. Using these functions helps with database abstraction (e.g. running on either MySQL or Postgres) as well as maintaining a single database connection. Moodle uses ADODB for database abstraction.&lt;br /&gt;
&lt;br /&gt;
Look at [http://phpdocs.moodle.org/19/moodlecore/_lib---datalib.php.html  the documentation for datalib.php - Broken Link] for the list of functions and details of use.&lt;br /&gt;
&lt;br /&gt;
===How do I get/set configuration settings?===&lt;br /&gt;
&lt;br /&gt;
To get config values you would typically access the global $CFG object directly, which is automatically created by the core Moodle scripts. To set these &amp;quot;main&amp;quot; config values use set_config($name, $value). The values are stored in the Moodle &amp;quot;config&amp;quot; database table, but these functions take care of cacheing on your behalf, so you should always use these rather than fetching the records directly.&lt;br /&gt;
&lt;br /&gt;
There is also a second table of config settings specifically for plugins (&amp;quot;config_plugin&amp;quot;). These are not automatically loaded into the $CFG object, so to fetch these you would use get_config($plugin, $name). To set them use set_config($name, $value, $plugin).&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
*Using Moodle [http://moodle.org/mod/forum/discuss.php?d=55719 How does date / time in DB convert to real Date / Time?] forum discussion&lt;br /&gt;
&lt;br /&gt;
[[Category: Developer]]&lt;br /&gt;
[[Category: FAQ]]&lt;br /&gt;
&lt;br /&gt;
[[es:FAQ Desarrollador]]&lt;br /&gt;
[[fr:FAQ de développement]]&lt;br /&gt;
[[pl:Developer FAQ]]&lt;/div&gt;</summary>
		<author><name>Vf</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=User:Valery_Fremaux&amp;diff=20421</id>
		<title>User:Valery Fremaux</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=User:Valery_Fremaux&amp;diff=20421"/>
		<updated>2008-02-06T15:48:31Z</updated>

		<summary type="html">&lt;p&gt;Vf: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Valery Fremaux is Computer Sciences and IT teacher at the EISTI, french graduate school of computer sciences.&lt;br /&gt;
&lt;br /&gt;
He has a master degree in Ethnomethodology related to Computer Sciences topics, and a master degree in Hypermedia and Sociologic Issues. &lt;br /&gt;
&lt;br /&gt;
He is working on IT architectures for 12 years, has developped some complete technologies such as the DIML templating language and is Perl and Php expert.&lt;/div&gt;</summary>
		<author><name>Vf</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=User:Valery_Fremaux&amp;diff=20420</id>
		<title>User:Valery Fremaux</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=User:Valery_Fremaux&amp;diff=20420"/>
		<updated>2008-02-06T15:47:52Z</updated>

		<summary type="html">&lt;p&gt;Vf: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Valery Fremaux is Computer Sciences and IT teacher at the EISTI, french graduate school of computer sciences.&lt;br /&gt;
&lt;br /&gt;
He has a master degree in Ethnomethodology related to Computer Sciences topics, and a master degree in Hypermedia and Sociologic Issues. &lt;br /&gt;
&lt;br /&gt;
He is working on IT architectures for 12 years, and has developped some complete technologies such as the DIML templating language.&lt;/div&gt;</summary>
		<author><name>Vf</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=User:Valery_Fremaux&amp;diff=20419</id>
		<title>User:Valery Fremaux</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=User:Valery_Fremaux&amp;diff=20419"/>
		<updated>2008-02-06T15:44:17Z</updated>

		<summary type="html">&lt;p&gt;Vf: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Valery Fremaux is Computer Sciences and IT teacher at the EISTI, french graduate school of computer sciences.&lt;br /&gt;
&lt;br /&gt;
He has a master degree in Ethnomethodology related to Computer Sciences topics, and a master degree of Hypermedia. &lt;br /&gt;
&lt;br /&gt;
He is working on IT architectures for 12 years, and has developped some complete technologies such as the DIML templating language.&lt;/div&gt;</summary>
		<author><name>Vf</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Search_engine_adapters&amp;diff=7453</id>
		<title>Search engine adapters</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Search_engine_adapters&amp;diff=7453"/>
		<updated>2007-11-29T22:48:03Z</updated>

		<summary type="html">&lt;p&gt;Vf: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Global Search Engine of Moodle, available as experimental feature till the Moodle 1.9 release, allows plugin new document types for being searched and indexed by the Lucene indexer.&lt;br /&gt;
&lt;br /&gt;
Each module or block should have an adapter written to wrap the plugin&#039;s internal data model to a searchable document. The actual implementation allows a module to provide the search engine with a set of virtual documents. The search engine will index the text content of these documents, recording sufficiant data to access back the exact context in which it was appearing (i.e, access URL, course context, etc.).&lt;br /&gt;
&lt;br /&gt;
Virtual documents are defined as subclasses of the SearchDocument class. Only the constructor of the subclass must be written in order to map an input record to an internal document definition.&lt;br /&gt;
&lt;br /&gt;
The goals of the adapter are : &lt;br /&gt;
&lt;br /&gt;
* extract all virtual documents from the module data model and give them to the indexer (index first construction) through an &#039;&#039;iterator&#039;&#039;.&lt;br /&gt;
* extract a single document for index update&lt;br /&gt;
* provide sufficiant information for index delete of obsolete content&lt;br /&gt;
* define the access URL that will access back the resource&lt;br /&gt;
* define the access check algorithm so that the user will only access resources he is allowed to&lt;br /&gt;
&lt;br /&gt;
== Adapters For Modules And Blocks ==&lt;br /&gt;
&lt;br /&gt;
Any adapter for a module or a block must reside in the &amp;lt;pre&amp;gt;/search/documents&amp;lt;/pre&amp;gt; subdirectory, and will be named such as &amp;lt;pre&amp;gt;&amp;lt;module&amp;gt;_document.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search defines ===&lt;br /&gt;
&lt;br /&gt;
Each searchable module should add at least both (typical) following defines in /search/lib.php :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
define(&#039;SEARCH_TYPE_&amp;lt;MODULE&amp;gt;&#039;, &#039;&amp;lt;module&amp;gt;&#039;);&lt;br /&gt;
define(&#039;PATH_FOR_SEARCH_TYPE_&amp;lt;MODULE&amp;gt;&#039;, &#039;mod/&amp;lt;module&amp;gt;&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
define(&#039;SEARCH_TYPE_&amp;lt;BLOCK&amp;gt;&#039;, &#039;&amp;lt;block&amp;gt;&#039;);&lt;br /&gt;
define(&#039;PATH_FOR_SEARCH_TYPE_&amp;lt;BLOCK&amp;gt;&#039;, &#039;blocks/&amp;lt;block&amp;gt;&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Constructor ===&lt;br /&gt;
&lt;br /&gt;
The constructor of the SearchDocument class has the following signature :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public function __construct(&amp;amp;$doc, &amp;amp;$data, $course_id, $group_id, $user_id, $path)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where : &lt;br /&gt;
* &#039;&#039;&#039;&amp;amp;$doc&#039;&#039;&#039; is a reference onto a PHP object that should provide the fields :&lt;br /&gt;
** docid : the id of the document, as suitable for reconstructing the access URL.&lt;br /&gt;
** documenttype : in general, the name of the module itself&lt;br /&gt;
** itemtype : a subclassifier, if the module provides more than one virtual document to the search engine.&lt;br /&gt;
** contextid : the context object id that should be considered when checking accessor&#039;s capabilities&lt;br /&gt;
** title : the title string to appear in search results as a caption&lt;br /&gt;
** author : if the author is known, the user id (mdl_user.id) representing the author.&lt;br /&gt;
** contents : a text bulk from the document content, filtered out from any formatting attributes or tags&lt;br /&gt;
** url : the document url, that will be constructed by the adapter to access back the resource&lt;br /&gt;
** date : usually the date when the resource was created&lt;br /&gt;
* &#039;&#039;&#039;&amp;amp;$data&#039;&#039;&#039; is a reference onto a contextual metadata object that will be serialized among with the record, but will not be used as searchable content&lt;br /&gt;
* &#039;&#039;&#039;$course_id&#039;&#039;&#039; is the current course the ressource is within&lt;br /&gt;
* &#039;&#039;&#039;$group_id&#039;&#039;&#039; is the current group the resource belongs to, if the ressource is in a group scope (i.e. separate group wiki attachements), 0 elsewhere.&lt;br /&gt;
* &#039;&#039;&#039;$user_id&#039;&#039;&#039; is the id of the user the resource beslongs to, in case the ressource is in a user specific scope (i.e. post or assignment attachements), 0 elsewhere.&lt;br /&gt;
* &#039;&#039;&#039;$path&#039;&#039;&#039; is one of the above PATH defines for the module.&lt;br /&gt;
&lt;br /&gt;
== Providing The indexer Documents From The Module ==&lt;br /&gt;
&lt;br /&gt;
When first constructing the index, The Indexer needs scanning all the instances of the plugin. &lt;br /&gt;
&lt;br /&gt;
The adapter API must provide the&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;module&amp;gt;_iterator(){ ... }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
function that will give a set of consistant plugin instances. Here is a &#039;&#039;very standard&#039;&#039; template code for this method : &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_iterator() {&lt;br /&gt;
    $&amp;lt;module&amp;gt; = get_records(&#039;&amp;lt;module&amp;gt;&#039;);&lt;br /&gt;
    return $&amp;lt;module&amp;gt;;&lt;br /&gt;
} //&amp;lt;module&amp;gt;_iterator&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On each instance, the function :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_get_content_for_index(&amp;amp;$plugininstance) { ... }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
is called for constructing relevant instances of the SearchDocument subclass. This function MUST return an array of SearchDocuments or false. The typical synopsis of this function is : &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_get_content_for_index(&amp;amp;$plugininstance){&lt;br /&gt;
    $documents = array();&lt;br /&gt;
&lt;br /&gt;
    // invalid plugin&lt;br /&gt;
    if (!$plugininstance) return $documents;&lt;br /&gt;
&lt;br /&gt;
    // TODO : get an indexable item set&lt;br /&gt;
&lt;br /&gt;
    foreach($indexableitems as $indexableitem) {&lt;br /&gt;
&lt;br /&gt;
       // TODO : Prepare params with &lt;br /&gt;
&lt;br /&gt;
       $documents[] = new ForumSearchDocument(... params ...);&lt;br /&gt;
    } &lt;br /&gt;
    return $documents;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Making The Backaccess Link ===&lt;br /&gt;
&lt;br /&gt;
The constructor of the SearchDocument subclass must construct a backaccess link for the document, and give it as the &#039;url&#039; attribute of the first constructor parameter (&amp;amp;$doc). this is usually done using a callback to the document API. the synopsys is : &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_make_link(...contextual params...) {&lt;br /&gt;
    global $CFG;&lt;br /&gt;
    &lt;br /&gt;
    return $CFG-&amp;gt;wwwroot.&amp;lt;moodle path expression that drives back to the content&amp;gt;;&lt;br /&gt;
} //&amp;lt;module&amp;gt;_make_link&lt;br /&gt;
&amp;lt;/pre&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
Contextual params are usually ids of course module, or internal entities depending on the module construction, modal values...&lt;br /&gt;
&lt;br /&gt;
== Updating The index Database ==&lt;br /&gt;
&lt;br /&gt;
The search engine, once fed with its first indexing results from scratch, will be regularily updating by a cron job. The index is updated in diff mode, so only modified entries in the Moodle data model should be considered. &lt;br /&gt;
&lt;br /&gt;
The update process will : &lt;br /&gt;
* add new items, as far as they are handled by the search engine&lt;br /&gt;
* update modified items&lt;br /&gt;
* drop indexes on deleted resources and contents&lt;br /&gt;
&lt;br /&gt;
An API callback tells each of these three actions where the items to consider are in the Moodle database. This callback SHOULD return an array of arrays of strings, each containing the following fieldset : &lt;br /&gt;
* primary id fieldname, &lt;br /&gt;
* table name, &lt;br /&gt;
* time created field name,&lt;br /&gt;
* time modified field name,&lt;br /&gt;
* itemtype,&lt;br /&gt;
* [additional SELECT clause for filtering rows]   // optional&lt;br /&gt;
&lt;br /&gt;
Here comes a synopsys for such code. There should be as many arrays as known document subtypes in the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_db_names() {&lt;br /&gt;
    return array(&lt;br /&gt;
        array(&#039;id&#039;, &#039;&amp;lt;module&amp;gt;_&amp;lt;entity&amp;gt;&#039;, &#039;created&#039;, &#039;modified&#039;, &#039;&amp;lt;itemtype&amp;gt;&#039;, &#039;&#039;)&lt;br /&gt;
    );&lt;br /&gt;
} //&amp;lt;module&amp;gt;_db_names&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note : &#039;created&#039; and &#039;modified&#039; have several expression among the variety of modules/blocks. Sometimes, both of these informations are not available. Consider using the dates of a parent dependency in case they are missing.&lt;br /&gt;
&lt;br /&gt;
Knowing where the items to update/add/delete are, both first operation will use a &amp;quot;Single Document Wrapper&amp;quot; to process to the update/add operation individually. This is the purpose of the &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_single_document($id, $itemtype) { ... }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
function. Here comes a rough prototype for such a callback : &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_single_document($id, $itemtype) {&lt;br /&gt;
&lt;br /&gt;
    switch($itemtype){&lt;br /&gt;
        case &amp;lt;type1&amp;gt;:&lt;br /&gt;
           ... get content holding record ...&lt;br /&gt;
           ... get module_obj from previous ...&lt;br /&gt;
        break;&lt;br /&gt;
        case &amp;lt;type2&amp;gt;:&lt;br /&gt;
           ... get content holding record ...&lt;br /&gt;
           ... get module_obj from previous ...&lt;br /&gt;
        break;&lt;br /&gt;
        ... and so on ...&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    $coursemodule = get_field(&#039;modules&#039;, &#039;id&#039;, &#039;name&#039;, &#039;&amp;lt;module&amp;gt;&#039;);&lt;br /&gt;
    $cm = get_record(&#039;course_modules&#039;, &#039;course&#039;, $&amp;lt;module_obj&amp;gt;-&amp;gt;course, &lt;br /&gt;
                     &#039;module&#039;, $coursemodule, &#039;instance&#039;, $&amp;lt;module_obj&amp;gt;-&amp;gt;id);&lt;br /&gt;
    if ($cm){&lt;br /&gt;
        $context = get_context_instance(CONTEXT_MODULE, $cm-&amp;gt;id);&lt;br /&gt;
        ... preparing some data eventually ... &lt;br /&gt;
        return new &amp;lt;ModuleItem&amp;gt;SearchDocument(get_object_vars($&amp;lt;content_obj&amp;gt;), &lt;br /&gt;
               $&amp;lt;module_obj&amp;gt;-&amp;gt;id, $&amp;lt;module_obj&amp;gt;-&amp;gt;course, $itemtype, $context-&amp;gt;id);&lt;br /&gt;
    }&lt;br /&gt;
    return null;&lt;br /&gt;
} // &amp;lt;module&amp;gt;_single_document&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note : we need use get_object_vars() as historical implementation uses a hash in constructors rather than an object.&lt;br /&gt;
&lt;br /&gt;
For deletion, you will have to reproduce a callback which remains from an old unexplained implementation : &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_delete($info, $itemtype) {&lt;br /&gt;
    $object-&amp;gt;id = $info;&lt;br /&gt;
    $object-&amp;gt;itemtype = $itemtype;&lt;br /&gt;
    return $object;&lt;br /&gt;
} // &amp;lt;module&amp;gt;_delete&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just rewrite it AS IS, nothing to think about here.&lt;br /&gt;
&lt;br /&gt;
== Checking Access Back To The Content ==&lt;br /&gt;
&lt;br /&gt;
When searching, the Zend Lucene engine dig into its own word index organization, and then retrieves a set of matching &amp;quot;Documents&amp;quot;. You will want now to filter out those documents that the user who activated the search engine DO NOT have permission to see. &lt;br /&gt;
&lt;br /&gt;
The search results function calls back an access checker for each results, depending on the known document type. This is the :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_check_text_access($path, $itemtype, $this_id, $user, $group_id, $context_id){ ... }&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
function, that will have to implement the access policy, depending on the plugin&#039;s contextual logic. The function traps any access revocation condition (and than will return false). In cas no trap was triggered, it will return true. The admin role bypasses this check call and will access all documents.&lt;br /&gt;
&lt;br /&gt;
Here comes a standard synopsys for that implementation : &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_check_text_access($path, $itemtype, $this_id, $user, $group_id, $context_id){&lt;br /&gt;
    global $CFG, $USER;&lt;br /&gt;
&lt;br /&gt;
    // may include some plugins libs&lt;br /&gt;
    include_once(&amp;quot;{$CFG-&amp;gt;dirroot}/{$path}/lib.php&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
    ... get the course module and content record ...&lt;br /&gt;
&lt;br /&gt;
    // this part is very standard for modules, reconsider it for blocks&lt;br /&gt;
    // or other stuff &lt;br /&gt;
    $context = get_record(&#039;context&#039;, &#039;id&#039;, $context_id);&lt;br /&gt;
    $cm = get_record(&#039;course_modules&#039;, &#039;id&#039;, $context-&amp;gt;instanceid);&lt;br /&gt;
    if (!$cm-&amp;gt;visible and !has_capability(&#039;moodle/course:viewhiddenactivities&#039;, $context)){&lt;br /&gt;
        // nice for debugging undued visibility or non visibility&lt;br /&gt;
        if (!empty($CFG-&amp;gt;search_access_debug)) &lt;br /&gt;
                   echo &amp;quot;search reject : &amp;lt;reject cause&amp;gt; &amp;quot;;&lt;br /&gt;
        return false;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    // user check : entries should not be owner private or we are that user    &lt;br /&gt;
&lt;br /&gt;
    // group check : entries should be in accessible groups&lt;br /&gt;
&lt;br /&gt;
    // date checks : we are in an open window&lt;br /&gt;
    &lt;br /&gt;
    return true;&lt;br /&gt;
} //&amp;lt;module&amp;gt;_check_text_access&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note : Debugging access policy&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Use the above construction for any &#039;&#039;false&#039;&#039; you will return : &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        if (!empty($CFG-&amp;gt;search_access_debug)){ &lt;br /&gt;
           echo &amp;quot;search reject : &amp;lt;reject cause&amp;gt; &amp;quot;;&lt;br /&gt;
        return false;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For debugging, add a simple key in {$CFG-&amp;gt;prefix}_config table : &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
INSERT INTO {$CFG-&amp;gt;prefix}_config VALUES (&#039;search_access_debug&#039;, 1);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Delete it for normal operations :  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DELETE FROM {$CFG-&amp;gt;prefix}_config WHERE name = &#039;search_access_debug&#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Physical Document Adapters ==&lt;/div&gt;</summary>
		<author><name>Vf</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Search_engine_adapters&amp;diff=7452</id>
		<title>Search engine adapters</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Search_engine_adapters&amp;diff=7452"/>
		<updated>2007-11-18T14:46:43Z</updated>

		<summary type="html">&lt;p&gt;Vf: /* Checking Access Back To The Content */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The global search engine of Moodle, available as experimental feature till the Moodle 1.9 release, allows plugin new document types for being searched and indexed by the Lucene indexer.&lt;br /&gt;
&lt;br /&gt;
Each module or block should have an adapter written to wrap the plugin&#039;s internal data model to a searchable document. The actual implementation allows a module to provide the search engine with a set of virtual documents. The search engine will index the text content of these documents, recording sufficiant data to access back the exact context in which it was appearing (i.e, access URL, course context, etc.).&lt;br /&gt;
&lt;br /&gt;
Virtual documents are defined as subclasses of the SearchDocument class. Only the constructor of the subclass must be written in order to map an input record to an internal document definition.&lt;br /&gt;
&lt;br /&gt;
The goals of the adapter are : &lt;br /&gt;
&lt;br /&gt;
* extract all virtual documents from the module data model and give them to the indexer (index first construction) through an &#039;&#039;iterator&#039;&#039;.&lt;br /&gt;
* extract a single document for index update&lt;br /&gt;
* provide sufficiant information for index delete of obsolete content&lt;br /&gt;
* define the access URL that will access back the resource&lt;br /&gt;
* define the access check algorithm so that the user will only access resources he is allowed to&lt;br /&gt;
&lt;br /&gt;
== Adapters For Modules And Blocks ==&lt;br /&gt;
&lt;br /&gt;
Any adapter for a module or a block must reside in the &amp;lt;pre&amp;gt;/search/documents&amp;lt;/pre&amp;gt; subdirectory, and will be named such as &amp;lt;pre&amp;gt;&amp;lt;module&amp;gt;_document.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search defines ===&lt;br /&gt;
&lt;br /&gt;
Each searchable module should add at least both (typical) following defines in /search/lib.php :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
define(&#039;SEARCH_TYPE_&amp;lt;MODULE&amp;gt;&#039;, &#039;&amp;lt;module&amp;gt;&#039;);&lt;br /&gt;
define(&#039;PATH_FOR_SEARCH_TYPE_&amp;lt;MODULE&amp;gt;&#039;, &#039;mod/&amp;lt;module&amp;gt;&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
define(&#039;SEARCH_TYPE_&amp;lt;BLOCK&amp;gt;&#039;, &#039;&amp;lt;block&amp;gt;&#039;);&lt;br /&gt;
define(&#039;PATH_FOR_SEARCH_TYPE_&amp;lt;BLOCK&amp;gt;&#039;, &#039;blocks/&amp;lt;block&amp;gt;&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Constructor ===&lt;br /&gt;
&lt;br /&gt;
The constructor of the SearchDocument class has the following signature :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public function __construct(&amp;amp;$doc, &amp;amp;$data, $course_id, $group_id, $user_id, $path)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where : &lt;br /&gt;
* &#039;&#039;&#039;&amp;amp;$doc&#039;&#039;&#039; is a reference onto a PHP object that should provide the fields :&lt;br /&gt;
** docid : the id of the document, as suitable for reconstructing the access URL.&lt;br /&gt;
** documenttype : in general, the name of the module itself&lt;br /&gt;
** itemtype : a subclassifier, if the module provides more than one virtual document to the search engine.&lt;br /&gt;
** contextid : the context object id that should be considered when checking accessor&#039;s capabilities&lt;br /&gt;
** title : the title string to appear in search results as a caption&lt;br /&gt;
** author : if the author is known, the user id (mdl_user.id) representing the author.&lt;br /&gt;
** contents : a text bulk from the document content, filtered out from any formatting attributes or tags&lt;br /&gt;
** url : the document url, that will be constructed by the adapter to access back the resource&lt;br /&gt;
** date : usually the date when the resource was created&lt;br /&gt;
* &#039;&#039;&#039;&amp;amp;$data&#039;&#039;&#039; is a reference onto a contextual metadata object that will be serialized among with the record, but will not be used as searchable content&lt;br /&gt;
* &#039;&#039;&#039;$course_id&#039;&#039;&#039; is the current course the ressource is within&lt;br /&gt;
* &#039;&#039;&#039;$group_id&#039;&#039;&#039; is the current group the resource belongs to, if the ressource is in a group scope (i.e. separate group wiki attachements), 0 elsewhere.&lt;br /&gt;
* &#039;&#039;&#039;$user_id&#039;&#039;&#039; is the id of the user the resource beslongs to, in case the ressource is in a user specific scope (i.e. post or assignment attachements), 0 elsewhere.&lt;br /&gt;
* &#039;&#039;&#039;$path&#039;&#039;&#039; is one of the above PATH defines for the module.&lt;br /&gt;
&lt;br /&gt;
== Providing The indexer Documents From The Module ==&lt;br /&gt;
&lt;br /&gt;
When first constructing the index, The Indexer needs scanning all the instances of the plugin. &lt;br /&gt;
&lt;br /&gt;
The adapter API must provide the&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;module&amp;gt;_iterator(){ ... }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
function that will give a set of consistant plugin instances. Here is a &#039;&#039;very standard&#039;&#039; template code for this method : &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_iterator() {&lt;br /&gt;
    $&amp;lt;module&amp;gt; = get_records(&#039;&amp;lt;module&amp;gt;&#039;);&lt;br /&gt;
    return $&amp;lt;module&amp;gt;;&lt;br /&gt;
} //&amp;lt;module&amp;gt;_iterator&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On each instance, the function :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_get_content_for_index(&amp;amp;$plugininstance) { ... }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
is called for constructing relevant instances of the SearchDocument subclass. This function MUST return an array of SearchDocuments or false. The typical synopsis of this function is : &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_get_content_for_index(&amp;amp;$plugininstance){&lt;br /&gt;
    $documents = array();&lt;br /&gt;
&lt;br /&gt;
    // invalid plugin&lt;br /&gt;
    if (!$plugininstance) return $documents;&lt;br /&gt;
&lt;br /&gt;
    // TODO : get an indexable item set&lt;br /&gt;
&lt;br /&gt;
    foreach($indexableitems as $indexableitem) {&lt;br /&gt;
&lt;br /&gt;
       // TODO : Prepare params with &lt;br /&gt;
&lt;br /&gt;
       $documents[] = new ForumSearchDocument(... params ...);&lt;br /&gt;
    } &lt;br /&gt;
    return $documents;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Making The Backaccess Link ===&lt;br /&gt;
&lt;br /&gt;
The constructor of the SearchDocument subclass must construct a backaccess link for the document, and give it as the &#039;url&#039; attribute of the first constructor parameter (&amp;amp;$doc). this is usually done using a callback to the document API. the synopsys is : &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_make_link(...contextual params...) {&lt;br /&gt;
    global $CFG;&lt;br /&gt;
    &lt;br /&gt;
    return $CFG-&amp;gt;wwwroot.&amp;lt;moodle path expression that drives back to the content&amp;gt;;&lt;br /&gt;
} //&amp;lt;module&amp;gt;_make_link&lt;br /&gt;
&amp;lt;/pre&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
Contextual params are usually ids of course module, or internal entities depending on the module construction, modal values...&lt;br /&gt;
&lt;br /&gt;
== Updating The index Database ==&lt;br /&gt;
&lt;br /&gt;
The search engine, once fed with its first indexing results from scratch, will be regularily updating by a cron job. The index is updated in diff mode, so only modified entries in the Moodle data model should be considered. &lt;br /&gt;
&lt;br /&gt;
The update process will : &lt;br /&gt;
* add new items, as far as they are handled by the search engine&lt;br /&gt;
* update modified items&lt;br /&gt;
* drop indexes on deleted resources and contents&lt;br /&gt;
&lt;br /&gt;
An API callback tells each of these three actions where the items to consider are in the Moodle database. This callback SHOULD return an array of arrays of strings, each containing the following fieldset : &lt;br /&gt;
* primary id fieldname, &lt;br /&gt;
* table name, &lt;br /&gt;
* time created field name,&lt;br /&gt;
* time modified field name,&lt;br /&gt;
* itemtype,&lt;br /&gt;
* [additional SELECT clause for filtering rows]   // optional&lt;br /&gt;
&lt;br /&gt;
Here comes a synopsys for such code. There should be as many arrays as known document subtypes in the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_db_names() {&lt;br /&gt;
    return array(&lt;br /&gt;
        array(&#039;id&#039;, &#039;&amp;lt;module&amp;gt;_&amp;lt;entity&amp;gt;&#039;, &#039;created&#039;, &#039;modified&#039;, &#039;&amp;lt;itemtype&amp;gt;&#039;, &#039;&#039;)&lt;br /&gt;
    );&lt;br /&gt;
} //&amp;lt;module&amp;gt;_db_names&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note : &#039;created&#039; and &#039;modified&#039; have several expression among the variety of modules/blocks. Sometimes, both of these informations are not available. Consider using the dates of a parent dependency in case they are missing.&lt;br /&gt;
&lt;br /&gt;
Knowing where the items to update/add/delete are, both first operation will use a &amp;quot;Single Document Wrapper&amp;quot; to process to the update/add operation individually. This is the purpose of the &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_single_document($id, $itemtype) { ... }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
function. Here comes a rough prototype for such a callback : &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_single_document($id, $itemtype) {&lt;br /&gt;
&lt;br /&gt;
    switch($itemtype){&lt;br /&gt;
        case &amp;lt;type1&amp;gt;:&lt;br /&gt;
           ... get content holding record ...&lt;br /&gt;
           ... get module_obj from previous ...&lt;br /&gt;
        break;&lt;br /&gt;
        case &amp;lt;type2&amp;gt;:&lt;br /&gt;
           ... get content holding record ...&lt;br /&gt;
           ... get module_obj from previous ...&lt;br /&gt;
        break;&lt;br /&gt;
        ... and so on ...&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    $coursemodule = get_field(&#039;modules&#039;, &#039;id&#039;, &#039;name&#039;, &#039;&amp;lt;module&amp;gt;&#039;);&lt;br /&gt;
    $cm = get_record(&#039;course_modules&#039;, &#039;course&#039;, $&amp;lt;module_obj&amp;gt;-&amp;gt;course, &lt;br /&gt;
                     &#039;module&#039;, $coursemodule, &#039;instance&#039;, $&amp;lt;module_obj&amp;gt;-&amp;gt;id);&lt;br /&gt;
    if ($cm){&lt;br /&gt;
        $context = get_context_instance(CONTEXT_MODULE, $cm-&amp;gt;id);&lt;br /&gt;
        ... preparing some data eventually ... &lt;br /&gt;
        return new &amp;lt;ModuleItem&amp;gt;SearchDocument(get_object_vars($&amp;lt;content_obj&amp;gt;), &lt;br /&gt;
               $&amp;lt;module_obj&amp;gt;-&amp;gt;id, $&amp;lt;module_obj&amp;gt;-&amp;gt;course, $itemtype, $context-&amp;gt;id);&lt;br /&gt;
    }&lt;br /&gt;
    return null;&lt;br /&gt;
} // &amp;lt;module&amp;gt;_single_document&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note : we need use get_object_vars() as historical implementation uses a hash in constructors rather than an object.&lt;br /&gt;
&lt;br /&gt;
For deletion, you will have to reproduce a callback which remains from an old unexplained implementation : &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_delete($info, $itemtype) {&lt;br /&gt;
    $object-&amp;gt;id = $info;&lt;br /&gt;
    $object-&amp;gt;itemtype = $itemtype;&lt;br /&gt;
    return $object;&lt;br /&gt;
} // &amp;lt;module&amp;gt;_delete&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just rewrite it AS IS, nothing to think about here.&lt;br /&gt;
&lt;br /&gt;
== Checking Access Back To The Content ==&lt;br /&gt;
&lt;br /&gt;
When searching, the Zend Lucene engine dig into its own word index organization, and then retrieves a set of matching &amp;quot;Documents&amp;quot;. You will want now to filter out those documents that the user who activated the search engine DO NOT have permission to see. &lt;br /&gt;
&lt;br /&gt;
The search results function calls back an access checker for each results, depending on the known document type. This is the :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_check_text_access($path, $itemtype, $this_id, $user, $group_id, $context_id){ ... }&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
function, that will have to implement the access policy, depending on the plugin&#039;s contextual logic. The function traps any access revocation condition (and than will return false). In cas no trap was triggered, it will return true. The admin role bypasses this check call and will access all documents.&lt;br /&gt;
&lt;br /&gt;
Here comes a standard synopsys for that implementation : &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_check_text_access($path, $itemtype, $this_id, $user, $group_id, $context_id){&lt;br /&gt;
    global $CFG, $USER;&lt;br /&gt;
&lt;br /&gt;
    // may include some plugins libs&lt;br /&gt;
    include_once(&amp;quot;{$CFG-&amp;gt;dirroot}/{$path}/lib.php&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
    ... get the course module and content record ...&lt;br /&gt;
&lt;br /&gt;
    // this part is very standard for modules, reconsider it for blocks&lt;br /&gt;
    // or other stuff &lt;br /&gt;
    $context = get_record(&#039;context&#039;, &#039;id&#039;, $context_id);&lt;br /&gt;
    $cm = get_record(&#039;course_modules&#039;, &#039;id&#039;, $context-&amp;gt;instanceid);&lt;br /&gt;
    if (!$cm-&amp;gt;visible and !has_capability(&#039;moodle/course:viewhiddenactivities&#039;, $context)){&lt;br /&gt;
        // nice for debugging undued visibility or non visibility&lt;br /&gt;
        if (!empty($CFG-&amp;gt;search_access_debug)) &lt;br /&gt;
                   echo &amp;quot;search reject : &amp;lt;reject cause&amp;gt; &amp;quot;;&lt;br /&gt;
        return false;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    // user check : entries should not be owner private or we are that user    &lt;br /&gt;
&lt;br /&gt;
    // group check : entries should be in accessible groups&lt;br /&gt;
&lt;br /&gt;
    // date checks : we are in an open window&lt;br /&gt;
    &lt;br /&gt;
    return true;&lt;br /&gt;
} //&amp;lt;module&amp;gt;_check_text_access&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note : Debugging access policy&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Use the above construction for any &#039;&#039;false&#039;&#039; you will return : &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        if (!empty($CFG-&amp;gt;search_access_debug)){ &lt;br /&gt;
           echo &amp;quot;search reject : &amp;lt;reject cause&amp;gt; &amp;quot;;&lt;br /&gt;
        return false;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For debugging, add a simple key in {$CFG-&amp;gt;prefix}_config table : &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
INSERT INTO {$CFG-&amp;gt;prefix}_config VALUES (&#039;search_access_debug&#039;, 1);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Delete it for normal operations :  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DELETE FROM {$CFG-&amp;gt;prefix}_config WHERE name = &#039;search_access_debug&#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Physical Document Adapters ==&lt;/div&gt;</summary>
		<author><name>Vf</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Search_engine_adapters&amp;diff=7451</id>
		<title>Search engine adapters</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Search_engine_adapters&amp;diff=7451"/>
		<updated>2007-11-18T14:30:21Z</updated>

		<summary type="html">&lt;p&gt;Vf: /* Updating The index Database */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The global search engine of Moodle, available as experimental feature till the Moodle 1.9 release, allows plugin new document types for being searched and indexed by the Lucene indexer.&lt;br /&gt;
&lt;br /&gt;
Each module or block should have an adapter written to wrap the plugin&#039;s internal data model to a searchable document. The actual implementation allows a module to provide the search engine with a set of virtual documents. The search engine will index the text content of these documents, recording sufficiant data to access back the exact context in which it was appearing (i.e, access URL, course context, etc.).&lt;br /&gt;
&lt;br /&gt;
Virtual documents are defined as subclasses of the SearchDocument class. Only the constructor of the subclass must be written in order to map an input record to an internal document definition.&lt;br /&gt;
&lt;br /&gt;
The goals of the adapter are : &lt;br /&gt;
&lt;br /&gt;
* extract all virtual documents from the module data model and give them to the indexer (index first construction) through an &#039;&#039;iterator&#039;&#039;.&lt;br /&gt;
* extract a single document for index update&lt;br /&gt;
* provide sufficiant information for index delete of obsolete content&lt;br /&gt;
* define the access URL that will access back the resource&lt;br /&gt;
* define the access check algorithm so that the user will only access resources he is allowed to&lt;br /&gt;
&lt;br /&gt;
== Adapters For Modules And Blocks ==&lt;br /&gt;
&lt;br /&gt;
Any adapter for a module or a block must reside in the &amp;lt;pre&amp;gt;/search/documents&amp;lt;/pre&amp;gt; subdirectory, and will be named such as &amp;lt;pre&amp;gt;&amp;lt;module&amp;gt;_document.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search defines ===&lt;br /&gt;
&lt;br /&gt;
Each searchable module should add at least both (typical) following defines in /search/lib.php :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
define(&#039;SEARCH_TYPE_&amp;lt;MODULE&amp;gt;&#039;, &#039;&amp;lt;module&amp;gt;&#039;);&lt;br /&gt;
define(&#039;PATH_FOR_SEARCH_TYPE_&amp;lt;MODULE&amp;gt;&#039;, &#039;mod/&amp;lt;module&amp;gt;&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
define(&#039;SEARCH_TYPE_&amp;lt;BLOCK&amp;gt;&#039;, &#039;&amp;lt;block&amp;gt;&#039;);&lt;br /&gt;
define(&#039;PATH_FOR_SEARCH_TYPE_&amp;lt;BLOCK&amp;gt;&#039;, &#039;blocks/&amp;lt;block&amp;gt;&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Constructor ===&lt;br /&gt;
&lt;br /&gt;
The constructor of the SearchDocument class has the following signature :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public function __construct(&amp;amp;$doc, &amp;amp;$data, $course_id, $group_id, $user_id, $path)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where : &lt;br /&gt;
* &#039;&#039;&#039;&amp;amp;$doc&#039;&#039;&#039; is a reference onto a PHP object that should provide the fields :&lt;br /&gt;
** docid : the id of the document, as suitable for reconstructing the access URL.&lt;br /&gt;
** documenttype : in general, the name of the module itself&lt;br /&gt;
** itemtype : a subclassifier, if the module provides more than one virtual document to the search engine.&lt;br /&gt;
** contextid : the context object id that should be considered when checking accessor&#039;s capabilities&lt;br /&gt;
** title : the title string to appear in search results as a caption&lt;br /&gt;
** author : if the author is known, the user id (mdl_user.id) representing the author.&lt;br /&gt;
** contents : a text bulk from the document content, filtered out from any formatting attributes or tags&lt;br /&gt;
** url : the document url, that will be constructed by the adapter to access back the resource&lt;br /&gt;
** date : usually the date when the resource was created&lt;br /&gt;
* &#039;&#039;&#039;&amp;amp;$data&#039;&#039;&#039; is a reference onto a contextual metadata object that will be serialized among with the record, but will not be used as searchable content&lt;br /&gt;
* &#039;&#039;&#039;$course_id&#039;&#039;&#039; is the current course the ressource is within&lt;br /&gt;
* &#039;&#039;&#039;$group_id&#039;&#039;&#039; is the current group the resource belongs to, if the ressource is in a group scope (i.e. separate group wiki attachements), 0 elsewhere.&lt;br /&gt;
* &#039;&#039;&#039;$user_id&#039;&#039;&#039; is the id of the user the resource beslongs to, in case the ressource is in a user specific scope (i.e. post or assignment attachements), 0 elsewhere.&lt;br /&gt;
* &#039;&#039;&#039;$path&#039;&#039;&#039; is one of the above PATH defines for the module.&lt;br /&gt;
&lt;br /&gt;
== Providing The indexer Documents From The Module ==&lt;br /&gt;
&lt;br /&gt;
When first constructing the index, The Indexer needs scanning all the instances of the plugin. &lt;br /&gt;
&lt;br /&gt;
The adapter API must provide the&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;module&amp;gt;_iterator(){ ... }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
function that will give a set of consistant plugin instances. Here is a &#039;&#039;very standard&#039;&#039; template code for this method : &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_iterator() {&lt;br /&gt;
    $&amp;lt;module&amp;gt; = get_records(&#039;&amp;lt;module&amp;gt;&#039;);&lt;br /&gt;
    return $&amp;lt;module&amp;gt;;&lt;br /&gt;
} //&amp;lt;module&amp;gt;_iterator&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On each instance, the function :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_get_content_for_index(&amp;amp;$plugininstance) { ... }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
is called for constructing relevant instances of the SearchDocument subclass. This function MUST return an array of SearchDocuments or false. The typical synopsis of this function is : &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_get_content_for_index(&amp;amp;$plugininstance){&lt;br /&gt;
    $documents = array();&lt;br /&gt;
&lt;br /&gt;
    // invalid plugin&lt;br /&gt;
    if (!$plugininstance) return $documents;&lt;br /&gt;
&lt;br /&gt;
    // TODO : get an indexable item set&lt;br /&gt;
&lt;br /&gt;
    foreach($indexableitems as $indexableitem) {&lt;br /&gt;
&lt;br /&gt;
       // TODO : Prepare params with &lt;br /&gt;
&lt;br /&gt;
       $documents[] = new ForumSearchDocument(... params ...);&lt;br /&gt;
    } &lt;br /&gt;
    return $documents;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Making The Backaccess Link ===&lt;br /&gt;
&lt;br /&gt;
The constructor of the SearchDocument subclass must construct a backaccess link for the document, and give it as the &#039;url&#039; attribute of the first constructor parameter (&amp;amp;$doc). this is usually done using a callback to the document API. the synopsys is : &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_make_link(...contextual params...) {&lt;br /&gt;
    global $CFG;&lt;br /&gt;
    &lt;br /&gt;
    return $CFG-&amp;gt;wwwroot.&amp;lt;moodle path expression that drives back to the content&amp;gt;;&lt;br /&gt;
} //&amp;lt;module&amp;gt;_make_link&lt;br /&gt;
&amp;lt;/pre&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
Contextual params are usually ids of course module, or internal entities depending on the module construction, modal values...&lt;br /&gt;
&lt;br /&gt;
== Updating The index Database ==&lt;br /&gt;
&lt;br /&gt;
The search engine, once fed with its first indexing results from scratch, will be regularily updating by a cron job. The index is updated in diff mode, so only modified entries in the Moodle data model should be considered. &lt;br /&gt;
&lt;br /&gt;
The update process will : &lt;br /&gt;
* add new items, as far as they are handled by the search engine&lt;br /&gt;
* update modified items&lt;br /&gt;
* drop indexes on deleted resources and contents&lt;br /&gt;
&lt;br /&gt;
An API callback tells each of these three actions where the items to consider are in the Moodle database. This callback SHOULD return an array of arrays of strings, each containing the following fieldset : &lt;br /&gt;
* primary id fieldname, &lt;br /&gt;
* table name, &lt;br /&gt;
* time created field name,&lt;br /&gt;
* time modified field name,&lt;br /&gt;
* itemtype,&lt;br /&gt;
* [additional SELECT clause for filtering rows]   // optional&lt;br /&gt;
&lt;br /&gt;
Here comes a synopsys for such code. There should be as many arrays as known document subtypes in the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_db_names() {&lt;br /&gt;
    return array(&lt;br /&gt;
        array(&#039;id&#039;, &#039;&amp;lt;module&amp;gt;_&amp;lt;entity&amp;gt;&#039;, &#039;created&#039;, &#039;modified&#039;, &#039;&amp;lt;itemtype&amp;gt;&#039;, &#039;&#039;)&lt;br /&gt;
    );&lt;br /&gt;
} //&amp;lt;module&amp;gt;_db_names&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note : &#039;created&#039; and &#039;modified&#039; have several expression among the variety of modules/blocks. Sometimes, both of these informations are not available. Consider using the dates of a parent dependency in case they are missing.&lt;br /&gt;
&lt;br /&gt;
Knowing where the items to update/add/delete are, both first operation will use a &amp;quot;Single Document Wrapper&amp;quot; to process to the update/add operation individually. This is the purpose of the &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_single_document($id, $itemtype) { ... }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
function. Here comes a rough prototype for such a callback : &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_single_document($id, $itemtype) {&lt;br /&gt;
&lt;br /&gt;
    switch($itemtype){&lt;br /&gt;
        case &amp;lt;type1&amp;gt;:&lt;br /&gt;
           ... get content holding record ...&lt;br /&gt;
           ... get module_obj from previous ...&lt;br /&gt;
        break;&lt;br /&gt;
        case &amp;lt;type2&amp;gt;:&lt;br /&gt;
           ... get content holding record ...&lt;br /&gt;
           ... get module_obj from previous ...&lt;br /&gt;
        break;&lt;br /&gt;
        ... and so on ...&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    $coursemodule = get_field(&#039;modules&#039;, &#039;id&#039;, &#039;name&#039;, &#039;&amp;lt;module&amp;gt;&#039;);&lt;br /&gt;
    $cm = get_record(&#039;course_modules&#039;, &#039;course&#039;, $&amp;lt;module_obj&amp;gt;-&amp;gt;course, &lt;br /&gt;
                     &#039;module&#039;, $coursemodule, &#039;instance&#039;, $&amp;lt;module_obj&amp;gt;-&amp;gt;id);&lt;br /&gt;
    if ($cm){&lt;br /&gt;
        $context = get_context_instance(CONTEXT_MODULE, $cm-&amp;gt;id);&lt;br /&gt;
        ... preparing some data eventually ... &lt;br /&gt;
        return new &amp;lt;ModuleItem&amp;gt;SearchDocument(get_object_vars($&amp;lt;content_obj&amp;gt;), &lt;br /&gt;
               $&amp;lt;module_obj&amp;gt;-&amp;gt;id, $&amp;lt;module_obj&amp;gt;-&amp;gt;course, $itemtype, $context-&amp;gt;id);&lt;br /&gt;
    }&lt;br /&gt;
    return null;&lt;br /&gt;
} // &amp;lt;module&amp;gt;_single_document&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note : we need use get_object_vars() as historical implementation uses a hash in constructors rather than an object.&lt;br /&gt;
&lt;br /&gt;
For deletion, you will have to reproduce a callback which remains from an old unexplained implementation : &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_delete($info, $itemtype) {&lt;br /&gt;
    $object-&amp;gt;id = $info;&lt;br /&gt;
    $object-&amp;gt;itemtype = $itemtype;&lt;br /&gt;
    return $object;&lt;br /&gt;
} // &amp;lt;module&amp;gt;_delete&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just rewrite it AS IS, nothing to think about here.&lt;br /&gt;
&lt;br /&gt;
== Checking Access Back To The Content ==&lt;br /&gt;
&lt;br /&gt;
== Physical Document Adapters ==&lt;/div&gt;</summary>
		<author><name>Vf</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Search_engine_adapters&amp;diff=7450</id>
		<title>Search engine adapters</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Search_engine_adapters&amp;diff=7450"/>
		<updated>2007-11-18T14:27:14Z</updated>

		<summary type="html">&lt;p&gt;Vf: /* Updating The index Database */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The global search engine of Moodle, available as experimental feature till the Moodle 1.9 release, allows plugin new document types for being searched and indexed by the Lucene indexer.&lt;br /&gt;
&lt;br /&gt;
Each module or block should have an adapter written to wrap the plugin&#039;s internal data model to a searchable document. The actual implementation allows a module to provide the search engine with a set of virtual documents. The search engine will index the text content of these documents, recording sufficiant data to access back the exact context in which it was appearing (i.e, access URL, course context, etc.).&lt;br /&gt;
&lt;br /&gt;
Virtual documents are defined as subclasses of the SearchDocument class. Only the constructor of the subclass must be written in order to map an input record to an internal document definition.&lt;br /&gt;
&lt;br /&gt;
The goals of the adapter are : &lt;br /&gt;
&lt;br /&gt;
* extract all virtual documents from the module data model and give them to the indexer (index first construction) through an &#039;&#039;iterator&#039;&#039;.&lt;br /&gt;
* extract a single document for index update&lt;br /&gt;
* provide sufficiant information for index delete of obsolete content&lt;br /&gt;
* define the access URL that will access back the resource&lt;br /&gt;
* define the access check algorithm so that the user will only access resources he is allowed to&lt;br /&gt;
&lt;br /&gt;
== Adapters For Modules And Blocks ==&lt;br /&gt;
&lt;br /&gt;
Any adapter for a module or a block must reside in the &amp;lt;pre&amp;gt;/search/documents&amp;lt;/pre&amp;gt; subdirectory, and will be named such as &amp;lt;pre&amp;gt;&amp;lt;module&amp;gt;_document.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search defines ===&lt;br /&gt;
&lt;br /&gt;
Each searchable module should add at least both (typical) following defines in /search/lib.php :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
define(&#039;SEARCH_TYPE_&amp;lt;MODULE&amp;gt;&#039;, &#039;&amp;lt;module&amp;gt;&#039;);&lt;br /&gt;
define(&#039;PATH_FOR_SEARCH_TYPE_&amp;lt;MODULE&amp;gt;&#039;, &#039;mod/&amp;lt;module&amp;gt;&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
define(&#039;SEARCH_TYPE_&amp;lt;BLOCK&amp;gt;&#039;, &#039;&amp;lt;block&amp;gt;&#039;);&lt;br /&gt;
define(&#039;PATH_FOR_SEARCH_TYPE_&amp;lt;BLOCK&amp;gt;&#039;, &#039;blocks/&amp;lt;block&amp;gt;&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Constructor ===&lt;br /&gt;
&lt;br /&gt;
The constructor of the SearchDocument class has the following signature :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public function __construct(&amp;amp;$doc, &amp;amp;$data, $course_id, $group_id, $user_id, $path)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where : &lt;br /&gt;
* &#039;&#039;&#039;&amp;amp;$doc&#039;&#039;&#039; is a reference onto a PHP object that should provide the fields :&lt;br /&gt;
** docid : the id of the document, as suitable for reconstructing the access URL.&lt;br /&gt;
** documenttype : in general, the name of the module itself&lt;br /&gt;
** itemtype : a subclassifier, if the module provides more than one virtual document to the search engine.&lt;br /&gt;
** contextid : the context object id that should be considered when checking accessor&#039;s capabilities&lt;br /&gt;
** title : the title string to appear in search results as a caption&lt;br /&gt;
** author : if the author is known, the user id (mdl_user.id) representing the author.&lt;br /&gt;
** contents : a text bulk from the document content, filtered out from any formatting attributes or tags&lt;br /&gt;
** url : the document url, that will be constructed by the adapter to access back the resource&lt;br /&gt;
** date : usually the date when the resource was created&lt;br /&gt;
* &#039;&#039;&#039;&amp;amp;$data&#039;&#039;&#039; is a reference onto a contextual metadata object that will be serialized among with the record, but will not be used as searchable content&lt;br /&gt;
* &#039;&#039;&#039;$course_id&#039;&#039;&#039; is the current course the ressource is within&lt;br /&gt;
* &#039;&#039;&#039;$group_id&#039;&#039;&#039; is the current group the resource belongs to, if the ressource is in a group scope (i.e. separate group wiki attachements), 0 elsewhere.&lt;br /&gt;
* &#039;&#039;&#039;$user_id&#039;&#039;&#039; is the id of the user the resource beslongs to, in case the ressource is in a user specific scope (i.e. post or assignment attachements), 0 elsewhere.&lt;br /&gt;
* &#039;&#039;&#039;$path&#039;&#039;&#039; is one of the above PATH defines for the module.&lt;br /&gt;
&lt;br /&gt;
== Providing The indexer Documents From The Module ==&lt;br /&gt;
&lt;br /&gt;
When first constructing the index, The Indexer needs scanning all the instances of the plugin. &lt;br /&gt;
&lt;br /&gt;
The adapter API must provide the&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;module&amp;gt;_iterator(){ ... }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
function that will give a set of consistant plugin instances. Here is a &#039;&#039;very standard&#039;&#039; template code for this method : &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_iterator() {&lt;br /&gt;
    $&amp;lt;module&amp;gt; = get_records(&#039;&amp;lt;module&amp;gt;&#039;);&lt;br /&gt;
    return $&amp;lt;module&amp;gt;;&lt;br /&gt;
} //&amp;lt;module&amp;gt;_iterator&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On each instance, the function :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_get_content_for_index(&amp;amp;$plugininstance) { ... }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
is called for constructing relevant instances of the SearchDocument subclass. This function MUST return an array of SearchDocuments or false. The typical synopsis of this function is : &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_get_content_for_index(&amp;amp;$plugininstance){&lt;br /&gt;
    $documents = array();&lt;br /&gt;
&lt;br /&gt;
    // invalid plugin&lt;br /&gt;
    if (!$plugininstance) return $documents;&lt;br /&gt;
&lt;br /&gt;
    // TODO : get an indexable item set&lt;br /&gt;
&lt;br /&gt;
    foreach($indexableitems as $indexableitem) {&lt;br /&gt;
&lt;br /&gt;
       // TODO : Prepare params with &lt;br /&gt;
&lt;br /&gt;
       $documents[] = new ForumSearchDocument(... params ...);&lt;br /&gt;
    } &lt;br /&gt;
    return $documents;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Making The Backaccess Link ===&lt;br /&gt;
&lt;br /&gt;
The constructor of the SearchDocument subclass must construct a backaccess link for the document, and give it as the &#039;url&#039; attribute of the first constructor parameter (&amp;amp;$doc). this is usually done using a callback to the document API. the synopsys is : &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_make_link(...contextual params...) {&lt;br /&gt;
    global $CFG;&lt;br /&gt;
    &lt;br /&gt;
    return $CFG-&amp;gt;wwwroot.&amp;lt;moodle path expression that drives back to the content&amp;gt;;&lt;br /&gt;
} //&amp;lt;module&amp;gt;_make_link&lt;br /&gt;
&amp;lt;/pre&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
Contextual params are usually ids of course module, or internal entities depending on the module construction, modal values...&lt;br /&gt;
&lt;br /&gt;
== Updating The index Database ==&lt;br /&gt;
&lt;br /&gt;
The search engine, once fed with its first indexing results from scratch, will be regularily updating by a cron job. The index is updated in diff mode, so only modified entries in the Moodle data model should be considered. &lt;br /&gt;
&lt;br /&gt;
The update process will : &lt;br /&gt;
* add new items, as far as they are handled by the search engine&lt;br /&gt;
* update modified items&lt;br /&gt;
* drop indexes on deleted resources and contents&lt;br /&gt;
&lt;br /&gt;
An API callback tells each of these three actions where the items to consider are in the Moodle database. This callback SHOULD return an array of arrays of strings, each containing the following fieldset : &lt;br /&gt;
* primary id fieldname, &lt;br /&gt;
* table name, &lt;br /&gt;
* time created field name,&lt;br /&gt;
* time modified field name,&lt;br /&gt;
* itemtype,&lt;br /&gt;
* [additional SELECT clause for filtering rows]   // optional&lt;br /&gt;
&lt;br /&gt;
Here comes a synopsys for such code. There should be as many arrays as known document subtypes in the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_db_names() {&lt;br /&gt;
    return array(&lt;br /&gt;
        array(&#039;id&#039;, &#039;&amp;lt;module&amp;gt;_&amp;lt;entity&amp;gt;&#039;, &#039;created&#039;, &#039;modified&#039;, &#039;&amp;lt;itemtype&amp;gt;&#039;, &#039;&#039;)&lt;br /&gt;
    );&lt;br /&gt;
} //&amp;lt;module&amp;gt;_db_names&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note : &#039;created&#039; and &#039;modified&#039; have several expression among the variety of modules/blocks. Sometimes, both of these informations are not available. Consider using the dates of a parent dependency in case they are missing.&lt;br /&gt;
&lt;br /&gt;
Knowing where the items to update/add/delete are, both first operation will use a &amp;quot;Single Document Wrapper&amp;quot; to process to the update/add operation individually. This is the purpose of the &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_single_document($id, $itemtype) { ... }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
function. Here comes a rough prototype for such a callback : &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_single_document($id, $itemtype) {&lt;br /&gt;
&lt;br /&gt;
    switch($itemtype){&lt;br /&gt;
        case &amp;lt;type1&amp;gt;:&lt;br /&gt;
           ... get content holding record ...&lt;br /&gt;
           ... get module_obj from previous ...&lt;br /&gt;
        break;&lt;br /&gt;
        case &amp;lt;type2&amp;gt;:&lt;br /&gt;
           ... get content holding record ...&lt;br /&gt;
           ... get module_obj from previous ...&lt;br /&gt;
        break;&lt;br /&gt;
        ... and so on ...&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    $coursemodule = get_field(&#039;modules&#039;, &#039;id&#039;, &#039;name&#039;, &#039;&amp;lt;module&amp;gt;&#039;);&lt;br /&gt;
    $cm = get_record(&#039;course_modules&#039;, &#039;course&#039;, $&amp;lt;module_obj&amp;gt;-&amp;gt;course, &#039;module&#039;, $coursemodule, &#039;instance&#039;, $&amp;lt;module_obj&amp;gt;-&amp;gt;id);&lt;br /&gt;
    if ($cm){&lt;br /&gt;
        $context = get_context_instance(CONTEXT_MODULE, $cm-&amp;gt;id);&lt;br /&gt;
        ... preparing some data eventually ... &lt;br /&gt;
        return new &amp;lt;ModuleItem&amp;gt;SearchDocument(get_object_vars($&amp;lt;content_obj&amp;gt;), $&amp;lt;module_obj&amp;gt;-&amp;gt;id, $&amp;lt;module_obj&amp;gt;-&amp;gt;course, $itemtype, $context-&amp;gt;id);&lt;br /&gt;
    }&lt;br /&gt;
    return null;&lt;br /&gt;
} // &amp;lt;module&amp;gt;_single_document&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note : we need use get_object_vars() as historical implementation uses a hash in constructors rather than an object.&lt;br /&gt;
&lt;br /&gt;
== Checking Access Back To The Content ==&lt;br /&gt;
&lt;br /&gt;
== Physical Document Adapters ==&lt;/div&gt;</summary>
		<author><name>Vf</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Search_engine_adapters&amp;diff=7449</id>
		<title>Search engine adapters</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Search_engine_adapters&amp;diff=7449"/>
		<updated>2007-11-18T14:26:38Z</updated>

		<summary type="html">&lt;p&gt;Vf: /* Making The Backaccess Link */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The global search engine of Moodle, available as experimental feature till the Moodle 1.9 release, allows plugin new document types for being searched and indexed by the Lucene indexer.&lt;br /&gt;
&lt;br /&gt;
Each module or block should have an adapter written to wrap the plugin&#039;s internal data model to a searchable document. The actual implementation allows a module to provide the search engine with a set of virtual documents. The search engine will index the text content of these documents, recording sufficiant data to access back the exact context in which it was appearing (i.e, access URL, course context, etc.).&lt;br /&gt;
&lt;br /&gt;
Virtual documents are defined as subclasses of the SearchDocument class. Only the constructor of the subclass must be written in order to map an input record to an internal document definition.&lt;br /&gt;
&lt;br /&gt;
The goals of the adapter are : &lt;br /&gt;
&lt;br /&gt;
* extract all virtual documents from the module data model and give them to the indexer (index first construction) through an &#039;&#039;iterator&#039;&#039;.&lt;br /&gt;
* extract a single document for index update&lt;br /&gt;
* provide sufficiant information for index delete of obsolete content&lt;br /&gt;
* define the access URL that will access back the resource&lt;br /&gt;
* define the access check algorithm so that the user will only access resources he is allowed to&lt;br /&gt;
&lt;br /&gt;
== Adapters For Modules And Blocks ==&lt;br /&gt;
&lt;br /&gt;
Any adapter for a module or a block must reside in the &amp;lt;pre&amp;gt;/search/documents&amp;lt;/pre&amp;gt; subdirectory, and will be named such as &amp;lt;pre&amp;gt;&amp;lt;module&amp;gt;_document.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search defines ===&lt;br /&gt;
&lt;br /&gt;
Each searchable module should add at least both (typical) following defines in /search/lib.php :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
define(&#039;SEARCH_TYPE_&amp;lt;MODULE&amp;gt;&#039;, &#039;&amp;lt;module&amp;gt;&#039;);&lt;br /&gt;
define(&#039;PATH_FOR_SEARCH_TYPE_&amp;lt;MODULE&amp;gt;&#039;, &#039;mod/&amp;lt;module&amp;gt;&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
define(&#039;SEARCH_TYPE_&amp;lt;BLOCK&amp;gt;&#039;, &#039;&amp;lt;block&amp;gt;&#039;);&lt;br /&gt;
define(&#039;PATH_FOR_SEARCH_TYPE_&amp;lt;BLOCK&amp;gt;&#039;, &#039;blocks/&amp;lt;block&amp;gt;&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Constructor ===&lt;br /&gt;
&lt;br /&gt;
The constructor of the SearchDocument class has the following signature :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public function __construct(&amp;amp;$doc, &amp;amp;$data, $course_id, $group_id, $user_id, $path)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where : &lt;br /&gt;
* &#039;&#039;&#039;&amp;amp;$doc&#039;&#039;&#039; is a reference onto a PHP object that should provide the fields :&lt;br /&gt;
** docid : the id of the document, as suitable for reconstructing the access URL.&lt;br /&gt;
** documenttype : in general, the name of the module itself&lt;br /&gt;
** itemtype : a subclassifier, if the module provides more than one virtual document to the search engine.&lt;br /&gt;
** contextid : the context object id that should be considered when checking accessor&#039;s capabilities&lt;br /&gt;
** title : the title string to appear in search results as a caption&lt;br /&gt;
** author : if the author is known, the user id (mdl_user.id) representing the author.&lt;br /&gt;
** contents : a text bulk from the document content, filtered out from any formatting attributes or tags&lt;br /&gt;
** url : the document url, that will be constructed by the adapter to access back the resource&lt;br /&gt;
** date : usually the date when the resource was created&lt;br /&gt;
* &#039;&#039;&#039;&amp;amp;$data&#039;&#039;&#039; is a reference onto a contextual metadata object that will be serialized among with the record, but will not be used as searchable content&lt;br /&gt;
* &#039;&#039;&#039;$course_id&#039;&#039;&#039; is the current course the ressource is within&lt;br /&gt;
* &#039;&#039;&#039;$group_id&#039;&#039;&#039; is the current group the resource belongs to, if the ressource is in a group scope (i.e. separate group wiki attachements), 0 elsewhere.&lt;br /&gt;
* &#039;&#039;&#039;$user_id&#039;&#039;&#039; is the id of the user the resource beslongs to, in case the ressource is in a user specific scope (i.e. post or assignment attachements), 0 elsewhere.&lt;br /&gt;
* &#039;&#039;&#039;$path&#039;&#039;&#039; is one of the above PATH defines for the module.&lt;br /&gt;
&lt;br /&gt;
== Providing The indexer Documents From The Module ==&lt;br /&gt;
&lt;br /&gt;
When first constructing the index, The Indexer needs scanning all the instances of the plugin. &lt;br /&gt;
&lt;br /&gt;
The adapter API must provide the&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;module&amp;gt;_iterator(){ ... }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
function that will give a set of consistant plugin instances. Here is a &#039;&#039;very standard&#039;&#039; template code for this method : &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_iterator() {&lt;br /&gt;
    $&amp;lt;module&amp;gt; = get_records(&#039;&amp;lt;module&amp;gt;&#039;);&lt;br /&gt;
    return $&amp;lt;module&amp;gt;;&lt;br /&gt;
} //&amp;lt;module&amp;gt;_iterator&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On each instance, the function :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_get_content_for_index(&amp;amp;$plugininstance) { ... }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
is called for constructing relevant instances of the SearchDocument subclass. This function MUST return an array of SearchDocuments or false. The typical synopsis of this function is : &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_get_content_for_index(&amp;amp;$plugininstance){&lt;br /&gt;
    $documents = array();&lt;br /&gt;
&lt;br /&gt;
    // invalid plugin&lt;br /&gt;
    if (!$plugininstance) return $documents;&lt;br /&gt;
&lt;br /&gt;
    // TODO : get an indexable item set&lt;br /&gt;
&lt;br /&gt;
    foreach($indexableitems as $indexableitem) {&lt;br /&gt;
&lt;br /&gt;
       // TODO : Prepare params with &lt;br /&gt;
&lt;br /&gt;
       $documents[] = new ForumSearchDocument(... params ...);&lt;br /&gt;
    } &lt;br /&gt;
    return $documents;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Making The Backaccess Link ===&lt;br /&gt;
&lt;br /&gt;
The constructor of the SearchDocument subclass must construct a backaccess link for the document, and give it as the &#039;url&#039; attribute of the first constructor parameter (&amp;amp;$doc). this is usually done using a callback to the document API. the synopsys is : &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_make_link(...contextual params...) {&lt;br /&gt;
    global $CFG;&lt;br /&gt;
    &lt;br /&gt;
    return $CFG-&amp;gt;wwwroot.&amp;lt;moodle path expression that drives back to the content&amp;gt;;&lt;br /&gt;
} //&amp;lt;module&amp;gt;_make_link&lt;br /&gt;
&amp;lt;/pre&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
Contextual params are usually ids of course module, or internal entities depending on the module construction, modal values...&lt;br /&gt;
&lt;br /&gt;
== Updating The index Database ==&lt;br /&gt;
&lt;br /&gt;
The search engine, once fed with its first indexing results from scratch, will be regularily updating by a cron job. The index is updated in diff mode, so only modified entries in the Moodle data model should be considered. &lt;br /&gt;
&lt;br /&gt;
The update process will : &lt;br /&gt;
* add new items, as far as they are handled by the search engine&lt;br /&gt;
* update modified items&lt;br /&gt;
* drop indexes on deleted resources and contents&lt;br /&gt;
&lt;br /&gt;
An API call back tells each of these three actions where the items to consider are in the Moodle database. This callback SHOULD return an array of arrays of strings, each containing the following fieldset : &lt;br /&gt;
* primary id fieldname, &lt;br /&gt;
* table name, &lt;br /&gt;
* time created field name,&lt;br /&gt;
* time modified field name,&lt;br /&gt;
* itemtype,&lt;br /&gt;
* [additional SELECT clause for filtering rows]   // optional&lt;br /&gt;
&lt;br /&gt;
Here comes a synopsys for such code. There should be as many arrays as known document subtypes in the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_db_names() {&lt;br /&gt;
    return array(&lt;br /&gt;
        array(&#039;id&#039;, &#039;&amp;lt;module&amp;gt;_&amp;lt;entity&amp;gt;&#039;, &#039;created&#039;, &#039;modified&#039;, &#039;&amp;lt;itemtype&amp;gt;&#039;, &#039;&#039;)&lt;br /&gt;
    );&lt;br /&gt;
} //&amp;lt;module&amp;gt;_db_names&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note : &#039;created&#039; and &#039;modified&#039; have several expression among the variety of modules/blocks. Sometimes, both of these informations are not available. Consider using the dates of a parent dependency in case they are missing.&lt;br /&gt;
&lt;br /&gt;
Knowing where the items to update/add/delete are, both first operation will use a &amp;quot;Single Document Wrapper&amp;quot; to process to the update/add operation individually. This is the purpose of the &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_single_document($id, $itemtype) { ... }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
function. Here comes a rough prototype for such a callback : &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_single_document($id, $itemtype) {&lt;br /&gt;
&lt;br /&gt;
    switch($itemtype){&lt;br /&gt;
        case &amp;lt;type1&amp;gt;:&lt;br /&gt;
           ... get content holding record ...&lt;br /&gt;
           ... get module_obj from previous ...&lt;br /&gt;
        break;&lt;br /&gt;
        case &amp;lt;type2&amp;gt;:&lt;br /&gt;
           ... get content holding record ...&lt;br /&gt;
           ... get module_obj from previous ...&lt;br /&gt;
        break;&lt;br /&gt;
        ... and so on ...&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    $coursemodule = get_field(&#039;modules&#039;, &#039;id&#039;, &#039;name&#039;, &#039;&amp;lt;module&amp;gt;&#039;);&lt;br /&gt;
    $cm = get_record(&#039;course_modules&#039;, &#039;course&#039;, $&amp;lt;module_obj&amp;gt;-&amp;gt;course, &#039;module&#039;, $coursemodule, &#039;instance&#039;, $&amp;lt;module_obj&amp;gt;-&amp;gt;id);&lt;br /&gt;
    if ($cm){&lt;br /&gt;
        $context = get_context_instance(CONTEXT_MODULE, $cm-&amp;gt;id);&lt;br /&gt;
        ... preparing some data eventually ... &lt;br /&gt;
        return new &amp;lt;ModuleItem&amp;gt;SearchDocument(get_object_vars($&amp;lt;content_obj&amp;gt;), $&amp;lt;module_obj&amp;gt;-&amp;gt;id, $&amp;lt;module_obj&amp;gt;-&amp;gt;course, $itemtype, $context-&amp;gt;id);&lt;br /&gt;
    }&lt;br /&gt;
    return null;&lt;br /&gt;
} // &amp;lt;module&amp;gt;_single_document&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note : we need use get_object_vars() as historical implementation uses a hash in constructors rather than an object.&lt;br /&gt;
&lt;br /&gt;
== Checking Access Back To The Content ==&lt;br /&gt;
&lt;br /&gt;
== Physical Document Adapters ==&lt;/div&gt;</summary>
		<author><name>Vf</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Search_engine_adapters&amp;diff=7448</id>
		<title>Search engine adapters</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Search_engine_adapters&amp;diff=7448"/>
		<updated>2007-11-18T14:04:42Z</updated>

		<summary type="html">&lt;p&gt;Vf: /* Providing The indexer Documents From The Module */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The global search engine of Moodle, available as experimental feature till the Moodle 1.9 release, allows plugin new document types for being searched and indexed by the Lucene indexer.&lt;br /&gt;
&lt;br /&gt;
Each module or block should have an adapter written to wrap the plugin&#039;s internal data model to a searchable document. The actual implementation allows a module to provide the search engine with a set of virtual documents. The search engine will index the text content of these documents, recording sufficiant data to access back the exact context in which it was appearing (i.e, access URL, course context, etc.).&lt;br /&gt;
&lt;br /&gt;
Virtual documents are defined as subclasses of the SearchDocument class. Only the constructor of the subclass must be written in order to map an input record to an internal document definition.&lt;br /&gt;
&lt;br /&gt;
The goals of the adapter are : &lt;br /&gt;
&lt;br /&gt;
* extract all virtual documents from the module data model and give them to the indexer (index first construction) through an &#039;&#039;iterator&#039;&#039;.&lt;br /&gt;
* extract a single document for index update&lt;br /&gt;
* provide sufficiant information for index delete of obsolete content&lt;br /&gt;
* define the access URL that will access back the resource&lt;br /&gt;
* define the access check algorithm so that the user will only access resources he is allowed to&lt;br /&gt;
&lt;br /&gt;
== Adapters For Modules And Blocks ==&lt;br /&gt;
&lt;br /&gt;
Any adapter for a module or a block must reside in the &amp;lt;pre&amp;gt;/search/documents&amp;lt;/pre&amp;gt; subdirectory, and will be named such as &amp;lt;pre&amp;gt;&amp;lt;module&amp;gt;_document.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search defines ===&lt;br /&gt;
&lt;br /&gt;
Each searchable module should add at least both (typical) following defines in /search/lib.php :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
define(&#039;SEARCH_TYPE_&amp;lt;MODULE&amp;gt;&#039;, &#039;&amp;lt;module&amp;gt;&#039;);&lt;br /&gt;
define(&#039;PATH_FOR_SEARCH_TYPE_&amp;lt;MODULE&amp;gt;&#039;, &#039;mod/&amp;lt;module&amp;gt;&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
define(&#039;SEARCH_TYPE_&amp;lt;BLOCK&amp;gt;&#039;, &#039;&amp;lt;block&amp;gt;&#039;);&lt;br /&gt;
define(&#039;PATH_FOR_SEARCH_TYPE_&amp;lt;BLOCK&amp;gt;&#039;, &#039;blocks/&amp;lt;block&amp;gt;&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Constructor ===&lt;br /&gt;
&lt;br /&gt;
The constructor of the SearchDocument class has the following signature :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public function __construct(&amp;amp;$doc, &amp;amp;$data, $course_id, $group_id, $user_id, $path)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where : &lt;br /&gt;
* &#039;&#039;&#039;&amp;amp;$doc&#039;&#039;&#039; is a reference onto a PHP object that should provide the fields :&lt;br /&gt;
** docid : the id of the document, as suitable for reconstructing the access URL.&lt;br /&gt;
** documenttype : in general, the name of the module itself&lt;br /&gt;
** itemtype : a subclassifier, if the module provides more than one virtual document to the search engine.&lt;br /&gt;
** contextid : the context object id that should be considered when checking accessor&#039;s capabilities&lt;br /&gt;
** title : the title string to appear in search results as a caption&lt;br /&gt;
** author : if the author is known, the user id (mdl_user.id) representing the author.&lt;br /&gt;
** contents : a text bulk from the document content, filtered out from any formatting attributes or tags&lt;br /&gt;
** url : the document url, that will be constructed by the adapter to access back the resource&lt;br /&gt;
** date : usually the date when the resource was created&lt;br /&gt;
* &#039;&#039;&#039;&amp;amp;$data&#039;&#039;&#039; is a reference onto a contextual metadata object that will be serialized among with the record, but will not be used as searchable content&lt;br /&gt;
* &#039;&#039;&#039;$course_id&#039;&#039;&#039; is the current course the ressource is within&lt;br /&gt;
* &#039;&#039;&#039;$group_id&#039;&#039;&#039; is the current group the resource belongs to, if the ressource is in a group scope (i.e. separate group wiki attachements), 0 elsewhere.&lt;br /&gt;
* &#039;&#039;&#039;$user_id&#039;&#039;&#039; is the id of the user the resource beslongs to, in case the ressource is in a user specific scope (i.e. post or assignment attachements), 0 elsewhere.&lt;br /&gt;
* &#039;&#039;&#039;$path&#039;&#039;&#039; is one of the above PATH defines for the module.&lt;br /&gt;
&lt;br /&gt;
== Providing The indexer Documents From The Module ==&lt;br /&gt;
&lt;br /&gt;
When first constructing the index, The Indexer needs scanning all the instances of the plugin. &lt;br /&gt;
&lt;br /&gt;
The adapter API must provide the&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;module&amp;gt;_iterator(){ ... }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
function that will give a set of consistant plugin instances. Here is a &#039;&#039;very standard&#039;&#039; template code for this method : &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_iterator() {&lt;br /&gt;
    $&amp;lt;module&amp;gt; = get_records(&#039;&amp;lt;module&amp;gt;&#039;);&lt;br /&gt;
    return $&amp;lt;module&amp;gt;;&lt;br /&gt;
} //&amp;lt;module&amp;gt;_iterator&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On each instance, the function :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_get_content_for_index(&amp;amp;$plugininstance) { ... }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
is called for constructing relevant instances of the SearchDocument subclass. This function MUST return an array of SearchDocuments or false. The typical synopsis of this function is : &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_get_content_for_index(&amp;amp;$plugininstance){&lt;br /&gt;
    $documents = array();&lt;br /&gt;
&lt;br /&gt;
    // invalid plugin&lt;br /&gt;
    if (!$plugininstance) return $documents;&lt;br /&gt;
&lt;br /&gt;
    // TODO : get an indexable item set&lt;br /&gt;
&lt;br /&gt;
    foreach($indexableitems as $indexableitem) {&lt;br /&gt;
&lt;br /&gt;
       // TODO : Prepare params with &lt;br /&gt;
&lt;br /&gt;
       $documents[] = new ForumSearchDocument(... params ...);&lt;br /&gt;
    } &lt;br /&gt;
    return $documents;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Making The Backaccess Link ===&lt;br /&gt;
&lt;br /&gt;
The constructor of the SearchDocument subclass must construct a backaccess link for the document, and give it as the &#039;url&#039; attribute of the first constructor parameter (&amp;amp;$doc). this is usually done using a callback to the document API. the synopsys is : &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_make_link(...contextual params...) {&lt;br /&gt;
    global $CFG;&lt;br /&gt;
    &lt;br /&gt;
    return $CFG-&amp;gt;wwwroot.&amp;lt;moodle path expression that drives back to the content&amp;gt;;&lt;br /&gt;
} //&amp;lt;module&amp;gt;_make_link&lt;br /&gt;
&amp;lt;/pre&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
Contextual params are usually ids of course module, or internal entities depending on the module construction, modal values...&lt;br /&gt;
&lt;br /&gt;
== Checking Access Back To The Content ==&lt;br /&gt;
&lt;br /&gt;
== Physical Document Adapters ==&lt;/div&gt;</summary>
		<author><name>Vf</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Search_engine_adapters&amp;diff=7447</id>
		<title>Search engine adapters</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Search_engine_adapters&amp;diff=7447"/>
		<updated>2007-11-17T21:56:18Z</updated>

		<summary type="html">&lt;p&gt;Vf: /* Providing The indexer Documents From The Module */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The global search engine of Moodle, available as experimental feature till the Moodle 1.9 release, allows plugin new document types for being searched and indexed by the Lucene indexer.&lt;br /&gt;
&lt;br /&gt;
Each module or block should have an adapter written to wrap the plugin&#039;s internal data model to a searchable document. The actual implementation allows a module to provide the search engine with a set of virtual documents. The search engine will index the text content of these documents, recording sufficiant data to access back the exact context in which it was appearing (i.e, access URL, course context, etc.).&lt;br /&gt;
&lt;br /&gt;
Virtual documents are defined as subclasses of the SearchDocument class. Only the constructor of the subclass must be written in order to map an input record to an internal document definition.&lt;br /&gt;
&lt;br /&gt;
The goals of the adapter are : &lt;br /&gt;
&lt;br /&gt;
* extract all virtual documents from the module data model and give them to the indexer (index first construction) through an &#039;&#039;iterator&#039;&#039;.&lt;br /&gt;
* extract a single document for index update&lt;br /&gt;
* provide sufficiant information for index delete of obsolete content&lt;br /&gt;
* define the access URL that will access back the resource&lt;br /&gt;
* define the access check algorithm so that the user will only access resources he is allowed to&lt;br /&gt;
&lt;br /&gt;
== Adapters For Modules And Blocks ==&lt;br /&gt;
&lt;br /&gt;
Any adapter for a module or a block must reside in the &amp;lt;pre&amp;gt;/search/documents&amp;lt;/pre&amp;gt; subdirectory, and will be named such as &amp;lt;pre&amp;gt;&amp;lt;module&amp;gt;_document.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search defines ===&lt;br /&gt;
&lt;br /&gt;
Each searchable module should add at least both (typical) following defines in /search/lib.php :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
define(&#039;SEARCH_TYPE_&amp;lt;MODULE&amp;gt;&#039;, &#039;&amp;lt;module&amp;gt;&#039;);&lt;br /&gt;
define(&#039;PATH_FOR_SEARCH_TYPE_&amp;lt;MODULE&amp;gt;&#039;, &#039;mod/&amp;lt;module&amp;gt;&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
define(&#039;SEARCH_TYPE_&amp;lt;BLOCK&amp;gt;&#039;, &#039;&amp;lt;block&amp;gt;&#039;);&lt;br /&gt;
define(&#039;PATH_FOR_SEARCH_TYPE_&amp;lt;BLOCK&amp;gt;&#039;, &#039;blocks/&amp;lt;block&amp;gt;&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Constructor ===&lt;br /&gt;
&lt;br /&gt;
The constructor of the SearchDocument class has the following signature :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public function __construct(&amp;amp;$doc, &amp;amp;$data, $course_id, $group_id, $user_id, $path)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where : &lt;br /&gt;
* &#039;&#039;&#039;&amp;amp;$doc&#039;&#039;&#039; is a reference onto a PHP object that should provide the fields :&lt;br /&gt;
** docid : the id of the document, as suitable for reconstructing the access URL.&lt;br /&gt;
** documenttype : in general, the name of the module itself&lt;br /&gt;
** itemtype : a subclassifier, if the module provides more than one virtual document to the search engine.&lt;br /&gt;
** contextid : the context object id that should be considered when checking accessor&#039;s capabilities&lt;br /&gt;
** title : the title string to appear in search results as a caption&lt;br /&gt;
** author : if the author is known, the user id (mdl_user.id) representing the author.&lt;br /&gt;
** contents : a text bulk from the document content, filtered out from any formatting attributes or tags&lt;br /&gt;
** url : the document url, that will be constructed by the adapter to access back the resource&lt;br /&gt;
** date : usually the date when the resource was created&lt;br /&gt;
* &#039;&#039;&#039;&amp;amp;$data&#039;&#039;&#039; is a reference onto a contextual metadata object that will be serialized among with the record, but will not be used as searchable content&lt;br /&gt;
* &#039;&#039;&#039;$course_id&#039;&#039;&#039; is the current course the ressource is within&lt;br /&gt;
* &#039;&#039;&#039;$group_id&#039;&#039;&#039; is the current group the resource belongs to, if the ressource is in a group scope (i.e. separate group wiki attachements), 0 elsewhere.&lt;br /&gt;
* &#039;&#039;&#039;$user_id&#039;&#039;&#039; is the id of the user the resource beslongs to, in case the ressource is in a user specific scope (i.e. post or assignment attachements), 0 elsewhere.&lt;br /&gt;
* &#039;&#039;&#039;$path&#039;&#039;&#039; is one of the above PATH defines for the module.&lt;br /&gt;
&lt;br /&gt;
== Providing The indexer Documents From The Module ==&lt;br /&gt;
&lt;br /&gt;
When first constructing the index, The Indexer needs scanning all the instances of the plugin. &lt;br /&gt;
&lt;br /&gt;
The adapter API must provide the&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;module&amp;gt;_iterator(){ ... }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
function that will give a set of consistant plugin instances. Here is a &#039;&#039;very standard&#039;&#039; template code for this method : &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_iterator() {&lt;br /&gt;
    $&amp;lt;module&amp;gt; = get_records(&#039;&amp;lt;module&amp;gt;&#039;);&lt;br /&gt;
    return $&amp;lt;module&amp;gt;;&lt;br /&gt;
} //&amp;lt;module&amp;gt;_iterator&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On each instance, the function :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_get_content_for_index(&amp;amp;$plugininstance) { ... }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
is called for constructing relevant instances of the SearchDocument subclass. This function MUST return an array of SearchDocuments or false. The typical synopsis of this function is : &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_get_content_for_index(&amp;amp;$plugininstance){&lt;br /&gt;
    $documents = array();&lt;br /&gt;
&lt;br /&gt;
    // invalid plugin&lt;br /&gt;
    if (!$plugininstance) return $documents;&lt;br /&gt;
&lt;br /&gt;
    // TODO : get an indexable item set&lt;br /&gt;
&lt;br /&gt;
    foreach($indexableitems as $indexableitem) {&lt;br /&gt;
&lt;br /&gt;
       // TODO : Prepare params with &lt;br /&gt;
&lt;br /&gt;
       $documents[] = new ForumSearchDocument(... params ...);&lt;br /&gt;
    } &lt;br /&gt;
    return $documents;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Checking Access Back To The Content ==&lt;br /&gt;
&lt;br /&gt;
== Physical Document Adapters ==&lt;/div&gt;</summary>
		<author><name>Vf</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Search_engine_adapters&amp;diff=7446</id>
		<title>Search engine adapters</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Search_engine_adapters&amp;diff=7446"/>
		<updated>2007-11-17T21:55:36Z</updated>

		<summary type="html">&lt;p&gt;Vf: /* Providing The indexer Documents From The Module */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The global search engine of Moodle, available as experimental feature till the Moodle 1.9 release, allows plugin new document types for being searched and indexed by the Lucene indexer.&lt;br /&gt;
&lt;br /&gt;
Each module or block should have an adapter written to wrap the plugin&#039;s internal data model to a searchable document. The actual implementation allows a module to provide the search engine with a set of virtual documents. The search engine will index the text content of these documents, recording sufficiant data to access back the exact context in which it was appearing (i.e, access URL, course context, etc.).&lt;br /&gt;
&lt;br /&gt;
Virtual documents are defined as subclasses of the SearchDocument class. Only the constructor of the subclass must be written in order to map an input record to an internal document definition.&lt;br /&gt;
&lt;br /&gt;
The goals of the adapter are : &lt;br /&gt;
&lt;br /&gt;
* extract all virtual documents from the module data model and give them to the indexer (index first construction) through an &#039;&#039;iterator&#039;&#039;.&lt;br /&gt;
* extract a single document for index update&lt;br /&gt;
* provide sufficiant information for index delete of obsolete content&lt;br /&gt;
* define the access URL that will access back the resource&lt;br /&gt;
* define the access check algorithm so that the user will only access resources he is allowed to&lt;br /&gt;
&lt;br /&gt;
== Adapters For Modules And Blocks ==&lt;br /&gt;
&lt;br /&gt;
Any adapter for a module or a block must reside in the &amp;lt;pre&amp;gt;/search/documents&amp;lt;/pre&amp;gt; subdirectory, and will be named such as &amp;lt;pre&amp;gt;&amp;lt;module&amp;gt;_document.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search defines ===&lt;br /&gt;
&lt;br /&gt;
Each searchable module should add at least both (typical) following defines in /search/lib.php :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
define(&#039;SEARCH_TYPE_&amp;lt;MODULE&amp;gt;&#039;, &#039;&amp;lt;module&amp;gt;&#039;);&lt;br /&gt;
define(&#039;PATH_FOR_SEARCH_TYPE_&amp;lt;MODULE&amp;gt;&#039;, &#039;mod/&amp;lt;module&amp;gt;&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
define(&#039;SEARCH_TYPE_&amp;lt;BLOCK&amp;gt;&#039;, &#039;&amp;lt;block&amp;gt;&#039;);&lt;br /&gt;
define(&#039;PATH_FOR_SEARCH_TYPE_&amp;lt;BLOCK&amp;gt;&#039;, &#039;blocks/&amp;lt;block&amp;gt;&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Constructor ===&lt;br /&gt;
&lt;br /&gt;
The constructor of the SearchDocument class has the following signature :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public function __construct(&amp;amp;$doc, &amp;amp;$data, $course_id, $group_id, $user_id, $path)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where : &lt;br /&gt;
* &#039;&#039;&#039;&amp;amp;$doc&#039;&#039;&#039; is a reference onto a PHP object that should provide the fields :&lt;br /&gt;
** docid : the id of the document, as suitable for reconstructing the access URL.&lt;br /&gt;
** documenttype : in general, the name of the module itself&lt;br /&gt;
** itemtype : a subclassifier, if the module provides more than one virtual document to the search engine.&lt;br /&gt;
** contextid : the context object id that should be considered when checking accessor&#039;s capabilities&lt;br /&gt;
** title : the title string to appear in search results as a caption&lt;br /&gt;
** author : if the author is known, the user id (mdl_user.id) representing the author.&lt;br /&gt;
** contents : a text bulk from the document content, filtered out from any formatting attributes or tags&lt;br /&gt;
** url : the document url, that will be constructed by the adapter to access back the resource&lt;br /&gt;
** date : usually the date when the resource was created&lt;br /&gt;
* &#039;&#039;&#039;&amp;amp;$data&#039;&#039;&#039; is a reference onto a contextual metadata object that will be serialized among with the record, but will not be used as searchable content&lt;br /&gt;
* &#039;&#039;&#039;$course_id&#039;&#039;&#039; is the current course the ressource is within&lt;br /&gt;
* &#039;&#039;&#039;$group_id&#039;&#039;&#039; is the current group the resource belongs to, if the ressource is in a group scope (i.e. separate group wiki attachements), 0 elsewhere.&lt;br /&gt;
* &#039;&#039;&#039;$user_id&#039;&#039;&#039; is the id of the user the resource beslongs to, in case the ressource is in a user specific scope (i.e. post or assignment attachements), 0 elsewhere.&lt;br /&gt;
* &#039;&#039;&#039;$path&#039;&#039;&#039; is one of the above PATH defines for the module.&lt;br /&gt;
&lt;br /&gt;
== Providing The indexer Documents From The Module ==&lt;br /&gt;
&lt;br /&gt;
When first constructing the index, The Indexer needs scanning all the instances of the plugin. &lt;br /&gt;
&lt;br /&gt;
The adapter API must provide the&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;module&amp;gt;_iterator(){ ... }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
function that will give a set of consistant plugin instances. Here is a &#039;&#039;very standard&#039;&#039; template code for this method : &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_iterator() {&lt;br /&gt;
    $&amp;lt;module&amp;gt; = get_records(&#039;&amp;lt;module&amp;gt;&#039;);&lt;br /&gt;
    return $&amp;lt;module&amp;gt;;&lt;br /&gt;
} //&amp;lt;module&amp;gt;_iterator&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On each instance, the function :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_get_content_for_index(&amp;amp;$plugininstance) { ... }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
is called for constructing relevant instances of the SearchDocument subclass. This functino MUST return an array of SearchDocuments or false. The typical synopsis of this functon is : &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_get_content_for_index(&amp;amp;$plugininstance){&lt;br /&gt;
    $documents = array();&lt;br /&gt;
&lt;br /&gt;
    // invalid plugin&lt;br /&gt;
    if (!$plugininstance) return $documents;&lt;br /&gt;
&lt;br /&gt;
    // TODO : get an indexable item set&lt;br /&gt;
&lt;br /&gt;
    foreach($indexableitems as $indexableitem) {&lt;br /&gt;
&lt;br /&gt;
       // TODO : Prepare params with &lt;br /&gt;
&lt;br /&gt;
       $documents[] = new ForumSearchDocument(... params ...);&lt;br /&gt;
    } &lt;br /&gt;
    return $documents;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Checking Access Back To The Content ==&lt;br /&gt;
&lt;br /&gt;
== Physical Document Adapters ==&lt;/div&gt;</summary>
		<author><name>Vf</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Search_engine_adapters&amp;diff=7445</id>
		<title>Search engine adapters</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Search_engine_adapters&amp;diff=7445"/>
		<updated>2007-11-17T21:49:44Z</updated>

		<summary type="html">&lt;p&gt;Vf: /* Providing The indexer Documents From The Module */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The global search engine of Moodle, available as experimental feature till the Moodle 1.9 release, allows plugin new document types for being searched and indexed by the Lucene indexer.&lt;br /&gt;
&lt;br /&gt;
Each module or block should have an adapter written to wrap the plugin&#039;s internal data model to a searchable document. The actual implementation allows a module to provide the search engine with a set of virtual documents. The search engine will index the text content of these documents, recording sufficiant data to access back the exact context in which it was appearing (i.e, access URL, course context, etc.).&lt;br /&gt;
&lt;br /&gt;
Virtual documents are defined as subclasses of the SearchDocument class. Only the constructor of the subclass must be written in order to map an input record to an internal document definition.&lt;br /&gt;
&lt;br /&gt;
The goals of the adapter are : &lt;br /&gt;
&lt;br /&gt;
* extract all virtual documents from the module data model and give them to the indexer (index first construction) through an &#039;&#039;iterator&#039;&#039;.&lt;br /&gt;
* extract a single document for index update&lt;br /&gt;
* provide sufficiant information for index delete of obsolete content&lt;br /&gt;
* define the access URL that will access back the resource&lt;br /&gt;
* define the access check algorithm so that the user will only access resources he is allowed to&lt;br /&gt;
&lt;br /&gt;
== Adapters For Modules And Blocks ==&lt;br /&gt;
&lt;br /&gt;
Any adapter for a module or a block must reside in the &amp;lt;pre&amp;gt;/search/documents&amp;lt;/pre&amp;gt; subdirectory, and will be named such as &amp;lt;pre&amp;gt;&amp;lt;module&amp;gt;_document.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search defines ===&lt;br /&gt;
&lt;br /&gt;
Each searchable module should add at least both (typical) following defines in /search/lib.php :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
define(&#039;SEARCH_TYPE_&amp;lt;MODULE&amp;gt;&#039;, &#039;&amp;lt;module&amp;gt;&#039;);&lt;br /&gt;
define(&#039;PATH_FOR_SEARCH_TYPE_&amp;lt;MODULE&amp;gt;&#039;, &#039;mod/&amp;lt;module&amp;gt;&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
define(&#039;SEARCH_TYPE_&amp;lt;BLOCK&amp;gt;&#039;, &#039;&amp;lt;block&amp;gt;&#039;);&lt;br /&gt;
define(&#039;PATH_FOR_SEARCH_TYPE_&amp;lt;BLOCK&amp;gt;&#039;, &#039;blocks/&amp;lt;block&amp;gt;&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Constructor ===&lt;br /&gt;
&lt;br /&gt;
The constructor of the SearchDocument class has the following signature :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public function __construct(&amp;amp;$doc, &amp;amp;$data, $course_id, $group_id, $user_id, $path)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where : &lt;br /&gt;
* &#039;&#039;&#039;&amp;amp;$doc&#039;&#039;&#039; is a reference onto a PHP object that should provide the fields :&lt;br /&gt;
** docid : the id of the document, as suitable for reconstructing the access URL.&lt;br /&gt;
** documenttype : in general, the name of the module itself&lt;br /&gt;
** itemtype : a subclassifier, if the module provides more than one virtual document to the search engine.&lt;br /&gt;
** contextid : the context object id that should be considered when checking accessor&#039;s capabilities&lt;br /&gt;
** title : the title string to appear in search results as a caption&lt;br /&gt;
** author : if the author is known, the user id (mdl_user.id) representing the author.&lt;br /&gt;
** contents : a text bulk from the document content, filtered out from any formatting attributes or tags&lt;br /&gt;
** url : the document url, that will be constructed by the adapter to access back the resource&lt;br /&gt;
** date : usually the date when the resource was created&lt;br /&gt;
* &#039;&#039;&#039;&amp;amp;$data&#039;&#039;&#039; is a reference onto a contextual metadata object that will be serialized among with the record, but will not be used as searchable content&lt;br /&gt;
* &#039;&#039;&#039;$course_id&#039;&#039;&#039; is the current course the ressource is within&lt;br /&gt;
* &#039;&#039;&#039;$group_id&#039;&#039;&#039; is the current group the resource belongs to, if the ressource is in a group scope (i.e. separate group wiki attachements), 0 elsewhere.&lt;br /&gt;
* &#039;&#039;&#039;$user_id&#039;&#039;&#039; is the id of the user the resource beslongs to, in case the ressource is in a user specific scope (i.e. post or assignment attachements), 0 elsewhere.&lt;br /&gt;
* &#039;&#039;&#039;$path&#039;&#039;&#039; is one of the above PATH defines for the module.&lt;br /&gt;
&lt;br /&gt;
== Providing The indexer Documents From The Module ==&lt;br /&gt;
&lt;br /&gt;
When first constructing the index, The Indexer needs scanning all the instances of the plugin. &lt;br /&gt;
&lt;br /&gt;
The adapter API must provide the&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;module&amp;gt;_iterator(){ ... }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
function that will give a set of consistant plugin instances. Here is a &#039;&#039;very standard&#039;&#039; template code for this method : &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_iterator() {&lt;br /&gt;
    $&amp;lt;module&amp;gt; = get_records(&#039;&amp;lt;module&amp;gt;&#039;);&lt;br /&gt;
    return $&amp;lt;module&amp;gt;;&lt;br /&gt;
} //&amp;lt;module&amp;gt;_iterator&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On each instance, the function :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_get_content_for_index(&amp;amp;$plugininstance) { ... }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
is called for constructing relevant instances of the SearchDocument subclass.&lt;br /&gt;
&lt;br /&gt;
== Checking Access Back To The Content ==&lt;br /&gt;
&lt;br /&gt;
== Physical Document Adapters ==&lt;/div&gt;</summary>
		<author><name>Vf</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Search_engine_adapters&amp;diff=7444</id>
		<title>Search engine adapters</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Search_engine_adapters&amp;diff=7444"/>
		<updated>2007-11-17T21:49:20Z</updated>

		<summary type="html">&lt;p&gt;Vf: /* Providing Documents From The Module */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The global search engine of Moodle, available as experimental feature till the Moodle 1.9 release, allows plugin new document types for being searched and indexed by the Lucene indexer.&lt;br /&gt;
&lt;br /&gt;
Each module or block should have an adapter written to wrap the plugin&#039;s internal data model to a searchable document. The actual implementation allows a module to provide the search engine with a set of virtual documents. The search engine will index the text content of these documents, recording sufficiant data to access back the exact context in which it was appearing (i.e, access URL, course context, etc.).&lt;br /&gt;
&lt;br /&gt;
Virtual documents are defined as subclasses of the SearchDocument class. Only the constructor of the subclass must be written in order to map an input record to an internal document definition.&lt;br /&gt;
&lt;br /&gt;
The goals of the adapter are : &lt;br /&gt;
&lt;br /&gt;
* extract all virtual documents from the module data model and give them to the indexer (index first construction) through an &#039;&#039;iterator&#039;&#039;.&lt;br /&gt;
* extract a single document for index update&lt;br /&gt;
* provide sufficiant information for index delete of obsolete content&lt;br /&gt;
* define the access URL that will access back the resource&lt;br /&gt;
* define the access check algorithm so that the user will only access resources he is allowed to&lt;br /&gt;
&lt;br /&gt;
== Adapters For Modules And Blocks ==&lt;br /&gt;
&lt;br /&gt;
Any adapter for a module or a block must reside in the &amp;lt;pre&amp;gt;/search/documents&amp;lt;/pre&amp;gt; subdirectory, and will be named such as &amp;lt;pre&amp;gt;&amp;lt;module&amp;gt;_document.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search defines ===&lt;br /&gt;
&lt;br /&gt;
Each searchable module should add at least both (typical) following defines in /search/lib.php :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
define(&#039;SEARCH_TYPE_&amp;lt;MODULE&amp;gt;&#039;, &#039;&amp;lt;module&amp;gt;&#039;);&lt;br /&gt;
define(&#039;PATH_FOR_SEARCH_TYPE_&amp;lt;MODULE&amp;gt;&#039;, &#039;mod/&amp;lt;module&amp;gt;&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
define(&#039;SEARCH_TYPE_&amp;lt;BLOCK&amp;gt;&#039;, &#039;&amp;lt;block&amp;gt;&#039;);&lt;br /&gt;
define(&#039;PATH_FOR_SEARCH_TYPE_&amp;lt;BLOCK&amp;gt;&#039;, &#039;blocks/&amp;lt;block&amp;gt;&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Constructor ===&lt;br /&gt;
&lt;br /&gt;
The constructor of the SearchDocument class has the following signature :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public function __construct(&amp;amp;$doc, &amp;amp;$data, $course_id, $group_id, $user_id, $path)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where : &lt;br /&gt;
* &#039;&#039;&#039;&amp;amp;$doc&#039;&#039;&#039; is a reference onto a PHP object that should provide the fields :&lt;br /&gt;
** docid : the id of the document, as suitable for reconstructing the access URL.&lt;br /&gt;
** documenttype : in general, the name of the module itself&lt;br /&gt;
** itemtype : a subclassifier, if the module provides more than one virtual document to the search engine.&lt;br /&gt;
** contextid : the context object id that should be considered when checking accessor&#039;s capabilities&lt;br /&gt;
** title : the title string to appear in search results as a caption&lt;br /&gt;
** author : if the author is known, the user id (mdl_user.id) representing the author.&lt;br /&gt;
** contents : a text bulk from the document content, filtered out from any formatting attributes or tags&lt;br /&gt;
** url : the document url, that will be constructed by the adapter to access back the resource&lt;br /&gt;
** date : usually the date when the resource was created&lt;br /&gt;
* &#039;&#039;&#039;&amp;amp;$data&#039;&#039;&#039; is a reference onto a contextual metadata object that will be serialized among with the record, but will not be used as searchable content&lt;br /&gt;
* &#039;&#039;&#039;$course_id&#039;&#039;&#039; is the current course the ressource is within&lt;br /&gt;
* &#039;&#039;&#039;$group_id&#039;&#039;&#039; is the current group the resource belongs to, if the ressource is in a group scope (i.e. separate group wiki attachements), 0 elsewhere.&lt;br /&gt;
* &#039;&#039;&#039;$user_id&#039;&#039;&#039; is the id of the user the resource beslongs to, in case the ressource is in a user specific scope (i.e. post or assignment attachements), 0 elsewhere.&lt;br /&gt;
* &#039;&#039;&#039;$path&#039;&#039;&#039; is one of the above PATH defines for the module.&lt;br /&gt;
&lt;br /&gt;
== Providing The indexer Documents From The Module ==&lt;br /&gt;
&lt;br /&gt;
When first constructing the index, The Indexer needs scanning all the instances of the plugin. &lt;br /&gt;
&lt;br /&gt;
The adapter API must provide the&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;module&amp;gt;_iterator(){ ... }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
function that will give a set of consistant plugin instances. Here is a &#039;&#039;very standard&#039;&#039; template code for this method : &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_iterator() {&lt;br /&gt;
    $&amp;lt;module&amp;gt; = get_records(&#039;&amp;lt;module&amp;gt;&#039;);&lt;br /&gt;
    return $&amp;lt;module&amp;gt;;&lt;br /&gt;
} //&amp;lt;module&amp;gt;_iterator&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On each instance, the function :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function &amp;lt;module&amp;gt;_get_content_for_index(&amp;amp;$plugininstance) { ... }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
is called for constructing relavant instances of the SearchDocument subclass.&lt;br /&gt;
&lt;br /&gt;
== Checking Access Back To The Content ==&lt;br /&gt;
&lt;br /&gt;
== Physical Document Adapters ==&lt;/div&gt;</summary>
		<author><name>Vf</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Search_engine_adapters&amp;diff=7443</id>
		<title>Search engine adapters</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Search_engine_adapters&amp;diff=7443"/>
		<updated>2007-11-17T21:39:27Z</updated>

		<summary type="html">&lt;p&gt;Vf: /* Adapters for modules and blocks */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The global search engine of Moodle, available as experimental feature till the Moodle 1.9 release, allows plugin new document types for being searched and indexed by the Lucene indexer.&lt;br /&gt;
&lt;br /&gt;
Each module or block should have an adapter written to wrap the plugin&#039;s internal data model to a searchable document. The actual implementation allows a module to provide the search engine with a set of virtual documents. The search engine will index the text content of these documents, recording sufficiant data to access back the exact context in which it was appearing (i.e, access URL, course context, etc.).&lt;br /&gt;
&lt;br /&gt;
Virtual documents are defined as subclasses of the SearchDocument class. Only the constructor of the subclass must be written in order to map an input record to an internal document definition.&lt;br /&gt;
&lt;br /&gt;
The goals of the adapter are : &lt;br /&gt;
&lt;br /&gt;
* extract all virtual documents from the module data model and give them to the indexer (index first construction) through an &#039;&#039;iterator&#039;&#039;.&lt;br /&gt;
* extract a single document for index update&lt;br /&gt;
* provide sufficiant information for index delete of obsolete content&lt;br /&gt;
* define the access URL that will access back the resource&lt;br /&gt;
* define the access check algorithm so that the user will only access resources he is allowed to&lt;br /&gt;
&lt;br /&gt;
== Adapters For Modules And Blocks ==&lt;br /&gt;
&lt;br /&gt;
Any adapter for a module or a block must reside in the &amp;lt;pre&amp;gt;/search/documents&amp;lt;/pre&amp;gt; subdirectory, and will be named such as &amp;lt;pre&amp;gt;&amp;lt;module&amp;gt;_document.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search defines ===&lt;br /&gt;
&lt;br /&gt;
Each searchable module should add at least both (typical) following defines in /search/lib.php :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
define(&#039;SEARCH_TYPE_&amp;lt;MODULE&amp;gt;&#039;, &#039;&amp;lt;module&amp;gt;&#039;);&lt;br /&gt;
define(&#039;PATH_FOR_SEARCH_TYPE_&amp;lt;MODULE&amp;gt;&#039;, &#039;mod/&amp;lt;module&amp;gt;&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
define(&#039;SEARCH_TYPE_&amp;lt;BLOCK&amp;gt;&#039;, &#039;&amp;lt;block&amp;gt;&#039;);&lt;br /&gt;
define(&#039;PATH_FOR_SEARCH_TYPE_&amp;lt;BLOCK&amp;gt;&#039;, &#039;blocks/&amp;lt;block&amp;gt;&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Constructor ===&lt;br /&gt;
&lt;br /&gt;
The constructor of the SearchDocument class has the following signature :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public function __construct(&amp;amp;$doc, &amp;amp;$data, $course_id, $group_id, $user_id, $path)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where : &lt;br /&gt;
* &#039;&#039;&#039;&amp;amp;$doc&#039;&#039;&#039; is a reference onto a PHP object that should provide the fields :&lt;br /&gt;
** docid : the id of the document, as suitable for reconstructing the access URL.&lt;br /&gt;
** documenttype : in general, the name of the module itself&lt;br /&gt;
** itemtype : a subclassifier, if the module provides more than one virtual document to the search engine.&lt;br /&gt;
** contextid : the context object id that should be considered when checking accessor&#039;s capabilities&lt;br /&gt;
** title : the title string to appear in search results as a caption&lt;br /&gt;
** author : if the author is known, the user id (mdl_user.id) representing the author.&lt;br /&gt;
** contents : a text bulk from the document content, filtered out from any formatting attributes or tags&lt;br /&gt;
** url : the document url, that will be constructed by the adapter to access back the resource&lt;br /&gt;
** date : usually the date when the resource was created&lt;br /&gt;
* &#039;&#039;&#039;&amp;amp;$data&#039;&#039;&#039; is a reference onto a contextual metadata object that will be serialized among with the record, but will not be used as searchable content&lt;br /&gt;
* &#039;&#039;&#039;$course_id&#039;&#039;&#039; is the current course the ressource is within&lt;br /&gt;
* &#039;&#039;&#039;$group_id&#039;&#039;&#039; is the current group the resource belongs to, if the ressource is in a group scope (i.e. separate group wiki attachements), 0 elsewhere.&lt;br /&gt;
* &#039;&#039;&#039;$user_id&#039;&#039;&#039; is the id of the user the resource beslongs to, in case the ressource is in a user specific scope (i.e. post or assignment attachements), 0 elsewhere.&lt;br /&gt;
* &#039;&#039;&#039;$path&#039;&#039;&#039; is one of the above PATH defines for the module.&lt;br /&gt;
&lt;br /&gt;
== Providing Documents From The Module ==&lt;br /&gt;
&lt;br /&gt;
== Checking Access Back To The Content ==&lt;br /&gt;
&lt;br /&gt;
== Physical Document Adapters ==&lt;/div&gt;</summary>
		<author><name>Vf</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Search_engine_adapters&amp;diff=7442</id>
		<title>Search engine adapters</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Search_engine_adapters&amp;diff=7442"/>
		<updated>2007-11-17T21:39:07Z</updated>

		<summary type="html">&lt;p&gt;Vf: /* Physical document adapters */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The global search engine of Moodle, available as experimental feature till the Moodle 1.9 release, allows plugin new document types for being searched and indexed by the Lucene indexer.&lt;br /&gt;
&lt;br /&gt;
Each module or block should have an adapter written to wrap the plugin&#039;s internal data model to a searchable document. The actual implementation allows a module to provide the search engine with a set of virtual documents. The search engine will index the text content of these documents, recording sufficiant data to access back the exact context in which it was appearing (i.e, access URL, course context, etc.).&lt;br /&gt;
&lt;br /&gt;
Virtual documents are defined as subclasses of the SearchDocument class. Only the constructor of the subclass must be written in order to map an input record to an internal document definition.&lt;br /&gt;
&lt;br /&gt;
The goals of the adapter are : &lt;br /&gt;
&lt;br /&gt;
* extract all virtual documents from the module data model and give them to the indexer (index first construction) through an &#039;&#039;iterator&#039;&#039;.&lt;br /&gt;
* extract a single document for index update&lt;br /&gt;
* provide sufficiant information for index delete of obsolete content&lt;br /&gt;
* define the access URL that will access back the resource&lt;br /&gt;
* define the access check algorithm so that the user will only access resources he is allowed to&lt;br /&gt;
&lt;br /&gt;
== Adapters for modules and blocks ==&lt;br /&gt;
&lt;br /&gt;
Any adapter for a module or a block must reside in the &amp;lt;pre&amp;gt;/search/documents&amp;lt;/pre&amp;gt; subdirectory, and will be named such as &amp;lt;pre&amp;gt;&amp;lt;module&amp;gt;_document.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search defines ===&lt;br /&gt;
&lt;br /&gt;
Each searchable module should add at least both (typical) following defines in /search/lib.php :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
define(&#039;SEARCH_TYPE_&amp;lt;MODULE&amp;gt;&#039;, &#039;&amp;lt;module&amp;gt;&#039;);&lt;br /&gt;
define(&#039;PATH_FOR_SEARCH_TYPE_&amp;lt;MODULE&amp;gt;&#039;, &#039;mod/&amp;lt;module&amp;gt;&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
define(&#039;SEARCH_TYPE_&amp;lt;BLOCK&amp;gt;&#039;, &#039;&amp;lt;block&amp;gt;&#039;);&lt;br /&gt;
define(&#039;PATH_FOR_SEARCH_TYPE_&amp;lt;BLOCK&amp;gt;&#039;, &#039;blocks/&amp;lt;block&amp;gt;&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Constructor ===&lt;br /&gt;
&lt;br /&gt;
The constructor of the SearchDocument class has the following signature :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public function __construct(&amp;amp;$doc, &amp;amp;$data, $course_id, $group_id, $user_id, $path)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where : &lt;br /&gt;
* &#039;&#039;&#039;&amp;amp;$doc&#039;&#039;&#039; is a reference onto a PHP object that should provide the fields :&lt;br /&gt;
** docid : the id of the document, as suitable for reconstructing the access URL.&lt;br /&gt;
** documenttype : in general, the name of the module itself&lt;br /&gt;
** itemtype : a subclassifier, if the module provides more than one virtual document to the search engine.&lt;br /&gt;
** contextid : the context object id that should be considered when checking accessor&#039;s capabilities&lt;br /&gt;
** title : the title string to appear in search results as a caption&lt;br /&gt;
** author : if the author is known, the user id (mdl_user.id) representing the author.&lt;br /&gt;
** contents : a text bulk from the document content, filtered out from any formatting attributes or tags&lt;br /&gt;
** url : the document url, that will be constructed by the adapter to access back the resource&lt;br /&gt;
** date : usually the date when the resource was created&lt;br /&gt;
* &#039;&#039;&#039;&amp;amp;$data&#039;&#039;&#039; is a reference onto a contextual metadata object that will be serialized among with the record, but will not be used as searchable content&lt;br /&gt;
* &#039;&#039;&#039;$course_id&#039;&#039;&#039; is the current course the ressource is within&lt;br /&gt;
* &#039;&#039;&#039;$group_id&#039;&#039;&#039; is the current group the resource belongs to, if the ressource is in a group scope (i.e. separate group wiki attachements), 0 elsewhere.&lt;br /&gt;
* &#039;&#039;&#039;$user_id&#039;&#039;&#039; is the id of the user the resource beslongs to, in case the ressource is in a user specific scope (i.e. post or assignment attachements), 0 elsewhere.&lt;br /&gt;
* &#039;&#039;&#039;$path&#039;&#039;&#039; is one of the above PATH defines for the module.&lt;br /&gt;
&lt;br /&gt;
== Providing Documents From The Module ==&lt;br /&gt;
&lt;br /&gt;
== Checking Access Back To The Content ==&lt;br /&gt;
&lt;br /&gt;
== Physical Document Adapters ==&lt;/div&gt;</summary>
		<author><name>Vf</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Search_engine_adapters&amp;diff=7441</id>
		<title>Search engine adapters</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Search_engine_adapters&amp;diff=7441"/>
		<updated>2007-11-17T21:37:53Z</updated>

		<summary type="html">&lt;p&gt;Vf: /* Adapters for modules and blocks */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The global search engine of Moodle, available as experimental feature till the Moodle 1.9 release, allows plugin new document types for being searched and indexed by the Lucene indexer.&lt;br /&gt;
&lt;br /&gt;
Each module or block should have an adapter written to wrap the plugin&#039;s internal data model to a searchable document. The actual implementation allows a module to provide the search engine with a set of virtual documents. The search engine will index the text content of these documents, recording sufficiant data to access back the exact context in which it was appearing (i.e, access URL, course context, etc.).&lt;br /&gt;
&lt;br /&gt;
Virtual documents are defined as subclasses of the SearchDocument class. Only the constructor of the subclass must be written in order to map an input record to an internal document definition.&lt;br /&gt;
&lt;br /&gt;
The goals of the adapter are : &lt;br /&gt;
&lt;br /&gt;
* extract all virtual documents from the module data model and give them to the indexer (index first construction) through an &#039;&#039;iterator&#039;&#039;.&lt;br /&gt;
* extract a single document for index update&lt;br /&gt;
* provide sufficiant information for index delete of obsolete content&lt;br /&gt;
* define the access URL that will access back the resource&lt;br /&gt;
* define the access check algorithm so that the user will only access resources he is allowed to&lt;br /&gt;
&lt;br /&gt;
== Adapters for modules and blocks ==&lt;br /&gt;
&lt;br /&gt;
Any adapter for a module or a block must reside in the &amp;lt;pre&amp;gt;/search/documents&amp;lt;/pre&amp;gt; subdirectory, and will be named such as &amp;lt;pre&amp;gt;&amp;lt;module&amp;gt;_document.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search defines ===&lt;br /&gt;
&lt;br /&gt;
Each searchable module should add at least both (typical) following defines in /search/lib.php :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
define(&#039;SEARCH_TYPE_&amp;lt;MODULE&amp;gt;&#039;, &#039;&amp;lt;module&amp;gt;&#039;);&lt;br /&gt;
define(&#039;PATH_FOR_SEARCH_TYPE_&amp;lt;MODULE&amp;gt;&#039;, &#039;mod/&amp;lt;module&amp;gt;&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
define(&#039;SEARCH_TYPE_&amp;lt;BLOCK&amp;gt;&#039;, &#039;&amp;lt;block&amp;gt;&#039;);&lt;br /&gt;
define(&#039;PATH_FOR_SEARCH_TYPE_&amp;lt;BLOCK&amp;gt;&#039;, &#039;blocks/&amp;lt;block&amp;gt;&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Constructor ===&lt;br /&gt;
&lt;br /&gt;
The constructor of the SearchDocument class has the following signature :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public function __construct(&amp;amp;$doc, &amp;amp;$data, $course_id, $group_id, $user_id, $path)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where : &lt;br /&gt;
* &#039;&#039;&#039;&amp;amp;$doc&#039;&#039;&#039; is a reference onto a PHP object that should provide the fields :&lt;br /&gt;
** docid : the id of the document, as suitable for reconstructing the access URL.&lt;br /&gt;
** documenttype : in general, the name of the module itself&lt;br /&gt;
** itemtype : a subclassifier, if the module provides more than one virtual document to the search engine.&lt;br /&gt;
** contextid : the context object id that should be considered when checking accessor&#039;s capabilities&lt;br /&gt;
** title : the title string to appear in search results as a caption&lt;br /&gt;
** author : if the author is known, the user id (mdl_user.id) representing the author.&lt;br /&gt;
** contents : a text bulk from the document content, filtered out from any formatting attributes or tags&lt;br /&gt;
** url : the document url, that will be constructed by the adapter to access back the resource&lt;br /&gt;
** date : usually the date when the resource was created&lt;br /&gt;
* &#039;&#039;&#039;&amp;amp;$data&#039;&#039;&#039; is a reference onto a contextual metadata object that will be serialized among with the record, but will not be used as searchable content&lt;br /&gt;
* &#039;&#039;&#039;$course_id&#039;&#039;&#039; is the current course the ressource is within&lt;br /&gt;
* &#039;&#039;&#039;$group_id&#039;&#039;&#039; is the current group the resource belongs to, if the ressource is in a group scope (i.e. separate group wiki attachements), 0 elsewhere.&lt;br /&gt;
* &#039;&#039;&#039;$user_id&#039;&#039;&#039; is the id of the user the resource beslongs to, in case the ressource is in a user specific scope (i.e. post or assignment attachements), 0 elsewhere.&lt;br /&gt;
* &#039;&#039;&#039;$path&#039;&#039;&#039; is one of the above PATH defines for the module.&lt;br /&gt;
&lt;br /&gt;
== Physical document adapters ==&lt;/div&gt;</summary>
		<author><name>Vf</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Search_engine_adapters&amp;diff=7440</id>
		<title>Search engine adapters</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Search_engine_adapters&amp;diff=7440"/>
		<updated>2007-11-17T21:37:09Z</updated>

		<summary type="html">&lt;p&gt;Vf: /* Constructor */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The global search engine of Moodle, available as experimental feature till the Moodle 1.9 release, allows plugin new document types for being searched and indexed by the Lucene indexer.&lt;br /&gt;
&lt;br /&gt;
Each module or block should have an adapter written to wrap the plugin&#039;s internal data model to a searchable document. The actual implementation allows a module to provide the search engine with a set of virtual documents. The search engine will index the text content of these documents, recording sufficiant data to access back the exact context in which it was appearing (i.e, access URL, course context, etc.).&lt;br /&gt;
&lt;br /&gt;
Virtual documents are defined as subclasses of the SearchDocument class. Only the constructor of the subclass must be written in order to map an input record to an internal document definition.&lt;br /&gt;
&lt;br /&gt;
The goals of the adapter are : &lt;br /&gt;
&lt;br /&gt;
* extract all virtual documents from the module data model and give them to the indexer (index first construction) through an &#039;&#039;iterator&#039;&#039;.&lt;br /&gt;
* extract a single document for index update&lt;br /&gt;
* provide sufficiant information for index delete of obsolete content&lt;br /&gt;
* define the access URL that will access back the resource&lt;br /&gt;
* define the access check algorithm so that the user will only access resources he is allowed to&lt;br /&gt;
&lt;br /&gt;
== Adapters for modules and blocks ==&lt;br /&gt;
&lt;br /&gt;
Any adapter for a module or a block must reside in the &amp;lt;pre&amp;gt;/search/documents&amp;lt;/pre&amp;gt; subdirectory, and will be named such as &amp;lt;pre&amp;gt;&amp;lt;module&amp;gt;_document.php&amp;lt;/pre&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Search defines ===&lt;br /&gt;
&lt;br /&gt;
Each searchable module should add both following defines in /search/lib.php :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
define(&#039;SEARCH_TYPE_&amp;lt;MODULE&amp;gt;&#039;, &#039;&amp;lt;module&amp;gt;&#039;);&lt;br /&gt;
define(&#039;PATH_FOR_SEARCH_TYPE_&amp;lt;MODULE&amp;gt;&#039;, &#039;mod/&amp;lt;module&amp;gt;&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
define(&#039;SEARCH_TYPE_&amp;lt;BLOCK&amp;gt;&#039;, &#039;&amp;lt;block&amp;gt;&#039;);&lt;br /&gt;
define(&#039;PATH_FOR_SEARCH_TYPE_&amp;lt;BLOCK&amp;gt;&#039;, &#039;blocks/&amp;lt;block&amp;gt;&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Constructor ===&lt;br /&gt;
&lt;br /&gt;
The constructor of the SearchDocument class has the following signature :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public function __construct(&amp;amp;$doc, &amp;amp;$data, $course_id, $group_id, $user_id, $path)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where : &lt;br /&gt;
* &#039;&#039;&#039;&amp;amp;$doc&#039;&#039;&#039; is a reference onto a PHP object that should provide the fields :&lt;br /&gt;
** docid : the id of the document, as suitable for reconstructing the access URL.&lt;br /&gt;
** documenttype : in general, the name of the module itself&lt;br /&gt;
** itemtype : a subclassifier, if the module provides more than one virtual document to the search engine.&lt;br /&gt;
** contextid : the context object id that should be considered when checking accessor&#039;s capabilities&lt;br /&gt;
** title : the title string to appear in search results as a caption&lt;br /&gt;
** author : if the author is known, the user id (mdl_user.id) representing the author.&lt;br /&gt;
** contents : a text bulk from the document content, filtered out from any formatting attributes or tags&lt;br /&gt;
** url : the document url, that will be constructed by the adapter to access back the resource&lt;br /&gt;
** date : usually the date when the resource was created&lt;br /&gt;
* &#039;&#039;&#039;&amp;amp;$data&#039;&#039;&#039; is a reference onto a contextual metadata object that will be serialized among with the record, but will not be used as searchable content&lt;br /&gt;
* &#039;&#039;&#039;$course_id&#039;&#039;&#039; is the current course the ressource is within&lt;br /&gt;
* &#039;&#039;&#039;$group_id&#039;&#039;&#039; is the current group the resource belongs to, if the ressource is in a group scope (i.e. separate group wiki attachements), 0 elsewhere.&lt;br /&gt;
* &#039;&#039;&#039;$user_id&#039;&#039;&#039; is the id of the user the resource beslongs to, in case the ressource is in a user specific scope (i.e. post or assignment attachements), 0 elsewhere.&lt;br /&gt;
* &#039;&#039;&#039;$path&#039;&#039;&#039; is one of the above PATH defines for the module.&lt;br /&gt;
&lt;br /&gt;
== Physical document adapters ==&lt;/div&gt;</summary>
		<author><name>Vf</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Search_engine_adapters&amp;diff=7439</id>
		<title>Search engine adapters</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Search_engine_adapters&amp;diff=7439"/>
		<updated>2007-11-17T21:36:23Z</updated>

		<summary type="html">&lt;p&gt;Vf: /* Constructor */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The global search engine of Moodle, available as experimental feature till the Moodle 1.9 release, allows plugin new document types for being searched and indexed by the Lucene indexer.&lt;br /&gt;
&lt;br /&gt;
Each module or block should have an adapter written to wrap the plugin&#039;s internal data model to a searchable document. The actual implementation allows a module to provide the search engine with a set of virtual documents. The search engine will index the text content of these documents, recording sufficiant data to access back the exact context in which it was appearing (i.e, access URL, course context, etc.).&lt;br /&gt;
&lt;br /&gt;
Virtual documents are defined as subclasses of the SearchDocument class. Only the constructor of the subclass must be written in order to map an input record to an internal document definition.&lt;br /&gt;
&lt;br /&gt;
The goals of the adapter are : &lt;br /&gt;
&lt;br /&gt;
* extract all virtual documents from the module data model and give them to the indexer (index first construction) through an &#039;&#039;iterator&#039;&#039;.&lt;br /&gt;
* extract a single document for index update&lt;br /&gt;
* provide sufficiant information for index delete of obsolete content&lt;br /&gt;
* define the access URL that will access back the resource&lt;br /&gt;
* define the access check algorithm so that the user will only access resources he is allowed to&lt;br /&gt;
&lt;br /&gt;
== Adapters for modules and blocks ==&lt;br /&gt;
&lt;br /&gt;
Any adapter for a module or a block must reside in the &amp;lt;pre&amp;gt;/search/documents&amp;lt;/pre&amp;gt; subdirectory, and will be named such as &amp;lt;pre&amp;gt;&amp;lt;module&amp;gt;_document.php&amp;lt;/pre&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Search defines ===&lt;br /&gt;
&lt;br /&gt;
Each searchable module should add both following defines in /search/lib.php :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
define(&#039;SEARCH_TYPE_&amp;lt;MODULE&amp;gt;&#039;, &#039;&amp;lt;module&amp;gt;&#039;);&lt;br /&gt;
define(&#039;PATH_FOR_SEARCH_TYPE_&amp;lt;MODULE&amp;gt;&#039;, &#039;mod/&amp;lt;module&amp;gt;&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
define(&#039;SEARCH_TYPE_&amp;lt;BLOCK&amp;gt;&#039;, &#039;&amp;lt;block&amp;gt;&#039;);&lt;br /&gt;
define(&#039;PATH_FOR_SEARCH_TYPE_&amp;lt;BLOCK&amp;gt;&#039;, &#039;blocks/&amp;lt;block&amp;gt;&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Constructor ===&lt;br /&gt;
&lt;br /&gt;
The constructor of the SearchDocument class has the following signature :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public function __construct(&amp;amp;$doc, &amp;amp;$data, $course_id, $group_id, $user_id, $path)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where : &lt;br /&gt;
* &#039;&#039;&#039;&amp;amp;$doc&#039;&#039;&#039; is a reference onto a PHP object that should provide the fields :&lt;br /&gt;
** docid : the id of the document, as suitable for reconstructing the access URL.&lt;br /&gt;
** documenttype : in general, the name of the module itself&lt;br /&gt;
** itemtype : a subclassifier, if the module provides more than one virtual document to the search engine.&lt;br /&gt;
** contextid : the context object id that should be considered when checking accessor&#039;s capabilities&lt;br /&gt;
** title : the title string to appear in search results as a caption&lt;br /&gt;
** author : if the author is known, the user id (mdl_user.id) representing the author.&lt;br /&gt;
** contents : a text bulk from the document content, filtered out from any formatting attributes or tags&lt;br /&gt;
** url : the document url, that will be constructed by the adapter to access back the resource&lt;br /&gt;
** date : usually the date when the resource was created&lt;br /&gt;
* &#039;&#039;&#039;&amp;amp;$data&#039;&#039;&#039; is a reference onto a contextual metadata object that will be serialized among with the record, but will not be used as searchable content&lt;br /&gt;
* &#039;&#039;&#039;$course_id&#039;&#039;&#039; is the current course the ressource is within&lt;br /&gt;
* &#039;&#039;&#039;$group_id&#039;&#039;&#039; is the current group the resource belongs to, if the ressource is in a group scope (i.e. separate group wiki attachements), 0 elsewhere.&lt;br /&gt;
* &#039;&#039;&#039;$user_id&#039;&#039;&#039; is the id of the user the resource beslongs to, in case the ressource is in a user specific scope (i.e. post or assignment attachements), 0 elsewhere.&lt;br /&gt;
&lt;br /&gt;
== Physical document adapters ==&lt;/div&gt;</summary>
		<author><name>Vf</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Search_engine_adapters&amp;diff=7438</id>
		<title>Search engine adapters</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Search_engine_adapters&amp;diff=7438"/>
		<updated>2007-11-17T21:32:35Z</updated>

		<summary type="html">&lt;p&gt;Vf: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The global search engine of Moodle, available as experimental feature till the Moodle 1.9 release, allows plugin new document types for being searched and indexed by the Lucene indexer.&lt;br /&gt;
&lt;br /&gt;
Each module or block should have an adapter written to wrap the plugin&#039;s internal data model to a searchable document. The actual implementation allows a module to provide the search engine with a set of virtual documents. The search engine will index the text content of these documents, recording sufficiant data to access back the exact context in which it was appearing (i.e, access URL, course context, etc.).&lt;br /&gt;
&lt;br /&gt;
Virtual documents are defined as subclasses of the SearchDocument class. Only the constructor of the subclass must be written in order to map an input record to an internal document definition.&lt;br /&gt;
&lt;br /&gt;
The goals of the adapter are : &lt;br /&gt;
&lt;br /&gt;
* extract all virtual documents from the module data model and give them to the indexer (index first construction) through an &#039;&#039;iterator&#039;&#039;.&lt;br /&gt;
* extract a single document for index update&lt;br /&gt;
* provide sufficiant information for index delete of obsolete content&lt;br /&gt;
* define the access URL that will access back the resource&lt;br /&gt;
* define the access check algorithm so that the user will only access resources he is allowed to&lt;br /&gt;
&lt;br /&gt;
== Adapters for modules and blocks ==&lt;br /&gt;
&lt;br /&gt;
Any adapter for a module or a block must reside in the &amp;lt;pre&amp;gt;/search/documents&amp;lt;/pre&amp;gt; subdirectory, and will be named such as &amp;lt;pre&amp;gt;&amp;lt;module&amp;gt;_document.php&amp;lt;/pre&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Search defines ===&lt;br /&gt;
&lt;br /&gt;
Each searchable module should add both following defines in /search/lib.php :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
define(&#039;SEARCH_TYPE_&amp;lt;MODULE&amp;gt;&#039;, &#039;&amp;lt;module&amp;gt;&#039;);&lt;br /&gt;
define(&#039;PATH_FOR_SEARCH_TYPE_&amp;lt;MODULE&amp;gt;&#039;, &#039;mod/&amp;lt;module&amp;gt;&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
define(&#039;SEARCH_TYPE_&amp;lt;BLOCK&amp;gt;&#039;, &#039;&amp;lt;block&amp;gt;&#039;);&lt;br /&gt;
define(&#039;PATH_FOR_SEARCH_TYPE_&amp;lt;BLOCK&amp;gt;&#039;, &#039;blocks/&amp;lt;block&amp;gt;&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Constructor ===&lt;br /&gt;
&lt;br /&gt;
The constructor of the SearchDocument class has the following signature :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public function __construct(&amp;amp;$doc, &amp;amp;$data, $course_id, $group_id, $user_id, $path)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where : &lt;br /&gt;
* &amp;amp;$doc is a reference onto a PHP object that should provide the fields :&lt;br /&gt;
** docid : the id of the document, as suitable for reconstructing the access URL.&lt;br /&gt;
** documenttype : in general, the name of the module itself&lt;br /&gt;
** itemtype : a subclassifier, if the module provides more than one virtual document to the search engine.&lt;br /&gt;
** contextid : the context object id that should be considered when checking accessor&#039;s capabilities&lt;br /&gt;
** title : the title string to appear in search results as a caption&lt;br /&gt;
** author : if the author is known, the user id (mdl_user.id) representing the author.&lt;br /&gt;
** contents : a text bulk from the document content, filtered out from any formatting attributes or tags&lt;br /&gt;
** url : the document url, that will be constructed by the adapter to access back the resource&lt;br /&gt;
** date : usually the date when the resource was created&lt;br /&gt;
*$data is a reference onto a contextual metadata object that will be serialized among with the record, but will not be used as searchable content&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Physical document adapters ==&lt;/div&gt;</summary>
		<author><name>Vf</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Search_engine_adapters&amp;diff=7437</id>
		<title>Search engine adapters</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Search_engine_adapters&amp;diff=7437"/>
		<updated>2007-11-17T21:15:40Z</updated>

		<summary type="html">&lt;p&gt;Vf: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The global search engine of Moodle, available as experimental feature till the Moodle 1.9 release, allows plugin new document types for being searched and indexed by the Lucene indexer.&lt;br /&gt;
&lt;br /&gt;
Each module or block should have an adapter written to wrap the plugin&#039;s internal data model to a searchable document. The actual implementation allows a module to provide the search engine with a set of virtual documents. The search engine will index the text content of these documents, recording sufficiant data to access back the exact context in which it was appearing (i.e, access URL, course context, etc.).&lt;br /&gt;
&lt;br /&gt;
Virtual documents are defined as subclasses of the SearchDocument class. Only the constructor of the subclass must be written in order to map an input record to an internal document definition.&lt;br /&gt;
&lt;br /&gt;
The goals of the adapter are : &lt;br /&gt;
&lt;br /&gt;
* extract all virtual documents from the module data model and give them to the indexer (index first construction) through an &#039;&#039;iterator&#039;&#039;.&lt;br /&gt;
* extract a single document for index update&lt;br /&gt;
* provide sufficiant information for index delete of obsolete content&lt;br /&gt;
* define the access URL that will access back the resource&lt;br /&gt;
* define the access check algorithm so that the user will only access resources he is allowed to&lt;br /&gt;
&lt;br /&gt;
== Adapters for modules ==&lt;br /&gt;
&lt;br /&gt;
Any adapter for a module or a block must reside in the &amp;lt;pre&amp;gt;/search/documents&amp;lt;/pre&amp;gt; subdirectory, and will be named such as &amp;lt;pre&amp;gt;&amp;lt;module&amp;gt;_document.php&amp;lt;/pre&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Physical document adapters ==&lt;/div&gt;</summary>
		<author><name>Vf</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Search_engine_adapters&amp;diff=7436</id>
		<title>Search engine adapters</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Search_engine_adapters&amp;diff=7436"/>
		<updated>2007-11-17T21:14:07Z</updated>

		<summary type="html">&lt;p&gt;Vf: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The global search engine of Moodle, available as experimental feature till the Moodle 1.9 release, allows plugin new document types for being searched and indexed by the Lucene indexer.&lt;br /&gt;
&lt;br /&gt;
Each module or block should have an adapter written to wrap the plugin&#039;s internal data model to a searchable document. The actual implementation allows a module to provide the search engine with a set of virtual documents. The search engine will index the text content of these documents, recording sufficiant data to access back the exact context in which it was appearing (i.e, access URL, course context, etc.).&lt;br /&gt;
&lt;br /&gt;
Virtual documents are defined as subclasses of the SearchDocument class. Only the constructor of the subclass must be written in order to map an input record to an internal document definition.&lt;br /&gt;
&lt;br /&gt;
The goals of the adapter are : &lt;br /&gt;
&lt;br /&gt;
* extract all virtual documents from the module data model and give them to the indexer (index first construction) through an &#039;&#039;iterator&#039;&#039;.&lt;br /&gt;
* extract a single document for index update&lt;br /&gt;
* provide sufficiant information for index delete of obsolete content&lt;br /&gt;
* define the access URL that will access back the resource&lt;br /&gt;
* define the access check algorithm so that the user will only access resources he is allowed to&lt;br /&gt;
&lt;br /&gt;
== Adapters for modules ==&lt;br /&gt;
&lt;br /&gt;
Any adapter for a module or a block must reside in the /search/documents subdirectory, and will be named such as &amp;lt;module&amp;gt;_document.php.&lt;br /&gt;
&lt;br /&gt;
== Physical document adapters ==&lt;/div&gt;</summary>
		<author><name>Vf</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Developer_documentation&amp;diff=551</id>
		<title>Developer documentation</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Developer_documentation&amp;diff=551"/>
		<updated>2007-11-17T21:00:15Z</updated>

		<summary type="html">&lt;p&gt;Vf: /* Make a new plugin */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;p class=&amp;quot;note&amp;quot;&amp;gt;&#039;&#039;&#039;Note:&#039;&#039;&#039; New developer documentation pages should be added to the &#039;&#039;Development namespace&#039;&#039; by typing &amp;lt;code&amp;gt;Development:&amp;lt;/code&amp;gt; before the new page name i.e. &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;[[New page name]]&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;If you are a developer, you probably want to change your [[Special:Preferences|preferences]] to include the Development namespace in searches.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;A page may be added to the Developer category by typing &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;[[Category:New page name]]&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; at the bottom of the page.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==How Moodle development works==&lt;br /&gt;
&lt;br /&gt;
This [[Overview|overview of the Moodle development process]] may be handy in understanding how the development of Moodle occurs and how people become Moodle developers.&lt;br /&gt;
&lt;br /&gt;
==Guidelines==&lt;br /&gt;
&lt;br /&gt;
The following guidelines are crucial reading for anyone wanting to contribute to the Moodle code base:&lt;br /&gt;
*[[Coding|Coding guidelines]] have to be followed by all Moodle developers&lt;br /&gt;
*[[Moodle design goals]] spells out the basic design goals behind Moodle&lt;br /&gt;
*[[Interface guidelines]] aim to provide a common feel to the Moodle user interface&lt;br /&gt;
*[[CVS (developer)|Moodle CVS for developers]] explains how to work with the Moodle code in CVS&lt;br /&gt;
*[[Tracker]] explains the Moodle Tracker for keeping track of bugs, issues, feature requests etc&lt;br /&gt;
*[[Working with the Community|Working with the Community]] explains how to engage with the dev community and discuss changes&lt;br /&gt;
*[[Unit tests]] explains how to run the unit tests, and how to write new test cases.&lt;br /&gt;
&lt;br /&gt;
==Documentation for core components==&lt;br /&gt;
&lt;br /&gt;
This section is for documentation of specific components of the existing core Moodle code. Discussion of components that are under discussion or in development can be found in the [[Developer notes]] or on the [[Roadmap]].&lt;br /&gt;
&lt;br /&gt;
The documents below give a general overview. For detailed function-by-function documentation, see the [http://phpdocs.moodle.org/ phpDocumentor] documentation that is automatically generated from the comments in the code. And don&#039;t forget that the most up-to-date and detailed description of how the code works is the code itself. Moodle code should be easy to read and understand. Use the source, Luke!&lt;br /&gt;
&lt;br /&gt;
===Core components that affect everything===&lt;br /&gt;
&lt;br /&gt;
*[[Database schema introduction|The database schema]]&lt;br /&gt;
*lib/moodlelib.php &lt;br /&gt;
*[[lib/weblib.php|lib/weblib.php]] for outputting stuff.&lt;br /&gt;
*[[XMLDB_Documentation|Database abstraction layer]] @ v[[1.7]]&lt;br /&gt;
*[[Roles|Roles and Capabilities system]] @ v[[1.7]] for controlling who can do what.&lt;br /&gt;
*[[lib/formslib.php|Forms library]] @ v[[1.8]] for creating accessible and secure HTML forms that let users edit things.&lt;br /&gt;
&lt;br /&gt;
===Core libraries with a more specific uses===&lt;br /&gt;
&lt;br /&gt;
*[[Authentication API]]&lt;br /&gt;
*[[Cookieless Sessions]]&lt;br /&gt;
*[[Moodle Network|Moodle Network]]&lt;br /&gt;
*[[Email processing]]&lt;br /&gt;
*[[Environment checking|Environment checking]] before install, check the user&#039;s server to ensure Moodle will work there.&lt;br /&gt;
*[[Question engine]]&lt;br /&gt;
*[[Stats package]]&lt;br /&gt;
*[[UTF-8 migration|Migration to UTF-8]] @ v[[:Category:Moodle 1.6|1.6]]&lt;br /&gt;
*[http://developer.yahoo.com/yui YUI JavaScript library] - YUI was selected as the official AJAX library for Moodle.&lt;br /&gt;
&lt;br /&gt;
===Modules included in the standard distribution===&lt;br /&gt;
&lt;br /&gt;
*[[Quiz developer docs|Quiz module]]&lt;br /&gt;
*[[SCORM schema|SCORM module 1.5 schema]]&lt;br /&gt;
&lt;br /&gt;
==How you can contribute==&lt;br /&gt;
&lt;br /&gt;
===Make a new plugin===&lt;br /&gt;
&lt;br /&gt;
The M in Moodle stands for modular, and the easiest, most maintainable way to add new functionality to Moodle is by using one of the many plugin APIs. There are many types of plugin you can write:&lt;br /&gt;
*[[Modules|Activity modules]]&lt;br /&gt;
*[[Admin reports|Admin reports]]&lt;br /&gt;
*[[Assignment types|Assignment types]]&lt;br /&gt;
*[[Authentication plugins|Authentication plugins]]&lt;br /&gt;
*[[Blocks|Blocks]]&lt;br /&gt;
*[[Course formats]]&lt;br /&gt;
*[[Course Report Plugins|Course reports]]&lt;br /&gt;
*[[Database fields|Database fields]]&lt;br /&gt;
*[[Database presets|Database presets]]&lt;br /&gt;
*[[Enrolment plugins|Enrolment plugins]]&lt;br /&gt;
*[[Filters|Filters]]&lt;br /&gt;
*[[Grade export/import|Grade export/import]]&lt;br /&gt;
*[[Grade report|Grade report]]&lt;br /&gt;
*[[Question engine|Question engine]]&lt;br /&gt;
*[[Question import/export formats|Question import/export formats]]&lt;br /&gt;
*[[Quiz reports]]&lt;br /&gt;
*[[Resource types|Resource types]]&lt;br /&gt;
*[[SSO plugins|SSO plugins]]&lt;br /&gt;
*[[Search engine adapters|Search engine adapters]]&lt;br /&gt;
*[[Course Report Plugins|Course Report Plugins]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When you have developed a new component please publish it in the [http://moodle.org/mod/data/view.php?id=6009 Moodle modules and plugins database].&lt;br /&gt;
&lt;br /&gt;
===Change core code===&lt;br /&gt;
&lt;br /&gt;
Some types of change can only be made by editing the core Moodle code. Such changes are much harder to maintain than plugins. If you want your core change to be considered for inclusion in the official Moodle release, you need to create an issue in the [[Tracker|tracker]], and attach your change as a [[How_to_create_a_patch|patch]]. It is also a good idea to discuss your ideas in the forums first.&lt;br /&gt;
&lt;br /&gt;
===Ways to contribute that do not involve PHP programming===&lt;br /&gt;
&lt;br /&gt;
*[[Themes|Create Moodle themes]]&lt;br /&gt;
*[[Translation|Translate Moodle into other languages]]&lt;br /&gt;
*[[MoodleDocs:Guidelines for contributors|Help document Moodle]]&lt;br /&gt;
*[[Database schemas|Database schemas]]&lt;br /&gt;
*[[Tests|Join the testing effort]], which involves [[Tracker|participating in the bug tracker]]&lt;br /&gt;
&lt;br /&gt;
==Plans for the future==&lt;br /&gt;
&lt;br /&gt;
Ideas for and details of planned future features of Moodle are initially discussed on the forums in the [http://moodle.org/course/view.php?id=5 Using Moodle] course at moodle.org. That developer discussions are intermixed with user discussions in the same forums may seem strange at first but is one of the reasons for the success of Moodle. It is important that both end-users and developers discuss the future features together.&lt;br /&gt;
&lt;br /&gt;
Once ideas begin to crystallize on the forums they can be summarized in this wiki, either as part of the [[Roadmap]] or in the form of [[Developer notes]]. These pages then form the basis for further discussion in the forums.&lt;br /&gt;
&lt;br /&gt;
*[[Roadmap]]&lt;br /&gt;
*[[Developer notes|Developer notes]]&lt;br /&gt;
*[[Student projects]]&lt;br /&gt;
*[[Developer conferences]]&lt;br /&gt;
&lt;br /&gt;
== Resources and tools ==&lt;br /&gt;
&lt;br /&gt;
*[[Developer FAQ]] - frequently asked questions, especially useful for newcomers to Moodle&lt;br /&gt;
*[[Finding_your_way_into_the_Moodle_code|Finding your way into the Moodle code]] - also aimed at newcomers&lt;br /&gt;
*[http://tracker.moodle.org/ Moodle tracker] - bug reports, feature requests and other tracked issues&lt;br /&gt;
**[[Firefox tracker search]] - How to setup a firefox quicksearch to easily navigate to moodle bugs&lt;br /&gt;
*[[Unmerged files]] - changes on the stable branch in CVS that have not been merged to HEAD&lt;br /&gt;
*Browse the code online:&lt;br /&gt;
**[http://moodle.cvs.sourceforge.net/moodle/moodle/ the code with a complete change history from CVS]&lt;br /&gt;
**[http://xref.moodle.org/index.html the code, with links generated by PHPXref]&lt;br /&gt;
*[http://phpdocs.moodle.org/ Moodle PHP doc reference] - compiled from the comment attached to each class and function in the code&lt;br /&gt;
*[[Database Schema|Database Schema]] - for recent releases&lt;br /&gt;
*[http://moodle.org/course/view.php?id=5#4 Development news and discussion] section of Using Moodle course&lt;br /&gt;
**especially the [http://moodle.org/mod/forum/view.php?id=55 General developer forum]&lt;br /&gt;
**[[Filters used on the Moodle.org forums|cool tricks you can use in the moodle.org forums]]&lt;br /&gt;
*Some tools people use when working on Moodle code:&lt;br /&gt;
**[[Setting_up_Eclipse|Setting up Eclipse for Moodle development]] - Eclipse is a great editor to use for php development, if you can work out how to set it up.&lt;br /&gt;
**[[vim|Setting up Vim for Moodle development]]&lt;br /&gt;
**[[ctags|Ctags]] - Using a tags file to navigate code&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
*[http://security.moodle.org/ Moodle Security Centre]&lt;br /&gt;
*[http://moodle.com/partners/ Moodle Partners] - providers of custom Moodle development services&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[es:Documentación para Desarrolladores]]&lt;br /&gt;
[[fr:Documentation développeur]]&lt;br /&gt;
[[zh:开发者文档]]&lt;br /&gt;
[[ja:開発者ドキュメント]]&lt;/div&gt;</summary>
		<author><name>Vf</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Roles&amp;diff=3164</id>
		<title>Roles</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Roles&amp;diff=3164"/>
		<updated>2007-09-21T22:37:12Z</updated>

		<summary type="html">&lt;p&gt;Vf: /* Core-level Capabilities */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Moodle 1.7}}&lt;br /&gt;
&#039;&#039;&#039;Roles and permissions&#039;&#039;&#039; is in Moodle 1.7 onwards.&lt;br /&gt;
&lt;br /&gt;
==Definitions==&lt;br /&gt;
&lt;br /&gt;
A role 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 capability 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 permission 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 context is a &amp;quot;space&amp;quot; in the Moodle, such as courses, activity modules, blocks etc.&lt;br /&gt;
&lt;br /&gt;
==The existing system==&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;
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 - role assignment in course context is simitar 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 context (eg assign Fred as a teacher in a particular course)&lt;br /&gt;
&lt;br /&gt;
Here are the possible contexts, listed from the most general to the most specific. &lt;br /&gt;
&lt;br /&gt;
#CONTEXT_SYSTEM       -- the whole site&lt;br /&gt;
#CONTEXT_PERSONAL     -- yourself&lt;br /&gt;
#CONTEXT_USER         -- another user&lt;br /&gt;
#CONTEXT_COURSECAT    -- a course category&lt;br /&gt;
#CONTEXT_COURSE       -- a course&lt;br /&gt;
&#039;&#039;&#039;#CONTEXT_GROUP        -- a group&lt;br /&gt;
#CONTEXT_MODULE       -- an activity module&lt;br /&gt;
#CONTEXT_BLOCK        -- a block&lt;br /&gt;
&lt;br /&gt;
[[Image:Moodle-contexts-1.8.png|right|thumb|A diagram of the contexts in Moodle 1.8, based on the [[Talk:Roles_and_capabilities|text diagram by Martin Dougiamas]]. Click on the diagram to see a more detailed view of it.]]&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;
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;
Since the capabilities in each role could be different, there could be conflict in capabilities. This is resolved by enforcing the rule that the capability defined for a more specific context will win, unless a prohibit is encountered in a less specific context.&lt;br /&gt;
&lt;br /&gt;
For example, Mark has a student role at course level, which allows him to write into a wiki. But Mark also got assigned a Visitor role at a module context level (for a particular wiki) which prevents him from writing to the wiki (read only). Therefore, for this particular wiki, Mark will not be able to write to the wiki since the more specific context wins.&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;
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.&lt;br /&gt;
&lt;br /&gt;
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;
===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 simplified, 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;
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;
==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&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&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 [http://www.moodle.org/bugs/bug.php?op=show&amp;amp;bugid=6118&amp;amp;pos= bug 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 access.php inside the db folder 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;
    &#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;legacy&#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;admin&#039; =&amp;gt; CAP_ALLOW&lt;br /&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 get_context_instance() function.  For example, in the forum module:&lt;br /&gt;
&lt;br /&gt;
  $context = get_context_instance(CONTEXT_MODULE, $cm-&amp;gt;id);&lt;br /&gt;
* or to at the course level:&lt;br /&gt;
  $context = get_context_instance(CONTEXT_COURSE, $id);&lt;br /&gt;
* Then, whenever you want to check that the current user has rights to do something, call has_capability() like this:&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;
* 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 require_capability() like this:&lt;br /&gt;
&lt;br /&gt;
    require_capability(&#039;mod/forum:viewforum&#039;, $context);&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;
&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;
==Metacourses==&lt;br /&gt;
&lt;br /&gt;
The behaviour of metacourses in Moodle 1.7 changed slightly, in that where it used to just synch students from child courses to the parent course, it will now synch ALL roles. Teachers etc of the child courses will have the same role in the meta course. Technically metacourse synchronises all role assignments in CONTEXT_COURSE with its child courses; the only exception are users with moodle/course:managemetacourse capability, these users are synchronized only upwards, they are not unenrolled from metacourse when unenroling from child course or when removing the child from metacourse.&lt;br /&gt;
&lt;br /&gt;
In order to import/enrol other courses into metacoure you need to have moodle/course:managemetacourse capability. You can add manually only participants with moodle/course:managemetacourse, all other participants are automatically synced with child courses - if you try to manually enrol user without this capability error is displayed. Similar error is shown also when you try to manually unenrol participant from meta course while still being enrolled in child course.&lt;br /&gt;
&lt;br /&gt;
Sample setup:&lt;br /&gt;
* metacourse manager has been assigned role with moodle/course:managemetacourse capability in system or course category context&lt;br /&gt;
* students are enrolled in several child courses&lt;br /&gt;
* teachers are enrolled in separate child course(s)&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;Please add text here...&#039;&#039;&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=== An ALUMNUS should be able to search for all other ALUMNI of the school, interact with them and be enrolled in a seperate 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;
==Things to finish for 1.7 Beta==&lt;br /&gt;
&#039;&#039;&#039;18 Sept 2006&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
#Remove core references to user_student, user_teacher, user_admin, user_coursecreator tables.  [Yu]&lt;br /&gt;
#Address function: isteacher, isadmin, isstudent [Yu]&lt;br /&gt;
#Remove &amp;quot;view&amp;quot; capabilities from all modules unless required [Vy]&lt;br /&gt;
#Remove all old references from remaining Blocks [Vy]&lt;br /&gt;
#Metacourses [Skodak]&lt;br /&gt;
#Add risks to GUI[Skodak]&lt;br /&gt;
#Enrolment plugins  [Martin and Alastair]&lt;br /&gt;
#[[Stats_roles_1.7|Statistics]] [Penny]&lt;br /&gt;
#Fix Loginas&lt;br /&gt;
#Add category-level assigns [Yu]&lt;br /&gt;
#[[Backup_roles_1.7|Backups]] [Eloy?]&lt;br /&gt;
&lt;br /&gt;
===Proposal for interface enhancement===&lt;br /&gt;
Martin asked some questions, here are my answers. The sketches below are not worked out proposals. Their task is to visualize the idea. The exact colours and functionality may be defined after possible agreement about the proposals. The Green, orange and red columns support the meaning of the options from &amp;quot;allow&amp;quot; to &amp;quot;prohibit&amp;quot; (If you may want to see larger images please click onto the image or the &amp;quot;Enlarge&amp;quot; icon below the image.)&lt;br /&gt;
&lt;br /&gt;
The list of possible settings is very long and &#039;&#039; &amp;quot;... the problem is not to overwhelm people with information&amp;quot; &#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
[[Image:01_moodle_define_roles_structured.png|thumb=01_moodle_define_roles_structured_pre.png]]&lt;br /&gt;
&lt;br /&gt;
1) One proposal is to use colour to structure the sections and the columns. Picture 1 shows that the user can keep a much better overview when the list is divided into meaningful different coloured columns and clear sections.&lt;br /&gt;
&amp;lt;br style=&amp;quot;clear:both;&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Image:02_moodle_define_roles_collapsed.png|thumb=02_moodle_define_roles_collapsed_pre.png]]&lt;br /&gt;
&lt;br /&gt;
2) A second proposal is to reduce the amount of information the user is shown at the same time. The YUI interface library offers great support to show/hide sections of the page by clicking on specific elements. &lt;br /&gt;
&lt;br /&gt;
For example click on an icon beside the sub heading &amp;quot;Course categories&amp;quot; and show/hide all table rows with the CLASS &amp;quot;course-category&amp;quot;.&lt;br /&gt;
&amp;lt;br style=&amp;quot;clear:both;&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Image:03_moodle_define_roles_tooltip.png|thumb=03_moodle_define_roles_tooltip_pre.png]]&lt;br /&gt;
&lt;br /&gt;
3) &#039;&#039; &amp;quot;The main problem is the last column for risk ... we were thinking of putting little icons in there ...&amp;quot; &#039;&#039;&lt;br /&gt;
Icons are good when they tell the user more about possible actions/meanings then the letters. I am not sure if this is the case here. For both - icons or letters - the YUI tool-tip function would be able to give the user valuable information about the meaning.&lt;br /&gt;
&amp;lt;br style=&amp;quot;clear:both;&amp;quot; /&amp;gt;&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;
&lt;br /&gt;
[[Category:Roles]]&lt;br /&gt;
[[Category:Roles]]&lt;br /&gt;
&lt;br /&gt;
[[fr:Developpement:Roles]]&lt;/div&gt;</summary>
		<author><name>Vf</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Old_Events_API&amp;diff=6534</id>
		<title>Old Events API</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Old_Events_API&amp;diff=6534"/>
		<updated>2007-07-12T20:13:42Z</updated>

		<summary type="html">&lt;p&gt;Vf: /* Handling an event */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Events API is a new core system in Moodle to allow better communication between modules.  It&#039;s based on modules triggering new events with attached data, and the other modules handling those events with custom functions.&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
We&#039;ll be using the example of a grade being posted from a module into the [[Grades|new gradebook in Moodle 1.9]], but there are obviously all kinds of events possible.&lt;br /&gt;
&lt;br /&gt;
===Triggering an event===&lt;br /&gt;
&lt;br /&gt;
Whenever a grade is created or changed by a module, it should “tell” the system about it (in addition to any local working storage it uses).   So, using the quiz as an example, we first define an object as follows:&lt;br /&gt;
&lt;br /&gt;
 $eventdata = new object();&lt;br /&gt;
 $eventdata-&amp;gt;itemid = $grade_item-&amp;gt;id;&lt;br /&gt;
 $eventdata-&amp;gt;userid = $USER-&amp;gt;id;&lt;br /&gt;
 $eventdata-&amp;gt;gradevalue = $currentvalue;&lt;br /&gt;
&lt;br /&gt;
Then we post the object as an event and forget about it:&lt;br /&gt;
&lt;br /&gt;
 events_trigger(&#039;grade_updated&#039;, $eventdata);&lt;br /&gt;
&lt;br /&gt;
===Handling an event===&lt;br /&gt;
&lt;br /&gt;
Modules can define an events.php in their db directory which defines events they want to be notified about, and describes which of their functions or class methods should be notified.   For example, an export  plugin could register something like:&lt;br /&gt;
&lt;br /&gt;
 $handlers = array (&lt;br /&gt;
     &#039;grade_updated&#039; =&amp;gt; array (&lt;br /&gt;
         &#039;handlerfile&#039;      =&amp;gt; &#039;/grade/export/banner/lib.php&#039;,&lt;br /&gt;
         &#039;handlerfunction&#039;  =&amp;gt; &#039;banner_handle_grade_test&#039;,    // argument to call_user_func(), could be an array&lt;br /&gt;
         &#039;schedule&#039;         =&amp;gt; &#039;cron&#039;&lt;br /&gt;
     ) &lt;br /&gt;
 );&lt;br /&gt;
These are parsed during install / upgrade and stored in a simple database table.&lt;br /&gt;
&lt;br /&gt;
Then, when a grade_added event happens, all the registered functions for that event will be called something like this (but with more error handling):&lt;br /&gt;
&lt;br /&gt;
          include_once($CFG-&amp;gt;dirroot.$handlers[&#039;grade_updated&#039;][&#039;file&#039;]);&lt;br /&gt;
          call_user_func($handlers[&#039;grade_updated&#039;][&#039;function&#039;], $eventdata);&lt;br /&gt;
&lt;br /&gt;
All plugins in Moodle have access to this and can this easily “hook in” to &#039;grade_updated&#039; events (and of course any other events).&lt;br /&gt;
&lt;br /&gt;
==Database structure==&lt;br /&gt;
&lt;br /&gt;
There are 3 core tables for events. Note that if a handler is queued, and yet to be processed or processing failed, then all subsequent calls on that handler must be queued.&lt;br /&gt;
&lt;br /&gt;
===events_handlers===&lt;br /&gt;
&lt;br /&gt;
This table is for storing which components requests what type of event, and the location of the responsible handlers. For example, the grade book can register &#039;grade_added&#039; event with a function add_grade() that should be called event time an &#039;grade_added&#039; event is triggered by a module.&lt;br /&gt;
&lt;br /&gt;
These entries are created by parsing events.php files in all the modules, and can be rebuilt any time (during an upgrade, say).&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;2&amp;quot; cellspacing=&amp;quot;0&amp;quot;&lt;br /&gt;
|&#039;&#039;&#039;Field&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Type&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Info&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|id&lt;br /&gt;
|int(10)&lt;br /&gt;
|auto increment identifier&lt;br /&gt;
|-&lt;br /&gt;
|eventname&lt;br /&gt;
|varchar(255)&lt;br /&gt;
|name of the event, e.g. &#039;grade_updated&#039;&lt;br /&gt;
|-&lt;br /&gt;
|handlermodule&lt;br /&gt;
|varchar(255)&lt;br /&gt;
|e.g. moodle, mod/forum, block/rss_client&lt;br /&gt;
|-&lt;br /&gt;
|handlerfile&lt;br /&gt;
|varchar(255)&lt;br /&gt;
|path to the file of the function, eg /grade/export/lib.php&lt;br /&gt;
|-&lt;br /&gt;
|handlerfunction&lt;br /&gt;
|text&lt;br /&gt;
|serialized string or array describing function, suitable to be passed to &#039;&#039;&#039;call_user_func()&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|schedule 	&lt;br /&gt;
|varchar(255) 	&lt;br /&gt;
|&#039;cron&#039; or &#039;instant&#039;.&lt;br /&gt;
|-&lt;br /&gt;
|status&lt;br /&gt;
|int(10)&lt;br /&gt;
|number of failed attempts to process this handler&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===events_queue===&lt;br /&gt;
&lt;br /&gt;
This table is for storing queued events. It stores only one copy of the eventdata here, and entries from this table are being references by the events_queue_handlers table.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;2&amp;quot; cellspacing=&amp;quot;0&amp;quot;&lt;br /&gt;
|&#039;&#039;&#039;Field&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Type&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Info&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|id&lt;br /&gt;
|int(10)&lt;br /&gt;
|auto increment identifier&lt;br /&gt;
|-&lt;br /&gt;
|eventdata 	&lt;br /&gt;
|longtext 	&lt;br /&gt;
|serialized version of the data object passed to the event handler.&lt;br /&gt;
|-&lt;br /&gt;
|stackdump&lt;br /&gt;
|text&lt;br /&gt;
|serialized debug_backtrace showing where the event was fired from&lt;br /&gt;
|-&lt;br /&gt;
|userid&lt;br /&gt;
|int(10)&lt;br /&gt;
|$USER-&amp;gt;id when the event was fired&lt;br /&gt;
|-&lt;br /&gt;
|timecreated&lt;br /&gt;
|int(10) 	&lt;br /&gt;
|time stamp of the first time this was added&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===events_queue_handlers===&lt;br /&gt;
&lt;br /&gt;
This is the list of queued handlers for processing. The event object is retrieved from the events_queue table. When no further reference is made to the events_queue table, the corresponding entry in the events_queue table should be deleted. Entry should get deleted (?) after a successful event processing by the specified handler.  The status field keeps track of failures, after it gets to a certain number (eg 10?) it should trigger an &amp;quot;event failed&amp;quot; event (that could result in admin being emailed etc, or perhaps even the originating module taking care of it or rolling something back etc).&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;2&amp;quot; cellspacing=&amp;quot;0&amp;quot;&lt;br /&gt;
|&#039;&#039;&#039;Field&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Type&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Info&#039;&#039;&#039;&lt;br /&gt;
|- &lt;br /&gt;
|id&lt;br /&gt;
|int(10)&lt;br /&gt;
|auto increment identifier&lt;br /&gt;
|-&lt;br /&gt;
|queuedeventid&lt;br /&gt;
|int(10)&lt;br /&gt;
|foreign key id corresponding to the id of the event_queues table&lt;br /&gt;
|-&lt;br /&gt;
|handlerid&lt;br /&gt;
|int(10)&lt;br /&gt;
|foreign key id corresponding to the id of the event_handlers table&lt;br /&gt;
|-&lt;br /&gt;
|status&lt;br /&gt;
|int(10)&lt;br /&gt;
|number of failed attempts to process this handler&lt;br /&gt;
|-&lt;br /&gt;
|errormessage&lt;br /&gt;
|text&lt;br /&gt;
|if an error happened last time we tried to process this event, record it here.&lt;br /&gt;
|-&lt;br /&gt;
|timemodified&lt;br /&gt;
|int(10)&lt;br /&gt;
|time stamp of the last attempt to run this from the queue&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Standards for naming events==&lt;br /&gt;
&lt;br /&gt;
All event names should follow a consistent naming pattern, such as modulename_noun_verb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=69103 General Developer Forum thread for discussing this proposal]. &lt;br /&gt;
* [[:Development:Grades]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Events]]&lt;br /&gt;
[[Category:Grades]]&lt;/div&gt;</summary>
		<author><name>Vf</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=lib/formslib.php&amp;diff=5546</id>
		<title>lib/formslib.php</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=lib/formslib.php&amp;diff=5546"/>
		<updated>2007-06-22T09:56:05Z</updated>

		<summary type="html">&lt;p&gt;Vf: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Formslib}}&lt;br /&gt;
{{Moodle 1.8}}&lt;br /&gt;
{{Moodle 1.7}}&lt;br /&gt;
&lt;br /&gt;
The formslib api has now been backported and is available in Moodle 1.7. There may be a few minor styles missing from 1.7 stylesheets and be warned formslib has not been thoroughly tested in 1.7.&lt;br /&gt;
&lt;br /&gt;
== Features of Formslib ==&lt;br /&gt;
&lt;br /&gt;
* Created xhtml structure aiming for compliance with xhtml strict DTD and section 508 accessibility guidelines.&lt;br /&gt;
* Stylesheet for forms in Moodle standard themes.&lt;br /&gt;
* Accessibility improvements :&lt;br /&gt;
** Input fields labeled&lt;br /&gt;
** Tableless layout.&lt;br /&gt;
** Tested and optimised for use on major screenreaders Dragon and JAWS.&lt;br /&gt;
* New functionality :&lt;br /&gt;
** Facility to process form data securely as is currently done with required_param, optional_param using setType.&lt;br /&gt;
** Form elements process submitted data themselves and check the submitted data. For instance in select type only options that have been added to the select are accepted when submitted.&lt;br /&gt;
** Form validation with custom validation function or addRule QuickForms validation. QuickForms validation allows for clientside validation.&lt;br /&gt;
** Feedback to the user about required input and errors in user input.&lt;br /&gt;
** Facility to add Moodle help buttons to forms.&lt;br /&gt;
** upload_manager processes uploaded files securely.&lt;br /&gt;
** Many custom Moodle specific and non specific form elements to add to forms.&lt;br /&gt;
*** Moodle specific elements modgrade, modvisible, modgroupmode and choosecoursefile, format&lt;br /&gt;
*** Non specific elements htmleditor, dateselector, datetimeselector, selectyesno&lt;br /&gt;
*** Lots of modification to regular elements.&lt;br /&gt;
*** Easy to define your own custom elements.&lt;br /&gt;
* Some advanced functionality :&lt;br /&gt;
** Methods for adding repeated elements to a page. With button to add more elements.&lt;br /&gt;
** Working on hiding / unhiding advanced options on a form.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
See the menu to the top right for pages on using formslib.php&lt;br /&gt;
&lt;br /&gt;
== To Do ==&lt;br /&gt;
&lt;br /&gt;
* Conversion of forms to use the new forms API. See list of initial forms to be done  [http://tracker.moodle.org/browse/MDL-6937 in the tracker].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Forms Which May Not Use Quick Forms But Need Some Recoding of HTML ==&lt;br /&gt;
&lt;br /&gt;
Forms below were initially not deemed good candidates for migration to using the quickform library because they are either too big and complex or mostly because they are very small forms. (I don&#039;t see the problem with very small forms. I would still use the library, but I would not bother putting the form class definition in a separate file.[[User:Tim Hunt|Tim Hunt]]) But they do still need some recoding of the html to make it more accessible.&lt;br /&gt;
&lt;br /&gt;
* auth\cas\index_form.html (18) &lt;br /&gt;
* auth\cas\index_form.html (32) &lt;br /&gt;
* auth\cas\index_form.html (45) &lt;br /&gt;
* blocks\search\block_search.php (49) &lt;br /&gt;
* blog\tags.html (13) &lt;br /&gt;
* blog\tags.html (43) &lt;br /&gt;
* blog\tags.html (79) &lt;br /&gt;
* blog\tags.html (90) &lt;br /&gt;
* calendar\event_delete.html (4) &lt;br /&gt;
* calendar\event_delete.html (21) &lt;br /&gt;
* calendar\event_delete.html (38) &lt;br /&gt;
* calendar\event_select.html (3) &lt;br /&gt;
* course\import\activities\mod.php (55) &lt;br /&gt;
* course\import\activities\mod.php (55) &lt;br /&gt;
* course\import\activities\mod.php (55) &lt;br /&gt;
* course\import\groups\mod.php (19) &lt;br /&gt;
* course\index.php (279) &lt;br /&gt;
* course\lib.php (1607) &lt;br /&gt;
* course\lib.php (1613) &lt;br /&gt;
* course\lib.php (1619) &lt;br /&gt;
* course\loginas.php (68) &lt;br /&gt;
* course\pending-reject.html(1) &lt;br /&gt;
* course\report\log\lib.php (154) &lt;br /&gt;
* course\report\participation\index.php (115) &lt;br /&gt;
* course\report\participation\index.php (181) &lt;br /&gt;
* course\report\participation\index.php (326) &lt;br /&gt;
* course\report\participation\mod.php (73) &lt;br /&gt;
* course\report\stats\lib.php (30) &lt;br /&gt;
* course\report\stats\report.php (15) &lt;br /&gt;
* course\search.php (162) &lt;br /&gt;
* course\teacher.php (214) &lt;br /&gt;
* enrol\authorize\locallib.php (193) &lt;br /&gt;
* enrol\manual\enrol.html (16) &lt;br /&gt;
* enrol\manual\enrol.html (44) &lt;br /&gt;
* error\index.php (33) &lt;br /&gt;
* files\index.php (180) &lt;br /&gt;
* files\index.php (191) &lt;br /&gt;
* files\index.php (321) &lt;br /&gt;
* files\index.php (332) &lt;br /&gt;
* files\index.php (362) &lt;br /&gt;
* files\index.php (372) &lt;br /&gt;
* files\index.php (408) &lt;br /&gt;
* files\index.php (420) &lt;br /&gt;
* files\index.php (466) &lt;br /&gt;
* files\index.php (476) &lt;br /&gt;
* files\index.php (506) &lt;br /&gt;
* files\index.php (554) &lt;br /&gt;
* files\index.php (702) &lt;br /&gt;
* files\index.php (832) &lt;br /&gt;
* files\index.php (843) &lt;br /&gt;
* files\index.php (852) &lt;br /&gt;
* files\index.php (858) &lt;br /&gt;
* grade\exceptions.html (107) &lt;br /&gt;
* grade\exceptions.html (128) &lt;br /&gt;
* grade\exceptions.html (150) &lt;br /&gt;
* grade\lib.php (2314) &lt;br /&gt;
* grade\lib.php (2368) &lt;br /&gt;
* grade\lib.php (2553) &lt;br /&gt;
* grade\lib.php (2566) &lt;br /&gt;
* grade\lib.php (2652) &lt;br /&gt;
* grade\lib.php (2804) &lt;br /&gt;
* install.php (667) &lt;br /&gt;
* install.php (870) &lt;br /&gt;
* iplookup\ipatlas\ip-atlas_prefs.php (106) &lt;br /&gt;
* iplookup\ipatlas\plot.php (132) &lt;br /&gt;
* lib\editor\htmlarea\coursefiles.php (232) &lt;br /&gt;
* lib\editor\htmlarea\coursefiles.php (242) &lt;br /&gt;
* lib\editor\htmlarea\coursefiles.php (336) &lt;br /&gt;
* lib\editor\htmlarea\coursefiles.php (346) &lt;br /&gt;
* lib\editor\htmlarea\coursefiles.php (375) &lt;br /&gt;
* lib\editor\htmlarea\coursefiles.php (384) &lt;br /&gt;
* lib\editor\htmlarea\coursefiles.php (412) &lt;br /&gt;
* lib\editor\htmlarea\coursefiles.php (423) &lt;br /&gt;
* lib\editor\htmlarea\coursefiles.php (468) &lt;br /&gt;
* lib\editor\htmlarea\coursefiles.php (477) &lt;br /&gt;
* lib\editor\htmlarea\coursefiles.php (506) &lt;br /&gt;
* lib\editor\htmlarea\coursefiles.php (553) &lt;br /&gt;
* lib\editor\htmlarea\coursefiles.php (698) &lt;br /&gt;
* lib\editor\htmlarea\coursefiles.php (817) &lt;br /&gt;
* lib\editor\htmlarea\plugins\SpellChecker\spell-check-ui.html (63) &lt;br /&gt;
* lib\editor\htmlarea\popups\createanchor.php (54) &lt;br /&gt;
* lib\editor\htmlarea\popups\fullscreen.php (171) &lt;br /&gt;
* lib\editor\htmlarea\popups\insert_image.php (181) &lt;br /&gt;
* lib\editor\htmlarea\popups\insert_image.php (285) &lt;br /&gt;
* lib\editor\htmlarea\popups\insert_image.php (287) &lt;br /&gt;
* lib\editor\htmlarea\popups\insert_image.php (289) &lt;br /&gt;
* lib\editor\htmlarea\popups\insert_image.php (291) &lt;br /&gt;
* lib\editor\htmlarea\popups\insert_image.php (319) &lt;br /&gt;
* lib\editor\htmlarea\popups\insert_image.php (328) &lt;br /&gt;
* lib\editor\htmlarea\popups\insert_image_std.php (154) &lt;br /&gt;
* lib\editor\htmlarea\popups\insert_table.php (83) &lt;br /&gt;
* lib\editor\htmlarea\popups\link.php (103) &lt;br /&gt;
* lib\editor\htmlarea\popups\link.php (105) &lt;br /&gt;
* lib\editor\htmlarea\popups\link.php (107) &lt;br /&gt;
* lib\editor\htmlarea\popups\link.php (109) &lt;br /&gt;
* lib\editor\htmlarea\popups\link.php (128) &lt;br /&gt;
* lib\editor\htmlarea\popups\link.php (136) &lt;br /&gt;
* lib\editor\htmlarea\popups\searchandreplace.php (107) &lt;br /&gt;
* lib\editor\htmlarea\popups\select_color.php (65) &lt;br /&gt;
* lib\editor\tinymce\jscripts\tiny_mce\plugins\advimage\image.htm (12) &lt;br /&gt;
* lib\editor\tinymce\jscripts\tiny_mce\plugins\fullscreen\fullscreen.htm (87) &lt;br /&gt;
* lib\editor\tinymce\jscripts\tiny_mce\themes\advanced\anchor.htm (9) &lt;br /&gt;
* lib\editor\tinymce\jscripts\tiny_mce\themes\advanced\editor_template_src.js (90) &lt;br /&gt;
* lib\editor\tinymce\jscripts\tiny_mce\themes\advanced\image.htm (11) &lt;br /&gt;
* lib\editor\tinymce\jscripts\tiny_mce\themes\advanced\jscripts\image.js (52) &lt;br /&gt;
* lib\editor\tinymce\jscripts\tiny_mce\themes\advanced\jscripts\link.js (46) &lt;br /&gt;
* lib\editor\tinymce\jscripts\tiny_mce\themes\advanced\link.htm (11) &lt;br /&gt;
* lib\editor\tinymce\jscripts\tiny_mce\themes\advanced\source_editor.htm (10) &lt;br /&gt;
* lib\editor\tinymce\jscripts\tiny_mce\tiny_mce_src.js (531) &lt;br /&gt;
* lib\editor\tinymce\jscripts\tiny_mce\tiny_mce_src.js (874) &lt;br /&gt;
* lib\html2text.php (94) &lt;br /&gt;
* lib\html2text.php (140) &lt;br /&gt;
* lib\questionlib.php (1174) &lt;br /&gt;
* lib\rsslib.php (465) &lt;br /&gt;
* lib\speller\controls.html (77) &lt;br /&gt;
* lib\uploadlib.php (466) &lt;br /&gt;
* lib\weblib.php (987) &lt;br /&gt;
* login\change_password_form.html (45) &lt;br /&gt;
* login\forgot_password.php (251) &lt;br /&gt;
* login\index_form.html (25) &lt;br /&gt;
* message\search.php (95) &lt;br /&gt;
* message\send.php (95) &lt;br /&gt;
* mod\assignment\lib.php (881) &lt;br /&gt;
* mod\assignment\lib.php (1183) &lt;br /&gt;
* mod\assignment\lib.php (1200) &lt;br /&gt;
* mod\assignment\type\online\assignment.class.php (132) &lt;br /&gt;
* mod\assignment\type\upload\assignment.class.php (826) &lt;br /&gt;
* mod\assignment\type\upload\assignment.class.php (1302) &lt;br /&gt;
* mod\assignment\type\upload\assignment.class.php (1318) &lt;br /&gt;
* mod\assignment\type\uploadsingle\assignment.class.php (86) &lt;br /&gt;
* mod\data\comment.php (65) &lt;br /&gt;
* mod\data\edit.php (238) --recode html in all 12 field.class.php files&lt;br /&gt;
* mod\data\edit.php (288) &lt;br /&gt;
* mod\data\field\latlong\field.class.php (98) &lt;br /&gt;
* mod\data\field.php (301) &lt;br /&gt;
* mod\data\lib.php (184) --recode html in all 12 field mod.html files&lt;br /&gt;
* mod\data\lib.php (953) &lt;br /&gt;
* mod\data\lib.php (1003) &lt;br /&gt;
* mod\data\lib.php (1150) &lt;br /&gt;
* mod\data\preset.php (297) &lt;br /&gt;
* mod\data\preset.php (319) &lt;br /&gt;
* mod\data\preset.php (625) &lt;br /&gt;
* mod\data\templates.php (139) &lt;br /&gt;
* mod\exercise\assessments.php (88) &lt;br /&gt;
* mod\exercise\assessments.php (274) &lt;br /&gt;
* mod\exercise\locallib.php (1573) &lt;br /&gt;
* mod\exercise\locallib.php (2374) &lt;br /&gt;
* mod\exercise\locallib.php (2874) &lt;br /&gt;
* mod\exercise\submissions.php (72) &lt;br /&gt;
* mod\exercise\view.php (254) &lt;br /&gt;
* mod\forum\lib.php (2316) &lt;br /&gt;
* mod\forum\lib.php (3197) &lt;br /&gt;
* mod\forum\prune.html (1) &lt;br /&gt;
* mod\glossary\comment.php (101) &lt;br /&gt;
* mod\glossary\editcategories.html (6) &lt;br /&gt;
* mod\glossary\editcategories.php (109) &lt;br /&gt;
* mod\glossary\export.php (65) &lt;br /&gt;
* mod\glossary\view.php (269) &lt;br /&gt;
* mod\glossary\view.php (332) &lt;br /&gt;
* mod\journal\edit.html (1) &lt;br /&gt;
* mod\journal\mod.html (20) &lt;br /&gt;
* mod\journal\report.php (116) &lt;br /&gt;
* mod\lesson\action\addbranchtable.php (36) &lt;br /&gt;
* mod\lesson\action\continue.php (817) &lt;br /&gt;
* mod\lesson\action\editpage.php (55) &lt;br /&gt;
* mod\lesson\import.php (86) &lt;br /&gt;
* mod\lesson\importppt.php (85) &lt;br /&gt;
* mod\lesson\view.php (142) &lt;br /&gt;
* mod\lesson\view.php (692) &lt;br /&gt;
* mod\lesson\view.php (917) &lt;br /&gt;
* mod\lesson\view.php (1195) &lt;br /&gt;
* mod\lesson\view.php (1649) &lt;br /&gt;
* mod\lesson\view.php (1986) &lt;br /&gt;
* mod\quiz\attempt.php (142) &lt;br /&gt;
* mod\quiz\attempt.php (475) --inlvolves rewriting question plugins&lt;br /&gt;
* mod\quiz\editlib.php (178) &lt;br /&gt;
* mod\quiz\editlib.php (310) &lt;br /&gt;
* mod\quiz\report\analysis\report.php (364) &lt;br /&gt;
* mod\quiz\report\grading\report.php (356) &lt;br /&gt;
* mod\quiz\report\overview\report.php (451) &lt;br /&gt;
* mod\quiz\report\overview\report.php (510) &lt;br /&gt;
* mod\resource\type\file\localfile.php (39) &lt;br /&gt;
* mod\resource\type\file\localpath.php (43) &lt;br /&gt;
* mod\scorm\coefficientsetting.php (173) &lt;br /&gt;
* mod\scorm\locallib.php (441) &lt;br /&gt;
* mod\survey\report.php (397) &lt;br /&gt;
* mod\survey\view.php (106) &lt;br /&gt;
* mod\wiki\admin.php (265) &lt;br /&gt;
* mod\wiki\checklinks.html (5) &lt;br /&gt;
* mod\wiki\ewiki\ewiki.php (524) &lt;br /&gt;
* mod\wiki\ewiki\ewiki.php (1478) &lt;br /&gt;
* mod\wiki\ewiki\ewiki.php (1535) &lt;br /&gt;
* mod\wiki\ewiki\ewiki.php (1607) &lt;br /&gt;
* mod\wiki\ewiki\plugins\email_protect.php (123) &lt;br /&gt;
* mod\wiki\ewiki\plugins\moodle\downloads.php (105) &lt;br /&gt;
* mod\wiki\ewiki\plugins\moodle\moodle_wikidump.php (68) &lt;br /&gt;
* mod\wiki\lib.php (1016) &lt;br /&gt;
* mod\wiki\removepages.html (8) &lt;br /&gt;
* mod\wiki\setpageflags.html (5) &lt;br /&gt;
* mod\wiki\strippages.html (5) &lt;br /&gt;
* mod\wiki\view.php (265) &lt;br /&gt;
* mod\workshop\assessments.php (95) &lt;br /&gt;
* mod\workshop\assessments.php (426) &lt;br /&gt;
* mod\workshop\locallib.php (1993) &lt;br /&gt;
* mod\workshop\locallib.php (2933) &lt;br /&gt;
* mod\workshop\submissions.php (77) &lt;br /&gt;
* mod\workshop\submissions.php (253) &lt;br /&gt;
* mod\workshop\view.php (156) &lt;br /&gt;
* question\category_class.php (192) &lt;br /&gt;
* question\category_class.php (445) &lt;br /&gt;
* question\category_class.php (598) &lt;br /&gt;
* question\editlib.php (167) &lt;br /&gt;
* question\editlib.php (172) &lt;br /&gt;
* question\editlib.php (328) &lt;br /&gt;
* question\export.php (157) &lt;br /&gt;
* question\format\coursetestmanager\format.php (122) &lt;br /&gt;
* question\preview.php (190) &lt;br /&gt;
* question\type\datasetdependent\categorydatasetdefinitions.php (71) &lt;br /&gt;
* question\type\datasetdependent\datasetitems.php (252) &lt;br /&gt;
* question\type\datasetdependent\datasetitems.php (266) &lt;br /&gt;
* question\type\rqp\types.php (162) &lt;br /&gt;
* question\type\editquestionstart.html (1) &lt;br /&gt;
* question\type\random\editquestionstart.html (1) &lt;br /&gt;
* question\type\rqp\editquestionstart.html (1) &lt;br /&gt;
* question\type\rqp\types.php (162) &lt;br /&gt;
* sso\hive\expired.php (29) &lt;br /&gt;
* user\extendenrol.php (48) &lt;br /&gt;
* user\index.php (174) &lt;br /&gt;
* user\index.php (311) &lt;br /&gt;
* user\index.php (574) &lt;br /&gt;
* user\message.html (1)&lt;br /&gt;
&lt;br /&gt;
== These forms do not need any work ==&lt;br /&gt;
&lt;br /&gt;
Admin forms have been worked on by others in a seperate project.&lt;br /&gt;
&lt;br /&gt;
* auth\cas\index_form.html (59) &lt;br /&gt;
* auth\cas\index_form.html (76) &lt;br /&gt;
* blocks\search_forums\block_search_forums.php (31) &lt;br /&gt;
* blog\blogpage.php (173) &lt;br /&gt;
* blog\edit.php (62) &lt;br /&gt;
* calendar\export_basic.html (3) &lt;br /&gt;
* calendar\export_basic.html (34) &lt;br /&gt;
* calendar\lib.php (1224) &lt;br /&gt;
* calendar\view.php (207) &lt;br /&gt;
* calendar\view.php (330) &lt;br /&gt;
* calendar\view.php (525) &lt;br /&gt;
* course\category.php (434) &lt;br /&gt;
* course\reset.php (59) &lt;br /&gt;
* enrol\manual\enrol.html (32) &lt;br /&gt;
* enrol\paypal\enrol.html (7) &lt;br /&gt;
* filter\algebra\algebradebug.php (331) &lt;br /&gt;
* filter\tex\texdebug.php (208) &lt;br /&gt;
* filter\tex\texed.php (74) &lt;br /&gt;
* lang\en_utf8\help\quiz\multianswer.html (16) &lt;br /&gt;
* lang\en_utf8\help\quiz\multianswer.html (32) &lt;br /&gt;
* lib\adodb\adodb-perf.inc.php (675) &lt;br /&gt;
* lib\adodb\adodb-perf.inc.php (894) &lt;br /&gt;
* lib\speller\spellchecker.html (46) &lt;br /&gt;
* lib\speller\wordWindow.js (146) &lt;br /&gt;
* lib\weblib.php (674) &lt;br /&gt;
* lib\weblib.php (2840) &lt;br /&gt;
* lib\weblib.php (3675) &lt;br /&gt;
* lib\weblib.php (3704) &lt;br /&gt;
* lib\weblib.php (3722) &lt;br /&gt;
* lib\weblib.php (3752) &lt;br /&gt;
* lib\weblib.php (3778) &lt;br /&gt;
* lib\weblib.php (3802) &lt;br /&gt;
* lib\weblib.php (3826) &lt;br /&gt;
* lib\weblib.php (3854) &lt;br /&gt;
* lib\weblib.php (4021) &lt;br /&gt;
* lib\weblib.php (4026) &lt;br /&gt;
* lib\yui\container\container-debug.js (6469) &lt;br /&gt;
* lib\yui\container\container-debug.js (6481) &lt;br /&gt;
* lib\yui\container\container-debug.js (7017) &lt;br /&gt;
* lib\yui\container\container-debug.js (7053) &lt;br /&gt;
* lib\yui\container\container-debug.js (7073) &lt;br /&gt;
* lib\yui\container\container-min.js (457) &lt;br /&gt;
* lib\yui\container\container-min.js (505) &lt;br /&gt;
* lib\yui\container\container.js (6381) &lt;br /&gt;
* lib\yui\container\container.js (6393) &lt;br /&gt;
* lib\yui\container\container.js (6929) &lt;br /&gt;
* lib\yui\container\container.js (6965) &lt;br /&gt;
* lib\yui\container\container.js (6985) &lt;br /&gt;
* login\index_form.html (59) &lt;br /&gt;
* login\index_form.html (73) &lt;br /&gt;
* login\index_form.html (86) &lt;br /&gt;
* login\index_form.html (102) &lt;br /&gt;
* mod\assignment\type\common.html (1) &lt;br /&gt;
* mod\assignment\type\upload\assignment.class.php (102) &lt;br /&gt;
* mod\assignment\type\upload\assignment.class.php (129) &lt;br /&gt;
* mod\assignment\type\upload\assignment.class.php (163) &lt;br /&gt;
* mod\assignment\type\upload\assignment.class.php (1412) &lt;br /&gt;
* mod\chat\gui_header_js\chatinput.php (59) &lt;br /&gt;
* mod\chat\gui_header_js\chatinput.php (65) &lt;br /&gt;
* mod\chat\gui_sockets\chatinput.php (115) &lt;br /&gt;
* mod\chat\gui_sockets\chatinput.php (127) &lt;br /&gt;
* mod\chat\pagelib.php (68) &lt;br /&gt;
* mod\data\pagelib.php (71) &lt;br /&gt;
* mod\data\preset.php (120) &lt;br /&gt;
* mod\data\preset.php (131) &lt;br /&gt;
* mod\data\preset.php (148) &lt;br /&gt;
* mod\data\preset.php (161) &lt;br /&gt;
* mod\data\preset.php (168) &lt;br /&gt;
* mod\data\preset.php (193) &lt;br /&gt;
* mod\data\preset.php (326) &lt;br /&gt;
* mod\forum\lib.php (2991) &lt;br /&gt;
* mod\forum\lib.php (3517) &lt;br /&gt;
* mod\glossary\editcategories.php (178) &lt;br /&gt;
* mod\hotpot\hotpot-full.js (957) &lt;br /&gt;
* mod\hotpot\hotpot-full.js (4145) &lt;br /&gt;
* mod\hotpot\hotpot-full.js (4217) &lt;br /&gt;
* mod\hotpot\hotpot-full.js (5705) &lt;br /&gt;
* mod\hotpot\index.php (112) &lt;br /&gt;
* mod\hotpot\index.php (120) &lt;br /&gt;
* mod\hotpot\index.php (385) &lt;br /&gt;
* mod\hotpot\index.php (403) &lt;br /&gt;
* mod\hotpot\lib.php (1608) &lt;br /&gt;
* mod\hotpot\lib.php (1626) &lt;br /&gt;
* mod\hotpot\report\fullstat\report.php (425) &lt;br /&gt;
* mod\hotpot\report\overview\report.php (233) &lt;br /&gt;
* mod\hotpot\template\v6.php (2499) &lt;br /&gt;
* mod\hotpot\template\v6.php (2603) &lt;br /&gt;
* mod\hotpot\view.php (79) &lt;br /&gt;
* mod\lesson\mediafile.php (28) &lt;br /&gt;
* mod\lesson\report.php (106) &lt;br /&gt;
* mod\lesson\report.php (273) &lt;br /&gt;
* mod\lesson\view.php (81) &lt;br /&gt;
* mod\lesson\view.php (93) &lt;br /&gt;
* mod\quiz\index.php (29) &lt;br /&gt;
* mod\quiz\jstimer.php (35) &lt;br /&gt;
* mod\quiz\pagelib.php (69) &lt;br /&gt;
* mod\resource\type\repository\hive\openhive.php (43) &lt;br /&gt;
* mod\scorm\locallib.php (465) &lt;br /&gt;
* mod\wiki\ewiki\ewiki.php (1094) &lt;br /&gt;
* mod\wiki\ewiki\ewiki.php (1653) &lt;br /&gt;
* question\category_class.php (385) &lt;br /&gt;
* question\format\xhtml\format.php (128) &lt;br /&gt;
* question\type\datasetdependent\datasetitems.php (275) &lt;br /&gt;
* user\messageselect.php (79) &lt;br /&gt;
* user\view.php (312) &lt;br /&gt;
* user\view.php (317) &lt;br /&gt;
* user\view.php (325) &lt;br /&gt;
* user\view.php (340) &lt;br /&gt;
* user\view.php (353) &lt;br /&gt;
* user\view.php (357) &lt;br /&gt;
* user\view.php (365)&lt;br /&gt;
&lt;br /&gt;
[[Category:Lib/formslib.php]]&lt;br /&gt;
&lt;br /&gt;
[[fr:Developpement:lib/formslib.php]]&lt;/div&gt;</summary>
		<author><name>Vf</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Roles&amp;diff=3157</id>
		<title>Roles</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Roles&amp;diff=3157"/>
		<updated>2007-06-22T09:24:04Z</updated>

		<summary type="html">&lt;p&gt;Vf: /* See also */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Moodle 1.7}}&lt;br /&gt;
&#039;&#039;&#039;Roles and permissions&#039;&#039;&#039; is in Moodle 1.7 onwards.&lt;br /&gt;
&lt;br /&gt;
==Definitions==&lt;br /&gt;
&lt;br /&gt;
A role 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 capability 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 permission 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 context is a &amp;quot;space&amp;quot; in the Moodle, such as courses, activity modules, blocks etc.&lt;br /&gt;
&lt;br /&gt;
==The existing system==&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;
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 erolments - role assignment in course context is simitar 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 context (eg assign Fred as a teacher in a particular course)&lt;br /&gt;
&lt;br /&gt;
Here are the possible contexts, listed from the most general to the most specific. &lt;br /&gt;
&lt;br /&gt;
#CONTEXT_SYSTEM       -- the whole site&lt;br /&gt;
#CONTEXT_PERSONAL     -- yourself&lt;br /&gt;
#CONTEXT_USER         -- another user&lt;br /&gt;
#CONTEXT_COURSECAT    -- a course category&lt;br /&gt;
#CONTEXT_COURSE       -- a course&lt;br /&gt;
#CONTEXT_GROUP        -- a group&lt;br /&gt;
#CONTEXT_MODULE       -- an activity module&lt;br /&gt;
#CONTEXT_BLOCK        -- a block&lt;br /&gt;
&lt;br /&gt;
[[Image:Moodle-contexts-1.8.png|right|thumb|A diagram of the contexts in Moodle 1.8, based on the [[Talk:Roles_and_capabilities|text diagram by Martin Dougiamas]]. Click on the diagram to see a more detailed view of it.]]&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;
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;
Since the capabilities in each role could be different, there could be conflict in capabilities. This is resolved by enforcing the rule that the capability defined for a more specific context will win, unless a prohibit is encountered in a less specific context.&lt;br /&gt;
&lt;br /&gt;
For example, Mark has a student role at course level, which allows him to write into a wiki. But Mark also got assigned a Visitor role at a module context level (for a particular wiki) which prevents him from writing to the wiki (read only). Therefore, for this particular wiki, Mark will not be able to write to the wiki since the more specific context wins.&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;
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.&lt;br /&gt;
&lt;br /&gt;
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;
==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&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&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:managecateory - 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 [http://www.moodle.org/bugs/bug.php?op=show&amp;amp;bugid=6118&amp;amp;pos= bug 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 access.php inside the db folder 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;
    &#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;legacy&#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;admin&#039; =&amp;gt; CAP_ALLOW&lt;br /&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 get_context_instance() function.  For example, in the forum module:&lt;br /&gt;
&lt;br /&gt;
  $context = get_context_instance(CONTEXT_MODULE, $cm-&amp;gt;id);&lt;br /&gt;
* Then, whenever you want to check that the current user has rights to do something, call has_capability() like this:&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;
* 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 require_capability() like this:&lt;br /&gt;
&lt;br /&gt;
    require_capability(&#039;mod/forum:viewforum&#039;, $context);&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;
&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;
==Metacourses==&lt;br /&gt;
&lt;br /&gt;
The behaviour of metacourses in Moodle 1.7 changed slightly, in that where it used to just synch students from child courses to the parent course, it will now synch ALL roles. Teachers etc of the child courses will have the same role in the meta course. Technically metacourse synchronises all role assignments in CONTEXT_COURSE with its child courses; the only exception are users with moodle/course:managemetacourse capability, these users are synchronized only upwards, they are not unenrolled from metacourse when unenroling from child course or when removing the child from metacourse.&lt;br /&gt;
&lt;br /&gt;
In order to import/enrol other courses into metacoure you need to have moodle/course:managemetacourse capability. You can add manually only participants with moodle/course:managemetacourse, all other participants are automatically synced with child courses - if you try to manually enrol user without this capability error is displayed. Similar error is shown also when you try to manually unenrol participant from meta course while still being enrolled in child course.&lt;br /&gt;
&lt;br /&gt;
Sample setup:&lt;br /&gt;
* metacourse manager has been assigned role with moodle/course:managemetacourse capability in system or course category context&lt;br /&gt;
* students are enrolled in several child courses&lt;br /&gt;
* teachers are enrolled in separate child course(s)&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;Please add text here...&#039;&#039;&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=== An ALUMNUS should be able to search for all other ALUMNI of the school, interact with them and be enrolled in a seperate 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;
==Things to finish for 1.7 Beta==&lt;br /&gt;
&#039;&#039;&#039;18 Sept 2006&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
#Remove core references to user_student, user_teacher, user_admin, user_coursecreator tables.  [Yu]&lt;br /&gt;
#Address function: isteacher, isadmin, isstudent [Yu]&lt;br /&gt;
#Remove &amp;quot;view&amp;quot; capabilities from all modules unless required [Vy]&lt;br /&gt;
#Remove all old references from remaining Blocks [Vy]&lt;br /&gt;
#Metacourses [Skodak]&lt;br /&gt;
#Add risks to GUI[Skodak]&lt;br /&gt;
#Enrolment plugins  [Martin and Alastair]&lt;br /&gt;
#[[Stats_roles_1.7|Statistics]] [Penny]&lt;br /&gt;
#Fix Loginas&lt;br /&gt;
#Add category-level assigns [Yu]&lt;br /&gt;
#[[Backup_roles_1.7|Backups]] [Eloy?]&lt;br /&gt;
&lt;br /&gt;
===Proposal for interface enhancement===&lt;br /&gt;
Martin asked some questions, here are my answers. The sketches below are not worked out proposals. Their task is to visualize the idea. The exact colours and functionality may be defined after possible agreement about the proposals. The Green, orange and red columns support the meaning of the options from &amp;quot;allow&amp;quot; to &amp;quot;prohibit&amp;quot; (If you may want to see larger images please click onto the image or the &amp;quot;Enlarge&amp;quot; icon below the image.)&lt;br /&gt;
&lt;br /&gt;
The list of possible settings is very long and &#039;&#039; &amp;quot;... the problem is not to overwhelm people with information&amp;quot; &#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
[[Image:01_moodle_define_roles_structured.png|thumb=01_moodle_define_roles_structured_pre.png]]&lt;br /&gt;
&lt;br /&gt;
1) One proposal is to use colour to structure the sections and the columns. Picture 1 shows that the user can keep a much better overview when the list is divided into meaningful different coloured columns and clear sections.&lt;br /&gt;
&amp;lt;br style=&amp;quot;clear:both;&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Image:02_moodle_define_roles_collapsed.png|thumb=02_moodle_define_roles_collapsed_pre.png]]&lt;br /&gt;
&lt;br /&gt;
2) A second proposal is to reduce the amount of information the user is shown at the same time. The YUI interface library offers great support to show/hide sections of the page by clicking on specific elements. &lt;br /&gt;
&lt;br /&gt;
For example click on an icon beside the sub heading &amp;quot;Course categories&amp;quot; and show/hide all table rows with the CLASS &amp;quot;course-category&amp;quot;.&lt;br /&gt;
&amp;lt;br style=&amp;quot;clear:both;&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Image:03_moodle_define_roles_tooltip.png|thumb=03_moodle_define_roles_tooltip_pre.png]]&lt;br /&gt;
&lt;br /&gt;
3) &#039;&#039; &amp;quot;The main problem is the last column for risk ... we were thinking of putting little icons in there ...&amp;quot; &#039;&#039;&lt;br /&gt;
Icons are good when they tell the user more about possible actions/meanings then the letters. I am not sure if this is the case here. For both - icons or letters - the YUI tool-tip function would be able to give the user valuable information about the meaning.&lt;br /&gt;
&amp;lt;br style=&amp;quot;clear:both;&amp;quot; /&amp;gt;&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;
&lt;br /&gt;
[[Category:Roles]]&lt;br /&gt;
[[Category:Roles]]&lt;br /&gt;
&lt;br /&gt;
[[fr:Developpement:Roles]]&lt;/div&gt;</summary>
		<author><name>Vf</name></author>
	</entry>
</feed>