Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.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
如何在moodle的“我的课程”部分的课程名称后显示培训师名称?_Moodle - Fatal编程技术网

如何在moodle的“我的课程”部分的课程名称后显示培训师名称?

如何在moodle的“我的课程”部分的课程名称后显示培训师名称?,moodle,Moodle,我使用的是moodle 28版本。我想在我的课程部分的课程名称后面显示特定课程的培训师名称 我想只从编码方式显示,不添加任何块或插件 谢谢 在“/blocks/course\u overview/renderer.php”中,在第124行之后添加以下代码: require_once($CFG->libdir. '/coursecatlib.php'); $tmpCourse = new course_in_list($course); //Add teacher name if ($tmp

我使用的是moodle 28版本。我想在我的课程部分的课程名称后面显示特定课程的培训师名称

我想只从编码方式显示,不添加任何块或插件

谢谢

在“/blocks/course\u overview/renderer.php”中,在第124行之后添加以下代码:

require_once($CFG->libdir. '/coursecatlib.php');
$tmpCourse = new course_in_list($course);
//Add teacher name
if ($tmpCourse->has_course_contacts()) {
    $html .= html_writer::start_tag('ul', array('class' => 'teachers'));
    foreach ($tmpCourse->get_course_contacts() as $userid => $coursecontact) {
        $name = $coursecontact['rolename'].': '.
            html_writer::link(new moodle_url('/user/view.php',
                array('id' => $userid, 'course' => SITEID)),
                $coursecontact['username']);
        $html .= html_writer::tag('li', $name);
    }
    $html .= html_writer::end_tag('ul'); // .teachers
}
编辑的

或替换课程概述功能

public function course_overview($courses, $overviews) {
    global $DB,$CFG;
    $html = '';
    $config = get_config('block_course_overview');
    if ($config->showcategories != BLOCKS_COURSE_OVERVIEW_SHOWCATEGORIES_NONE) {
        global $CFG;
        require_once($CFG->libdir.'/coursecatlib.php');
    }
    $ismovingcourse = false;
    $courseordernumber = 0;
    $maxcourses = count($courses);
    $userediting = false;
    // Intialise string/icon etc if user is editing and courses > 1
    if ($this->page->user_is_editing() && (count($courses) > 1)) {
        $userediting = true;
        $this->page->requires->js_init_call('M.block_course_overview.add_handles');

        // Check if course is moving
        $ismovingcourse = optional_param('movecourse', FALSE, PARAM_BOOL);
        $movingcourseid = optional_param('courseid', 0, PARAM_INT);
    }

    // Render first movehere icon.
    if ($ismovingcourse) {
        // Remove movecourse param from url.
        $this->page->ensure_param_not_in_url('movecourse');

        // Show moving course notice, so user knows what is being moved.
        $html .= $this->output->box_start('notice');
        $a = new stdClass();
        $a->fullname = $courses[$movingcourseid]->fullname;
        $a->cancellink = html_writer::link($this->page->url, get_string('cancel'));
        $html .= get_string('movingcourse', 'block_course_overview', $a);
        $html .= $this->output->box_end();

        $moveurl = new moodle_url('/blocks/course_overview/move.php',
                    array('sesskey' => sesskey(), 'moveto' => 0, 'courseid' => $movingcourseid));
        // Create move icon, so it can be used.
        $movetofirsticon = html_writer::empty_tag('img',
                array('src' => $this->output->pix_url('movehere'),
                    'alt' => get_string('movetofirst', 'block_course_overview', $courses[$movingcourseid]->fullname),
                    'title' => get_string('movehere')));
        $moveurl = html_writer::link($moveurl, $movetofirsticon);
        $html .= html_writer::tag('div', $moveurl, array('class' => 'movehere'));
    }

    foreach ($courses as $key => $course) {
        // If moving course, then don't show course which needs to be moved.
        if ($ismovingcourse && ($course->id == $movingcourseid)) {
            continue;
        }
        $html .= $this->output->box_start('coursebox', "course-{$course->id}");
        $html .= html_writer::start_tag('div', array('class' => 'course_title'));
        // If user is editing, then add move icons.
        if ($userediting && !$ismovingcourse) {
            $moveicon = html_writer::empty_tag('img',
                    array('src' => $this->pix_url('t/move')->out(false),
                        'alt' => get_string('movecourse', 'block_course_overview', $course->fullname),
                        'title' => get_string('move')));
            $moveurl = new moodle_url($this->page->url, array('sesskey' => sesskey(), 'movecourse' => 1, 'courseid' => $course->id));
            $moveurl = html_writer::link($moveurl, $moveicon);
            $html .= html_writer::tag('div', $moveurl, array('class' => 'move'));

        }

        // No need to pass title through s() here as it will be done automatically by html_writer.
        $attributes = array('title' => $course->fullname);
        if ($course->id > 0) {
            if (empty($course->visible)) {
                $attributes['class'] = 'dimmed';
            }
            $courseurl = new moodle_url('/course/view.php', array('id' => $course->id));
            $coursefullname = format_string(get_course_display_name_for_list($course), true, $course->id);
            $link = html_writer::link($courseurl, $coursefullname, $attributes);
            $html .= $this->output->heading($link, 2, 'title');
        } else {
            $html .= $this->output->heading(html_writer::link(
                new moodle_url('/auth/mnet/jump.php', array('hostid' => $course->hostid, 'wantsurl' => '/course/view.php?id='.$course->remoteid)),
                format_string($course->shortname, true), $attributes) . ' (' . format_string($course->hostname) . ')', 2, 'title');
        }
        $html .= $this->output->box('', 'flush');
        $html .= html_writer::end_tag('div');

        require_once($CFG->libdir. '/coursecatlib.php');
        $tmpCourse = new course_in_list($course);
        //Add teacher name
        // display course contacts. See course_in_list::get_course_contacts()
        if ($tmpCourse->has_course_contacts()) {
            $html .= html_writer::start_tag('ul', array('class' => 'teachers'));
            foreach ($tmpCourse->get_course_contacts() as $userid => $coursecontact) {
                $name = $coursecontact['rolename'].': '.
                    html_writer::link(new moodle_url('/user/view.php',
                        array('id' => $userid, 'course' => SITEID)),
                        $coursecontact['username']);
                $html .= html_writer::tag('li', $name);
            }
            $html .= html_writer::end_tag('ul'); // .teachers
        }

        if (!empty($config->showchildren) && ($course->id > 0)) {
            // List children here.
            if ($children = block_course_overview_get_child_shortnames($course->id)) {
                $html .= html_writer::tag('span', $children, array('class' => 'coursechildren'));
            }
        }

        // If user is moving courses, then down't show overview.
        if (isset($overviews[$course->id]) && !$ismovingcourse) {
            $html .= $this->activity_display($course->id, $overviews[$course->id]);
        }

        if ($config->showcategories != BLOCKS_COURSE_OVERVIEW_SHOWCATEGORIES_NONE) {
            // List category parent or categories path here.
            $currentcategory = coursecat::get($course->category, IGNORE_MISSING);
            if ($currentcategory !== null) {
                $html .= html_writer::start_tag('div', array('class' => 'categorypath'));
                if ($config->showcategories == BLOCKS_COURSE_OVERVIEW_SHOWCATEGORIES_FULL_PATH) {
                    foreach ($currentcategory->get_parents() as $categoryid) {
                        $category = coursecat::get($categoryid, IGNORE_MISSING);
                        if ($category !== null) {
                            $html .= $category->get_formatted_name().' / ';
                        }
                    }
                }
                $html .= $currentcategory->get_formatted_name();
                $html .= html_writer::end_tag('div');
            }
        }

        $html .= $this->output->box('', 'flush');
        $html .= $this->output->box_end();
        $courseordernumber++;
        if ($ismovingcourse) {
            $moveurl = new moodle_url('/blocks/course_overview/move.php',
                        array('sesskey' => sesskey(), 'moveto' => $courseordernumber, 'courseid' => $movingcourseid));
            $a = new stdClass();
            $a->movingcoursename = $courses[$movingcourseid]->fullname;
            $a->currentcoursename = $course->fullname;
            $movehereicon = html_writer::empty_tag('img',
                    array('src' => $this->output->pix_url('movehere'),
                        'alt' => get_string('moveafterhere', 'block_course_overview', $a),
                        'title' => get_string('movehere')));
            $moveurl = html_writer::link($moveurl, $movehereicon);
            $html .= html_writer::tag('div', $moveurl, array('class' => 'movehere'));
        }
    }
    // Wrap course list in a div and return.
    return html_writer::tag('div', $html, array('class' => 'course_list'));
}
编辑以直接显示教师姓名

public function course_overview($courses, $overviews) {
    global $DB,$CFG;
    $html = '';
    $config = get_config('block_course_overview');
    if ($config->showcategories != BLOCKS_COURSE_OVERVIEW_SHOWCATEGORIES_NONE) {
        global $CFG;
        require_once($CFG->libdir.'/coursecatlib.php');
    }
    $ismovingcourse = false;
    $courseordernumber = 0;
    $maxcourses = count($courses);
    $userediting = false;
    // Intialise string/icon etc if user is editing and courses > 1
    if ($this->page->user_is_editing() && (count($courses) > 1)) {
        $userediting = true;
        $this->page->requires->js_init_call('M.block_course_overview.add_handles');

        // Check if course is moving
        $ismovingcourse = optional_param('movecourse', FALSE, PARAM_BOOL);
        $movingcourseid = optional_param('courseid', 0, PARAM_INT);
    }

    // Render first movehere icon.
    if ($ismovingcourse) {
        // Remove movecourse param from url.
        $this->page->ensure_param_not_in_url('movecourse');

        // Show moving course notice, so user knows what is being moved.
        $html .= $this->output->box_start('notice');
        $a = new stdClass();
        $a->fullname = $courses[$movingcourseid]->fullname;
        $a->cancellink = html_writer::link($this->page->url, get_string('cancel'));
        $html .= get_string('movingcourse', 'block_course_overview', $a);
        $html .= $this->output->box_end();

        $moveurl = new moodle_url('/blocks/course_overview/move.php',
                    array('sesskey' => sesskey(), 'moveto' => 0, 'courseid' => $movingcourseid));
        // Create move icon, so it can be used.
        $movetofirsticon = html_writer::empty_tag('img',
                array('src' => $this->output->pix_url('movehere'),
                    'alt' => get_string('movetofirst', 'block_course_overview', $courses[$movingcourseid]->fullname),
                    'title' => get_string('movehere')));
        $moveurl = html_writer::link($moveurl, $movetofirsticon);
        $html .= html_writer::tag('div', $moveurl, array('class' => 'movehere'));
    }

    foreach ($courses as $key => $course) {
        // If moving course, then don't show course which needs to be moved.
        if ($ismovingcourse && ($course->id == $movingcourseid)) {
            continue;
        }
        $html .= $this->output->box_start('coursebox', "course-{$course->id}");
        $html .= html_writer::start_tag('div', array('class' => 'course_title'));
        // If user is editing, then add move icons.
        if ($userediting && !$ismovingcourse) {
            $moveicon = html_writer::empty_tag('img',
                    array('src' => $this->pix_url('t/move')->out(false),
                        'alt' => get_string('movecourse', 'block_course_overview', $course->fullname),
                        'title' => get_string('move')));
            $moveurl = new moodle_url($this->page->url, array('sesskey' => sesskey(), 'movecourse' => 1, 'courseid' => $course->id));
            $moveurl = html_writer::link($moveurl, $moveicon);
            $html .= html_writer::tag('div', $moveurl, array('class' => 'move'));

        }

        // No need to pass title through s() here as it will be done automatically by html_writer.
        $attributes = array('title' => $course->fullname);
        if ($course->id > 0) {
            if (empty($course->visible)) {
                $attributes['class'] = 'dimmed';
            }
            $courseurl = new moodle_url('/course/view.php', array('id' => $course->id));
            $coursefullname = format_string(get_course_display_name_for_list($course), true, $course->id);
            $link = html_writer::link($courseurl, $coursefullname, $attributes);
            $html .= $this->output->heading($link, 2, 'title');
        } else {
            $html .= $this->output->heading(html_writer::link(
                new moodle_url('/auth/mnet/jump.php', array('hostid' => $course->hostid, 'wantsurl' => '/course/view.php?id='.$course->remoteid)),
                format_string($course->shortname, true), $attributes) . ' (' . format_string($course->hostname) . ')', 2, 'title');
        }
        $html .= $this->output->box('', 'flush');
        $html .= html_writer::end_tag('div');

        //Add teacher name
        $teacher = $DB->get_record_sql("SELECT c.id, c.shortname, u.id as userid, u.username, u.firstname, u.lastname
                              FROM mdl_course c
                              LEFT OUTER JOIN mdl_context cx ON c.id = cx.instanceid
                              LEFT OUTER JOIN mdl_role_assignments ra ON cx.id = ra.contextid AND ra.roleid = '3'
                              LEFT OUTER JOIN mdl_user u ON ra.userid = u.id
                              WHERE cx.contextlevel = '50' AND c.id=".$course->id . ";");
        // display course contacts. See course_in_list::get_course_contacts()
        if ($teacher) {
            $html .= html_writer::start_tag('ul', array('class' => 'teachers'));
            //get role name
            $role = new stdClass();
            if ($roles = get_user_roles(context_course::instance($course->id), $teacher->userid)) {
                $role = array_pop($roles);
            }
            $role = role_get_name($role, context_course::instance($course->id), ROLENAME_ALIAS);

            $name = $role .': '.
                html_writer::link(new moodle_url('/user/view.php',
                    array('id' => $teacher->id, 'course' => SITEID)),
                    $teacher->firstname . " " .  $teacher->lastname);
            $html .= html_writer::tag('li', $name);
            $html .= html_writer::end_tag('ul'); // .teachers
        }

        if (!empty($config->showchildren) && ($course->id > 0)) {
            // List children here.
            if ($children = block_course_overview_get_child_shortnames($course->id)) {
                $html .= html_writer::tag('span', $children, array('class' => 'coursechildren'));
            }
        }

        // If user is moving courses, then down't show overview.
        if (isset($overviews[$course->id]) && !$ismovingcourse) {
            $html .= $this->activity_display($course->id, $overviews[$course->id]);
        }

        if ($config->showcategories != BLOCKS_COURSE_OVERVIEW_SHOWCATEGORIES_NONE) {
            // List category parent or categories path here.
            $currentcategory = coursecat::get($course->category, IGNORE_MISSING);
            if ($currentcategory !== null) {
                $html .= html_writer::start_tag('div', array('class' => 'categorypath'));
                if ($config->showcategories == BLOCKS_COURSE_OVERVIEW_SHOWCATEGORIES_FULL_PATH) {
                    foreach ($currentcategory->get_parents() as $categoryid) {
                        $category = coursecat::get($categoryid, IGNORE_MISSING);
                        if ($category !== null) {
                            $html .= $category->get_formatted_name().' / ';
                        }
                    }
                }
                $html .= $currentcategory->get_formatted_name();
                $html .= html_writer::end_tag('div');
            }
        }

        $html .= $this->output->box('', 'flush');
        $html .= $this->output->box_end();
        $courseordernumber++;
        if ($ismovingcourse) {
            $moveurl = new moodle_url('/blocks/course_overview/move.php',
                        array('sesskey' => sesskey(), 'moveto' => $courseordernumber, 'courseid' => $movingcourseid));
            $a = new stdClass();
            $a->movingcoursename = $courses[$movingcourseid]->fullname;
            $a->currentcoursename = $course->fullname;
            $movehereicon = html_writer::empty_tag('img',
                    array('src' => $this->output->pix_url('movehere'),
                        'alt' => get_string('moveafterhere', 'block_course_overview', $a),
                        'title' => get_string('movehere')));
            $moveurl = html_writer::link($moveurl, $movehereicon);
            $html .= html_writer::tag('div', $moveurl, array('class' => 'movehere'));
        }
    }
    // Wrap course list in a div and return.
    return html_writer::tag('div', $html, array('class' => 'course_list'));
}

“培训师姓名”!您的意思是:教师还是课程创建者???当用户单击“我的课程->显示所有带教师姓名的课程”时,我的答案还有一个问题?是吗?是的,这就是我需要的。此外,我还检查了培训师在网站管理->外观->课程,这是课程联系人您的定制只适用于编码安装插件。无法从Moodle设置自定义。这可能需要一点时间。请耐心点,但不要为我工作。这可能是你的行:124和我的行可能不同,所以请告诉我之后的代码块,我可以添加此代码谢谢你这么多VũTuấ它对我有用吗。现在我想从用户名中删除用户配置文件链接。我能做的事…谢谢你ấn-Anh,一切正常,但如果我取消培训师课程,培训师名称不会更新。当我取消选中“课程联系人”复选框时,它会更新。一个小问题!你是开发者吗:)如果你是,我想你可以做得很简单:)关于课程联系复选框,是的,你是对的。我在主页上也这么做了。