Permalink
Browse files

MDL-37085 Move print_section() to the course renderer

Added two functions in the renderer:
- core_course_renderer::course_section_cm_list()
- core_course_renderer::course_section_cm()
  • Loading branch information...
1 parent ed513fa commit c58a25d6ebc15c5a866622584b9c93e515cc14d4 @marinaglancy marinaglancy committed Dec 13, 2012
Showing with 177 additions and 127 deletions.
  1. +4 −127 course/lib.php
  2. +173 −0 course/renderer.php
View
@@ -1324,6 +1324,8 @@ function get_print_section_cm_text(cm_info $cm, $course) {
/**
* Prints a section full of activity modules
*
+ * @deprecated since 2.5
+ *
* @param stdClass $course The course
* @param stdClass|section_info $section The section object containing properties id and section
* @param array $mods (argument not used)
@@ -1335,135 +1337,10 @@ function get_print_section_cm_text(cm_info $cm, $course) {
* @return void
*/
function print_section($course, $section, $mods, $modnamesused, $absolute=false, $width="100%", $hidecompletion=false, $sectionreturn=null) {
- global $CFG, $USER, $DB, $PAGE, $OUTPUT;
-
- static $initialised;
-
- static $isediting;
- static $ismoving;
- static $movingpix;
- static $strmovefull;
- static $strunreadpostsone;
-
- if (!isset($initialised)) {
- $isediting = $PAGE->user_is_editing();
- $ismoving = $isediting && ismoving($course->id);
- if ($ismoving) {
- $movingpix = new pix_icon('movehere', get_string('movehere'), 'moodle', array('class' => 'movetarget'));
- $strmovefull = strip_tags(get_string("movefull", "", "'$USER->activitycopyname'"));
- }
- $initialised = true;
- }
-
+ global $PAGE;
$displayoptions = array('hidecompletion' => $hidecompletion);
- $modinfo = get_fast_modinfo($course);
- $completioninfo = new completion_info($course);
$courserenderer = $PAGE->get_renderer('core', 'course');
-
- // Get the list of modules visible to user (excluding the module being moved if there is one)
- $moduleslist = array();
- if (!empty($modinfo->sections[$section->section])) {
- foreach ($modinfo->sections[$section->section] as $modnumber) {
- $mod = $modinfo->cms[$modnumber];
-
- if ($ismoving and $mod->id == $USER->activitycopy) {
- // do not display moving mod
- continue;
- }
- // We can continue (because it will not be displayed at all)
- // if:
- // 1) The activity is not visible to users
- // and
- // 2a) The 'showavailability' option is not set (if that is set,
- // we need to display the activity so we can show
- // availability info)
- // or
- // 2b) The 'availableinfo' is empty, i.e. the activity was
- // hidden in a way that leaves no info, such as using the
- // eye icon.
- if (!$mod->uservisible &&
- (empty($mod->showavailability) ||
- empty($mod->availableinfo))) {
- // visibility shortcut
- continue;
- }
-
- $moduleslist[$modnumber] = $mod;
- }
- }
-
- if (!empty($moduleslist) || $ismoving) {
-
- echo html_writer::start_tag('ul', array('class' => 'section img-text'));
-
- foreach ($moduleslist as $modnumber => $mod) {
- $modclasses = 'activity '. $mod->modname. 'modtype_'.$mod->modname. ' '. $mod->get_extra_classes();
- if ($ismoving) {
- $movingurl = new moodle_url('/course/mod.php', array('moveto' => $mod->id, 'sesskey' => sesskey()));
- echo html_writer::tag('li', html_writer::link($movingurl, $OUTPUT->render($movingpix)), array('class' => 'movehere'));
- }
-
- echo html_writer::start_tag('li', array('class' => $modclasses, 'id' => 'module-'. $modnumber));
- $indentclasses = 'mod-indent';
- if (!empty($mod->indent)) {
- $indentclasses .= ' mod-indent-'.$mod->indent;
- if ($mod->indent > 15) {
- $indentclasses .= ' mod-indent-huge';
- }
- }
- echo html_writer::start_tag('div', array('class' => $indentclasses));
-
- // Start the div for the activity title, excluding the edit icons.
- echo html_writer::start_tag('div', array('class' => 'activityinstance'));
-
- // Display the link to the module (or do nothing if module has no url)
- echo $courserenderer->course_section_cm_name($mod, $displayoptions);
-
- // Module can put text after the link (e.g. forum unread)
- echo $mod->get_after_link();
-
- // Closing the tag which contains everything but edit icons. Content part of the module should not be part of this.
- echo html_writer::end_tag('div');
-
- // If there is content but NO link (eg label), then display the
- // content here (BEFORE any icons). In this case cons must be
- // displayed after the content so that it makes more sense visually
- // and for accessibility reasons, e.g. if you have a one-line label
- // it should work similarly (at least in terms of ordering) to an
- // activity.
- $contentpart = $courserenderer->course_section_cm_text($mod, $displayoptions);
- $url = $mod->get_url();
- if (empty($url)) {
- echo $contentpart;
- }
-
- if ($isediting) {
- echo make_editing_buttons($mod, $absolute, true, $mod->indent, $sectionreturn);
- echo $mod->get_after_edit_icons();
- }
-
- echo $courserenderer->course_section_cm_completion($course, $completioninfo, $mod, $displayoptions);
-
- // If there is content AND a link, then display the content here
- // (AFTER any icons). Otherwise it was displayed before
- if (!empty($url)) {
- echo $contentpart;
- }
-
- // show availability info (if module is not available)
- echo $courserenderer->course_section_cm_availability($mod, $displayoptions);
-
- echo html_writer::end_tag('div');
- echo html_writer::end_tag('li')."\n";
- }
-
- if ($ismoving) {
- $movingurl = new moodle_url('/course/mod.php', array('movetosection' => $section->id, 'sesskey' => sesskey()));
- echo html_writer::tag('li', html_writer::link($movingurl, $OUTPUT->render($movingpix)), array('class' => 'movehere'));
- }
-
- echo html_writer::end_tag('ul'); // .section
- }
+ echo $courserenderer->course_section_cm_list($course, $section, $sectionreturn, $displayoptions);
}
/**
View
@@ -805,4 +805,177 @@ public function course_section_cm_availability(cm_info $mod, $displayoptions = a
}
return '';
}
+
+ /**
+ * Renders HTML to display one course module in a course section
+ *
+ * This includes link, content, availability, completion info and additional information
+ * that module type wants to display (i.e. number of unread forum posts)
+ *
+ * This function calls:
+ * {@link core_course_renderer::course_section_cm_name()}
+ * {@link cm_info::get_after_link()}
+ * {@link core_course_renderer::course_section_cm_text()}
+ * {@link core_course_renderer::course_section_cm_availability()}
+ * {@link core_course_renderer::course_section_cm_completion()}
+ * {@link course_get_cm_edit_actions()}
+ * {@link core_course_renderer::course_section_cm_edit_actions()}
+ *
+ * @param stdClass $course
+ * @param completion_info $completioninfo
+ * @param cm_info $mod
+ * @param int|null $sectionreturn
+ * @param array $displayoptions
+ * @return string
+ */
+ public function course_section_cm($course, &$completioninfo, cm_info $mod, $sectionreturn, $displayoptions = array()) {
+ $output = '';
+ // We return empty string (because course module will not be displayed at all)
+ // if:
+ // 1) The activity is not visible to users
+ // and
+ // 2a) The 'showavailability' option is not set (if that is set,
+ // we need to display the activity so we can show
+ // availability info)
+ // or
+ // 2b) The 'availableinfo' is empty, i.e. the activity was
+ // hidden in a way that leaves no info, such as using the
+ // eye icon.
+ if (!$mod->uservisible &&
+ (empty($mod->showavailability) || empty($mod->availableinfo))) {
+ return $output;
+ }
+
+ $indentclasses = 'mod-indent';
+ if (!empty($mod->indent)) {
+ $indentclasses .= ' mod-indent-'.$mod->indent;
+ if ($mod->indent > 15) {
+ $indentclasses .= ' mod-indent-huge';
+ }
+ }
+ $output .= html_writer::start_tag('div', array('class' => $indentclasses));
+
+ // Start the div for the activity title, excluding the edit icons.
+ $output .= html_writer::start_tag('div', array('class' => 'activityinstance'));
+
+ // Display the link to the module (or do nothing if module has no url)
+ $output .= $this->course_section_cm_name($mod, $displayoptions);
+
+ // Module can put text after the link (e.g. forum unread)
+ $output .= $mod->get_after_link();
+
+ // Closing the tag which contains everything but edit icons. Content part of the module should not be part of this.
+ $output .= html_writer::end_tag('div'); // .activityinstance
+
+ // If there is content but NO link (eg label), then display the
+ // content here (BEFORE any icons). In this case cons must be
+ // displayed after the content so that it makes more sense visually
+ // and for accessibility reasons, e.g. if you have a one-line label
+ // it should work similarly (at least in terms of ordering) to an
+ // activity.
+ $contentpart = $this->course_section_cm_text($mod, $displayoptions);
+ $url = $mod->get_url();
+ if (empty($url)) {
+ $output .= $contentpart;
+ }
+
+ if ($this->page->user_is_editing()) {
+ $editactions = course_get_cm_edit_actions($mod, $mod->indent, $sectionreturn);
+ $output .= ' '. $this->course_section_cm_edit_actions($editactions);
+ $output .= $mod->get_after_edit_icons();
+ }
+
+ $output .= $this->course_section_cm_completion($course, $completioninfo, $mod, $displayoptions);
+
+ // If there is content AND a link, then display the content here
+ // (AFTER any icons). Otherwise it was displayed before
+ if (!empty($url)) {
+ $output .= $contentpart;
+ }
+
+ // show availability info (if module is not available)
+ $output .= $this->course_section_cm_availability($mod, $displayoptions);
+
+ $output .= html_writer::end_tag('div'); // $indentclasses
+ return $output;
+ }
+
+ /**
+ * Renders HTML to display a list of course modules in a course section
+ * Also displays "move here" controls in Javascript-disabled mode
+ *
+ * This function calls {@link core_course_renderer::course_section_cm()}
+ *
+ * @param stdClass $course course object
+ * @param int|stdClass|section_info $section relative section number or section object
+ * @param int $sectionreturn section number to return to
+ * @param int $displayoptions
+ * @return void
+ */
+ public function course_section_cm_list($course, $section, $sectionreturn = null, $displayoptions = array()) {
+ global $USER;
+
+ $output = '';
+ $modinfo = get_fast_modinfo($course);
+ if (is_object($section)) {
+ $section = $modinfo->get_section_info($section->section);
+ } else {
+ $section = $modinfo->get_section_info($section);
+ }
+ $completioninfo = new completion_info($course);
+
+ // check if we are currently in the process of moving a module with JavaScript disabled
+ $ismoving = $this->page->user_is_editing() && ismoving($course->id);
+ if ($ismoving) {
+ $movingpix = new pix_icon('movehere', get_string('movehere'), 'moodle', array('class' => 'movetarget'));
+ $strmovefull = strip_tags(get_string("movefull", "", "'$USER->activitycopyname'"));
+ }
+
+ // Get the list of modules visible to user (excluding the module being moved if there is one)
+ $moduleshtml = array();
+ if (!empty($modinfo->sections[$section->section])) {
+ foreach ($modinfo->sections[$section->section] as $modnumber) {
+ $mod = $modinfo->cms[$modnumber];
+
+ if ($ismoving and $mod->id == $USER->activitycopy) {
+ // do not display moving mod
+ continue;
+ }
+
+ if ($modulehtml = $this->course_section_cm($course,
+ $completioninfo, $mod, $sectionreturn, $displayoptions)) {
+ $moduleshtml[$modnumber] = $modulehtml;
+ }
+ }
+ }
+
+ if (!empty($moduleshtml) || $ismoving) {
+
+ $output .= html_writer::start_tag('ul', array('class' => 'section img-text'));
+
+ foreach ($moduleshtml as $modnumber => $modulehtml) {
+ if ($ismoving) {
+ $movingurl = new moodle_url('/course/mod.php', array('moveto' => $modnumber, 'sesskey' => sesskey()));
+ $output .= html_writer::tag('li', html_writer::link($movingurl, $this->output->render($movingpix)),
+ array('class' => 'movehere', 'title' => $strmovefull));
+ }
+
+ $mod = $modinfo->cms[$modnumber];
+ $modclasses = 'activity '. $mod->modname. 'modtype_'.$mod->modname. ' '. $mod->get_extra_classes();
+ $output .= html_writer::start_tag('li', array('class' => $modclasses, 'id' => 'module-'. $mod->id));
+ $output .= $modulehtml;
+ $output .= html_writer::end_tag('li');
+ }
+
+ if ($ismoving) {
+ $movingurl = new moodle_url('/course/mod.php', array('movetosection' => $section->id, 'sesskey' => sesskey()));
+ $output .= html_writer::tag('li', html_writer::link($movingurl, $this->output->render($movingpix)),
+ array('class' => 'movehere', 'title' => $strmovefull));
+ }
+
+ $output .= html_writer::end_tag('ul'); // .section
+ }
+
+ return $output;
+ }
}

0 comments on commit c58a25d

Please sign in to comment.