Course format是用来定义 course page的布局和显示。 Moodle提供了 6个 standard course formats :
l lams
l scorm
l social
l topics
l weeks
l weekscss
后面 3 个最常用, These display a course in sections known as topics or weeks
Social format 则只会显示一个 section
The LAMS and SCORM format are very specific formats that are used to display the specific types of learning activities associated with LAMS and SCORM, respectively
每一个 course format都最起码需要包含 3个 files under moodle_home/format/[your_course_format] 目录 :
l format.php 这是 main file,负责处理所有的 display logic for the course format 。它输出 all of the content for the course, 包括 blocks 。
l config.php 用来定义 default blocks(也就是一个 course缺省使用的 blocks),以及定义 block location.
l format_yourformat.php under lang相关目录下 , 用于 define a human readable name for the format
l ( optional ) ”db” 目录,里面包含 files 用于 create and upgrade specific data tables, access files for capabilities, a version file, backup and restore files, and a styles file
下面的例子是创建一个 course format,它会 display a forum in a specific section of our course in an expanded way that shows all of the discussions and their recent statuses directly in that section . 简单来说,就是 forum activity directly in the course section
1. 假设我们自定义的 course format 为“ extforum”,首先在 moodle_home/course/format目录下创建目录“ extforum”,然后把 moodle_home/course/format/topics 目录下的所有 files都复制到“ extforum”下。这样实际上你已经创建了一个 course format,它和 topics course format一摸一样,只不过 course format name不同。这样当你 create a course时,你会在“ format” pull down list里看到多了一个 course format named “[[formatextforum]] ”
2. 下面我们使用 language file 使该 course format有一个易读的 name。
创建 /lang/en_utf8/ format_extforum.php ,其 content为:
<?php
$string['formatextforum'] = 'Extended forum section';
?>
这样在 format的 pull down list里看到的 course format name不是 “[[formatextforum]] ”,而是“ Extended forum section ”
3. 打开 format.php ,大约在第 213行,你会看到下列代码:
print_section($course, $thissection, $mods, $modnamesused);
它是 call /course/lib.php里的 print_section函数来 all of the activities in the section 。我们需要修改该函数来按照我们的需求来 format 。当然我们不应该直接在 /course/ lib.php 里直接修改。应该在 moodle_home/course/format/extforum 里创建一个 lib.php ,然后把 /course/ lib.php 里的 print_section函数整个复制到 extforum/lib.php里,然后 rename to “ extforum_print_section ”
然后在 extforum_print_section 函数 的大概 110行( before the Normal activity comment )添加下列代码:
} else if (!$isediting && ($mod->modname == 'forum') && ($section->section == 1)) {
$page = optional_param('page', 0, PARAM_INT);
$forum = get_record("forum", "id", $mod->instance);
forum_print_latest_discussions($course, $forum, -1, 'header', '', -1, -1, $page, $CFG->forum_manydiscussions);
} else { // Normal activity
4. 然后在 format.php 里,把“ print_section ”改成“ extforum_print_section ”,然后在之前添加下列代码
require_once($CFG->dirroot.'/course/format/extforum/lib.php');