2011年2月22日 星期二

Add a field to Module Update page

By Module Update page, i mean the page shown when you add a new activity or update it.

Note: You should add a field to the database first if you want to save the entered field information.

  1. Open mod\your_mod\mod_form.php
  2. Add this line: $mform->addElement('text', 'your_field', 'label_shown', array('size'=>'64'));
  3. Done

Note2: your_field is the field name in the database of table mdl_your_mod, the field information will save to the table

Note3: To show the field, just use $your_mod->your_field

Add a field to Module Database

  1. Site administration -> Development -> XMLDB editor
  2. Find your module and click [Load]
  3. Click [Edit]
  4. At the Tables section, click the table you want to add field
  5. Click [New field] and fill in the detail
  6. [View PHP code]
  7. Select action: add field
  8. Select field/key/index: your_new_field_name
  9. Click "View"
  10. Copy the code to mod/your_mod/db/upgrade.php
  11. Change XXXXXXXXXX to new version number (e.g. 2011022301)
  12. Open mod/your_mod/version.php, change $module->version to the new version number
  13. Notification 
  14. Done

A good way to print message

Use: print_string( 'the_message', 'your_module_name' );

Then, at mod\your_mod\lang\en\your_mod.php, add:
$string[ 'the_message' ] = 'Welcome!!!';

Remove a Module

  1. Goto: Site administration -> Plugins -> Activity modules -> Manage activities
  2. Find your module and click Delete
  3. Remove the module from mod/ folder
  4. Done

2011年2月17日 星期四

Show Block on My Moodle page

By default, some of the blocks cannot be shown on My Moodle page. However, we can force them, but you need to take the risk that the block may be work on My Moodle page. (e.g. some course level functions)

  1. Go to blocks/your_block/ folder
  2. Edit block_your_block.php
  3. Go to function applicable_formats()
  4. Change "'my' => false" to "'my' => true"
  5. Done.

Redirect to My Moodle page after login

Site administrator -> Appearance -> Navigation -> Default home page for users -> My Moodle

2011年1月27日 星期四

GD problem

If you cannot find the upload picture area in moodle, there is a chance that the GD module does not installed to the PHP.

You can check by: Site administration -> Server -> PHP info (if it is installed, you will find the word "gd" somewhere on the page)


If GD is not installed:
1) If you are in Windows platform, go to php.ini, uncomment the line "extension=php_gd2.dll"
2) If you are unix platform, you need to reinstall php with "--with-gd" option


After installation, go to Site administration -> Server -> System paths, change GD version to "GD 2.x installed".

Good Luck! (It can be a big task!)