function sections($config)
{
global $COURSE, $CFG, $USER, $THEME;
// probably inefficient, but it works
get_all_mods($COURSE->id, $mods, $modnames, $modnamesplural, $modnamesused);
// sections
$sections = get_all_sections($COURSE->id);
// name for sections
$sectionname = get_string("name{$COURSE->format}", "format_{$COURSE->format}");
// TODO: this fallback should be unnecessary
if ($sectionname == "[[name{$COURSE->format}]]") {
$sectionname = get_string("name{$COURSE->format}");
}
$return = array();
// check what the course format is like
// highlight for current week or highlighted topic
if (in_array($COURSE->format, array('weeks', 'weekscss'))) {
$format = 'week';
$highlight = ceil((time() - $COURSE->startdate) / 604800);
} else {
$format = 'topic';
$highlight = $COURSE->marker;
}
$modinfo = unserialize($COURSE->modinfo);
// I think $display is the section currently being displayed
// Why are we calling course_set_display?
// For Moodle 2.0 we should just use $PAGE and check type
// and also $PAGE->activityrecord
$path = str_replace($CFG->httpswwwroot . '/', '', $CFG->pagepath);
if (substr($path, 0, 7) == 'course/') {
//TODO: this code is hackish, we shouldn't use course_set_display
# get current section being displayed
$week = optional_param('week', -1, PARAM_INT);
if ($week != -1) {
// the course format should already be doing this
$display = course_set_display($COURSE->id, $week);
} else {
if (isset($USER->display[$COURSE->id])) {
$display = $USER->display[$COURSE->id];
} else {
$display = course_set_display($COURSE->id, 0);
}
}
} elseif (substr($path, 0, 4) == 'mod/') {
// Moodle 2: use $PAGE->activityrecord->section;
$id = optional_param('id', -1, PARAM_INT);
if ($id == -1) {
$display = 0;
} else {
$sql = "select section from {$CFG->prefix}course_sections where id=(select section from {$CFG->prefix}course_modules where id={$id})";
$row = get_record_sql($sql);
$display = $row->section;
}
} else {
$display = 0;
}
foreach ($sections as $section) {
// don't show the flowing sections
if (!($section->visible && $section->section && $section->section <= $COURSE->numsections)) {
continue;
}
$text = trim($section->summary);
if (empty($text)) {
$text = ucwords($sectionname) . " " . $section->section;
} else {
$text = $this->truncate_html(filter_text($text, $COURSE->id), $config);
}
// expand section if it's the one currently displayed
$expand = false;
if ($section->section == $display) {
$expand = true;
}
$sectionstyle = 'yui_menu_icon_section';
// highlight marked section
if ($section->section == $highlight) {
$sectionstyle .= ' highlight';
}
$iconpath = $CFG->wwwroot;
if ($THEME->custompix) {
$iconpath .= "/theme/" . current_theme() . "/pix";
} else {
$iconpath .= '/pix';
//$iconpath .= '/';
}
$iconpath = $CFG->wwwroot . "/theme/" . current_theme() . "/pix";
// decide what URL we want to use
// A lot of this should really be done by the course format
//
// = intoaction config values =
// * 'introhide' link to the section page (this effectively
// hides the other sections
// * 'introscroll' link to the fragment id of the section on
// on the current page
// whether or not any of the sections are hidden
$hidden = false;
foreach (array('topic', 'week') as $param) {
if (isset($_GET[$param]) && $_GET[$param] != 'all') {
$hidden = true;
}
}
//.........这里部分代码省略.........
/**
* Generate the list of modules for the given course.
*
* @param stdClass $course The course to get modules for
*/
protected function get_course_modules($course)
{
global $CFG;
$mods = $modnames = $modnamesplural = $modnamesused = array();
// This function is included when we include course/lib.php at the top
// of this file
get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
$resources = array();
$activities = array();
foreach ($modnames as $modname => $modnamestr) {
if (!course_allowed_module($course, $modname)) {
continue;
}
$libfile = "{$CFG->dirroot}/mod/{$modname}/lib.php";
if (!file_exists($libfile)) {
continue;
}
include_once $libfile;
$gettypesfunc = $modname . '_get_types';
if (function_exists($gettypesfunc)) {
$types = $gettypesfunc();
foreach ($types as $type) {
if (!isset($type->modclass) || !isset($type->typestr)) {
debugging('Incorrect activity type in ' . $modname);
continue;
}
if ($type->modclass == MOD_CLASS_RESOURCE) {
$resources[html_entity_decode($type->type, ENT_QUOTES, 'UTF-8')] = $type->typestr;
} else {
$activities[html_entity_decode($type->type, ENT_QUOTES, 'UTF-8')] = $type->typestr;
}
}
} else {
$archetype = plugin_supports('mod', $modname, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER);
if ($archetype == MOD_ARCHETYPE_RESOURCE) {
$resources[$modname] = $modnamestr;
} else {
// all other archetypes are considered activity
$activities[$modname] = $modnamestr;
}
}
}
return array($resources, $activities);
}
/**
* Simply prints all grade of one student from all modules from a given course
* used in the grade book for student view, and grade button under user profile
* @param int $userid;
* @param int $courseid;
*/
function print_student_grade($user, $course)
{
global $CFG;
if (!empty($user)) {
$grades[$user->id] = array();
// Collect all grades in this array
$gradeshtml[$user->id] = array();
// Collect all grades html formatted in this array
$totals[$user->id] = array();
// Collect all totals in this array
}
$strmax = get_string("maximumshort");
/// Collect modules data
get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
/// Search through all the modules, pulling out grade data
$sections = get_all_sections($course->id);
// Sort everything the same as the course
// prints table
// flag for detecting whether to print table header or not
$nograde = 0;
for ($i = 0; $i <= $course->numsections; $i++) {
if (isset($sections[$i])) {
// should always be true
$section = $sections[$i];
if ($section->sequence) {
$sectionmods = explode(",", $section->sequence);
foreach ($sectionmods as $sectionmod) {
$mod = $mods[$sectionmod];
if (empty($mod->modname)) {
continue;
// Just in case, see MDL-7150
}
if (!($instance = get_record($mod->modname, 'id', $mod->instance))) {
continue;
}
if (!($cm = get_coursemodule_from_instance($mod->modname, $mod->instance))) {
continue;
}
if (!$cm->visible) {
$modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
if (!has_capability('moodle/course:viewhiddenactivities', $modcontext)) {
continue;
}
}
$libfile = "{$CFG->dirroot}/mod/{$mod->modname}/lib.php";
if (file_exists($libfile)) {
require_once $libfile;
$gradefunction = $mod->modname . '_grades';
if (function_exists($gradefunction)) {
// Skip modules without grade function
if ($modgrades = $gradefunction($mod->instance)) {
if (!empty($modgrades->maxgrade)) {
if ($mod->visible) {
$maxgrade = $modgrades->maxgrade;
} else {
$maxgrade = $modgrades->maxgrade;
}
} else {
$maxgrade = '';
}
if ($maxgrade) {
if (!$nograde) {
echo '<table align="center" class="grades"><tr><th scope="col">' . get_string('activity') . '</th><th scope="col">' . get_string('yourgrade', 'grades') . '</th><th scope="col">' . get_string('maxgrade', 'grades') . '</th></tr>';
}
$nograde++;
$link_id = grade_get_module_link($course->id, $mod->instance, $mod->module);
$link = $CFG->wwwroot . '/mod/' . $mod->modname . '/view.php?id=' . $link_id->id;
echo '<tr>';
if (!empty($modgrades->grades[$user->id])) {
$currentgrade = $modgrades->grades[$user->id];
echo "<td><a href='{$link}'>{$mod->modfullname}: " . format_string($instance->name, true) . "</a></td><td>{$currentgrade}</td><td>{$maxgrade}</td>";
} else {
echo "<td><a href='{$link}'>{$mod->modfullname}: " . format_string($instance->name, true) . "</a></td><td>" . get_string('nograde') . "</td><td>{$maxgrade}</td>";
}
echo '</tr>';
}
}
}
}
}
}
}
}
// a new Moodle nesting record? ;-)
if ($nograde) {
echo '</table>';
}
}
function display()
{
global $CFG, $PAGE, $COURSE;
require_capability('moodle/course:manageactivities', $this->context);
get_all_mods($COURSE->id, $mods, $modnames, $modnamesplural, $modnamesused);
// Right now storing modules in a section corresponding to the current
// page - probably should all be section 0 though
if ($COURSE->id == SITEID) {
$section = 1;
// Front page only has section 1 - so use 1 as default
} else {
if (isset($page->id)) {
$section = $page->id;
} else {
$section = 0;
}
}
$PAGE->print_tabs('activities');
print_box_start('boxwidthwide boxaligncenter pageeditingtable', 'editing-table');
print_section_add_menus($COURSE, $section, $modnames);
if (!empty($modnamesused)) {
$modinfo = get_fast_modinfo($COURSE);
$vars = new stdClass();
$vars->delete = get_string("delete");
$vars->update = get_string("update");
$vars->sesskey = sesskey();
foreach ($modnamesused as $module => $modnamestr) {
$orderby = 'i.name';
$fields = 'i.id, i.name, m.name ' . sql_as() . ' module, c.id ' . sql_as() . 'cmid, c.visible';
// Going to be executing SQL that could fail on purpose - avoid debug messages
$debug = $CFG->debug;
// Store current value
$CFG->debug = false;
// disable_debugging() doesn't seem to work
// Check for field named type
if (execute_sql("SELECT type FROM {$CFG->prefix}{$module} WHERE 1 = 2", false)) {
// Has type - incorperate it into the sql
$orderby = "i.type, {$orderby}";
$fields = "{$fields}, i.type";
}
// Restore debug value
$CFG->debug = $debug;
$instances = get_records_sql("SELECT {$fields}\n FROM {$CFG->prefix}course_modules c,\n {$CFG->prefix}modules m,\n {$CFG->prefix}{$module} i\n WHERE i.course = {$COURSE->id}\n AND m.name = '{$module}'\n AND c.instance = i.id\n AND c.module = m.id\n ORDER BY {$orderby}");
if (!empty($instances)) {
$lasttype = '';
print "<h2><a href=\"{$CFG->wwwroot}/mod/{$module}/index.php?id={$COURSE->id}\">{$modnamestr}</a></h2>\n";
print "<ul class=\"activity-list\">\n";
foreach ($instances as $instance) {
if (!empty($instance->type) and $lasttype != $instance->type) {
if (!empty($lasttype)) {
// Switching types and it isn't the first time, close previously opened list
print "</ul>\n</li>\n";
}
// Try to get a name for the type (check module first)
$strtype = get_string($instance->type, $module);
if (strpos($strtype, '[') !== false) {
$strtype = get_string($module . ':' . $instance->type, 'format_page');
}
print "<li><div class=\"plus-minus\"><p><span class=\"no-space\"><strong>{$strtype}</strong></span></p></div>\n<ul>\n";
$lasttype = $instance->type;
}
if (!empty($modinfo->cms[$instance->cmid]->icon)) {
$icon = "{$CFG->pixpath}/" . urldecode($modinfo->cms[$instance->cmid]->icon);
} else {
$icon = "{$CFG->modpixpath}/{$module}/icon.gif";
}
if (empty($instance->visible)) {
$linkclass = ' class="dimmed"';
} else {
$linkclass = '';
}
print '<li>';
print '<img src="' . $icon . '" class="icon" />';
print "<a{$linkclass} href=\"{$CFG->wwwroot}/mod/{$module}/view.php?id={$instance->cmid}\">" . format_string(strip_tags($instance->name), true, $COURSE->id) . '</a> ';
print '<span class="commands">';
print "<a title=\"{$vars->update}\" href=\"{$CFG->wwwroot}/course/mod.php?update={$instance->cmid}&sesskey={$vars->sesskey}\">";
print "<img src=\"{$CFG->pixpath}/t/edit.gif\" class=\"icon-edit\" alt=\"{$vars->update}\" /></a> ";
print "<a title=\"{$vars->delete}\" href=\"{$CFG->wwwroot}/course/format/page/format.php?id={$COURSE->id}&action=deletemod&sesskey={$vars->sesskey}&cmid={$instance->cmid}\">";
print "<img src=\"{$CFG->pixpath}/t/delete.gif\" class=\"icon-edit\" alt=\"{$vars->delete}\" /></a></span>";
print "</li>\n";
}
if (!empty($lasttype)) {
// Close type list since we know it was opened
print "</ul>\n</li>\n";
}
print "</ul>\n";
}
}
} else {
print_box(get_string('noacivitiesfound', 'format_page'));
}
print_box_end();
}
请发表评论