2011年3月14日 星期一

Set up role permission

First, add this to \mod\your_module\db\access.php (after line $capabilities = array( )
    'mod/your_module:view' => array(
        'captype' => 'read',
        'contextlevel' => CONTEXT_MODULE,
        'legacy' => array(
            'teacher' => CAP_ALLOW
        )
    )

Open \mod\your_module\lang\en\your_module.php, add this line:
$string['your_module:view'] = 'View your module';

Change version.php to new version, and then goto Notification.

Use this to test the permission:
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
has_capability('mod/your_module:view', $context)

2011年3月12日 星期六

2011年3月10日 星期四

Make new module with groupING

In mod_form.php, add this line:
$this->_features->groupings = true;

Note: But i still wonder why others module don't add this line but they are still available for groupING, any idea?

2011年3月8日 星期二

Add a table to Module Database

  1. Site administration -> Development -> XMLDB editor
  2. Find your module and click [Load]
  3. Click [Edit]
  4. Click [New table] and fill in the detail
  5. Click [Back]
  6. Click [View PHP code]
  7. Select action: create table
  8. Select table: select your table 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

2011年2月27日 星期日

Create a new format

  1. Goto course/format/ (read the README.txt there)
  2. Copy topics folder to a new folder (e.g. yourformat)
  3. Goto yourformat/lang/en/
  4. Rename "format_topics.php" to "format_yourformat.php"
  5. Open format_yourformat.php
  6. Change the $string
  7. Done.
Note: course/format/yourformat/format.php is the file for output view

    2011年2月22日 星期二

    Add new field to user profile

    Site administration -> Users -> Accounts -> User profile fields

    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