/** * Render contents of main part of subpage * @param mod_subpage $subpage * @param course_modinfo $modinfo * @param array $sections * @param boolean $editing whether the user is allowed to edit this page * @param int $moveitem (currently not used) * @param boolean $movesection whether the user is allowed to move sections * @return string html for display */ public function render_subpage($subpage, $modinfo, $sections, $editing, $moveitem, $movesection) { global $PAGE, $OUTPUT, $CFG, $USER; $this->subpagecm = $subpage->get_course_module()->id; if (!empty($USER->activitycopy) && $movesection) { $content = $this->render_cancel_link($this->subpagecm); } else { $content = ''; } $content .= $this->render_intro($subpage); $streditsummary = get_string('editsummary'); $strdelete = get_string('delete'); if ($editing) { $strmoveup = get_string('moveup'); $strmovedown = get_string('movedown'); $strhide = get_string('hide'); $strshow = get_string('show'); $strstealth = get_string('stealth', 'subpage'); $strunstealth = get_string('unstealth', 'subpage'); } $coursecontext = get_context_instance(CONTEXT_COURSE, $subpage->get_course()->id); get_all_mods($subpage->get_course()->id, $mods, $modnames, $modnamesplural, $modnamesused); foreach ($mods as $modid => $unused) { if (!isset($modinfo->cms[$modid])) { rebuild_course_cache($subpage->get_course()->id); $modinfo =& get_fast_modinfo($subpage->get_course()); debugging('Rebuilding course cache', DEBUG_DEVELOPER); break; } } $lastpageorder = $subpage->get_last_section_pageorder(); if ($subpage->get_course()->format == 'weeks') { $content .= html_writer::start_tag('ul', array('class' => 'weeks')); } else { $content .= html_writer::start_tag('ul', array('class' => 'topics')); } foreach ($sections as $section) { // Check to see whether cms within the section are visible or not // If all cms are not visible then we don't show the section at all, // unless editing $visible = false; if ($section->sequence) { // get cm_info for this resources $instances = explode(',', $section->sequence); } else { $instances = array(); } foreach ($instances as $instance) { $cm = $modinfo->get_cm($instance); // check to see whether cm is visible if ($cm->uservisible) { $visible = true; break; } } // If section is empty so should be hidden, record that in object $section->autohide = !$visible; $content .= html_writer::start_tag('li', array('class' => 'section main clearfix', 'id' => 'section-' . $section->section)); $content .= html_writer::tag('div', ' ', array('class' => 'left side')); $content .= html_writer::start_tag('div', array('class' => 'right side')); if ($editing && has_capability('moodle/course:update', $coursecontext)) { // Show the hide/show eye if ($section->visible) { $content .= html_writer::start_tag('a', array('href' => 'view.php?id=' . $subpage->get_course_module()->id . '&hide=' . $section->section . '&sesskey=' . sesskey() . '#section-' . $section->id, 'title' => $strhide)); $content .= html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/hide'), 'class' => 'icon hide', 'alt' => $strhide)); $content .= html_writer::end_tag('a'); } else { $content .= html_writer::start_tag('a', array('href' => 'view.php?id=' . $subpage->get_course_module()->id . '&show=' . $section->section . '&sesskey=' . sesskey() . '#section-' . $section->id, 'title' => $strshow)); $content .= html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/show'), 'class' => 'icon show', 'alt' => $strshow)); $content .= html_writer::end_tag('a'); } // Show the stealth/unstealth section link if ($section->stealth) { $content .= html_writer::start_tag('form', array('method' => 'post', 'action' => 'stealth.php')); $content .= html_writer::start_tag('div'); $content .= html_writer::empty_tag('input', array('name' => 'id', 'value' => $subpage->get_course_module()->id, 'type' => 'hidden')); $content .= html_writer::empty_tag('input', array('name' => 'sesskey', 'value' => sesskey(), 'type' => 'hidden')); $content .= html_writer::empty_tag('input', array('name' => 'unstealth', 'value' => $section->id, 'type' => 'hidden')); $content .= html_writer::empty_tag('input', array('name' => 'icon', 'src' => $OUTPUT->pix_url('unstealth', 'mod_subpage'), 'type' => 'image', 'title' => $strunstealth, 'alt' => $strunstealth)); $content .= html_writer::end_tag('div'); $content .= html_writer::end_tag('form'); } else { $content .= html_writer::start_tag('form', array('method' => 'post', 'action' => 'stealth.php')); $content .= html_writer::start_tag('div'); $content .= html_writer::empty_tag('input', array('name' => 'id', 'value' => $subpage->get_course_module()->id, 'type' => 'hidden')); $content .= html_writer::empty_tag('input', array('name' => 'sesskey', 'value' => sesskey(), 'type' => 'hidden')); $content .= html_writer::empty_tag('input', array('name' => 'stealth', 'value' => $section->id, 'type' => 'hidden')); $content .= html_writer::empty_tag('input', array('name' => 'icon', 'src' => $OUTPUT->pix_url('stealth', 'mod_subpage'), 'type' => 'image', 'title' => $strstealth, 'alt' => $strstealth)); $content .= html_writer::end_tag('div'); $content .= html_writer::end_tag('form'); } $content .= html_writer::empty_tag('br', array()); if ($movesection) { $content .= html_writer::start_tag('span', array('class' => 'section_move_commands')); if ($section->pageorder > 1) { // Add a arrow to move section up $content .= html_writer::start_tag('a', array('href' => 'view.php?id=' . $subpage->get_course_module()->id . '&random=' . rand(1, 10000) . '§ion=' . $section->id . '&move=-1&sesskey=' . sesskey() . '#section-' . ($section->id - 1), 'title' => $strmoveup)); $content .= html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('t/up'), 'class' => 'icon up', 'alt' => $strmoveup)); $content .= html_writer::end_tag('a'); $content .= html_writer::empty_tag('br', array()); } if ($section->pageorder < $lastpageorder) { // Add an arrow to move section down $content .= html_writer::start_tag('a', array('href' => 'view.php?id=' . $subpage->get_course_module()->id . '&random=' . rand(1, 10000) . '§ion=' . $section->id . '&move=1&sesskey=' . sesskey() . '#section-' . ($section->id + 1), 'title' => $strmovedown)); $content .= html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('t/down'), 'class' => 'icon down', 'alt' => $strmovedown)); $content .= html_writer::end_tag('a'); $content .= html_writer::empty_tag('br', array()); } $content .= html_writer::end_tag('span'); } } $content .= html_writer::end_tag('div'); $content .= html_writer::start_tag('div', array('class' => 'content')); // Only show the section if visible and not stealthed or to users with permission if (($section->visible && !$section->stealth || has_capability('moodle/course:viewhiddensections', $coursecontext)) && ($editing || !$section->autohide)) { if ($section->stealth) { $content .= html_writer::start_tag('div', array('class' => 'stealthed')); } if (!empty($section->name)) { $content .= html_writer::tag('h3', format_string($section->name), array('class' => 'sectionname')); } $summary = ''; if ($section->summary) { $summarytext = file_rewrite_pluginfile_urls($section->summary, 'pluginfile.php', $coursecontext->id, 'course', 'section', $section->id); $summaryformatoptions = new stdClass(); $summaryformatoptions->noclean = true; $summaryformatoptions->overflowdiv = true; $summary .= format_text($summarytext, $section->summaryformat, $summaryformatoptions); } if ($editing && has_capability('moodle/course:update', $coursecontext)) { $summary .= html_writer::start_tag('a', array('href' => $CFG->wwwroot . '/course/editsection.php?id=' . $section->id . '&returnurl=' . urlencode($CFG->wwwroot . '/mod/subpage/view.php?id=' . $subpage->get_course_module()->id . '&recache=1&sesskey=' . sesskey()), 'title' => $streditsummary)); $summary .= html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('t/edit'), 'class' => 'icon edit', 'alt' => $streditsummary)); $summary .= html_writer::end_tag('a'); $summary .= html_writer::empty_tag('br', array()); $summary .= html_writer::start_tag('a', array('href' => $CFG->wwwroot . '/mod/subpage/view.php?id=' . $subpage->get_course_module()->id . '&delete=' . $section->id . '&sesskey=' . sesskey(), 'title' => $strdelete)); if (empty($section->sequence)) { $summary .= html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('t/delete'), 'class' => 'icon delete', 'alt' => $strdelete)); } $summary .= html_writer::end_tag('a'); $summary .= html_writer::empty_tag('br', array()); $summary .= html_writer::empty_tag('br', array()); } if ($summary !== '') { $content .= html_writer::tag('div', $summary, array('class' => 'summary')); } $content .= $this->render_section($subpage, $modinfo, $section, $editing, $moveitem, $mods, $modnamesused); if ($editing) { $content .= print_section_add_menus($subpage->get_course(), $section->section, $modnames, false, true); if (!empty($CFG->enablecourseajax) and $PAGE->theme->enablecourseajax) { // hacky way to add list to empty section to allow drag/drop into // empty sections $content = str_replace('</div><div class="section_add_menus">', '</div><ul class="section img-text"><li></li></ul>' . '<div class="section_add_menus">', $content); } } //now add returnto links to editing links: $pattern = '/mod.php\\?[A-Za-z0-9-&;=%:\\/\\-.]+/'; $content = preg_replace_callback($pattern, 'mod_subpage_renderer::subpage_url_regex', $content); if ($section->stealth) { $content .= html_writer::end_tag('div'); } } $content .= html_writer::end_tag('div'); //end of div class=content $content .= html_writer::end_tag('li'); } $content .= html_writer::end_tag('ul'); if ($editing) { $content .= $this->render_add_button($subpage); $content .= $this->render_bulkmove_buttons($subpage); } return $content; }
/** * Return an array of modules that can be moved in this situation * The Array is keyed first with sections (subpage or main course) * and then the modules within each section by cmid * @param Object $subpage current subpage * @param Array $allsubpages * @param Array $coursesections * @param Object $modinfo * @param String $move to or from * @return Array mixed */ public static function moveable_modules($subpage, $allsubpages, $coursesections, course_modinfo $modinfo, $move) { global $OUTPUT; get_all_mods($subpage->get_course()->id, $allmods, $modnames, $modnamesplural, $modnamesused); $mods = array(); $subsections = array(); if (!empty($allsubpages) && $move === 'to') { foreach ($allsubpages as $sub) { $subsections += $sub->get_sections(); } $sections = $coursesections; } else { $subsections = $subpage->get_sections(); $sections = $subsections; } if ($sections) { foreach ($sections as $section) { if (!empty($section->sequence)) { if ($move === 'to' && array_key_exists($section->id, $subsections)) { continue; } $sectionalt = isset($section->pageorder) ? $section->pageorder : $section->section; if ($move === 'to') { // Include the required course/format library. global $CFG; require_once "{$CFG->dirroot}/course/format/" . $subpage->get_course()->format . "/lib.php"; $callbackfunction = 'callback_' . $subpage->get_course()->format . '_get_section_name'; if (function_exists($callbackfunction)) { $name = $callbackfunction($subpage->get_course(), $section); } else { $name = $section->name ? $section->name : get_string('section') . ' ' . $sectionalt; } } else { $name = $section->name ? $section->name : get_string('section') . ' ' . $sectionalt; } $sectionmods = explode(',', $section->sequence); foreach ($sectionmods as $modnumber) { if (empty($allmods[$modnumber]) || $modnumber === $subpage->get_course_module()->id) { continue; } $instancename = format_string($modinfo->cms[$modnumber]->name, true, $subpage->get_course()->id); $icon = $modinfo->get_cm($modnumber)->get_icon_url(); $mod = $allmods[$modnumber]; $mods[$section->section]['section'] = $name; $mods[$section->section]['pageorder'] = $sectionalt; $mods[$section->section]['mods'][$modnumber] = "<span><img src='{$icon}' /> " . $instancename . "</span>"; } } } } return $mods; }