Note:

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

Blocks/Appendix C

From MoodleDocs
Revision as of 18:09, 26 January 2009 by Frank Ralf (talk | contribs) (New page: == Creating Database Tables for Blocks == '''The following describes what to do in Moodle <= 1.6. For Moodle >= 1.7, you need to use XMLDB, that is, cr...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Creating Database Tables for Blocks

The following describes what to do in Moodle <= 1.6. For Moodle >= 1.7, you need to use XMLDB, that is, create an install.xml file, instead of *.sql files.

You can easily create a database table for your block by adding two files mysql.sql and postgres7.sql to a subdirectory db/ of your block. The tables HAVE TO be named the same way as the block (e.g. block_rss2_feeds) otherwise moodle will not be able to drop the table upon removal of the block from the system. Here is an example for mysql.sql:

CREATE TABLE prefix_rss2_feeds (

`id` int(11) NOT NULL auto_increment,
`userid` int(11) NOT NULL default '0',
`title` text NOT NULL default ,
`description` text NOT NULL default ,
`url` varchar(255) NOT NULL default ,
`pingbacktokenurl` varchar(255) NOT NULL default ,
PRIMARY KEY  (`id`)

) TYPE=MyISAM COMMENT='Remote news feed information.';

Pay attention that, furthermore, you might want to add a mysql.php and postgres7.php page that contains update routines for upgrading the database tables with evolving version numbers of the block. In case you use that be sure that you provide the necessary structure (again function name should be like the block name + "_upgrade"!). Here is an example:

function rss_pingback_upgrade( $oldversion ) {

   global $CFG;
   if ($oldversion < 2003111500) {
      # Do something ...
   }
   return true;

}