【问题标题】:Moodle theme change based on user type根据用户类型更改 Moodle 主题
【发布时间】:2014-01-28 11:02:10
【问题描述】:

我正在使用来自 Wordpress 网站的单点登录技术,一旦用户登录,他们就会自动定向到 Moodle LMS,即“courses/view.php?id=*relevant_id*”。

$USER 对象已经设置了用户类型(在本例中称为“部门”)。

我想根据这个用户类型做一个主题切换。

类似:

if($USER->department == 'redTeam') { $theme = '红队主题'; }

我的问题是: 我将把这段代码 sn-p 放在哪里? 有谁知道具体的语法吗?

我已经在 Google 上看了好几个小时,但我无法理解语法

【问题讨论】:

    标签: themes moodle


    【解决方案1】:

    我已经找到了如何在代码中做到这一点。

    在 lib 文件夹中,您需要修改 2 个文件:

    pagelib 和 weblib。 pagelib 文件是一个冗长的扩展名,因此我不会在此处粘贴该代码。如果有人想要,可以联系我,我很乐意分享。

    weblib 需要将其添加到其中才能进行主题切换:

      //create the function
        function _setTheme(){
    
            global $DB,$USER, $CFG, $THEME, $COURSE;//open abstraction layers
        //set the criteria for te switch in this case I used the department field, it can also      //be roles
            $getRole = $USER->department;
    
                if(!empty($getRole))  { //If the variable is not empty proceed with the switch 
                    switch($getRole){
    
                    case 'role1':
                    $val = 'sky_high';     
                    break;
    
                    case 'role2':
                    $val = 'leatherbound';     
                    break;
    
    }
        } else {
            //default theme
                        return 'leatherbound';
                    }
                    return $val;
            }
    

    【讨论】:

    • 能否让我知道如何与您联系以获取完整的 pagelib 和 weblib 代码。我有一个朋友真的很想看看它是如何完成的。谢谢!
    猜你喜欢
    • 2010-09-15
    • 1970-01-01
    • 1970-01-01
    • 2013-08-31
    • 2012-11-24
    • 2020-01-24
    • 2015-12-07
    • 2013-07-14
    • 1970-01-01
    相关资源
    最近更新 更多