现在的位置: 首页 > 综合 > 正文

Moodle二次开发(1)– 微创新

2013年08月23日 ⁄ 综合 ⁄ 共 2411字 ⁄ 字号 评论关闭

尊敬的公司领导参加了一个会议,回来大肆宣扬了下“微创新”的概念。所以,下面我对Moodle进行了下微创新,为了方便记忆,以及给各位对Moodle进行微创新的同学以启发,特在博客上记录下来。

Moodle版本:2.1

1、用户登录后导向到我的主页

在Moodle中遍寻不到这个设置,我记得在2.3版本好像有。没办法只有仔细了看了下代码。发现 login/index.php中有段代码比较合符要求。

    /// Go to my-moodle page instead of site homepage if defaulthomepage set to homepage_my
        if (!empty($CFG->defaulthomepage) && $CFG->defaulthomepage == HOMEPAGE_MY && !is_siteadmin() && !isguestuser()) {
            if ($urltogo == $CFG->wwwroot or $urltogo == $CFG->wwwroot.'/' or $urltogo == $CFG->wwwroot.'/index.php') {
                $urltogo = $CFG->wwwroot.'/my/';
            }
        }

其中“defaulthomepage”这个单词引起了我的注意,灵机一动,到数据库中配置表“mdl_config”中搜了下,居然发现了这个配置参数,默认值是0,将它修改成1。

登录后正常进入“我的主页”。功能实现。

 

2、普通用户在我的主页中无法返回网站首页

这个问题是上一个问题引起的,若使用管理员帐号登录,能正常回到首页,当是不能对首页再进行编辑;若是普通用户,根本就没有权限回首页了。悲催的规则,没搞明白是Moodle的bug,还是我没配置对。

处理的方式很简单,就是把“网站首页”先屏蔽吧。在lib目录下找到navigationlib.php,在函数initialise中有一段代码。

        if (get_home_page() == HOMEPAGE_SITE) {
            // The home element should be my moodle because the root element is the site
            if (isloggedin() && !isguestuser()) {  // Makes no sense if you aren't logged in
                $this->rootnodes['home'] = $this->add(get_string('myhome'), new moodle_url('/my/'), self::TYPE_SETTING, null, 'home');
            }
        } else {
            // The home element should be the site because the root node is my moodle
            $this->rootnodes['home'] = $this->add(get_string('sitehome'), new moodle_url('/'), self::TYPE_SETTING, null, 'home');
            if ($CFG->defaulthomepage == HOMEPAGE_MY) {
                // We need to stop automatic redirection
                $this->rootnodes['home']->action->param('redirect', '0');
            }
        }

将else语句后面的屏蔽掉吧。算是解决一个问题,功能完成。

3、成员列表中,屏蔽按字母搜索

在课程中,有个成员列表,其中的按字母搜索比较的有趣。为了不让它妨碍使用的心情,决定把它先屏蔽掉。

在lib目录下,其中有个tablelib.php,其中有段代码。

    /**
     * This function is not part of the public api.
     */
    function print_initials_bar() {
       /* if ((!empty($this->sess->i_last) || !empty($this->sess->i_first) ||$this->use_initials)
                    && isset($this->columns['fullname'])) {

            $alpha  = explode(',', get_string('alphabet', 'langconfig'));

            // Bar of first initials
            if (!empty($this->sess->i_first)) {
                $ifirst = $this->sess->i_first;
            } else {
                $ifirst = '';
            }
            $this->print_one_initials_bar($alpha, $ifirst, 'firstinitial',
                    get_string('firstname'), $this->request[TABLE_VAR_IFIRST]);

            // Bar of last initials
            if (!empty($this->sess->i_last)) {
                $ilast = $this->sess->i_last;
            } else {
                $ilast = '';
            }
            $this->print_one_initials_bar($alpha, $ilast, 'lastinitial',
                    get_string('lastname'), $this->request[TABLE_VAR_ILAST]);
        }*/
    }

如上屏蔽掉它里面的代码,再次刷新页面,功能完成。

 

4、屏蔽资源、活动中不要的选项

在课程中,添加活动或资源时,有很多选项,比如什么SCORM、IMS这些,平时基本不用,太专业了。如何把它屏蔽掉呢?

开始想法是改代码,后来发现一个好办法,就是把这些插件卸载掉。Moodle在这方面做得比较好,大部分东西都是插件的形式,不像我经常动不动就考虑改代码,改结构,差了不是一个档次啊。

卸载了相应插件后,还需要把对应目录全部删除,否则登录后无法正常访问,总是提示你插件安装不全,需要升级。

 

 

抱歉!评论已关闭.