また小ネタ。未ログイン時およびゲストログイン時、コース一覧にはゲストアクセス可のコースのみを表示して欲しい、というご要望がありました。
もうなんの抵抗もなく Moodle 本体をガシガシ修正してしまっていますが…ま、いいか。ということで以下のファイルを修正。
course/lib.php にゲストアクセス可のコースのみ表示するサブルーチンを追加。
function print_guest_courses() {
global $CFG;
$categories = get_child_categories(0); // Parent = 0 ie top-level categories only
if (is_array($categories) && count($categories) == 1) {
$category = array_shift($categories);
$courses = get_courses_wmanagers($category->id, 'c.sortorder ASC', array('password', 'summary', 'currency'));
} else {
$courses = get_courses_wmanagers('all', 'c.sortorder ASC', array('password', 'summary', 'currency'));
}
unset($categories);
if ($courses) {
echo '<ul class="unlist">';
foreach ($courses as $course) {
if ($course->guest) {
echo '<li>';
print_course($course);
echo "</li>\n";
}
}
echo "</ul>\n";
} else {
print_heading(get_string("nocoursesyet"));
}
}
index.php (サイトトップ用)内の $frontpagelayout を foreach 文でループしながら表示している部分の switch 文の部分に以下を追加。
case FRONTPAGECOURSELIST:
if (isloggedin() and !has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) and !isguest() and empty($CFG->disablemycourses)) {
print_heading_block(get_string('mycourses'));
print_my_moodle();
} else if (!isloggedin() or isguest()) {
print_heading_block(get_string('availablecourses'));
print_guest_courses(0);
} else if ((!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) and !isguest()) or (count_records('course') <= FRONTPAGECOURSELIMIT)) {
// admin should not see list of courses when there are too many of them
print_heading_block(get_string('availablecourses'));
print_courses(0);
}
break;
追加したのは else if (!isloggedin() or isguest()) のところ。
単独のコース一覧表示とブロックのコース一覧表示も修正が必要。
course/index.php に以下を追加。
} else if (!isloggedin() or isguest()) {
$strfulllistofcourses = get_string('fulllistofcourses');
print_header("$site->shortname: $strfulllistofcourses", $strfulllistofcourses,
build_navigation(array(array('name'=>$strfulllistofcourses, 'link'=>'','type'=>'misc'))),
'', '', true, update_category_button());
echo skip_main_destination();
print_box_start('courseboxes');
print_guest_courses();
print_box_end();
blocks/course_list/block_course_list.php に以下を追加。
foreach ($courses as $course) {
if ((!isloggedin() or isguest()) and !$course->guest) {
continue;
}
$linkcss = $course->visible ? "" : " class=\"dimmed\" ";
追加したのは if ((!isloggedin() or isguest()) and !$course->guest) からの 3行。
もう、こう、なんというか、やっつけ感が半端じゃないですが…納期優先。2.0 にバージョンアップする時のことは考えないことにしています。今のところ。全部作り直してやるぜー!という勢い。

