Note:

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

Blocks/Appendix C: Difference between revisions

From MoodleDocs
(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...)
 
No edit summary
(4 intermediate revisions by one other user not shown)
Line 1: Line 1:
== Creating Database Tables for Blocks ==
{{obsolete}}== Creating Database Tables for Blocks ==


'''The following describes what to do in Moodle <= 1.6. For Moodle >= 1.7, you need to use [[XMLDB_Documentation|XMLDB]], that is, create an install.xml file, instead of *.sql files.'''
=== Important Note: ===
 
The following describes what to do in Moodle <= 1.6. For Moodle >= 1.7, you need to use [[XMLDB_Documentation|XMLDB]], that is, create an '''install.xml''' file, instead of *.sql files.  
 
(See also [https://docs.moodle.org/en/Category:XMLDB Category:XMLDB].)
 
=== For Moodle <= 1.6 ===


You can easily create a database table for your block by adding
You can easily create a database table for your block by adding
two files mysql.sql and postgres7.sql to a subdirectory db/ of
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
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
block (e.g. block_rss2_feeds) otherwise Moodle will not be able
to drop the table upon removal of the block from the system.
to drop the table upon removal of the block from the system.
Here is an example for mysql.sql:
Here is an example for '''mysql.sql''':


<code php>
CREATE TABLE prefix_rss2_feeds (
CREATE TABLE prefix_rss2_feeds (
  `id` int(11) NOT NULL auto_increment,
  `id` int(11) NOT NULL auto_increment,
Line 19: Line 26:
  PRIMARY KEY  (`id`)
  PRIMARY KEY  (`id`)
) TYPE=MyISAM  COMMENT='Remote news feed information.';
) TYPE=MyISAM  COMMENT='Remote news feed information.';
</code>


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


<code php>
function rss_pingback_upgrade( $oldversion ) {
function rss_pingback_upgrade( $oldversion ) {
    global $CFG;
  global $CFG;
    if ($oldversion < 2003111500) {
  if ($oldversion < 2003111500) {
      # Do something ...
    // Do something ...
    }
  }
    return true;
  return TRUE;
}
}
</code>
[[es:Desarrollo de bloques]]

Revision as of 12:43, 10 November 2013

Warning: This page is no longer in use. The information contained on the page should NOT be seen as relevant or reliable.

Creating Database Tables for Blocks

Important Note:

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.

(See also Category:XMLDB.)

For Moodle <= 1.6

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;

}