Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Development:Developer FAQ: Difference between revisions

From MoodleDocs
m (Developer FAQ moved to Development:Developer FAQ)
m (56 revisions)
(41 intermediate revisions by 12 users not shown)
Line 1: Line 1:
{{FAQ}}
==Help for new coders==


==Help for new coders==
===Where can I start?===
 
* [[Development:Finding your way into the Moodle code]]
* [http://dev.moodle.org/ Moodle Developer Courses]


===Where can "newbies" to Moodle get help?===
===Where can "newbies" to Moodle get help?===


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.
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.
===How do I create a patch?===
See [[Development:How to create a patch]].
=== How do I create a new module or plugin? ===
See
* [[Development:NEWMODULE Documentation]]
* [[Development:Blocks]]
* [[Development:Authentication plugins]]
* [[Development:Developer_documentation#Make_a_new_plugin|full list of plugin types]].
* Also have a look at the [http://dev.moodle.org/ Moodle Developer Courses].
; Book
: [https://www.packtpub.com/moodle-1-9-extension-development/book Moodle 1.9 Extension Development - Customize and extend Moodle using its robust plug-in systems] by Jonathan Moore, Michael Churchward - highly recommended
===Is there any information on backup and restore?===
See [[Development:Backup]].
==I can't use one of the available plug-in points to make my change. What alternative is there?==
See [[Development:Local customisation]].


==Moodle's database==
==Moodle's database==
Line 11: Line 38:
===Where can I see a schema for the structure of the Moodle database?===
===Where can I see a schema for the structure of the Moodle database?===


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.
[[Development:Database_schema_introduction]] gives a high level overview of the database schema.


The reason that the database information isn't stored in one place is because of Moodle's '''modular structure'''. 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 "db" subfolder which define and update the database structure.
Because of Moodle's modular nature, there is no single, detailed representation of the full database schema. Instead, the tables for each part of Moodle are defined in a database-neutral XML format, see [[Database_FAQ#XMLDB| XMLDB]], in each part of Moodle. Look for files called install.xml in folders called db throughout the code. Alternatively, from Moodle 2.0 onwards, go to Administration -> Development -> XMLDB editor, and use the [Doc] links to see automatically generated documentation built form the comments in the install.xml files.
 
See also [[Database FAQ]].


==How to get/set information when writing new Moodle code==
==How to get/set information when writing new Moodle code==
Line 28: Line 57:
Always use the "datalib" 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.
Always use the "datalib" 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.


Look at [http://moodle.sourceforge.net/dhawes-phpdoc/moodlecore/_lib_datalib_php.html the documentation for datalib.php] for the list of functions and details of use.
See [http://xref.moodle.org/nav.html?lib/datalib.php.html /lib/datalib.php] for higher level functions and [http://xref.moodle.org/nav.html?lib/dmllib.php.html /lib/dmllib.php] for lower level functions.
 
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.
 
See [[Development talk:Coding style#Database code]] for further details.


===How do I get/set configuration settings?===
===How do I get/set configuration settings?===


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 "main" config values use set_config($name, $value). The values are stored in the Moodle "config" database table, but these functions take care of cacheing on your behalf, so you should always use these rather than fetching the records directly.
;config table
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 "main" config values use ''set_config($name, $value)''. The values are stored in the Moodle "config" database table, but these functions take care of cacheing on your behalf, so you should always use these rather than fetching the records directly.


;config_plugin table
There is also a second table of config settings specifically for plugins ("config_plugin"). 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).
There is also a second table of config settings specifically for plugins ("config_plugin"). 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).


On top of those global configuration values, individual blocks may also have configuration "object" associated with it (the data is serialized and stored in the "block_instance" table). Within blocks, this data is automatically loaded into the <tt>config</tt> attribute of the block.
==What is 'HEAD'?==
HEAD is version control jargon for the latest version, so at the moment it means Moodle 2.0 dev version. (After the Moodle 2.0 stable branch is made, HEAD will mean 2.1 dev). Look for example, at the links at the top of http://cvs.moodle.org/moodle/README.txt?view=log&pathrev=MOODLE_19_STABLE You can get it from http://download.moodle.org/ and install it if you want to play.
== How do I migrate code to Moodle 2.0? ==
* See [[Development:Migrating contrib code to 2.0]]
==See also==
*[[Contributed code FAQ]]
*Using Moodle [http://moodle.org/mod/forum/view.php?f=33 General developer forum]
Using Moodle forum discussions:
*[http://moodle.org/mod/forum/discuss.php?d=55719 How does date / time in DB convert to real Date / Time?]
*[http://moodle.org/mod/forum/discuss.php?d=158521 Why git?]


[[Category: Developer]]
[[Category: Developer]]
Line 41: Line 93:


[[es:FAQ Desarrollador]]
[[es:FAQ Desarrollador]]
[[fr:FAQ de développement]]
[[pl:Developer FAQ]]
[[ru:Development:Developer FAQ]]

Revision as of 06:43, 21 September 2011

Help for new coders

Where can I start?

Where can "newbies" to Moodle get help?

The 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.

How do I create a patch?

See Development:How to create a patch.

How do I create a new module or plugin?

See

Book
Moodle 1.9 Extension Development - Customize and extend Moodle using its robust plug-in systems by Jonathan Moore, Michael Churchward - highly recommended

Is there any information on backup and restore?

See Development:Backup.

I can't use one of the available plug-in points to make my change. What alternative is there?

See Development:Local customisation.

Moodle's database

Where can I see a schema for the structure of the Moodle database?

Development:Database_schema_introduction gives a high level overview of the database schema.

Because of Moodle's modular nature, there is no single, detailed representation of the full database schema. Instead, the tables for each part of Moodle are defined in a database-neutral XML format, see XMLDB, in each part of Moodle. Look for files called install.xml in folders called db throughout the code. Alternatively, from Moodle 2.0 onwards, go to Administration -> Development -> XMLDB editor, and use the [Doc] links to see automatically generated documentation built form the comments in the install.xml files.

See also Database FAQ.

How to get/set information when writing new Moodle code

How do I find out the currently-logged-on user?

The global object $USER, which contains the numeric $USER->id among other things.

How do I find out the current course?

The global object $COURSE, which contains the numeric $COURSE->id

How do I insert/retrieve records in the database, without creating my own database connections?

Always use the "datalib" 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.

See /lib/datalib.php for higher level functions and /lib/dmllib.php for lower level functions.

Look at the documentation for datalib.php for the list of functions and details of use.

See Development talk:Coding style#Database code for further details.

How do I get/set configuration settings?

config table

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 "main" config values use set_config($name, $value). The values are stored in the Moodle "config" database table, but these functions take care of cacheing on your behalf, so you should always use these rather than fetching the records directly.

config_plugin table

There is also a second table of config settings specifically for plugins ("config_plugin"). 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).

On top of those global configuration values, individual blocks may also have configuration "object" associated with it (the data is serialized and stored in the "block_instance" table). Within blocks, this data is automatically loaded into the config attribute of the block.

What is 'HEAD'?

HEAD is version control jargon for the latest version, so at the moment it means Moodle 2.0 dev version. (After the Moodle 2.0 stable branch is made, HEAD will mean 2.1 dev). Look for example, at the links at the top of http://cvs.moodle.org/moodle/README.txt?view=log&pathrev=MOODLE_19_STABLE You can get it from http://download.moodle.org/ and install it if you want to play.

How do I migrate code to Moodle 2.0?

See also

Using Moodle forum discussions:

pl:Developer FAQ ru:Development:Developer FAQ