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

    Build a Hello World new module

    1. Download the NEWMODULE.zip (HEAD) from http://docs.moodle.org/en/Development:NEWMODULE_Documentation (or download here) (Follow the README.txt from the zip file! (not the tutorial at moodle.org, it is not for 2.0))
    2. Rename all occurrences of "NEWMODULE" to "widget" (or your new module name) of the all files in the zip (161 replacements) (Also rename "newmodule" to "widget" for unix system)
    3. Rename "NEWMODULE" folder to "widget"
    4. Rename lang\en\NEWMODULE.php to widget.php
    5. In version.php, modify $module->version to current date (you need to change the XX for each update). Comment this line: $module->version = 0
    6. Optional: In view.php, just before the footer(), add -> echo 'Hello World';
    7. Copy the widget folder to moodle\mod\
    8. Site Administration -> Notifications, when you see the new module, -> Update
    9. Done.
    Note: It seems there will be some problem if the last character of the module name is digital

      2011年1月18日 星期二

      Word censorship

      To enable: Site Administration -> Plugins -> Filters -> Manage filters -> Word Censorship -> On -> Content and headings

      You can add words in the "Settings" link.

      The file contains the censor words: moodle\filter\censor\lang\en\filter_censor.php

      2011年1月13日 星期四

      Run cron.php

      Moodle use cron.php to handle some routine tasks, i think we need to setup something to make this script run regularly.

      Simple enough, download and run MoodleCron-Setup.exe, it will install a windows service for you to handle the everything.

      You can also configure cron.php to be executed via command line (ie. cannot run by browser), and set up password: Site administration -> Security -> Site policies

      For more details, come here:
      http://docs.moodle.org/en/Cron#Managing_Cron_on_Windows_systems

      Why no email is received from a subscribed forum?

      It is all because the cron.php does not run. The cron.php is for the regular tasks need to be done, including sending these emails.

      You can run the cron.php manual by this url: (oops, it can be run by everyone)
      http://yoursite/admin/cron.php

      I think we should make the cron.php run regularly, this is what i have done. Anyway, here is more detail about the cron.php:
      http://docs.moodle.org/en/Cron

      User cannot update their email address

      I don't understand the reason behide, but it does not work!

      Here is the discussion of this issue, it seems there is a solution but i have not tried yet:
      http://moodle.org/mod/forum/discuss.php?d=161993&parent=711518

      2011年1月10日 星期一

      Redirect to user course after login

      Aim: When I login to Moodle, the system will redirect the user to his last accessed course.

      Add the following code to \moodle\login\index.php (just before the "Go to my-moodle page instead of site homepage if defaulthomepage set to homepage_my" comment):

      ==================================================
      //redirect user to his course (ignore if it is his first time login)
         if ( !empty( $user->lastcourseaccess ) ) {
            $mostRecent = 0;
            $mostRecentCourse = 0;
            foreach ( $user->lastcourseaccess as $k => $v ) {
               if ( $v > $mostRecent ) {
                  $mostRecent = $v;
                  $mostRecentCourse = $k;
               }
            }
            if ( $mostRecent != 0 ) {
               $urltogo = $CFG->wwwroot.'/course/view.php?id='.$mostRecentCourse;
            }
         }
      }

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

      Add Login form on the Front Page

      Simple!
      1. Turn editing on
      2. Add a block -> Login
      3. Done!
      I have tried adding the Login form at the middle of the page (as a label), but it is no good. It is difficult to remove the Login form after login! The role/permission settings is not good.

      How to create a clean, 1 column Front Page

      I want to make a very clean first page.

      By first page, i mean the front page that the users first landed without login.

      By clean, i mean only the site title, the login link and some description text.

      This is what i want:

      Here are the steps:
      1. Site administration -> Front page -> Front page settings
      2. Clear all "Front page" combo box
      3. Clear all "Front page items when logged in" combo box
      4. Check "Include a topic section"
      5. Click "Save changes"
      6. Back to "Home"
      7. Front page Settings -> Turn editing on
      8. For Navigation block, click "Configuration", select "No" for On this page: Visible
      9. Click "Save changes"
      10. Hide or Delete all other blocks that are visible by other users
      11. Back to "Home"
      12. Add a resource: Label, just type some contents and save
      13. Done!
      Reference: Moodle site

      2011年1月9日 星期日

      Resource: Page

      "Page" resource is good to create a page for information

      Moodle 2.0 window installation package

      The installation packages of Moodle 2.0 for Windows is finally out! (It is already out for a few weeks)

      We don't need to install the Apache+PHP+Mysql by ourself now.

      Download page:
      http://download.moodle.org/windows/

      What is Front page questions?

      We can access "Question bank" from here. Question bank is used to create question template or standard questions.

      Please noted that moodle treats Front page as a course.

      What is this web log about?

      I am a newbie for moodle. Just start working on moodle project.

      This blog will record the problem that i have encountered during my development, and if possible, the solution.

      I will also drop developing notes here, so that i can come back to see what i have already done. (No need to re-invent the FORGOTTEN wheel)

      btw, I am working on Moodle 2.0.