Creating New Module

Creating New Module

di Johnathon Doherty -
Numero di risposte: 7

Hi everyone,

Im currently attempting to make a new module, but need a little bit of help on where to begin. I've downloaded the New Module Template, but I am having trouble following the various functions to their sources to learn what they do (there's so many....). I tried using the moodle xref page, but none of the functions have any descriptions. Right now Im trying to figure out how moodle creates new modules. I've managed to get it to recognise the new module, but I dont know how to customize the information required on the creation form. Right now the only things there are those that come with the New Module Template.

Any help you guys could give me would be fantastic.

Media dei voti: -
In riposta a Johnathon Doherty

Re: Creating New Module

di Jan Dierckx -

Every module has a file mod.html. You can customize the information required on the creation form, by adding fields to mod.html

The xref is outdated. If you are using vim or emacs you can lookup functions using the tags file included with Moodle That way you can lookup functions in the same screen you are editing. There is also a way to autocomplete Moodle functions.

Vim is a real timesaver once you get to know how to use it. Cream for Vim makes it a little bit easier to use.

In riposta a Jan Dierckx

Re: Creating New Module

di Johnathon Doherty -
Thanks. I'd managed to figure out that the mod.html is used in the create page. However, Im having a difficult time understanding exactly how it does that, how the page is actually constructed with the appropriate inputs and how it stores the information to the database.

Another thing, I managed to get moodle to add my module. But when I click "Add an Activity" the name appears as modulename. Im assuming this will be fixed once the database entries are made from the db/ folder?

I guess Im just having a hard time tying all these loose ends togetter and working out so many intricate interfaces.
In riposta a Johnathon Doherty

Re: Creating New Module

di Jan Dierckx -
  • Take a look at some of the mysql.sql files inside the db/ folder of exisiting modules. This is where you can include the sql instructions for the tables and fields you want your module to use. If you use the same names for the fields in mod.html the file moodle/course/mod.php will write these values to the database.

  • The name appears as modulename because you haven't added a file with language strings inside moodle/lang/en/ Don't worry. It doesn't influence the working of your code. You can always add it later when it is finished. See the coding guide

HTH

In riposta a Jan Dierckx

Re: Creating New Module

di Johnathon Doherty -
Thanks, thats quite useful. So how does the create page actually store the information it collects to the database? And how does it know whether to display an 'update' page or a new 'create' page?
In riposta a Jan Dierckx

Re: Creating New Module

di Samuli Karevaara -
Jan, are you using the tags file functionality with Cream? I installed Cream (WindowsXP), and jumping to one tag works, but jumping to a second one says that "a working installation of ctags is required". Also, the tag navigation function "Close and go back" doesn't work at all.

There seems to be very little documentation on Cream itself, the FAQ didn't give out anything and other help files are for Vim itself.

I downloaded ctags from ctags.sf.net but couldn't fiqure out what "installing" means for it. Putting it in PATH or in the same folder with Vim/Cream didn't do the trick, and I couldn't find any help with Google either...
In riposta a Samuli Karevaara

Re: Creating New Module

di Jan Dierckx -

Cream sure is lacking some documentation. I use vim, but Cream is just vim with some extra functions to make it behave more like a standard editor. In particular it removes vim's modal editing. (Vim uses different modes. Very confusing when I started using it, but now I like it because it means less switching from mouse to keyboard and back.)

To use the tags functionality you need:

  1. an editor with tags functionality

    I am using vim, but Cream is just vim with some extra stuff added to it. I'm sure it also has tags functionality, although it uses other keyboard shortcuts to use it. On the website it says Alt+ArrowDown to go to the tag under the cursor and Alt+ArrowUp to get back again. In vim this would be CTRL+] and CTRL+T.

  2. a file with a list of all the tags

    This might be related to the error you receive about ctags not installed. ctags is a program to create the tags. Good news is: you don't need to create the tags file, because it is included with every Moodle installation. So you don't need to install ctags. But why doesn't Cream use the tags file that comes with Moodle? We also need ...

  3. a way to tell the editor where this tags file is

    In vim I just use the command that Martin provided in his answer to Gustav:

    set tags=../../../../../tags,../../../../tags,../../../tags,../../tags,../tags,./tags,tags

    Don't worry. There is no need to type this everytime. You can include this in a file called _vimrc which is executed everytime Vim starts.

    Ay, there's the rub. I'm not sure which file Cream uses. But I think I've found a way to enter this command directly. To do this in Cream:

  • Type CTRL-L to get to Vim's normal mode

  • Type :set tags=../../../../../tags,../../../../tags,../../../tags,../../tags,../tags,./tags,tags

  • Hit Enter

  • Hit ESC

Tell me if this makes tags work in Cream. If it does, we can look for a way to automatically execute the command everytime Cream is started.

In riposta a Jan Dierckx

Re: Creating New Module

di Samuli Karevaara -
It's the same as before: I can jump to one tag, but no further. Also, the "go back" doesn't work. As if the "tag stack" is not activated? (If there is such a thing...) Regular Vim (more precisely gVim) works as expected. Though I have a problem with it also, with Ctrl-]. My keyboard has ] in AltGr-9, and the AltGr seems to throw Vim off course. I re-mapped it to Ctrl-J and it works nicely.

I put Cream aside for now, going with the regular gVim...