Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Moodle 2.7需要知道如何为不同的用户组创建自定义菜单_Php_Moodle - Fatal编程技术网

Php Moodle 2.7需要知道如何为不同的用户组创建自定义菜单

Php Moodle 2.7需要知道如何为不同的用户组创建自定义菜单,php,moodle,Php,Moodle,我一直在moodle 2.7框架上工作,我的要求是我想为教师和学生角色显示2个不同的自定义菜单,目前我已经在模板选项中创建了自定义菜单,但我不知道如何在moodle中创建多个自定义菜单。到目前为止,我尝试通过搜索组id,然后使用if语句来分配自定义菜单,但仍然没有输出,因此我请求任何人可以帮助我对这些问题进行排序。您可以扩展自定义菜单- 然后使用has_capability()查看用户是否可以看到菜单项 像这样的东西(我没试过) 拉塞尔, 下面是renderes.php中的代码 <?php

我一直在moodle 2.7框架上工作,我的要求是我想为教师和学生角色显示2个不同的自定义菜单,目前我已经在模板选项中创建了自定义菜单,但我不知道如何在moodle中创建多个自定义菜单。到目前为止,我尝试通过搜索组id,然后使用if语句来分配自定义菜单,但仍然没有输出,因此我请求任何人可以帮助我对这些问题进行排序。

您可以扩展自定义菜单-

然后使用
has_capability()
查看用户是否可以看到菜单项

像这样的东西(我没试过)

拉塞尔, 下面是renderes.php中的代码

<?php

Russell,首先。。非常感谢您抽出时间和提出想法,。。但是让我在我的机器上试试。。。所以我编辑了renderers.php并对其进行了修改,对吗?我今天会试一下,然后再给你回复。好的,我想展示一下下面的菜单。示例:教师菜单:主页|课程|课程|日历|报告学生菜单:主页|课程|课程|课程|简介|请让我知道如何从您给定的代码中执行此操作。嗨,我在moodle上真的看不到太多信息,只是为了为用户创建多个菜单,我们正在努力实现,但没有输出。。我认为moodle不是一个好的框架……嗨,有人能告诉我如何根据用户角色隐藏一些菜单项吗,例如,如果我有教师菜单1 |菜单2 |菜单3 |菜单4的菜单项,我喜欢在学生角色中隐藏菜单3 |菜单4。
<?php
/**
 * Prints a nice side block with an optional header.
 *
 * The content is described
 * by a {@link block_contents} object.
 *
 * @param block_contents $bc HTML for the content
 * @param string $region the region the block is appearing in.
 * @return string the HTML to be output.
 */
function block(block_contents $bc, $region) {

    $bc = clone($bc); // Avoid messing up the object passed in.
    if (empty($bc->blockinstanceid) || !strip_tags($bc->title)) {
        $bc->collapsible = block_contents::NOT_HIDEABLE;
    }
    if ($bc->collapsible == block_contents::HIDDEN) {
        $bc->add_class('hidden');
    }
    if (!empty($bc->controls)) {
        $bc->add_class('block_with_controls');
    }

    $skiptitle = strip_tags($bc->title);
    if (empty($skiptitle)) {
        $output = '';
        $skipdest = '';
    } else {
        $output = html_writer::tag('a', get_string('skipa', 'access', $skiptitle), array('href' => '#sb-' . $bc->skipid, 'class' => 'skip-block'));
        $skipdest = html_writer::tag('span', '', array('id' => 'sb-' . $bc->skipid, 'class' => 'skip-block-to'));
    }

     $title = '';
    if ($bc->title) {
        $title = html_writer::tag('h2', $bc->title);
    }

    $controlshtml = $this->block_controls($bc->controls);

    if ($title || $controlshtml) {
        $output .= html_writer::tag('div', html_writer::tag('div',  $title , array('class' => 'title')), array('class' => 'header-tab'));
    }

    $output .= html_writer::start_tag('div', $bc->attributes);

    if ($title || $controlshtml) {
        $output .= html_writer::tag('div', html_writer::tag('div', html_writer::tag('div', '', array('class'=>'block_action')). $title . $controlshtml, array('class' => 'title')), array('class' => 'header'));
    }

    $output .= html_writer::start_tag('div', array('class' => 'content'));
    if (!$title && !$controlshtml) {
        $output .= html_writer::tag('div', '', array('class'=>'block_action notitle'));
    }
    $output .= $bc->content;

    if ($bc->footer) {
        $output .= html_writer::tag('div', $bc->footer, array('class' => 'footer'));
    }

    $output .= html_writer::end_tag('div');


    $output .= html_writer::end_tag('div');

    if ($bc->annotation) {
        $output .= html_writer::tag('div', $bc->annotation, array('class' => 'blockannotation'));
    }
    $output .= $skipdest;

    $this->init_block_hider_js($bc);

    return $output;
}


/*
 * From boostrapbase
 * Overriding the custom_menu function ensures the custom menu is
 * always shown, even if no menu items are configured in the global
 * theme settings page.
 */
public function custom_menu($custommenuitems = '') {
    global $CFG;

    //TODO: Check this in a different way
    $langs = get_string_manager()->get_list_of_translations();
    if ( (count($langs) < 2) and (empty($CFG->custommenuitems))) {
        return '';
    }else{
        if (!empty($CFG->custommenuitems))
            $custommenuitems .= $CFG->custommenuitems;
        $custommenu = new custom_menu($custommenuitems, current_language());
        return $this->render_custom_menu($custommenu);
    }
}

// http://docs.moodle.org/dev/Extending_the_theme_custom_menu
protected function render_custom_menu(custom_menu $menu) {

    global $CFG;
    require_once($CFG->dirroot.'/course/lib.php');

    //navigation mycourses is no supported since 2.4
    if (isloggedin() && !isguestuser() && 
        $mycourses = enrol_get_my_courses(NULL, 'visible DESC, fullname ASC')) {  

        $branchlabel = get_string('mycourses') ;
        $branchurl   = new moodle_url('/course/index.php');
        $branchtitle = $branchlabel;
        $branchsort  = 8000 ;
        $branch = $menu->add($branchlabel, $branchurl, $branchtitle, $branchsort);

        foreach ($mycourses as $mycourse) {
            $branch->add($mycourse->shortname, new moodle_url(
                '/course/view.php', 
                array('id' => $mycourse->id)), 
                $mycourse->fullname
            );
        }
    }

    $course_id = $this->page->course->id;
    if (isloggedin() && $course_id > 1) {
        $branchlabel = get_string('grades');
        $branchurl   = new moodle_url('/grade/report/index.php?id='.$this->page->course->id);
        $branchtitle = $branchlabel;
        $branchsort  = 9000;
        $branch = $menu->add($branchlabel, $branchurl, $branchtitle, $branchsort);
    }

    //From boostrapbase

    // TODO: eliminate this duplicated logic, it belongs in core, not
    // here. See MDL-39565.
    $addlangmenu = true;
    $langs = get_string_manager()->get_list_of_translations();
    if (
        count($langs) < 2
        or empty($CFG->langmenu)
        or ($this->page->course != SITEID 
        and !empty($this->page->course->lang))) {

        $addlangmenu = false;
    }

    if ($addlangmenu) {
        $branchlabel =  get_string('language');
        $branchurl = new moodle_url('#');
        $branch = $menu->add($branchlabel, $branchurl, $branchlabel, 10000);

        foreach ($langs as $langtype => $langname) {
            $branch->add($langname, 
                new moodle_url(
                    $this->page->url, 
                    array('lang' => $langtype)
                ), 
                $langname
            );
        }
    }
    return parent::render_custom_menu($menu);
}

protected function render_custom_menu_item(custom_menu_item $menunode) {
    $transmutedmenunode = new theme_archaius_transmuted_custom_menu_item($menunode);
    return parent::render_custom_menu_item($transmutedmenunode);
}