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

时间:2016-02-01 06:48:21

标签: moodle

我正在使用moodle 28版本。我想在“我的课程”部分的课程名称之后显示特定课程的培训师姓名。

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

谢谢..!

1 个答案:

答案 0 :(得分:0)

In" /blocks/course_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
}

<强> EDITTED

或替换 course_overview 功能

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'));
}