function get_sections() { global $CFG, $USER, $DB, $OUTPUT; if (!empty($this->instance) && $this->page->course->id != SITEID) { require_once $CFG->dirroot . "/course/lib.php"; $context = get_context_instance(CONTEXT_COURSE, $this->course->id); $canviewhidden = has_capability('moodle/course:viewhiddensections', $context); $genericName = get_string("sectionname", 'format_' . $this->course->format); $modinfo = get_fast_modinfo($this->page->course); $mods = $modinfo->get_cms(); //keep backwards compatibillity with moodle 2.3 if (!isset($this->course->numsections) && function_exists('course_get_format')) { $this->course = course_get_format($this->course)->get_course(); } $allSections = $modinfo->get_section_info_all(); $sections = array(); if ($this->course->format != 'social' && $this->course->format != 'scorm') { foreach ($allSections as $k => $section) { if (!isset($this->course->numsections) || $k <= $this->course->numsections) { if (!empty($section)) { $newSec = array(); $newSec['visible'] = $section->visible; $newSec['uservisible'] = !empty($section->uservisible) ? $section->uservisible : 0; $newSec['availableinfo'] = !empty($section->availableinfo) ? $section->availableinfo : 0; $newSec['id'] = $section->section; $newSec['index'] = $k; if (!empty($section->name)) { $strsummary = trim($section->name); } else { $strsummary = ucwords($genericName) . " " . $k; // just a default name } $strsummary = $this->trim($strsummary); $newSec['name'] = $strsummary; $newSec['url'] = course_get_url($this->course, $k); // resources $newSec['resources'] = array(); $sectionmods = explode(",", $section->sequence); foreach ($sectionmods as $modnumber) { if (empty($mods[$modnumber])) { continue; } $mod = $mods[$modnumber]; if ($mod->visible or $canviewhidden) { $instancename = urldecode($modinfo->cms[$modnumber]->name); if (!empty($CFG->filterall)) { $instancename = filter_text($instancename, $this->course->id); } // don't do anything for labels if ($mod->modname != 'label') { // Normal activity if ($mod->visible or $canviewhidden) { if (!strlen(trim($instancename))) { $instancename = $mod->modfullname; } $resource = array(); if ($mod->modname != 'resource') { $resource['name'] = $instancename; $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'] = $info->name; $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'] = $info->name; $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'] = $OUTPUT->pix_url("icon", $mod->modname); } } } } if ($section->uservisible) { $newSec['resources'][] = $resource; } } } } } $showsection = $section->uservisible || $section->visible && !$section->available && $section->showavailability; //hide hidden sections from students if the course settings say that - bug #212 $coursecontext = get_context_instance(CONTEXT_COURSE, $this->course->id); if (!($section->visible == 0 && !has_capability('moodle/course:viewhiddensections', $coursecontext)) && $showsection) { $sections[] = $newSec; } } } } // get rid of the first one array_shift($sections); } return $sections; } return array(); }
continue; // Not available, render nothing. } // Get data about this course-module. $content = $mod->get_formatted_content(array('overflowdiv' => true, 'noclean' => true)); if (strlen($content) > 0) { $instancename = strip_tags($content); } else { $instancename = $mod->get_formatted_name(array('overflowdiv' => true, 'noclean' => true)); } $fullinstancename = urldecode($instancename); if ($mod->modname != 'resource') { $instancelogo = "<img src=\"{$CFG->wwwroot}/mod/{$mod->modname}/pix/icon.png\" alt=\"Resource\">"; } else { require_once $CFG->dirroot . '/mod/resource/lib.php'; $info = resource_get_coursemodule_info($mod); $instancelogo = "<img src=\"{$CFG->wwwroot}/pix/{$info->icon}.png\" alt=\"Resource\">"; } // First, we'll look for a custom compile.php page for the module. // If that doesn't exist, we'll fall back to the view.php page. if (file_exists($CFG->dirroot . "/local/compile/mod/" . $mod->modname . "/compile.php")) { // Does this module have a config file? If so load it. $configfile = $CFG->dirroot . "/local/compile/mod/" . $mod->modname . "/config.php"; if (isset($modconfig)) { // Discard config from previous module if present. unset($modconfig); } $modconfig = new stdClass(); // Initialize module config. if (file_exists($configfile)) { // Load module config, if present.
/** * Prints a section full of activity modules * * @author Steve Beaudry * date 2011-06-03 * @global object $CFG The Moodle configuration object * @param object course information * @param array section information * @param array mod modules of the course * @return string section table */ function print_course_section($course, $section, $mods) { global $CFG; $sectiontable = '<div>'; $modinfo = get_fast_modinfo($course); filter_preload_activities($modinfo); if (!empty($section->sequence)) { $sectionmods = explode(",", $section->sequence); foreach ($sectionmods as $modnumber) { if (empty($mods[$modnumber])) { continue; } $mod = $mods[$modnumber]; // Is this course-module available to the user? if (!$mod->uservisible && empty($mod->availableinfo)) { continue; // Not available, do not list. } if ($mod->visible) { $content = $mod->get_formatted_content(array('overflowdiv' => true, 'noclean' => true)); $instancename = $mod->get_formatted_name(array('overflowdiv' => true, 'noclean' => true)); if (strlen($content) > 0) { $instancename = strip_tags($content); } $fullinstancename = urldecode($instancename); $cm = $modinfo->get_cm($modnumber); if (!empty($cm->extra)) { $extra = urldecode($cm->extra); } else { $extra = ''; } // Normal activity. $compilable = get_config("local_compile", $mod->modname); if ($compilable && $mod->visible) { if (!strlen(trim($instancename))) { $instancename = $mod->modfullname; } if ($mod->modname != 'resource') { $sectiontable .= '<tr>'; $sectiontable .= '<td class="compile-select-spacer"></td>'; $sectiontable .= '<td class="compile-select-checkcell">' . "<input type=checkbox checked onclick=\"setparent(" . $modnumber . "," . $section->id . ")\" class=\"section-{$section->id}\" id=\"{$modnumber}\" name=checkboxlist[] value=\"{$modnumber}\" />" . '</td>'; $sectiontable .= '<td class="compile-select-desccell">' . "<a href=\"{$CFG->wwwroot}/mod/{$mod->modname}/view.php?id={$mod->id}\">" . "<img src=\"{$CFG->wwwroot}/mod/{$mod->modname}/pix/icon.png\">{$fullinstancename}</a>" . '</td>'; $sectiontable .= '</tr>'; } else { require_once $CFG->dirroot . '/mod/resource/lib.php'; $info = resource_get_coursemodule_info($mod); if ($info->icon) { $sectiontable .= '<tr>'; $sectiontable .= '<td class="compile-select-spacer"></td>'; $sectiontable .= '<td class="compile-select-checkcell">' . "<input type=checkbox onclick=\"setparent(" . $modnumber . "," . $section->id . ")\" checked class=\"section-{$section->id}\" " . "id={$modnumber} name=checkboxlist[] value={$modnumber} />" . '</td>'; $sectiontable .= '<td class="compile-select-desccell">' . "<a href=\"{$CFG->wwwroot}/mod/{$mod->modname}/view.php?id={$mod->id}\">" . "<img src=\"{$CFG->wwwroot}/pix/{$info->icon}.png\">{$fullinstancename}</a>" . '</td>'; $sectiontable .= '</tr>'; } else { if (!$info->icon) { $sectiontable .= '<tr>'; $sectiontable .= '<td class="compile-select-spacer"></td>'; $sectiontable .= '<td class="compile-select-checkcell">' . "<input type=checkbox onclick=\"setparent(" . $modnumber . "," . $section->id . ")\" checked class=\"section-{$section->id}\" " . "id=\"{$modnumber}\" name=checkboxlist[] value=\"{$modnumber}\" />" . '</td>'; $sectiontable .= '<td class="compile-select-desccell">' . "<a href=\"{$CFG->wwwroot}/mod/{$mod->modname}/view.php?id={$mod->id}\">" . "<img src=\"{$CFG->modpixpath}/{$mod->modname}/icon.gif\">{$fullinstancename}</a>" . '</td>'; $sectiontable .= '</tr>'; } } } } } } } $sectiontable .= '</div>'; if ($sectiontable == "<div></div>") { $sectiontable = ''; } return $sectiontable; }
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; } } $introaction = isset($config->introaction) ? $config->introaction : 'introhide'; if ($introaction == 'introhide' || $hidden) { // link to the section, this will effectively hide all // the other sections $url = "{$CFG->wwwroot}/course/view.php?id={$COURSE->id}" . "&{$format}={$section->section}"; } else { // this pretty much just a hack // use $PAGE in Moodle 2 for great justice if (strpos($_SERVER['REQUEST_URI'], 'course/view.php') != 0) { $url = "#section-{$section->section}"; } else { $url = false; } } if ($url === false) { $item = new yui_menu_item($this, $text, ''); //$iconpath . '/i/one.gif'); // redundant icons, lets save space (nadavkav) } else { $item = new yui_menu_item_link($this, $text, $url, ''); // $iconpath . '/i/one.gif'); // redundant icons, lets save space (nadavkav) } $item->expand = $expand; if (isset($section->sequence)) { $sectionmods = explode(",", $section->sequence); } else { $sectionmods = array(); } foreach ($sectionmods as $modnumber) { if (empty($mods[$modnumber])) { continue; } $mod = $mods[$modnumber]; // don't do anything invisible or labels if (!$mod->visible || $mod->modname == 'label') { continue; } // figure out the text and url $text = urldecode($modinfo[$modnumber]->name); if (!empty($CFG->filterall)) { $text = filter_text($text, $COURSE->id); } if (trim($text) == '') { $text = $mod->modfullname; } $text = $this->truncate_html($text, $config); $url = "{$CFG->wwwroot}/mod/{$mod->modname}/view.php?id={$mod->id}"; $name = "yui_menu_mod_{$mod->modname}_{$modnumber}"; // figure out if it is the current page $pageurl = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $pageurl = '~https?://' . preg_quote($pageurl, '~') . '~'; if (preg_match($pageurl, $CFG->wwwroot . $url)) { $style = "yui_menu_mod_{$mod->modname} highlight"; } else { $style = "yui_menu_mod_{$mod->modname}"; } $icon = "{$iconpath}/mod/{$mod->modname}/icon.gif"; if ($mod->modname == 'resource') { $info = resource_get_coursemodule_info($mod); if (isset($info) && isset($info->icon)) { $icon = "{$CFG->pixpath}/{$info->icon}"; } } $child = new yui_menu_item_link($this, $text, $url, $icon); $child->style = $style; $item->children[$modnumber] = $child; } $return[] = $item; } return $return; }
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(); } else { $resource['icon'] = $OUTPUT->pix_url("icon", $mod->modname); } } } } $newSec['resources'][] = $resource; } } } } //hide hidden sections from students if the course settings say that - bug #212 $coursecontext = get_context_instance(CONTEXT_COURSE, $this->course->id); if (!($section->visible == 0 && !has_capability('moodle/course:viewhiddensections', $coursecontext))) { $sections[] = $newSec; } } } } // get rid of the first one array_shift($sections); } return $sections; } return array(); }
/** * Prints a section full of activity modules */ function course_section($course, $section, $parent, $mods) { global $CFG, $USER; $out = ''; $modinfo = unserialize($course->modinfo); if (!empty($section->sequence)) { $sectionmods = explode(",", $section->sequence); foreach ($sectionmods as $modnumber) { if (empty($mods[$modnumber])) { continue; } $mod = $mods[$modnumber]; // don't do anything invisible or labels if (!$mod->visible || $mod->modname == 'label') { continue; } $instancename = urldecode($modinfo[$modnumber]->name); if (!empty($CFG->filterall)) { $instancename = filter_text($instancename, $course->id); } if (!empty($modinfo[$modnumber]->extra)) { $extra = urldecode($modinfo[$modnumber]->extra); } else { $extra = ""; } if (trim($instancename) == '') { $instancename = $mod->modfullname; } $instancename = $this->truncate_html($instancename); $instancename = addslashes(htmlspecialchars($instancename, ENT_QUOTES)); $url = htmlspecialchars($CFG->wwwroot . "/mod/{$mod->modname}/view.php?id={$mod->id}"); $name = "yui_menu_mod_{$mod->modname}_{$modnumber}"; $style = "yui_menu_mod_{$mod->modname}"; $out .= "\nvar {$name} = new YAHOO.widget.TextNode('{$instancename}', {$parent}, false);\n{$name}.href = '{$url}';\n{$name}.labelStyle = '{$style}';"; if ($mod->modname == 'resource') { $info = resource_get_coursemodule_info($mod); if (isset($info) && isset($info->icon)) { $out .= "\n{$name}._yui_menu_icon = '{$CFG->pixpath}/{$info->icon}';"; } } } } return $out; }