2011年4月3日 星期日

Add a style (CSS)

  1. Open \theme\standard\config.php (assume you are using "standard" theme)
  2. Find the last element of $THEME->sheets (should be css3 if you have not done anything yet)
  3. Open \theme\standard\style\css3.css and add your css code
  4. Goto \moodledata\cache\theme\standard\css and delete all files (anyone have a better way?)
  5. Done

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

    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!)

    2011年1月26日 星期三

    Create a new block

    Assume the new block name is your_new_block:
    1. Got to moodle/blocks/
    2. Create a folder: your_new_block
    3. Copy blog_menu/*.* to your_new_block/ (as blog_menu is a simple block)
    4. Go to your_new_block folder
    5. Rename block_blog_menu.php to block_your_new_block.php
    6. Open block_your_new_block.php
    7. Remove the "require_once" line at the top
    8. Change "class block_blog_menu extends block_base {" to "class block_your_new_block extends block_base {"
    9. In init(), change "$this->title = get_string('pluginname', 'block_blog_menu');" to "$this->title = get_string('pluginname', 'block_your_new_block');"
    10. In get_content(), you can delete from "* Prepare the content for this block" to "// Return the content object", just keep the last return line.
    11. All you have to do is fill in $this->content->text = "Your block content html";
    12. Go to lang\en\ folder
    13. Rename block_blog_menu.php to block_your_new_block.php
    14. Open the file, change "$string['pluginname'] = 'Blog menu';" to your block displace name
    15. Notifications
    16. Done

    Batch add new users

    Goto: Site administration -> Users -> Accounts -> Upload users

    Using the following file format:
    ==================================================
    username, password, firstname, lastname, email
    is1, shtm1234, Susan, Ng, susan@localhost.com
    is2, shtm1234, Ann, Chan, ann@localhost.com

    ==================================================

    How to change the Password Policy

    Site administration -> Security -> Site policies

    2011年1月25日 星期二

    How to get the student list of a course

    global $COURSE, $DB, $OUTPUT;
    $context = get_context_instance( CONTEXT_COURSE, $COURSE->id );

    $query = 'select u.id as id, firstname, lastname, picture, imagealt, email from mdl_role_assignments as a, mdl_user as u where contextid=' . $context->id . ' and roleid=5 and a.userid=u.id;';

    $rs = $DB->get_recordset_sql( $query );
    foreach( $rs as $r ) {
       echo $OUTPUT->user_picture($r, array('size' => 50, 'courseid'=>$COURSE->id));
       echo $r->firstname . ' ' . $r->lastname . '<br>';
    }

    Access phpMyAdmin

    Browse to: http://localhost/admin/mysql/

    (Not all installation package get this)

    2011年1月24日 星期一

    No more Topic Section for Topics format

    What i am trying to do is to hide all the topics when we are using the "Topics format".
    1. Open moodle\course\format\topics\format.php
    2. uncomment started from "/// Now all the normal modules by topic" to the end of the while loop (Just before "if (!displaysection and...") (from line 135 to 260)
    3. Done