Moodle插件开发笔记14: Activity module开发(二)

Step 2 修改mod_form.php (important)     mod_form.php提供了当teacher create a new modul…

Step 2 修改mod_form.php (important)

    mod_form.php提供了当teacher create a new module instance时出现的form interface,teacher可以在该form输入对该module instance的setting。
     mod_form.php要定义一个mod_<MODULE NAME>_mod_form class,该class需要extend moodleform_mod class.
require_once ($CFG->dirroot.’/course/moodleform_mod.php’);
class mod_bulletin_mod_form extends moodleform_mod {
    在mod_bulletin_mod_form class里,需要定义“definition”函数,并在该函数里创建窗体的实例,然后添加元素(活动实例的名称,指令,日期选择器和等级选项)到窗体实例。需要注意的是:添加元素名称必须和对应的数据库字段名称相匹配!!
function definition() {
global $COURSE, $CFG;
// Create form instance
$mform =& $this->_form;
// creates the form header
$mform->addElement(‘header’, ‘general’, get_string(‘general’, ‘form’));
// create text input
$mform->addElement(‘text’, ‘name’, get_string(‘bulletinname’, ‘bulletin’), array(‘size’=>’64’));
//input element type is controlled by the value of the setType element
$mform->setType(‘name’, PARAM_TEXT);
//UI rules are defined by setting addRule
$mform->addRule(‘name’, null, ‘required’, null, ‘client’);
// set instruction (html editor input)
$mform->addElement(‘htmleditor’, ‘instructions’, get_string(‘instructions’, ‘bulletin’));
$mform->setType(‘instructions’, PARAM_RAW);
$mform->addRule(‘instructions’, get_string(‘required’), ‘required’, null, ‘client’);
// create html editor help button
$mform->setHelpButton(‘instructions’, array(‘questions’, ‘richtext’), false, ‘editorhelpbutton’);
//create date available (date selector)
$mform->addElement(‘date_time_selector’, ‘timeavailable’, get_string(‘timeavailable’, ‘bulletin’), array(‘optional’=>true));
$mform->setDefault(‘timeavailable’, 0);
$mform->addElement(‘date_time_selector’, ‘timedue’, get_string(‘timedue’, ‘bulletin’), array(‘optional’=>true));
$mform->setDefault(‘timedue’, 0);
// set grade (scale type input)
$mform->addElement(‘modgrade’, ‘scale’, get_string(‘grade’), false);
$mform->disabledIf(‘scale’, ‘assessed’, ‘eq’, 0);
//调用standard_coursemodule_elements方法为common module进行设置。
//比如是否support group等
//该方法同时也会controls the display of multiple form elements.
$features = array(‘groups’=>true, ‘groupings’=>true,
‘groupmembersonly’=>true,’outcomes’=>false, ‘gradecat’=>false, ‘idnumber’=>false);
$this->standard_coursemodule_elements($features);
//add form buttons (cancel and submit)
$this->add_action_buttons();
}

Step 3 修改version.php
version.php用于管理数据库的升级,并执行所需的Moodle版本。upgrade.php会根据version.php的版本号来决定是否需要升级(例如在DB升级相关的表)。该文件里定义了
l 该module的当前版本
l Moodle的需要版本
l 以及cron
$module->version = 2009060103;
$module->requires = 2007101509;
$module->cron = 0;

Step 4 修改icon.gif (略)
未完,待续

(转自南方天夫百度空间)

作者: admin

为您推荐

联系我们

联系我们

邮箱:

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

关注微博
返回顶部