mirror of
https://github.com/moodle/moodle.git
synced 2025-07-25 08:11:39 +02:00
MDL-35339 Use get_fast_modinfo() in course sections display functions
- Avoid using field course_sections.sequence for retrieving the modules list, use functionality from get_fast_modinfo() instead; - In the following functions/methods mark arguments $mod, $modnames, $modnamesused and $sections as not used because they can be taken any time from get_fast_modinfo(): - function print_section() - protected function format_section_renderer_base::section_summary() - private function format_section_renderer_base::section_activity_summary - public function format_section_renderer_base::print_single_section_page - public function format_section_renderer_base::print_multiple_section_page
This commit is contained in:
@@ -271,7 +271,7 @@ abstract class format_section_renderer_base extends plugin_renderer_base {
|
||||
*
|
||||
* @param stdClass $section The course_section entry from DB
|
||||
* @param stdClass $course The course entry from DB
|
||||
* @param array $mods course modules indexed by id (from get_fast_modinfo()->get_cms())
|
||||
* @param array $mods (argument not used)
|
||||
* @return string HTML to output.
|
||||
*/
|
||||
protected function section_summary($section, $course, $mods) {
|
||||
@@ -303,7 +303,7 @@ abstract class format_section_renderer_base extends plugin_renderer_base {
|
||||
$o.= html_writer::start_tag('div', array('class' => 'summarytext'));
|
||||
$o.= $this->format_summary_text($section);
|
||||
$o.= html_writer::end_tag('div');
|
||||
$o.= $this->section_activity_summary($section, $course, $mods);
|
||||
$o.= $this->section_activity_summary($section, $course, null);
|
||||
|
||||
$o.= $this->section_availability_message($section);
|
||||
|
||||
@@ -318,11 +318,12 @@ abstract class format_section_renderer_base extends plugin_renderer_base {
|
||||
*
|
||||
* @param stdClass $section The course_section entry from DB
|
||||
* @param stdClass $course the course record from DB
|
||||
* @param array $mods course modules indexed by id (from get_fast_modinfo()->get_cms())
|
||||
* @param array $mods (argument not used)
|
||||
* @return string HTML to output.
|
||||
*/
|
||||
private function section_activity_summary($section, $course, $mods) {
|
||||
if (empty($section->sequence)) {
|
||||
$modinfo = get_fast_modinfo($course);
|
||||
if (empty($modinfo->sections[$section->section])) {
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -332,9 +333,8 @@ abstract class format_section_renderer_base extends plugin_renderer_base {
|
||||
$complete = 0;
|
||||
$cancomplete = isloggedin() && !isguestuser();
|
||||
$completioninfo = new completion_info($course);
|
||||
$modsequence = explode(',', $section->sequence);
|
||||
foreach ($modsequence as $cmid) {
|
||||
$thismod = $mods[$cmid];
|
||||
foreach ($modinfo->sections[$section->section] as $cmid) {
|
||||
$thismod = $modinfo->cms[$cmid];
|
||||
|
||||
if ($thismod->modname == 'label') {
|
||||
// Labels are special (not interesting for students)!
|
||||
@@ -343,9 +343,10 @@ abstract class format_section_renderer_base extends plugin_renderer_base {
|
||||
|
||||
if ($thismod->uservisible) {
|
||||
if (isset($sectionmods[$thismod->modname])) {
|
||||
$sectionmods[$thismod->modname]['name'] = $thismod->modplural;
|
||||
$sectionmods[$thismod->modname]['count']++;
|
||||
} else {
|
||||
$sectionmods[$thismod->modname]['name'] = $thismod->modplural;
|
||||
$sectionmods[$thismod->modname]['name'] = $thismod->modfullname;
|
||||
$sectionmods[$thismod->modname]['count'] = 1;
|
||||
}
|
||||
if ($cancomplete && $completioninfo->is_enabled($thismod) != COMPLETION_TRACKING_NONE) {
|
||||
@@ -531,26 +532,25 @@ abstract class format_section_renderer_base extends plugin_renderer_base {
|
||||
* Output the html for a single section page .
|
||||
*
|
||||
* @param stdClass $course The course entry from DB
|
||||
* @param array $sections The course_sections entries from the DB
|
||||
* @param array $mods used for print_section()
|
||||
* @param array $modnames used for print_section()
|
||||
* @param array $modnamesused used for print_section()
|
||||
* @param array $sections (argument not used)
|
||||
* @param array $mods (argument not used)
|
||||
* @param array $modnames (argument not used)
|
||||
* @param array $modnamesused (argument not used)
|
||||
* @param int $displaysection The section number in the course which is being displayed
|
||||
*/
|
||||
public function print_single_section_page($course, $sections, $mods, $modnames, $modnamesused, $displaysection) {
|
||||
global $PAGE;
|
||||
|
||||
// Can we view the section in question?
|
||||
$context = context_course::instance($course->id);
|
||||
$canviewhidden = has_capability('moodle/course:viewhiddensections', $context);
|
||||
$modinfo = get_fast_modinfo($course);
|
||||
|
||||
if (!isset($sections[$displaysection])) {
|
||||
// Can we view the section in question?
|
||||
if (!($sectioninfo = $modinfo->get_section_info($displaysection))) {
|
||||
// This section doesn't exist
|
||||
print_error('unknowncoursesection', 'error', null, $course->fullname);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$sections[$displaysection]->visible && !$canviewhidden) {
|
||||
if (!$sectioninfo->uservisible) {
|
||||
if (!$course->hiddensections) {
|
||||
echo $this->start_section_list();
|
||||
echo $this->section_hidden($displaysection);
|
||||
@@ -562,15 +562,13 @@ abstract class format_section_renderer_base extends plugin_renderer_base {
|
||||
|
||||
// Copy activity clipboard..
|
||||
echo $this->course_activity_clipboard($course, $displaysection);
|
||||
|
||||
// General section if non-empty.
|
||||
$thissection = $sections[0];
|
||||
if ($thissection->summary or $thissection->sequence or $PAGE->user_is_editing()) {
|
||||
$thissection = $modinfo->get_section_info(0);
|
||||
if ($thissection->summary or !empty($modinfo->sections[0]) or $PAGE->user_is_editing()) {
|
||||
echo $this->start_section_list();
|
||||
echo $this->section_header($thissection, $course, true, $displaysection);
|
||||
print_section($course, $thissection, $mods, $modnamesused, true, "100%", false, $displaysection);
|
||||
print_section($course, $thissection, null, null, true, "100%", false, $displaysection);
|
||||
if ($PAGE->user_is_editing()) {
|
||||
print_section_add_menus($course, 0, $modnames, false, false, $displaysection);
|
||||
print_section_add_menus($course, 0, null, false, false, $displaysection);
|
||||
}
|
||||
echo $this->section_footer();
|
||||
echo $this->end_section_list();
|
||||
@@ -579,34 +577,35 @@ abstract class format_section_renderer_base extends plugin_renderer_base {
|
||||
// Start single-section div
|
||||
echo html_writer::start_tag('div', array('class' => 'single-section'));
|
||||
|
||||
// The requested section page.
|
||||
$thissection = $modinfo->get_section_info($displaysection);
|
||||
|
||||
// Title with section navigation links.
|
||||
$sectionnavlinks = $this->get_nav_links($course, $sections, $displaysection);
|
||||
$sectionnavlinks = $this->get_nav_links($course, $modinfo->get_section_info_all(), $displaysection);
|
||||
$sectiontitle = '';
|
||||
$sectiontitle .= html_writer::start_tag('div', array('class' => 'section-navigation header headingblock'));
|
||||
$sectiontitle .= html_writer::tag('span', $sectionnavlinks['previous'], array('class' => 'mdl-left'));
|
||||
$sectiontitle .= html_writer::tag('span', $sectionnavlinks['next'], array('class' => 'mdl-right'));
|
||||
// Title attributes
|
||||
$titleattr = 'mdl-align title';
|
||||
if (!$sections[$displaysection]->visible) {
|
||||
if (!$thissection->visible) {
|
||||
$titleattr .= ' dimmed_text';
|
||||
}
|
||||
$sectiontitle .= html_writer::tag('div', get_section_name($course, $sections[$displaysection]), array('class' => $titleattr));
|
||||
$sectiontitle .= html_writer::tag('div', get_section_name($course, $displaysection), array('class' => $titleattr));
|
||||
$sectiontitle .= html_writer::end_tag('div');
|
||||
echo $sectiontitle;
|
||||
|
||||
// Now the list of sections..
|
||||
echo $this->start_section_list();
|
||||
|
||||
// The requested section page.
|
||||
$thissection = $sections[$displaysection];
|
||||
echo $this->section_header($thissection, $course, true, $displaysection);
|
||||
// Show completion help icon.
|
||||
$completioninfo = new completion_info($course);
|
||||
echo $completioninfo->display_help_icon();
|
||||
|
||||
print_section($course, $thissection, $mods, $modnamesused, true, '100%', false, $displaysection);
|
||||
print_section($course, $thissection, null, null, true, '100%', false, $displaysection);
|
||||
if ($PAGE->user_is_editing()) {
|
||||
print_section_add_menus($course, $displaysection, $modnames, false, false, $displaysection);
|
||||
print_section_add_menus($course, $displaysection, null, false, false, $displaysection);
|
||||
}
|
||||
echo $this->section_footer();
|
||||
echo $this->end_section_list();
|
||||
@@ -629,14 +628,16 @@ abstract class format_section_renderer_base extends plugin_renderer_base {
|
||||
* Output the html for a multiple section page
|
||||
*
|
||||
* @param stdClass $course The course entry from DB
|
||||
* @param array $sections The course_sections entries from the DB
|
||||
* @param array $mods used for print_section()
|
||||
* @param array $modnames used for print_section()
|
||||
* @param array $modnamesused used for print_section()
|
||||
* @param array $sections (argument not used)
|
||||
* @param array $mods (argument not used)
|
||||
* @param array $modnames (argument not used)
|
||||
* @param array $modnamesused (argument not used)
|
||||
*/
|
||||
public function print_multiple_section_page($course, $sections, $mods, $modnames, $modnamesused) {
|
||||
global $PAGE;
|
||||
|
||||
$modinfo = get_fast_modinfo($course);
|
||||
|
||||
$context = context_course::instance($course->id);
|
||||
// Title with completion help icon.
|
||||
$completioninfo = new completion_info($course);
|
||||
@@ -649,32 +650,22 @@ abstract class format_section_renderer_base extends plugin_renderer_base {
|
||||
// Now the list of sections..
|
||||
echo $this->start_section_list();
|
||||
|
||||
// General section if non-empty.
|
||||
$thissection = $sections[0];
|
||||
unset($sections[0]);
|
||||
if ($thissection->summary or $thissection->sequence or $PAGE->user_is_editing()) {
|
||||
echo $this->section_header($thissection, $course, false, 0);
|
||||
print_section($course, $thissection, $mods, $modnamesused, true, "100%", false, 0);
|
||||
if ($PAGE->user_is_editing()) {
|
||||
print_section_add_menus($course, 0, $modnames, false, false, 0);
|
||||
foreach ($modinfo->get_section_info_all() as $section => $thissection) {
|
||||
if ($section == 0) {
|
||||
// 0-section is displayed a little different then the others
|
||||
if ($thissection->summary or !empty($modinfo->sections[0]) or $PAGE->user_is_editing()) {
|
||||
echo $this->section_header($thissection, $course, false, 0);
|
||||
print_section($course, $thissection, null, null, true, "100%", false, 0);
|
||||
if ($PAGE->user_is_editing()) {
|
||||
print_section_add_menus($course, 0, null, false, false, 0);
|
||||
}
|
||||
echo $this->section_footer();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
echo $this->section_footer();
|
||||
}
|
||||
|
||||
$canviewhidden = has_capability('moodle/course:viewhiddensections', $context);
|
||||
for ($section = 1; $section <= $course->numsections; $section++) {
|
||||
if (!empty($sections[$section])) {
|
||||
$thissection = $sections[$section];
|
||||
} else {
|
||||
// This will create a course section if it doesn't exist..
|
||||
$thissection = get_course_section($section, $course->id);
|
||||
|
||||
// The returned section is only a bare database object rather than
|
||||
// a section_info object - we will need at least the uservisible
|
||||
// field in it.
|
||||
$thissection->uservisible = true;
|
||||
$thissection->availableinfo = null;
|
||||
$thissection->showavailability = 0;
|
||||
if ($section > $course->numsections) {
|
||||
// activities inside this section are 'orphaned', this section will be printed as 'stealth' below
|
||||
continue;
|
||||
}
|
||||
// Show the section if the user is permitted to access it, OR if it's not available
|
||||
// but showavailability is turned on
|
||||
@@ -687,36 +678,33 @@ abstract class format_section_renderer_base extends plugin_renderer_base {
|
||||
echo $this->section_hidden($section);
|
||||
}
|
||||
|
||||
unset($sections[$section]);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!$PAGE->user_is_editing() && $course->coursedisplay == COURSE_DISPLAY_MULTIPAGE) {
|
||||
// Display section summary only.
|
||||
echo $this->section_summary($thissection, $course, $mods);
|
||||
echo $this->section_summary($thissection, $course, null);
|
||||
} else {
|
||||
echo $this->section_header($thissection, $course, false, 0);
|
||||
if ($thissection->uservisible) {
|
||||
print_section($course, $thissection, $mods, $modnamesused, true, "100%", false, 0);
|
||||
print_section($course, $thissection, null, null, true, "100%", false, 0);
|
||||
if ($PAGE->user_is_editing()) {
|
||||
print_section_add_menus($course, $section, $modnames, false, false, 0);
|
||||
print_section_add_menus($course, $section, null, false, false, 0);
|
||||
}
|
||||
}
|
||||
echo $this->section_footer();
|
||||
}
|
||||
|
||||
unset($sections[$section]);
|
||||
}
|
||||
|
||||
if ($PAGE->user_is_editing() and has_capability('moodle/course:update', $context)) {
|
||||
// Print stealth sections if present.
|
||||
$modinfo = get_fast_modinfo($course);
|
||||
foreach ($sections as $section => $thissection) {
|
||||
if (empty($modinfo->sections[$section])) {
|
||||
foreach ($modinfo->get_section_info_all() as $section => $thissection) {
|
||||
if ($section <= $course->numsections or empty($modinfo->sections[$section])) {
|
||||
// this is not stealth section or it is empty
|
||||
continue;
|
||||
}
|
||||
echo $this->stealth_section_header($section);
|
||||
print_section($course, $thissection, $mods, $modnamesused, true, "100%", false, $displaysection);
|
||||
print_section($course, $thissection, null, null, true, "100%", false, 0);
|
||||
echo $this->stealth_section_footer();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user