We have just finished upacking our Moodle Module Template!
If we inspect the contents of our new directory, it's really not very assuming:

FIRST ORDER OF BUSINESS - MAKE THE PLUG-IN PLUGGABLE!
STEP 1 - the install.xml file
A plug-in is only a plug-in if we have "plugged it in". In Moodle, we accomplish this by registering the Module in the Moodle database. Towards this end, we focus on a single file in the package - the install.xml file.
It is located in the .\NEWMODULE\db\ directory.
So, I load it up in my trusty Notepad++ (here's a gratuitous plug for this great GPL editor: Notepad++ Home Page) and notice that install.xml is nothing but an XMLDB file. The file should something like this when you load it into your editor:

Click Image To Zoom
THE MODULE'S XMLDB FILE CAN BE EDITED USING MOODLE'S XMLDB EDITOR
This is the preferred method, and is covered in the post listed below. The editor is available after the module has been copied to the Moodle .\mod directory, so instructions for modifying the file manually are also provided below.
To learn a little about the XMLDB editor, VISIT THE XMLDB EDITOR ARTICLE.
TO EDIT THE XMLDB FILE MANUALLY:
I run a search & replace for the word "newmodule" and replace it with my module's name: inyourface. For version 1.9, it should result in 12 replacements.
We can also change the comments in the file, but we will save that for later. Before we can test our module, we still have a little more work to do!!! We will cover these steps in the next post.
CONTENTS OF install.xml after changes:
<?xml version="1.0" encoding="UTF-8" >
<XMLDB PATH="mod/inyourface/db" VERSION="20070401" COMMENT="XMLDB file for Moodle mod/inyourface"
xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
<TABLES>
<TABLE NAME="inyourface" COMMENT="Default comment for inyourface, please edit me">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="course"/>
<FIELD NAME="course" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="Course inyourface activity belongs to" PREVIOUS="id" NEXT="name"/>
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" ENUM="false" COMMENT="name field for moodle instances" PREVIOUS="course" NEXT="intro"/>
<FIELD NAME="intro" TYPE="text" LENGTH="medium" NOTNULL="false" SEQUENCE="false" ENUM="false" COMMENT="General introduction of the inyourface activity" PREVIOUS="name" NEXT="introformat"/>
<FIELD NAME="introformat" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="Format of the intro field (MOODLE, HTML, MARKDOWN...)" PREVIOUS="intro" NEXT="timecreated"/>
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="introformat" NEXT="timemodified"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="timecreated"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
</KEYS>
<INDEXES>
<INDEX NAME="course" UNIQUE="false" FIELDS="course"/>
</INDEXES>
</TABLE>
</TABLES>
<STATEMENTS>
<STATEMENT NAME="insert log_display" TYPE="insert" TABLE="log_display" COMMENT="Initial insert of records on table log_display. Each record describes how data will be showed by log reports.">
<SENTENCES>
<SENTENCE TEXT="(module, action, mtable, field) VALUES ('inyourface', 'add', 'inyourface', 'name')" />
<SENTENCE TEXT="(module, action, mtable, field) VALUES ('inyourface', 'update', 'inyourface', 'name')" />
<SENTENCE TEXT="(module, action, mtable, field) VALUES ('inyourface', 'view', 'inyourface', 'name')" />
</SENTENCES>
</STATEMENT>
</STATEMENTS>
</XMLDB>
NEXT ARTICLE IN SERIES
You might find it easier to use Moodle's built-in XMLDB editor to edit the database, rather than editing the XML file manually (where there's more scope for human error).
ReplyDeleteI agree. I wanted to illustrate the contents of the file, and introduce the XMLDB editor in a totally separate session - when the first upgrade of the module becomes necessary.
ReplyDeleteOnce that is available, I can place a link here, along with a reference to XMLDB editor documentation.
Thanks - good catch.
Hi there.. what means the "SEQUENCE" attribute? Where can i find a good tutorial explain all attributes? i don't know how to use the xmldb editor .. thanks
ReplyDelete