<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
	<id>http://wiki.mipt.ru/index.php?action=history&amp;feed=atom&amp;title=Development%3ADatabase_fields</id>
	<title>Development:Database fields - История изменений</title>
	<link rel="self" type="application/atom+xml" href="http://wiki.mipt.ru/index.php?action=history&amp;feed=atom&amp;title=Development%3ADatabase_fields"/>
	<link rel="alternate" type="text/html" href="http://wiki.mipt.ru/index.php?title=Development:Database_fields&amp;action=history"/>
	<updated>2026-05-06T16:37:04Z</updated>
	<subtitle>История изменений этой страницы в вики</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>http://wiki.mipt.ru/index.php?title=Development:Database_fields&amp;diff=11016&amp;oldid=prev</id>
		<title>Олег Давидович: 1 версия импортирована</title>
		<link rel="alternate" type="text/html" href="http://wiki.mipt.ru/index.php?title=Development:Database_fields&amp;diff=11016&amp;oldid=prev"/>
		<updated>2024-10-21T08:51:09Z</updated>

		<summary type="html">&lt;p&gt;1 версия импортирована&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Предыдущая версия&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Версия от 08:51, 21 октября 2024&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Олег Давидович</name></author>
	</entry>
	<entry>
		<id>http://wiki.mipt.ru/index.php?title=Development:Database_fields&amp;diff=11015&amp;oldid=prev</id>
		<title>1&gt;Topstone: link to Japanese page</title>
		<link rel="alternate" type="text/html" href="http://wiki.mipt.ru/index.php?title=Development:Database_fields&amp;diff=11015&amp;oldid=prev"/>
		<updated>2008-09-06T14:30:06Z</updated>

		<summary type="html">&lt;p&gt;link to Japanese page&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Moodle&amp;#039;s [[Database module]] has some predefined [[Database_fields|field types]] (text, date, URL, picture, etc), but you can customise this to create new field types. For example, you might like to create:&lt;br /&gt;
&lt;br /&gt;
; Discipline-specific field types : e.g. &amp;quot;Protein PDB code&amp;quot; - people can enter the PDB code for a protein, and then the display could (for example) include a 3D viewer for the protein structure, or link out to molecular databases.&lt;br /&gt;
; Institution-specific field types :  e.g. &amp;quot;library reference number&amp;quot; - people can enter a number into the field, and this is automatically turned into a direct link to your library webpages&lt;br /&gt;
; Module-specific field types : e.g. &amp;quot;wiki page&amp;quot; - people see a drop-down list containing the names of pages in your wiki, and can choose which page this particular entry refers to&lt;br /&gt;
&lt;br /&gt;
==Basic concepts==&lt;br /&gt;
&lt;br /&gt;
To create a new field type in Moodle we need to create a new folder in /moodle/mod/data/field. Inside this folder will be PHP code telling Moodle:&lt;br /&gt;
&lt;br /&gt;
# What HTML to output when people are looking at a record in the database&lt;br /&gt;
# What form fields to output when people are adding/editing a record in the database&lt;br /&gt;
# What to do (what info to store) when someone submits the record-add/edit form&lt;br /&gt;
# What form fields to output when the teacher is adding/editing an instance of the field&lt;br /&gt;
# What to do (what info to store) when the teacher submits the field-add/edit form&lt;br /&gt;
&lt;br /&gt;
==The files==&lt;br /&gt;
&lt;br /&gt;
The best way to get an understanding of the plugin architecture is to look at an existing field type - I recommend you look at &amp;#039;&amp;#039;&amp;#039;the URL field type&amp;#039;&amp;#039;&amp;#039;, stored in /moodle/mod/data/field/url. There are three files:&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;field.class.php&amp;#039;&amp;#039;&amp;#039; - the most important file, this defines a PHP class which defines the majority of the data field&amp;#039;s behaviour. See below for more detail on this.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;mod.html&amp;#039;&amp;#039;&amp;#039; - contains a HTML &amp;quot;fragment&amp;quot; defining how the form fields will appear when the teacher is adding/editing an instance of the field.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;icon.gif&amp;#039;&amp;#039;&amp;#039; - the icon to be displayed along with the field, as a visual cue to the teacher about what sort of data is stored in this field.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The PHP class==&lt;br /&gt;
&lt;br /&gt;
If you look at the file &amp;quot;field.class.php&amp;quot; for the URL field type you&amp;#039;ll see that the class is named &amp;quot;data_field_url&amp;quot; and it is a subclass of &amp;quot;data_field_base&amp;quot;. This is very important - the class &amp;quot;data_field_base&amp;quot; (defined in /moodle/mod/data/lib.php, by the way) defines some of the core behaviours without which your field will not work.&lt;br /&gt;
&lt;br /&gt;
Your class&amp;#039;s name should match the subfolder you have created. For example, if we&amp;#039;re creating a new data type called &amp;quot;Tastiness&amp;quot;, we want to create our plugin in a folder &amp;quot;tastiness&amp;quot; and the PHP class should be data_field_tastiness. The class should also define a class variable $type, which again should use the same name - in our example, we&amp;#039;d give it the value &amp;#039;tastiness&amp;#039;. So the top of our field.class.php would look like this:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;?php &lt;br /&gt;
 class data_field_tastiness extends data_field_base {&lt;br /&gt;
    var $type = &amp;#039;tastiness&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you want to take an existing field type, duplicate it, and rename it to a new type (which you can modify later), this is all you need to do. You might like to try this (again, the URL field is a good one to start with) and see how it works.&lt;br /&gt;
&lt;br /&gt;
The base class defines some simple behaviours which you can override in your subclass, to make the plugin do exactly what you want. For example:&lt;br /&gt;
&lt;br /&gt;
 function display_add_field($recordid=0) // Return some HTML for use when a user is adding/editing a record&lt;br /&gt;
 function display_browse_field($recordid, $template) // Return some HTML for displaying a record&lt;br /&gt;
 function update_content($recordid, $value, $name=&amp;#039;&amp;#039;) // Used when a user stores data for a record&lt;br /&gt;
 function get_sort_sql($fieldname) // Specify SQL for how this field should be sorted&lt;br /&gt;
&lt;br /&gt;
If you don&amp;#039;t bother to specify these functions inside your new class, then the default behaviours specified by data_field_base will be used. Simply add these functions to your new class to make something different happen. &lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;To be continued...&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer]]&lt;br /&gt;
&lt;br /&gt;
[[ja:データベースフィールド]]&lt;/div&gt;</summary>
		<author><name>1&gt;Topstone</name></author>
	</entry>
</feed>