本文整理汇总了PHP中course_set_display函数的典型用法代码示例。如果您正苦于以下问题:PHP course_set_display函数的具体用法?PHP course_set_display怎么用?PHP course_set_display使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了course_set_display函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: move_section_to
/**
* Moves a section within a course, from a position to another.
* Be very careful: $section and $destination refer to section number,
* not id!.
*
* @param object $course
* @param int $section Section number (not id!!!)
* @param int $destination
* @return boolean Result
*/
function move_section_to($course, $section, $destination)
{
/// Moves a whole course section up and down within the course
global $USER, $DB;
if (!$destination && $destination != 0) {
return true;
}
if ($destination > $course->numsections) {
return false;
}
// Get all sections for this course and re-order them (2 of them should now share the same section number)
if (!($sections = $DB->get_records_menu('course_sections', array('course' => $course->id), 'section ASC, id ASC', 'id, section'))) {
return false;
}
$movedsections = reorder_sections($sections, $section, $destination);
// Update all sections. Do this in 2 steps to avoid breaking database
// uniqueness constraint
$transaction = $DB->start_delegated_transaction();
foreach ($movedsections as $id => $position) {
if ($sections[$id] !== $position) {
$DB->set_field('course_sections', 'section', -$position, array('id' => $id));
}
}
foreach ($movedsections as $id => $position) {
if ($sections[$id] !== $position) {
$DB->set_field('course_sections', 'section', $position, array('id' => $id));
}
}
// Adjust destination to reflect the actual section
$moveup = false;
if ($section > $destination) {
$destination++;
$moveup = true;
}
// If we move the highlighted section itself, then just highlight the destination.
// Adjust the higlighted section location if we move something over it either direction.
if ($section == $course->marker) {
course_set_marker($course, $destination);
} elseif ($moveup && $section > $course->marker && $course->marker >= $destination) {
course_set_marker($course, $course->marker + 1);
} elseif (!$moveup && $section < $course->marker && $course->marker <= $destination) {
course_set_marker($course, $course->marker - 1);
}
// if the focus is on the section that is being moved, then move the focus along
if (course_get_display($course->id) == $section) {
course_set_display($course->id, $destination);
}
$transaction->allow_commit();
return true;
}
示例2: move_section_to
/**
* Moves a section within a course, from a position to another.
* Be very careful: $section and $destination refer to section number,
* not id!.
*
* @param object $course
* @param int $section Section number (not id!!!)
* @param int $destination
* @return boolean Result
*/
function move_section_to($course, $section, $destination)
{
/// Moves a whole course section up and down within the course
global $USER;
if (!$destination && $destination != 0) {
return true;
}
if ($destination > $course->numsections) {
return false;
}
// Get all sections for this course and re-order them (2 of them should now share the same section number)
if (!($sections = get_records_menu('course_sections', 'course', $course->id, 'section ASC, id ASC', 'id, section'))) {
return false;
}
$sections = reorder_sections($sections, $section, $destination);
// Update all sections
foreach ($sections as $id => $position) {
set_field('course_sections', 'section', $position, 'id', $id);
}
// if the focus is on the section that is being moved, then move the focus along
if (isset($USER->display[$course->id]) and $USER->display[$course->id] == $section) {
course_set_display($course->id, $destination);
}
return true;
}
示例3: empty
$lmax = empty($THEME->block_l_max_width) ? 210 : $THEME->block_l_max_width;
$rmin = empty($THEME->block_r_min_width) ? 100 : $THEME->block_r_min_width;
$rmax = empty($THEME->block_r_max_width) ? 210 : $THEME->block_r_max_width;
define('BLOCK_L_MIN_WIDTH', $lmin);
define('BLOCK_L_MAX_WIDTH', $lmax);
define('BLOCK_R_MIN_WIDTH', $rmin);
define('BLOCK_R_MAX_WIDTH', $rmax);
$preferred_width_left = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), BLOCK_L_MAX_WIDTH);
$preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]), BLOCK_R_MAX_WIDTH);
if ($week != -1) {
$displaysection = course_set_display($course->id, $week);
} else {
if (isset($USER->display[$course->id])) {
$displaysection = $USER->display[$course->id];
} else {
$displaysection = course_set_display($course->id, 0);
}
}
$streditsummary = get_string('editsummary');
$stradd = get_string('add');
$stractivities = get_string('activities');
$strshowallweeks = get_string('showallweeks');
$strweek = get_string('week');
$strgroups = get_string('groups');
$strgroupmy = get_string('groupmy');
$editing = $PAGE->user_is_editing();
if ($editing) {
$strstudents = moodle_strtolower($course->students);
$strweekhide = get_string('weekhide', '', $strstudents);
$strweekshow = get_string('weekshow', '', $strstudents);
$strmoveup = get_string('moveup');
示例4: move_section
function move_section($course, $section, $move)
{
/// Moves a whole course section up and down within the course
global $USER;
if (!$move) {
return true;
}
$sectiondest = $section + $move;
if ($sectiondest > $course->numsections or $sectiondest < 1) {
return false;
}
if (!($sectionrecord = get_record("course_sections", "course", $course->id, "section", $section))) {
return false;
}
if (!($sectiondestrecord = get_record("course_sections", "course", $course->id, "section", $sectiondest))) {
return false;
}
if (!set_field("course_sections", "section", $sectiondest, "id", $sectionrecord->id)) {
return false;
}
if (!set_field("course_sections", "section", $section, "id", $sectiondestrecord->id)) {
return false;
}
// if the focus is on the section that is being moved, then move the focus along
if (isset($USER->display[$course->id]) and $USER->display[$course->id] == $section) {
course_set_display($course->id, $sectiondest);
}
// Check for duplicates and fix order if needed.
// There is a very rare case that some sections in the same course have the same section id.
$sections = get_records_select('course_sections', "course = {$course->id}", 'section ASC');
$n = 0;
foreach ($sections as $section) {
if ($section->section != $n) {
if (!set_field('course_sections', 'section', $n, 'id', $section->id)) {
return false;
}
}
$n++;
}
return true;
}
示例5: defined
* 800x600, 1024x768... on IE6, Firefox. Below 800 columns will shift downwards.
*
* http://www.maxdesign.com.au/presentation/em/ Ideal length for content.
* http://www.svendtofte.com/code/max_width_in_ie/ Max width in IE.
*
* @copyright © 2006 The Open University
* @author N.D.Freear@open.ac.uk, and others.
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package
*/
defined('MOODLE_INTERNAL') || die;
require_once $CFG->libdir . '/filelib.php';
require_once $CFG->libdir . '/completionlib.php';
$topic = optional_param('topic', -1, PARAM_INT);
if ($topic != -1) {
$displaysection = course_set_display($course->id, $topic);
} else {
$displaysection = course_get_display($course->id);
}
$context = get_context_instance(CONTEXT_COURSE, $course->id);
if ($marker >= 0 && has_capability('moodle/course:setcurrentsection', $context) && confirm_sesskey()) {
$course->marker = $marker;
$DB->set_field("course", "marker", $marker, array("id" => $course->id));
}
$streditsummary = get_string('editsummary');
$stradd = get_string('add');
$stractivities = get_string('activities');
$strshowalltopics = get_string('showalltopics');
$strtopic = get_string('topic');
$strgroups = get_string('groups');
$strgroupmy = get_string('groupmy');
示例6: sections
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;
}
}
//.........这里部分代码省略.........
示例7: defined
* 800x600, 1024x768... on IE6, Firefox. Below 800 columns will shift downwards.
*
* http://www.maxdesign.com.au/presentation/em/ Ideal length for content.
* http://www.svendtofte.com/code/max_width_in_ie/ Max width in IE.
*
* @copyright © 2006 The Open University
* @author N.D.Freear@open.ac.uk, and others.
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package
*/
defined('MOODLE_INTERNAL') || die;
require_once $CFG->libdir . '/filelib.php';
require_once $CFG->libdir . '/completionlib.php';
$week = optional_param('week', -1, PARAM_INT);
if ($week != -1) {
$displaysection = course_set_display($course->id, $week);
} else {
$displaysection = course_get_display($course->id);
}
$streditsummary = get_string('editsummary');
$stradd = get_string('add');
$stractivities = get_string('activities');
$strshowallweeks = get_string('showallweeks');
$strweek = get_string('week');
$strgroups = get_string('groups');
$strgroupmy = get_string('groupmy');
$editing = $PAGE->user_is_editing();
if ($editing) {
$strweekhide = get_string('hideweekfromothers');
$strweekshow = get_string('showweekfromothers');
$strmoveup = get_string('moveup');
示例8: specialization
/**
* specialization
*/
function specialization()
{
global $COURSE, $DB, $USER, $displaysection, $section;
// set default config values
$defaults = array('title' => get_string('defaulttitle', 'block_taskchain_navigation'), 'showcourse' => 0, 'coursenamefield' => 'shortname', 'coursenametext' => '', 'coursegradeposition' => 0, 'minimumdepth' => 0, 'maximumdepth' => 0, 'categoryskipempty' => 0, 'categoryskiphidden' => 0, 'categoryskipzeroweighted' => 0, 'categorycollapse' => 0, 'categoryshortnames' => 0, 'categoryshowweighting' => 0, 'categoryignorechars' => '', 'categoryprefixlength' => 0, 'categoryprefixchars' => '', 'categoryprefixlong' => 0, 'categoryprefixkeep' => 0, 'categorysuffixlength' => 0, 'categorysuffixchars' => '', 'categorysuffixlong' => 0, 'categorysuffixkeep' => 0, 'sectionshowhidden' => 2, 'sectionshowburied' => 0, 'sectionshowungraded' => 0, 'sectionshowzeroweighted' => 0, 'sectionshowuncategorized' => 0, 'sectiontitletags' => '', 'sectionshorttitles' => 0, 'sectionignorecase' => 0, 'sectionignorechars' => '', 'sectionprefixlength' => 0, 'sectionprefixchars' => '', 'sectionprefixlong' => 0, 'sectionprefixkeep' => 0, 'sectionsuffixlength' => 0, 'sectionsuffixchars' => '', 'sectionsuffixlong' => 0, 'sectionsuffixkeep' => 0, 'gradedisplay' => 1, 'showaverages' => 1, 'highgrade' => 90, 'mediumgrade' => 60, 'lowgrade' => 0, 'showactivitygrades' => '', 'sectionjumpmenu' => 1, 'sectionnumbers' => 1, 'singlesection' => 1, 'defaultsection' => 1, 'arrowup' => '', 'arrowdown' => '', 'gradebooklink' => 0, 'accesscontrol' => 0, 'hiddensections' => 0, 'hiddensectionstitle' => 0, 'hiddensectionsstyle' => 0, 'namelength' => 28, 'headlength' => 10, 'taillength' => 10, 'currentsection' => 0, 'groupsmenu' => 0, 'groupslabel' => 0, 'groupscountusers' => 0, 'groupssort' => 0, 'loginasmenu' => 0, 'loginassort' => 1, 'moodlecss' => 2, 'externalcss' => '', 'internalcss' => '');
if (!isset($this->config)) {
$this->config = new stdClass();
}
foreach ($defaults as $name => $value) {
if (!isset($this->config->{$name})) {
$this->config->{$name} = $value;
}
}
// load user-defined title (may be empty)
$this->title = $this->config->title;
if (empty($COURSE->context)) {
$COURSE->context = self::context(CONTEXT_COURSE, $COURSE->id);
}
$this->config->numsections = self::get_numsections($COURSE);
// make sure user is only shown one course section at a time
if (isset($USER->id) && isset($COURSE->id) && $this->config->singlesection) {
$update = false;
if (function_exists('course_get_display')) {
// Moodle <= 2.2
$displaysection = course_get_display($COURSE->id);
} else {
// Moodle >= 2.3
$name = get_class($this) . '_course' . $COURSE->id;
$displaysection = get_user_preferences($name, 0);
if ($section == 0) {
$section = $displaysection;
} else {
if ($displaysection == $section) {
// do nothing
} else {
$displaysection = $section;
$update = true;
}
}
}
if ($displaysection == 0) {
// no course section is currently selected for this user
if ($displaysection = $this->config->defaultsection) {
// use default display section
} else {
if ($displaysection = $COURSE->marker) {
// use highlighted section
} else {
// use first visible section
$select = 'course = ? AND section > ? AND visible = ?';
$params = array($COURSE->id, 0, 1);
$displaysection = $DB->get_field_select('course_sections', 'MIN(section)', $select, $params);
}
}
$update = true;
}
if ($update) {
if (function_exists('course_set_display')) {
// Moodle <= 2.2
course_set_display($COURSE->id, $displaysection);
} else {
// Moodle >= 2.3
$name = get_class($this) . '_course' . $COURSE->id;
set_user_preference($name, $displaysection);
}
}
}
// disable up/down arrows on Moodle >= 2.3
if (function_exists('course_get_format')) {
$this->config->arrowup = '';
$this->config->arrowdown = '';
}
// disable hiddensections functionality, if the block is in the right column
if (isset($this->instance->region) && $this->instance->region == BLOCK_POS_RIGHT) {
$this->config->hiddensections = 0;
}
if (has_capability('moodle/course:manageactivities', $COURSE->context)) {
$this->fix_course_format();
$this->fix_section_visibility();
$this->fix_course_marker();
}
$this->config->displaysection = $displaysection;
$this->config->courseformat = $this->get_course_format($COURSE);
$this->config->sectiontype = $this->get_section_type();
$this->config->coursestartdate = $COURSE->startdate;
}
示例9: get_sections
function get_sections()
{
global $CFG, $USER, $DB, $OUTPUT;
if (!empty($this->instance)) {
get_all_mods($this->course->id, $mods, $modnames, $modnamesplural, $modnamesused);
$context = get_context_instance(CONTEXT_COURSE, $this->course->id);
$isteacher = has_capability('moodle/course:update', $context);
$courseFormat = $this->course->format == 'topics' ? 'topic' : 'week';
// displaysection - current section
$week = optional_param($courseFormat, -1, PARAM_INT);
if ($week != -1) {
$displaysection = course_set_display($this->course->id, $week);
} else {
if (isset($USER->display[$this->course->id])) {
$displaysection = $USER->display[$this->course->id];
} else {
$displaysection = course_set_display($this->course->id, 0);
}
}
$genericName = get_string("name" . $this->course->format, $this->blockname);
$allSections = get_all_sections($this->course->id);
$sections = array();
if ($this->course->format != 'social' && $this->course->format != 'scorm') {
foreach ($allSections as $k => $section) {
if ($k <= $this->course->numsections) {
// get_all_sections() may return sections that are in the db but not displayed because the number of the sections for this course was lowered - bug [CM-B10]
if (!empty($section)) {
$newSec = array();
$newSec['visible'] = $section->visible;
if (!empty($section->name)) {
$strsummary = trim($section->name);
} else {
$strsummary = ucwords($genericName) . " " . $k;
// just a default name
}
$strsummary = $this->trim($strsummary);
$strsummary = trim($this->clearEnters($strsummary));
$newSec['name'] = $strsummary;
// url
if ($displaysection != 0) {
$newSec['url'] = "{$CFG->wwwroot}/course/view.php?id={$this->course->id}&{$courseFormat}={$k}";
} else {
$newSec['url'] = "#section-{$k}";
}
// resources
$modinfo = unserialize($this->course->modinfo);
$newSec['resources'] = array();
$sectionmods = explode(",", $section->sequence);
foreach ($sectionmods as $modnumber) {
if (empty($mods[$modnumber])) {
continue;
}
$mod = $mods[$modnumber];
if ($mod->visible or $isteacher) {
$instancename = urldecode($modinfo[$modnumber]->name);
if (!empty($CFG->filterall)) {
$instancename = filter_text($instancename, $this->course->id);
}
if (!empty($modinfo[$modnumber]->extra)) {
$extra = urldecode($modinfo[$modnumber]->extra);
} else {
$extra = "";
}
// don't do anything for labels
if ($mod->modname != 'label') {
// Normal activity
if ($mod->visible) {
if (!strlen(trim($instancename))) {
$instancename = $mod->modfullname;
}
$instancename = $this->truncate_description($instancename);
$resource = array();
if ($mod->modname != 'resource') {
$resource['name'] = $this->truncate_description($instancename, 200);
$resource['url'] = "{$CFG->wwwroot}/mod/{$mod->modname}/view.php?id={$mod->id}";
$icon = $OUTPUT->pix_url("icon", $mod->modname);
if (is_object($icon)) {
$resource['icon'] = $icon->__toString();
} else {
$resource['icon'] = '';
}
} else {
require_once $CFG->dirroot . '/mod/resource/lib.php';
$info = resource_get_coursemodule_info($mod);
if (isset($info->icon)) {
$resource['name'] = $this->truncate_description($info->name, 200);
$resource['url'] = "{$CFG->wwwroot}/mod/{$mod->modname}/view.php?id={$mod->id}";
$icon = $OUTPUT->pix_url("icon", $mod->modname);
if (is_object($icon)) {
$resource['icon'] = $icon->__toString();
} else {
$resource['icon'] = '';
}
} else {
if (!isset($info->icon)) {
$resource['name'] = $this->truncate_description($info->name, 200);
$resource['url'] = "{$CFG->wwwroot}/mod/{$mod->modname}/view.php?id={$mod->id}";
$icon = $OUTPUT->pix_url("icon", $mod->modname);
if (is_object($icon)) {
$resource['icon'] = $icon->__toString();
//.........这里部分代码省略.........
示例10: json_encode
$responseobj->success = 0;
break;
}
$num--;
$section_id += $dir;
}
if ($responseobj->success == 1) {
$responseobj->reason = "Section moved ";
} else {
$responseobj->reason = "An error occurred while moving a section " . $dir . ". broke at " . $num;
}
// Clear the navigation cache at this point so that the affects
// are seen immediatly on the navigation.
// $PAGE->navigation->clear_cache();
}
break;
case ACTION_SET_DISPLAY :
if($section_id >= 0) {
course_set_display($course_id, $section_id);
} else {
$responseobj->success = 0;
$responseobj->reason = "Section out of range";
}
break;
case ACTION_POSITION :
break;
}
echo json_encode($responseobj);
示例11: test_version1importdeletecoursedeletesassociations
//.........这里部分代码省略.........
$page->subpage = false;
foreach ($instances as $instance) {
blocks_set_visibility($instance, $page, 1);
}
// Create a group.
$group = new stdClass();
$group->name = 'testgroup';
$group->courseid = $courseid;
$groupid = groups_create_group($group);
// Add the user to the group.
groups_add_member($groupid, $userid);
// Create a grouping containing our group.
$grouping = new stdClass();
$grouping->name = 'testgrouping';
$grouping->courseid = $courseid;
$groupingid = groups_create_grouping($grouping);
groups_assign_grouping($groupingid, $groupid);
// Set up a user tag.
tag_set('course', $courseid, array('testtag'));
// Add a course-level log.
add_to_log($courseid, 'bogus', 'bogus');
// Set up the default course question category.
$newcategory = question_make_default_categories(array($coursecontext));
// Create a test question.
$question = new stdClass();
$question->qtype = 'truefalse';
$form = new stdClass();
$form->category = $newcategory->id;
$form->name = 'testquestion';
$form->correctanswer = 1;
$form->feedbacktrue = array('text' => 'bogustext', 'format' => FORMAT_HTML);
$form->feedbackfalse = array('text' => 'bogustext', 'format' => FORMAT_HTML);
$question = question_bank::get_qtype('truefalse')->save_question($question, $form);
if (function_exists('course_set_display')) {
// Set a "course display" setting.
course_set_display($courseid, 1);
}
// Make a bogus backup record.
$backupcourse = new stdClass();
$backupcourse->courseid = $courseid;
$DB->insert_record('backup_courses', $backupcourse);
// Add a user lastaccess record.
$lastaccess = new stdClass();
$lastaccess->userid = $userid;
$lastaccess->courseid = $courseid;
$DB->insert_record('user_lastaccess', $lastaccess);
// Make a bogus backup log record.
$log = new stdClass();
$log->backupid = $courseid;
$log->timecreated = time();
$log->loglevel = 1;
$log->message = 'bogus';
$DB->insert_record('backup_logs', $log);
// Get initial counts.
$initialnumcourse = $DB->count_records('course');
$initialnumroleassignments = $DB->count_records('role_assignments');
$initialnumuserenrolments = $DB->count_records('user_enrolments');
$initialnumgradeitems = $DB->count_records('grade_items');
$initialnumgradegrades = $DB->count_records('grade_grades');
$initialnumgradeoutcomes = $DB->count_records('grade_outcomes');
$initialnumgradeoutcomescourses = $DB->count_records('grade_outcomes_courses');
$initialnumscale = $DB->count_records('scale');
$initialnumgradesettings = $DB->count_records('grade_settings');
$initialnumgradeletters = $DB->count_records('grade_letters');
$initialnumforum = $DB->count_records('forum');
$initialnumcoursemodules = $DB->count_records('course_modules');
示例12: get_content
function get_content()
{
// cache content
if (isset($this->content)) {
return $this->content;
}
global $USER, $CFG;
require_once $CFG->dirroot . '/course/lib.php';
require_once $CFG->libdir . '/ajax/ajaxlib.php';
$course = get_record('course', 'id', $this->instance->pageid);
// if we're looking at the course home page
if (strpos($_SERVER['REQUEST_URI'], 'course/view.php') != 0) {
# get current section being displayed
$week = optional_param('week', -1, PARAM_INT);
if ($week != -1) {
$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 (strpos($_SERVER['REQUEST_URI'], '/mod/') !== false) {
// use on a module page
$sql = 'select section from ' . $CFG->prefix . 'course_sections where id=(select section from ' . $CFG->prefix . 'course_modules where id=' . $_GET['id'] . ')';
$row = get_record_sql($sql);
$display = $row->section;
} else {
$display = 0;
}
if (in_array($course->format, array('topics', 'twu'))) {
$format = 'topic';
} else {
$format = 'week';
}
get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
$items = $this->visible_items($course);
if (isset($items['outline'])) {
//echo require_js(array('yui_yahoo','yui_event','yui_treeview'));
echo require_js(array('yui_yahoo', 'yui_event', 'yui_dom-event', 'yui_treeview'));
}
// merge items
$script = '';
$menu = '';
$menuid = 'yui_menu_tree_' . $this->instance->id;
$even = true;
$script = '';
foreach ($items as $item => $v) {
// add them to the tree in the order from configuration
// even/odd classes
$mod = 'r' . ($even ? '0' : '1');
$even = !$even;
// required parameters
$url = htmlspecialchars($CFG->wwwroot . $v['url']);
$ico = htmlspecialchars($v['icon']);
$txt = htmlspecialchars($v['text']);
// optional title attribute
if (isset($v['title'])) {
$title = " title = '" . htmlspecialchars($v['title']) . "'";
} else {
$title = '';
}
// add to menu
$menu .= "\n<li class='{$mod} yui_menu_item_{$item}'>\n<div class='icon column c0'><img src='{$ico}' alt='' /></div>\n<div class='column c1'><a href='{$url}'{$title}>{$txt}</a></div>";
if ($item == "outline") {
if ($course->format != 'course-view-social') {
$menu .= "<div id='{$menuid}' class='yui_menu_outline_tree'></div>";
$script .= $this->course_sections($course, $mods, $display);
}
}
$menu .= "</li>";
}
// print the tree
// note: YUI treeview css must be included in theme
$output = "\n <ul class='list'>\n {$menu}\n </ul>";
if (isset($items['outline'])) {
$output .= "\n<script type='text/javascript'>//<![CDATA[\n\nfunction addTreeIcons(node) {\n for(var c in node.children) {\n child = node.children[c];\n // e might be null, meaning the child hasn't been expanded yet\n if (child._yui_menu_icon && (e = child.getLabelEl())) {\n e.style.backgroundImage = 'url('+child._yui_menu_icon+')';\n // more efficent if this is added as and event\n child._yui_menu_icon = null;\n }\n }\n}\n\nvar tree = new YAHOO.widget.TreeView('{$menuid}');\nvar root = tree.getRoot();\n{$script}\ntree.draw();\n// configure icons for elements that have already been loaded\nfor(var c in root.children) addTreeIcons(root.children[c]);\n// for icons not yet loaded\ntree.subscribe('expandComplete', addTreeIcons);\n//]]>\n</script>\n";
}
$this->content = new stdClass();
$this->content->text = $output;
$this->content->footer = '';
return $this->content;
}