diff --git a/blocks/site_main_menu/block_site_main_menu.php b/blocks/site_main_menu/block_site_main_menu.php
index d4374bc122f..bc4420cb6fe 100644
--- a/blocks/site_main_menu/block_site_main_menu.php
+++ b/blocks/site_main_menu/block_site_main_menu.php
@@ -41,8 +41,8 @@ class block_site_main_menu extends block_list {
continue;
}
- list($content, $instancename) =
- get_print_section_cm_text($cm, $course);
+ $content = $cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
+ $instancename = $cm->get_formatted_name();
if (!($url = $cm->get_url())) {
$this->content->items[] = $content;
@@ -60,14 +60,12 @@ class block_site_main_menu extends block_list {
}
/// slow & hacky editing mode
+ $courserenderer = $this->page->get_renderer('core', 'course');
$ismoving = ismoving($course->id);
course_create_sections_if_missing($course, 0);
$modinfo = get_fast_modinfo($course);
$section = $modinfo->get_section_info(0);
- $groupbuttons = $course->groupmode;
- $groupbuttonslink = (!$course->groupmodeforce);
-
if ($ismoving) {
$strmovehere = get_string('movehere');
$strmovefull = strip_tags(get_string('movefull', '', "'$USER->activitycopyname'"));
@@ -90,15 +88,10 @@ class block_site_main_menu extends block_list {
continue;
}
if (!$ismoving) {
- if ($groupbuttons) {
- if (! $mod->groupmodelink = $groupbuttonslink) {
- $mod->groupmode = $course->groupmode;
- }
-
- } else {
- $mod->groupmode = false;
- }
- $editbuttons = '
'.make_editing_buttons($mod, true, true).'
';
+ $actions = course_get_cm_edit_actions($mod, -1);
+ $editbuttons = html_writer::tag('div',
+ $courserenderer->course_section_cm_edit_actions($actions),
+ array('class' => 'buttons'));
} else {
$editbuttons = '';
}
@@ -111,8 +104,8 @@ class block_site_main_menu extends block_list {
'
';
$this->content->icons[] = '';
}
- list($content, $instancename) =
- get_print_section_cm_text($modinfo->cms[$modnumber], $course);
+ $content = $mod->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
+ $instancename = $mod->get_formatted_name();
$linkcss = $mod->visible ? '' : ' class="dimmed" ';
if (!($url = $mod->get_url())) {
@@ -134,7 +127,8 @@ class block_site_main_menu extends block_list {
$this->content->icons[] = '';
}
- $this->content->footer = print_section_add_menus($course, 0, null, true, true);
+ $this->content->footer = $courserenderer->course_section_add_cm_control($course,
+ 0, null, array('inblock' => true));
return $this->content;
}
diff --git a/blocks/social_activities/block_social_activities.php b/blocks/social_activities/block_social_activities.php
index b98f44f9788..5e394e048b9 100644
--- a/blocks/social_activities/block_social_activities.php
+++ b/blocks/social_activities/block_social_activities.php
@@ -43,8 +43,8 @@ class block_social_activities extends block_list {
continue;
}
- list($content, $instancename) =
- get_print_section_cm_text($cm, $course);
+ $content = $cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
+ $instancename = $cm->get_formatted_name();
if (!($url = $cm->get_url())) {
$this->content->items[] = $content;
@@ -63,13 +63,11 @@ class block_social_activities extends block_list {
/// slow & hacky editing mode
+ $courserenderer = $this->page->get_renderer('core', 'course');
$ismoving = ismoving($course->id);
$modinfo = get_fast_modinfo($course);
$section = $modinfo->get_section_info(0);
- $groupbuttons = $course->groupmode;
- $groupbuttonslink = (!$course->groupmodeforce);
-
if ($ismoving) {
$strmovehere = get_string('movehere');
$strmovefull = strip_tags(get_string('movefull', '', "'$USER->activitycopyname'"));
@@ -92,15 +90,9 @@ class block_social_activities extends block_list {
continue;
}
if (!$ismoving) {
- if ($groupbuttons) {
- if (! $mod->groupmodelink = $groupbuttonslink) {
- $mod->groupmode = $course->groupmode;
- }
-
- } else {
- $mod->groupmode = false;
- }
- $editbuttons = '
'.make_editing_buttons($mod, true, true);
+ $actions = course_get_cm_edit_actions($mod, -1);
+ $editbuttons = '
'.
+ $courserenderer->course_section_cm_edit_actions($actions);
} else {
$editbuttons = '';
}
@@ -113,8 +105,8 @@ class block_social_activities extends block_list {
'
';
$this->content->icons[] = '';
}
- list($content, $instancename) =
- get_print_section_cm_text($modinfo->cms[$modnumber], $course);
+ $content = $mod->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
+ $instancename = $mod->get_formatted_name();
$linkcss = $mod->visible ? '' : ' class="dimmed" ';
@@ -137,7 +129,8 @@ class block_social_activities extends block_list {
$this->content->icons[] = '';
}
- $this->content->footer = print_section_add_menus($course, 0, null, true, true);
+ $this->content->footer = $courserenderer->course_section_add_cm_control($course,
+ 0, null, array('inblock' => true));
return $this->content;
}
diff --git a/course/dndupload.php b/course/dndupload.php
index c4df5a8c2b8..797e6883f8e 100644
--- a/course/dndupload.php
+++ b/course/dndupload.php
@@ -35,5 +35,7 @@ $modulename = required_param('module', PARAM_PLUGIN);
$displayname = optional_param('displayname', null, PARAM_TEXT);
$contents = optional_param('contents', null, PARAM_RAW); // It will be up to each plugin to clean this data, before saving it.
+$PAGE->set_url('/course/dndupload.php');
+
$dndproc = new dndupload_ajax_processor($courseid, $section, $type, $modulename);
$dndproc->process($displayname, $contents);
diff --git a/course/dnduploadlib.php b/course/dnduploadlib.php
index 26e41e8b265..ecb519bbabc 100644
--- a/course/dnduploadlib.php
+++ b/course/dnduploadlib.php
@@ -671,7 +671,8 @@ class dndupload_ajax_processor {
* @param cm_info $mod details of the mod just created
*/
protected function send_response($mod) {
- global $OUTPUT;
+ global $OUTPUT, $PAGE;
+ $courserenderer = $PAGE->get_renderer('core', 'course');
$resp = new stdClass();
$resp->error = self::ERROR_OK;
@@ -679,7 +680,8 @@ class dndupload_ajax_processor {
$resp->name = $mod->name;
$resp->link = $mod->get_url()->out();
$resp->elementid = 'module-'.$mod->id;
- $resp->commands = make_editing_buttons($mod, true, true, 0, $mod->sectionnum);
+ $actions = course_get_cm_edit_actions($mod, 0, $mod->sectionnum);
+ $resp->commands = ' '. $courserenderer->course_section_cm_edit_actions($actions);
$resp->onclick = $mod->get_on_click();
$resp->visible = $mod->visible;
diff --git a/course/externallib.php b/course/externallib.php
index b5c82f469a3..3476dccb72f 100644
--- a/course/externallib.php
+++ b/course/externallib.php
@@ -125,7 +125,7 @@ class core_course_external extends external_api {
$sectioncontents = array();
//for each module of the section
- foreach ($modinfo->sections[$section->section] as $cmid) { //matching /course/lib.php:print_section() logic
+ foreach ($modinfo->sections[$section->section] as $cmid) {
$cm = $modinfo->cms[$cmid];
// stop here if the module is not visible to the user
diff --git a/course/format/renderer.php b/course/format/renderer.php
index ceb3045c542..d9a7edc37a7 100644
--- a/course/format/renderer.php
+++ b/course/format/renderer.php
@@ -38,6 +38,20 @@ defined('MOODLE_INTERNAL') || die();
*/
abstract class format_section_renderer_base extends plugin_renderer_base {
+ /** @var contains instance of core course renderer */
+ protected $courserenderer;
+
+ /**
+ * Constructor method, calls the parent constructor
+ *
+ * @param moodle_page $page
+ * @param string $target one of rendering target constants
+ */
+ public function __construct(moodle_page $page, $target) {
+ parent::__construct($page, $target);
+ $this->courserenderer = $this->page->get_renderer('core', 'course');
+ }
+
/**
* Generate the starting container html for a list of sections
* @return string HTML to output.
@@ -587,10 +601,8 @@ abstract class format_section_renderer_base extends plugin_renderer_base {
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, null, null, true, "100%", false, $displaysection);
- if ($PAGE->user_is_editing()) {
- print_section_add_menus($course, 0, null, false, false, $displaysection);
- }
+ echo $this->courserenderer->course_section_cm_list($course, $thissection, $displaysection);
+ echo $this->courserenderer->course_section_add_cm_control($course, 0, $displaysection);
echo $this->section_footer();
echo $this->end_section_list();
}
@@ -624,10 +636,8 @@ abstract class format_section_renderer_base extends plugin_renderer_base {
$completioninfo = new completion_info($course);
echo $completioninfo->display_help_icon();
- print_section($course, $thissection, null, null, true, '100%', false, $displaysection);
- if ($PAGE->user_is_editing()) {
- print_section_add_menus($course, $displaysection, null, false, false, $displaysection);
- }
+ echo $this->courserenderer->course_section_cm_list($course, $thissection, $displaysection);
+ echo $this->courserenderer->course_section_add_cm_control($course, $displaysection, $displaysection);
echo $this->section_footer();
echo $this->end_section_list();
@@ -677,10 +687,8 @@ abstract class format_section_renderer_base extends plugin_renderer_base {
// 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->courserenderer->course_section_cm_list($course, $thissection);
+ echo $this->courserenderer->course_section_add_cm_control($course, 0);
echo $this->section_footer();
}
continue;
@@ -710,10 +718,8 @@ abstract class format_section_renderer_base extends plugin_renderer_base {
} else {
echo $this->section_header($thissection, $course, false, 0);
if ($thissection->uservisible) {
- print_section($course, $thissection, null, null, true, "100%", false, 0);
- if ($PAGE->user_is_editing()) {
- print_section_add_menus($course, $section, null, false, false, 0);
- }
+ echo $this->courserenderer->course_section_cm_list($course, $thissection);
+ echo $this->courserenderer->course_section_add_cm_control($course, $section);
}
echo $this->section_footer();
}
@@ -727,7 +733,7 @@ abstract class format_section_renderer_base extends plugin_renderer_base {
continue;
}
echo $this->stealth_section_header($section);
- print_section($course, $thissection, null, null, true, "100%", false, 0);
+ echo $this->courserenderer->course_section_cm_list($course, $thissection);
echo $this->stealth_section_footer();
}
diff --git a/course/jumpto.php b/course/jumpto.php
index c4d11ef7e11..98c4e49f794 100644
--- a/course/jumpto.php
+++ b/course/jumpto.php
@@ -34,7 +34,7 @@ if (!confirm_sesskey()) {
print_error('confirmsesskeybad');
}
-if (strpos($jump, '/') === 0) {
+if (strpos($jump, '/') === 0 || strpos($jump, $CFG->wwwroot) === 0) {
redirect(new moodle_url($jump));
} else {
print_error('error');
diff --git a/course/lib.php b/course/lib.php
index 52302409346..a7fc7cf7b66 100644
--- a/course/lib.php
+++ b/course/lib.php
@@ -1301,576 +1301,6 @@ function set_section_visible($courseid, $sectionnumber, $visibility) {
return $resourcestotoggle;
}
-/**
- * Obtains shared data that is used in print_section when displaying a
- * course-module entry.
- *
- * Calls format_text or format_string as appropriate, and obtains the correct icon.
- *
- * This data is also used in other areas of the code.
- * @param cm_info $cm Course-module data (must come from get_fast_modinfo)
- * @param object $course Moodle course object
- * @return array An array with the following values in this order:
- * $content (optional extra content for after link),
- * $instancename (text of link)
- */
-function get_print_section_cm_text(cm_info $cm, $course) {
- global $OUTPUT;
-
- // Get content from modinfo if specified. Content displays either
- // in addition to the standard link (below), or replaces it if
- // the link is turned off by setting ->url to null.
- if (($content = $cm->get_content()) !== '') {
- // Improve filter performance by preloading filter setttings for all
- // activities on the course (this does nothing if called multiple
- // times)
- filter_preload_activities($cm->get_modinfo());
-
- // Get module context
- $modulecontext = context_module::instance($cm->id);
- $labelformatoptions = new stdClass();
- $labelformatoptions->noclean = true;
- $labelformatoptions->overflowdiv = true;
- $labelformatoptions->context = $modulecontext;
- $content = format_text($content, FORMAT_HTML, $labelformatoptions);
- } else {
- $content = '';
- }
-
- // Get course context
- $coursecontext = context_course::instance($course->id);
- $stringoptions = new stdClass;
- $stringoptions->context = $coursecontext;
- $instancename = format_string($cm->name, true, $stringoptions);
- return array($content, $instancename);
-}
-
-/**
- * Prints a section full of activity modules
- *
- * @param stdClass $course The course
- * @param stdClass|section_info $section The section object containing properties id and section
- * @param array $mods (argument not used)
- * @param array $modnamesused (argument not used)
- * @param bool $absolute All links are absolute
- * @param string $width Width of the container
- * @param bool $hidecompletion Hide completion status
- * @param int $sectionreturn The section to return to
- * @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 $groupbuttons;
- static $groupbuttonslink;
- static $isediting;
- static $ismoving;
- static $strmovehere;
- static $strmovefull;
- static $strunreadpostsone;
-
- if (!isset($initialised)) {
- $groupbuttons = ($course->groupmode or (!$course->groupmodeforce));
- $groupbuttonslink = (!$course->groupmodeforce);
- $isediting = $PAGE->user_is_editing();
- $ismoving = $isediting && ismoving($course->id);
- if ($ismoving) {
- $strmovehere = get_string("movehere");
- $strmovefull = strip_tags(get_string("movefull", "", "'$USER->activitycopyname'"));
- }
- $initialised = true;
- }
-
- $modinfo = get_fast_modinfo($course);
- $completioninfo = new completion_info($course);
-
- //Accessibility: replace table with list , but don't output empty list.
- if (!empty($modinfo->sections[$section->section])) {
-
- // Fix bug #5027, don't want style=\"width:$width\".
- echo "\n";
-
- 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;
- }
-
- // In some cases the activity is visible to user, but it is
- // dimmed. This is done if viewhiddenactivities is true and if:
- // 1. the activity is not visible, or
- // 2. the activity has dates set which do not include current, or
- // 3. the activity has any other conditions set (regardless of whether
- // current user meets them)
- $modcontext = context_module::instance($mod->id);
- $canviewhidden = has_capability('moodle/course:viewhiddenactivities', $modcontext);
- $accessiblebutdim = false;
- $conditionalhidden = false;
- if ($canviewhidden) {
- $accessiblebutdim = !$mod->visible;
- if (!empty($CFG->enableavailability)) {
- $conditionalhidden = $mod->availablefrom > time() ||
- ($mod->availableuntil && $mod->availableuntil < time()) ||
- count($mod->conditionsgrade) > 0 ||
- count($mod->conditionscompletion) > 0;
- }
- $accessiblebutdim = $conditionalhidden || $accessiblebutdim;
- }
-
- $liclasses = array();
- $liclasses[] = 'activity';
- $liclasses[] = $mod->modname;
- $liclasses[] = 'modtype_'.$mod->modname;
- $extraclasses = $mod->get_extra_classes();
- if ($extraclasses) {
- $liclasses = array_merge($liclasses, explode(' ', $extraclasses));
- }
- echo html_writer::start_tag('li', array('class'=>join(' ', $liclasses), 'id'=>'module-'.$modnumber));
- if ($ismoving) {
- echo ''.
- ' . ')
- ';
- }
-
- $classes = array('mod-indent');
- if (!empty($mod->indent)) {
- $classes[] = 'mod-indent-'.$mod->indent;
- if ($mod->indent > 15) {
- $classes[] = 'mod-indent-huge';
- }
- }
- echo html_writer::start_tag('div', array('class'=>join(' ', $classes)));
-
- // Get data about this course-module
- list($content, $instancename) =
- get_print_section_cm_text($modinfo->cms[$modnumber], $course);
-
- //Accessibility: for files get description via icon, this is very ugly hack!
- $altname = '';
- $altname = $mod->modfullname;
- // Avoid unnecessary duplication: if e.g. a forum name already
- // includes the word forum (or Forum, etc) then it is unhelpful
- // to include that in the accessible description that is added.
- if (false !== strpos(textlib::strtolower($instancename),
- textlib::strtolower($altname))) {
- $altname = '';
- }
- // File type after name, for alphabetic lists (screen reader).
- if ($altname) {
- $altname = get_accesshide(' '.$altname);
- }
-
- // Start the div for the activity title, excluding the edit icons.
- echo html_writer::start_tag('div', array('class' => 'activityinstance'));
-
- // We may be displaying this just in order to show information
- // about visibility, without the actual link
- $contentpart = '';
- if ($mod->uservisible) {
- // Nope - in this case the link is fully working for user
- $linkclasses = '';
- $textclasses = '';
- if ($accessiblebutdim) {
- $linkclasses .= ' dimmed';
- $textclasses .= ' dimmed_text';
- if ($conditionalhidden) {
- $linkclasses .= ' conditionalhidden';
- $textclasses .= ' conditionalhidden';
- }
- $accesstext = get_accesshide(get_string('hiddenfromstudents').': ');
- } else {
- $accesstext = '';
- }
- if ($linkclasses) {
- $linkcss = trim($linkclasses) . ' ';
- } else {
- $linkcss = '';
- }
- if ($textclasses) {
- $textcss = trim($textclasses) . ' ';
- } else {
- $textcss = '';
- }
-
- // Get on-click attribute value if specified and decode the onclick - it
- // has already been encoded for display (puke).
- $onclick = htmlspecialchars_decode($mod->get_on_click(), ENT_QUOTES);
-
- $groupinglabel = '';
- if (!empty($mod->groupingid) && has_capability('moodle/course:managegroups', context_course::instance($course->id))) {
- $groupings = groups_get_all_groupings($course->id);
- $groupinglabel = html_writer::tag('span', '('.format_string($groupings[$mod->groupingid]->name).')',
- array('class' => 'groupinglabel'));
- }
-
- if ($url = $mod->get_url()) {
- // Display link itself.
- $activitylink = html_writer::empty_tag('img', array('src' => $mod->get_icon_url(),
- 'class' => 'iconlarge activityicon', 'alt' => $mod->modfullname)) . $accesstext .
- html_writer::tag('span', $instancename . $altname, array('class' => 'instancename'));
- echo html_writer::link($url, $activitylink, array('class' => $linkcss, 'onclick' => $onclick)) .
- $groupinglabel;
-
- // If specified, display extra content after link.
- if ($content) {
- $contentpart = html_writer::tag('div', $content, array('class' =>
- trim('contentafterlink ' . $textclasses)));
- }
- } else {
- // No link, so display only content.
- $contentpart = html_writer::tag('div', $accesstext . $content, array('class' => $textcss));
- }
-
- } else {
- $textclasses = $extraclasses;
- $textclasses .= ' dimmed_text';
- if ($textclasses) {
- $textcss = 'class="' . trim($textclasses) . '" ';
- } else {
- $textcss = '';
- }
- $accesstext = '' .
- get_string('notavailableyet', 'condition') .
- ': ';
-
- if ($url = $mod->get_url()) {
- // Display greyed-out text of link
- echo 'extra .
- ' >' . '
'. $instancename . $altname .
- ' ';
-
- // Do not display content after link when it is greyed out like this.
- } else {
- // No link, so display only content (also greyed)
- $contentpart = 'extra . '>' .
- $accesstext . $content . '
';
- }
- }
-
- // 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. $contentpart 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.
- if (empty($url)) {
- echo $contentpart;
- }
-
- if ($isediting) {
- if ($groupbuttons and plugin_supports('mod', $mod->modname, FEATURE_GROUPS, 0)) {
- if (! $mod->groupmodelink = $groupbuttonslink) {
- $mod->groupmode = $course->groupmode;
- }
-
- } else {
- $mod->groupmode = false;
- }
- echo make_editing_buttons($mod, $absolute, true, $mod->indent, $sectionreturn);
- echo $mod->get_after_edit_icons();
- }
-
- // Completion
- $completion = $hidecompletion
- ? COMPLETION_TRACKING_NONE
- : $completioninfo->is_enabled($mod);
- if ($completion!=COMPLETION_TRACKING_NONE && isloggedin() &&
- !isguestuser() && $mod->uservisible) {
- $completiondata = $completioninfo->get_data($mod,true);
- $completionicon = '';
- if ($isediting) {
- switch ($completion) {
- case COMPLETION_TRACKING_MANUAL :
- $completionicon = 'manual-enabled'; break;
- case COMPLETION_TRACKING_AUTOMATIC :
- $completionicon = 'auto-enabled'; break;
- default: // wtf
- }
- } else if ($completion==COMPLETION_TRACKING_MANUAL) {
- switch($completiondata->completionstate) {
- case COMPLETION_INCOMPLETE:
- $completionicon = 'manual-n'; break;
- case COMPLETION_COMPLETE:
- $completionicon = 'manual-y'; break;
- }
- } else { // Automatic
- switch($completiondata->completionstate) {
- case COMPLETION_INCOMPLETE:
- $completionicon = 'auto-n'; break;
- case COMPLETION_COMPLETE:
- $completionicon = 'auto-y'; break;
- case COMPLETION_COMPLETE_PASS:
- $completionicon = 'auto-pass'; break;
- case COMPLETION_COMPLETE_FAIL:
- $completionicon = 'auto-fail'; break;
- }
- }
- if ($completionicon) {
- $imgsrc = $OUTPUT->pix_url('i/completion-'.$completionicon);
- $formattedname = format_string($mod->name, true, array('context' => $modcontext));
- $imgalt = get_string('completion-alt-' . $completionicon, 'completion', $formattedname);
- if ($completion == COMPLETION_TRACKING_MANUAL && !$isediting) {
- $imgtitle = get_string('completion-title-' . $completionicon, 'completion', $formattedname);
- $newstate =
- $completiondata->completionstate==COMPLETION_COMPLETE
- ? COMPLETION_INCOMPLETE
- : COMPLETION_COMPLETE;
- // In manual mode the icon is a toggle form...
-
- // If this completion state is used by the
- // conditional activities system, we need to turn
- // off the JS.
- if (!empty($CFG->enableavailability) &&
- condition_info::completion_value_used_as_condition($course, $mod)) {
- $extraclass = ' preventjs';
- } else {
- $extraclass = '';
- }
- echo html_writer::start_tag('form', array(
- 'class' => 'togglecompletion' . $extraclass,
- 'method' => 'post',
- 'action' => $CFG->wwwroot . '/course/togglecompletion.php'));
- echo html_writer::start_tag('div');
- echo html_writer::empty_tag('input', array(
- 'type' => 'hidden', 'name' => 'id', 'value' => $mod->id));
- echo html_writer::empty_tag('input', array(
- 'type' => 'hidden', 'name' => 'modulename',
- 'value' => $mod->name));
- echo html_writer::empty_tag('input', array(
- 'type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()));
- echo html_writer::empty_tag('input', array(
- 'type' => 'hidden', 'name' => 'completionstate',
- 'value' => $newstate));
- echo html_writer::empty_tag('input', array(
- 'type' => 'image', 'src' => $imgsrc, 'alt' => $imgalt, 'title' => $imgtitle));
- echo html_writer::end_tag('div');
- echo html_writer::end_tag('form');
- } else {
- // In auto mode, or when editing, the icon is just an image
- echo "";
- echo "
";
- }
- }
- }
-
- // 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 information (for someone who isn't allowed to
- // see the activity itself, or for staff)
- if (!$mod->uservisible) {
- echo ''.$mod->availableinfo.'
';
- } else if ($canviewhidden && !empty($CFG->enableavailability)) {
- // Don't add availability information if user is not editing and activity is hidden.
- if ($mod->visible || $PAGE->user_is_editing()) {
- $hidinfoclass = '';
- if (!$mod->visible) {
- $hidinfoclass = 'hide';
- }
- $ci = new condition_info($mod);
- $fullinfo = $ci->get_full_information();
- if($fullinfo) {
- echo ''.get_string($mod->showavailability
- ? 'userrestriction_visible'
- : 'userrestriction_hidden','condition',
- $fullinfo).'
';
- }
- }
- }
-
- echo html_writer::end_tag('div');
- echo html_writer::end_tag('li')."\n";
- }
-
- } elseif ($ismoving) {
- echo "\n";
- }
-
- if ($ismoving) {
- echo '- '.
- '
 . ')
- ';
- }
- if (!empty($modinfo->sections[$section->section]) || $ismoving) {
- echo "
\n\n";
- }
-}
-
-/**
- * Prints the menus to add activities and resources.
- *
- * @param stdClass $course The course
- * @param int $section relative section number (field course_sections.section)
- * @param null|array $modnames An array containing the list of modules and their names
- * if omitted will be taken from get_module_types_names()
- * @param bool $vertical Vertical orientation
- * @param bool $return Return the menus or send them to output
- * @param int $sectionreturn The section to link back to
- * @return void|string depending on $return
- */
-function print_section_add_menus($course, $section, $modnames = null, $vertical=false, $return=false, $sectionreturn=null) {
- global $CFG, $OUTPUT;
-
- if ($modnames === null) {
- $modnames = get_module_types_names();
- }
-
- // check to see if user can add menus and there are modules to add
- if (!has_capability('moodle/course:manageactivities', context_course::instance($course->id))
- || empty($modnames)) {
- if ($return) {
- return '';
- } else {
- return false;
- }
- }
-
- // Retrieve all modules with associated metadata
- $modules = get_module_metadata($course, $modnames, $sectionreturn);
-
- // We'll sort resources and activities into two lists
- $resources = array();
- $activities = array();
-
- // We need to add the section section to the link for each module
- $sectionlink = '§ion=' . $section . '&sr=' . $sectionreturn;
-
- foreach ($modules as $module) {
- if (isset($module->types)) {
- // This module has a subtype
- // NOTE: this is legacy stuff, module subtypes are very strongly discouraged!!
- $subtypes = array();
- foreach ($module->types as $subtype) {
- $subtypes[$subtype->link . $sectionlink] = $subtype->title;
- }
-
- // Sort module subtypes into the list
- if (!empty($module->title)) {
- // This grouping has a name
- if ($module->archetype == MOD_CLASS_RESOURCE) {
- $resources[] = array($module->title=>$subtypes);
- } else {
- $activities[] = array($module->title=>$subtypes);
- }
- } else {
- // This grouping does not have a name
- if ($module->archetype == MOD_CLASS_RESOURCE) {
- $resources = array_merge($resources, $subtypes);
- } else {
- $activities = array_merge($activities, $subtypes);
- }
- }
- } else {
- // This module has no subtypes
- if ($module->archetype == MOD_ARCHETYPE_RESOURCE) {
- $resources[$module->link . $sectionlink] = $module->title;
- } else if ($module->archetype === MOD_ARCHETYPE_SYSTEM) {
- // System modules cannot be added by user, do not add to dropdown
- } else {
- $activities[$module->link . $sectionlink] = $module->title;
- }
- }
- }
-
- $straddactivity = get_string('addactivity');
- $straddresource = get_string('addresource');
- $sectionname = get_section_name($course, $section);
- $strresourcelabel = get_string('addresourcetosection', null, $sectionname);
- $stractivitylabel = get_string('addactivitytosection', null, $sectionname);
-
- $output = html_writer::start_tag('div', array('class' => 'section_add_menus', 'id' => 'add_menus-section-' . $section));
-
- if (!$vertical) {
- $output .= html_writer::start_tag('div', array('class' => 'horizontal'));
- }
-
- if (!empty($resources)) {
- $select = new url_select($resources, '', array(''=>$straddresource), "ressection$section");
- $select->set_help_icon('resources');
- $select->set_label($strresourcelabel, array('class' => 'accesshide'));
- $output .= $OUTPUT->render($select);
- }
-
- if (!empty($activities)) {
- $select = new url_select($activities, '', array(''=>$straddactivity), "section$section");
- $select->set_help_icon('activities');
- $select->set_label($stractivitylabel, array('class' => 'accesshide'));
- $output .= $OUTPUT->render($select);
- }
-
- if (!$vertical) {
- $output .= html_writer::end_tag('div');
- }
-
- $output .= html_writer::end_tag('div');
-
- if (course_ajax_enabled($course)) {
- $straddeither = get_string('addresourceoractivity');
- // The module chooser link
- $modchooser = html_writer::start_tag('div', array('class' => 'mdl-right'));
- $modchooser.= html_writer::start_tag('div', array('class' => 'section-modchooser'));
- $icon = $OUTPUT->pix_icon('t/add', '');
- $span = html_writer::tag('span', $straddeither, array('class' => 'section-modchooser-text'));
- $modchooser .= html_writer::tag('span', $icon . $span, array('class' => 'section-modchooser-link'));
- $modchooser.= html_writer::end_tag('div');
- $modchooser.= html_writer::end_tag('div');
-
- // Wrap the normal output in a noscript div
- $usemodchooser = get_user_preferences('usemodchooser', $CFG->modchooserdefault);
- if ($usemodchooser) {
- $output = html_writer::tag('div', $output, array('class' => 'hiddenifjs addresourcedropdown'));
- $modchooser = html_writer::tag('div', $modchooser, array('class' => 'visibleifjs addresourcemodchooser'));
- } else {
- // If the module chooser is disabled, we need to ensure that the dropdowns are shown even if javascript is disabled
- $output = html_writer::tag('div', $output, array('class' => 'show addresourcedropdown'));
- $modchooser = html_writer::tag('div', $modchooser, array('class' => 'hide addresourcemodchooser'));
- }
- $output = $modchooser . $output;
- }
-
- if ($return) {
- return $output;
- } else {
- echo $output;
- }
-}
-
/**
* Retrieve all metadata for the requested modules
*
@@ -1892,7 +1322,10 @@ function get_module_metadata($course, $modnames, $sectionreturn = null) {
}
$return = array();
- $urlbase = "/course/mod.php?id=$course->id&sesskey=".sesskey().'&sr='.$sectionreturn.'&add=';
+ $urlbase = new moodle_url('/course/mod.php', array('id' => $course->id, 'sesskey' => sesskey()));
+ if ($sectionreturn !== null) {
+ $urlbase->param('sr', $sectionreturn);
+ }
foreach($modnames as $modname => $modnamestr) {
if (!course_allowed_module($course, $modname)) {
continue;
@@ -1939,16 +1372,16 @@ function get_module_metadata($course, $modnames, $sectionreturn = null) {
if (get_string_manager()->string_exists('help' . $subtype->name, $modname)) {
$subtype->help = get_string('help' . $subtype->name, $modname);
}
- $subtype->link = $urlbase . $subtype->type;
+ $subtype->link = new moodle_url($urlbase, array('add' => $subtype->type));
$group->types[] = $subtype;
}
$modlist[$course->id][$modname] = $group;
}
} else {
$module = new stdClass();
- $module->title = get_string('modulename', $modname);
+ $module->title = $modnamestr;
$module->name = $modname;
- $module->link = $urlbase . $modname;
+ $module->link = new moodle_url($urlbase, array('add' => $modname));
$module->icon = $OUTPUT->pix_icon('icon', '', $module->name, array('class' => 'icon'));
$sm = get_string_manager();
if ($sm->string_exists('modulename_help', $modname)) {
@@ -3155,19 +2588,15 @@ function moveto_module($mod, $section, $beforemod=NULL) {
}
/**
- * Produces the editing buttons for a module
+ * Returns the list of all editing actions that current user can perform on the module
*
- * @global core_renderer $OUTPUT
- * @staticvar type $str
- * @param stdClass $mod The module to produce editing buttons for
- * @param bool $absolute_ignored ignored - all links are absolute
- * @param bool $moveselect If true a move seleciton process is used (default true)
- * @param int $indent The current indenting
- * @param int $section The section to link back to
- * @return string XHTML for the editing buttons
+ * @param cm_info $mod The module to produce editing buttons for
+ * @param int $indent The current indenting (default -1 means no move left-right actions)
+ * @param int $sr The section to link back to (used for creating the links)
+ * @return array array of action_link or pix_icon objects
*/
-function make_editing_buttons(stdClass $mod, $absolute_ignored = true, $moveselect = true, $indent=-1, $section=null) {
- global $CFG, $OUTPUT, $COURSE;
+function course_get_cm_edit_actions(cm_info $mod, $indent = -1, $sr = null) {
+ global $COURSE, $SITE;
static $str;
@@ -3179,43 +2608,36 @@ function make_editing_buttons(stdClass $mod, $absolute_ignored = true, $movesele
// no permission to edit anything
if (!has_any_capability($editcaps, $modcontext) and !has_all_capabilities($dupecaps, $coursecontext)) {
- return false;
+ return array();
}
$hasmanageactivities = has_capability('moodle/course:manageactivities', $modcontext);
if (!isset($str)) {
- $str = new stdClass;
- $str->assign = get_string("assignroles", 'role');
- $str->delete = get_string("delete");
- $str->move = get_string("move");
- $str->moveup = get_string("moveup");
- $str->movedown = get_string("movedown");
- $str->moveright = get_string("moveright");
- $str->moveleft = get_string("moveleft");
- $str->update = get_string("update");
- $str->duplicate = get_string("duplicate");
- $str->hide = get_string("hide");
- $str->show = get_string("show");
+ $str = get_strings(array('delete', 'move', 'moveright', 'moveleft',
+ 'update', 'duplicate', 'hide', 'show', 'edittitle'), 'moodle');
+ $str->assign = get_string('assignroles', 'role');
$str->groupsnone = get_string('clicktochangeinbrackets', 'moodle', get_string("groupsnone"));
$str->groupsseparate = get_string('clicktochangeinbrackets', 'moodle', get_string("groupsseparate"));
$str->groupsvisible = get_string('clicktochangeinbrackets', 'moodle', get_string("groupsvisible"));
$str->forcedgroupsnone = get_string('forcedmodeinbrackets', 'moodle', get_string("groupsnone"));
$str->forcedgroupsseparate = get_string('forcedmodeinbrackets', 'moodle', get_string("groupsseparate"));
$str->forcedgroupsvisible = get_string('forcedmodeinbrackets', 'moodle', get_string("groupsvisible"));
- $str->edittitle = get_string('edittitle', 'moodle');
}
$baseurl = new moodle_url('/course/mod.php', array('sesskey' => sesskey()));
- if ($section !== null) {
- $baseurl->param('sr', $section);
+ if ($sr !== null) {
+ $baseurl->param('sr', $sr);
}
$actions = array();
// AJAX edit title
- if ($mod->modname !== 'label' && $hasmanageactivities && course_ajax_enabled($COURSE)) {
- $actions[] = new action_link(
+ if ($mod->modname !== 'label' && $hasmanageactivities &&
+ (($mod->course == $COURSE->id && course_ajax_enabled($COURSE)) ||
+ ($mod->course == SITEID && course_ajax_enabled($SITE)))) {
+ // we will not display link if we are on some other-course page (where we should not see this module anyway)
+ $actions['title'] = new action_link(
new moodle_url($baseurl, array('update' => $mod->id)),
new pix_icon('t/editstring', $str->edittitle, 'moodle', array('class' => 'iconsmall visibleifjs', 'title' => '')),
null,
@@ -3234,7 +2656,7 @@ function make_editing_buttons(stdClass $mod, $absolute_ignored = true, $movesele
}
if ($indent > 0) {
- $actions[] = new action_link(
+ $actions['moveleft'] = new action_link(
new moodle_url($baseurl, array('id' => $mod->id, 'indent' => '-1')),
new pix_icon($leftarrow, $str->moveleft, 'moodle', array('class' => 'iconsmall', 'title' => '')),
null,
@@ -3242,7 +2664,7 @@ function make_editing_buttons(stdClass $mod, $absolute_ignored = true, $movesele
);
}
if ($indent >= 0) {
- $actions[] = new action_link(
+ $actions['moveright'] = new action_link(
new moodle_url($baseurl, array('id' => $mod->id, 'indent' => '1')),
new pix_icon($rightarrow, $str->moveright, 'moodle', array('class' => 'iconsmall', 'title' => '')),
null,
@@ -3253,32 +2675,17 @@ function make_editing_buttons(stdClass $mod, $absolute_ignored = true, $movesele
// move
if ($hasmanageactivities) {
- if ($moveselect) {
- $actions[] = new action_link(
- new moodle_url($baseurl, array('copy' => $mod->id)),
- new pix_icon('t/move', $str->move, 'moodle', array('class' => 'iconsmall', 'title' => '')),
- null,
- array('class' => 'editing_move', 'title' => $str->move)
- );
- } else {
- $actions[] = new action_link(
- new moodle_url($baseurl, array('id' => $mod->id, 'move' => '-1')),
- new pix_icon('t/up', $str->moveup, 'moodle', array('class' => 'iconsmall', 'title' => '')),
- null,
- array('class' => 'editing_moveup', 'title' => $str->moveup)
- );
- $actions[] = new action_link(
- new moodle_url($baseurl, array('id' => $mod->id, 'move' => '1')),
- new pix_icon('t/down', $str->movedown, 'moodle', array('class' => 'iconsmall', 'title' => '')),
- null,
- array('class' => 'editing_movedown', 'title' => $str->movedown)
- );
- }
+ $actions['move'] = new action_link(
+ new moodle_url($baseurl, array('copy' => $mod->id)),
+ new pix_icon('t/move', $str->move, 'moodle', array('class' => 'iconsmall', 'title' => '')),
+ null,
+ array('class' => 'editing_move', 'title' => $str->move)
+ );
}
// Update
if ($hasmanageactivities) {
- $actions[] = new action_link(
+ $actions['update'] = new action_link(
new moodle_url($baseurl, array('update' => $mod->id)),
new pix_icon('t/edit', $str->update, 'moodle', array('class' => 'iconsmall', 'title' => '')),
null,
@@ -3287,8 +2694,10 @@ function make_editing_buttons(stdClass $mod, $absolute_ignored = true, $movesele
}
// Duplicate (require both target import caps to be able to duplicate and backup2 support, see modduplicate.php)
- if (has_all_capabilities($dupecaps, $coursecontext) && plugin_supports('mod', $mod->modname, FEATURE_BACKUP_MOODLE2)) {
- $actions[] = new action_link(
+ // note that restoring on front page is never allowed
+ if ($mod->course != SITEID && has_all_capabilities($dupecaps, $coursecontext) &&
+ plugin_supports('mod', $mod->modname, FEATURE_BACKUP_MOODLE2)) {
+ $actions['duplicate'] = new action_link(
new moodle_url($baseurl, array('duplicate' => $mod->id)),
new pix_icon('t/copy', $str->duplicate, 'moodle', array('class' => 'iconsmall', 'title' => '')),
null,
@@ -3298,7 +2707,7 @@ function make_editing_buttons(stdClass $mod, $absolute_ignored = true, $movesele
// Delete
if ($hasmanageactivities) {
- $actions[] = new action_link(
+ $actions['delete'] = new action_link(
new moodle_url($baseurl, array('delete' => $mod->id)),
new pix_icon('t/delete', $str->delete, 'moodle', array('class' => 'iconsmall', 'title' => '')),
null,
@@ -3309,14 +2718,14 @@ function make_editing_buttons(stdClass $mod, $absolute_ignored = true, $movesele
// hideshow
if (has_capability('moodle/course:activityvisibility', $modcontext)) {
if ($mod->visible) {
- $actions[] = new action_link(
+ $actions['hide'] = new action_link(
new moodle_url($baseurl, array('hide' => $mod->id)),
new pix_icon('t/hide', $str->hide, 'moodle', array('class' => 'iconsmall', 'title' => '')),
null,
array('class' => 'editing_hide', 'title' => $str->hide)
);
} else {
- $actions[] = new action_link(
+ $actions['show'] = new action_link(
new moodle_url($baseurl, array('show' => $mod->id)),
new pix_icon('t/show', $str->show, 'moodle', array('class' => 'iconsmall', 'title' => '')),
null,
@@ -3326,61 +2735,54 @@ function make_editing_buttons(stdClass $mod, $absolute_ignored = true, $movesele
}
// groupmode
- if ($hasmanageactivities and $mod->groupmode !== false) {
- if ($mod->groupmode == SEPARATEGROUPS) {
- $groupmode = 0;
+ if ($hasmanageactivities and plugin_supports('mod', $mod->modname, FEATURE_GROUPS, 0)) {
+ if ($mod->coursegroupmodeforce) {
+ $modgroupmode = $mod->coursegroupmode;
+ } else {
+ $modgroupmode = $mod->groupmode;
+ }
+ if ($modgroupmode == SEPARATEGROUPS) {
+ $groupmode = NOGROUPS;
$grouptitle = $str->groupsseparate;
$forcedgrouptitle = $str->forcedgroupsseparate;
- $groupclass = 'editing_groupsseparate';
+ $actionname = 'groupsseparate';
$groupimage = 't/groups';
- } else if ($mod->groupmode == VISIBLEGROUPS) {
- $groupmode = 1;
+ } else if ($modgroupmode == VISIBLEGROUPS) {
+ $groupmode = SEPARATEGROUPS;
$grouptitle = $str->groupsvisible;
$forcedgrouptitle = $str->forcedgroupsvisible;
- $groupclass = 'editing_groupsvisible';
+ $actionname = 'groupsvisible';
$groupimage = 't/groupv';
} else {
- $groupmode = 2;
+ $groupmode = VISIBLEGROUPS;
$grouptitle = $str->groupsnone;
$forcedgrouptitle = $str->forcedgroupsnone;
- $groupclass = 'editing_groupsnone';
+ $actionname = 'groupsnone';
$groupimage = 't/groupn';
}
- if ($mod->groupmodelink) {
- $actions[] = new action_link(
+ if (!$mod->coursegroupmodeforce) {
+ $actions[$actionname] = new action_link(
new moodle_url($baseurl, array('id' => $mod->id, 'groupmode' => $groupmode)),
new pix_icon($groupimage, $grouptitle, 'moodle', array('class' => 'iconsmall', 'title' => '')),
null,
- array('class' => $groupclass, 'title' => $grouptitle)
+ array('class' => 'editing_'. $actionname, 'title' => $grouptitle)
);
} else {
- $actions[] = new pix_icon($groupimage, $forcedgrouptitle, 'moodle', array('title' => $forcedgrouptitle, 'class' => 'iconsmall'));
+ $actions[$actionname] = new pix_icon($groupimage, $forcedgrouptitle, 'moodle', array('title' => $forcedgrouptitle, 'class' => 'iconsmall'));
}
}
// Assign
if (has_capability('moodle/role:assign', $modcontext)){
- $actions[] = new action_link(
- new moodle_url('/'.$CFG->admin.'/roles/assign.php', array('contextid' => $modcontext->id)),
+ $actions['assign'] = new action_link(
+ new moodle_url('/admin/roles/assign.php', array('contextid' => $modcontext->id)),
new pix_icon('t/assignroles', $str->assign, 'moodle', array('class' => 'iconsmall', 'title' => '')),
null,
array('class' => 'editing_assign', 'title' => $str->assign)
);
}
- // The space added before the is a ugly hack but required to set the CSS property white-space: nowrap
- // and having it to work without attaching the preceding text along with it. Hopefully the refactoring of
- // the course page HTML will allow this to be removed.
- $output = ' ' . html_writer::start_tag('span', array('class' => 'commands'));
- foreach ($actions as $action) {
- if ($action instanceof renderable) {
- $output .= $OUTPUT->render($action);
- } else {
- $output .= $action;
- }
- }
- $output .= html_writer::end_tag('span');
- return $output;
+ return $actions;
}
/**
@@ -4548,17 +3950,6 @@ function include_course_ajax($course, $usedmodules = array(), $enabledmodules =
// Load drag and drop upload AJAX.
dndupload_add_to_course($course, $enabledmodules);
- // Add the module chooser
- $PAGE->requires->yui_module('moodle-course-modchooser',
- 'M.course.init_chooser',
- array(array('courseid' => $course->id, 'closeButtonTitle' => get_string('close', 'editor')))
- );
- $PAGE->requires->strings_for_js(array(
- 'addresourceoractivity',
- 'modchooserenable',
- 'modchooserdisable',
- ), 'moodle');
-
return true;
}
diff --git a/course/modduplicate.php b/course/modduplicate.php
index d175a87bdd2..72476713468 100644
--- a/course/modduplicate.php
+++ b/course/modduplicate.php
@@ -45,7 +45,7 @@ $section = $DB->get_record('course_sections', array('id' => $cm->section, 'co
require_login($course);
require_sesskey();
require_capability('moodle/course:manageactivities', $context);
-// Require both target import caps to be able to duplicate, see make_editing_buttons()
+// Require both target import caps to be able to duplicate, see course_get_cm_edit_actions()
require_capability('moodle/backup:backuptargetimport', $context);
require_capability('moodle/restore:restoretargetimport', $context);
diff --git a/course/renderer.php b/course/renderer.php
index 33c15b466ba..7147c08ac3d 100644
--- a/course/renderer.php
+++ b/course/renderer.php
@@ -211,7 +211,22 @@ class core_course_renderer extends plugin_renderer_base {
* @return string The composed HTML for the module
*/
public function course_modchooser($modules, $course) {
- global $OUTPUT;
+ static $isdisplayed = false;
+ if ($isdisplayed) {
+ return '';
+ }
+ $isdisplayed = true;
+
+ // Add the module chooser
+ $this->page->requires->yui_module('moodle-course-modchooser',
+ 'M.course.init_chooser',
+ array(array('courseid' => $course->id, 'closeButtonTitle' => get_string('close', 'editor')))
+ );
+ $this->page->requires->strings_for_js(array(
+ 'addresourceoractivity',
+ 'modchooserenable',
+ 'modchooserdisable',
+ ), 'moodle');
// Add the header
$header = html_writer::tag('div', get_string('addresourceoractivity', 'moodle'),
@@ -354,4 +369,613 @@ class core_course_renderer extends plugin_renderer_base {
$module->help = '';
return $this->course_modchooser_module($module, array('moduletypetitle'));
}
+
+ /**
+ * Renders HTML for displaying the sequence of course module editing buttons
+ *
+ * @see course_get_cm_edit_actions()
+ *
+ * @param array $actions array of action_link or pix_icon objects
+ * @return string
+ */
+ public function course_section_cm_edit_actions($actions) {
+ $output = html_writer::start_tag('span', array('class' => 'commands'));
+ foreach ($actions as $action) {
+ if ($action instanceof renderable) {
+ $output .= $this->output->render($action);
+ } else {
+ $output .= $action;
+ }
+ }
+ $output .= html_writer::end_tag('span');
+ return $output;
+ }
+
+ /**
+ * Renders HTML for the menus to add activities and resources to the current course
+ *
+ * @param stdClass $course
+ * @param int $section relative section number (field course_sections.section)
+ * @param int $sectionreturn The section to link back to
+ * @param array $displayoptions additional display options, for example blocks add
+ * option 'inblock' => true, suggesting to display controls vertically
+ * @return string
+ */
+ function course_section_add_cm_control($course, $section, $sectionreturn = null, $displayoptions = array()) {
+ global $CFG;
+
+ $vertical = !empty($displayoptions['inblock']);
+
+ // check to see if user can add menus and there are modules to add
+ if (!has_capability('moodle/course:manageactivities', context_course::instance($course->id))
+ || !$this->page->user_is_editing()
+ || !($modnames = get_module_types_names()) || empty($modnames)) {
+ return '';
+ }
+
+ // Retrieve all modules with associated metadata
+ $modules = get_module_metadata($course, $modnames, $sectionreturn);
+ $urlparams = array('section' => $section);
+
+ // We'll sort resources and activities into two lists
+ $activities = array(MOD_CLASS_ACTIVITY => array(), MOD_CLASS_RESOURCE => array());
+
+ foreach ($modules as $module) {
+ if (!array_key_exists($module->archetype, $activities)) {
+ // System modules cannot be added by user, do not add to dropdown
+ } else if (isset($module->types)) {
+ // This module has a subtype
+ // NOTE: this is legacy stuff, module subtypes are very strongly discouraged!!
+ $subtypes = array();
+ foreach ($module->types as $subtype) {
+ $link = $subtype->link->out(true, $urlparams);
+ $subtypes[$link] = $subtype->title;
+ }
+
+ // Sort module subtypes into the list
+ if (!empty($module->title)) {
+ // This grouping has a name
+ $activities[$module->archetype][] = array($module->title => $subtypes);
+ } else {
+ // This grouping does not have a name
+ $activities[$module->archetype] = array_merge($activities[$module->archetype], $subtypes);
+ }
+ } else {
+ // This module has no subtypes
+ $link = $module->link->out(true, $urlparams);
+ $activities[$module->archetype][$link] = $module->title;
+ }
+ }
+
+ $straddactivity = get_string('addactivity');
+ $straddresource = get_string('addresource');
+ $sectionname = get_section_name($course, $section);
+ $strresourcelabel = get_string('addresourcetosection', null, $sectionname);
+ $stractivitylabel = get_string('addactivitytosection', null, $sectionname);
+
+ $output = html_writer::start_tag('div', array('class' => 'section_add_menus', 'id' => 'add_menus-section-' . $section));
+
+ if (!$vertical) {
+ $output .= html_writer::start_tag('div', array('class' => 'horizontal'));
+ }
+
+ if (!empty($activities[MOD_CLASS_RESOURCE])) {
+ $select = new url_select($activities[MOD_CLASS_RESOURCE], '', array(''=>$straddresource), "ressection$section");
+ $select->set_help_icon('resources');
+ $select->set_label($strresourcelabel, array('class' => 'accesshide'));
+ $output .= $this->output->render($select);
+ }
+
+ if (!empty($activities[MOD_CLASS_ACTIVITY])) {
+ $select = new url_select($activities[MOD_CLASS_ACTIVITY], '', array(''=>$straddactivity), "section$section");
+ $select->set_help_icon('activities');
+ $select->set_label($stractivitylabel, array('class' => 'accesshide'));
+ $output .= $this->output->render($select);
+ }
+
+ if (!$vertical) {
+ $output .= html_writer::end_tag('div');
+ }
+
+ $output .= html_writer::end_tag('div');
+
+ if (course_ajax_enabled($course) && $course->id == $this->page->course->id) {
+ // modchooser can be added only for the current course set on the page!
+ $straddeither = get_string('addresourceoractivity');
+ // The module chooser link
+ $modchooser = html_writer::start_tag('div', array('class' => 'mdl-right'));
+ $modchooser.= html_writer::start_tag('div', array('class' => 'section-modchooser'));
+ $icon = $this->output->pix_icon('t/add', '');
+ $span = html_writer::tag('span', $straddeither, array('class' => 'section-modchooser-text'));
+ $modchooser .= html_writer::tag('span', $icon . $span, array('class' => 'section-modchooser-link'));
+ $modchooser.= html_writer::end_tag('div');
+ $modchooser.= html_writer::end_tag('div');
+
+ // Wrap the normal output in a noscript div
+ $usemodchooser = get_user_preferences('usemodchooser', $CFG->modchooserdefault);
+ if ($usemodchooser) {
+ $output = html_writer::tag('div', $output, array('class' => 'hiddenifjs addresourcedropdown'));
+ $modchooser = html_writer::tag('div', $modchooser, array('class' => 'visibleifjs addresourcemodchooser'));
+ } else {
+ // If the module chooser is disabled, we need to ensure that the dropdowns are shown even if javascript is disabled
+ $output = html_writer::tag('div', $output, array('class' => 'show addresourcedropdown'));
+ $modchooser = html_writer::tag('div', $modchooser, array('class' => 'hide addresourcemodchooser'));
+ }
+ $output = $this->course_modchooser($modules, $course) . $modchooser . $output;
+ }
+
+ return $output;
+ }
+
+ /**
+ * Renders html for completion box on course page
+ *
+ * If completion is disabled, returns empty string
+ * If completion is automatic, returns an icon of the current completion state
+ * If completion is manual, returns a form (with an icon inside) that allows user to
+ * toggle completion
+ *
+ * @param stdClass $course course object
+ * @param completion_info $completioninfo completion info for the course, it is recommended
+ * to fetch once for all modules in course/section for performance
+ * @param cm_info $mod module to show completion for
+ * @param array $displayoptions display options, not used in core
+ * @return string
+ */
+ public function course_section_cm_completion($course, &$completioninfo, cm_info $mod, $displayoptions = array()) {
+ global $CFG;
+ $output = '';
+ if (!empty($displayoptions['hidecompletion']) || !isloggedin() || isguestuser() || !$mod->uservisible) {
+ return $output;
+ }
+ if ($completioninfo === null) {
+ $completioninfo = new completion_info($course);
+ }
+ $completion = $completioninfo->is_enabled($mod);
+ if ($completion == COMPLETION_TRACKING_NONE) {
+ return $output;
+ }
+
+ $completiondata = $completioninfo->get_data($mod, true);
+ $completionicon = '';
+
+ if ($this->page->user_is_editing()) {
+ switch ($completion) {
+ case COMPLETION_TRACKING_MANUAL :
+ $completionicon = 'manual-enabled'; break;
+ case COMPLETION_TRACKING_AUTOMATIC :
+ $completionicon = 'auto-enabled'; break;
+ }
+ } else if ($completion == COMPLETION_TRACKING_MANUAL) {
+ switch($completiondata->completionstate) {
+ case COMPLETION_INCOMPLETE:
+ $completionicon = 'manual-n'; break;
+ case COMPLETION_COMPLETE:
+ $completionicon = 'manual-y'; break;
+ }
+ } else { // Automatic
+ switch($completiondata->completionstate) {
+ case COMPLETION_INCOMPLETE:
+ $completionicon = 'auto-n'; break;
+ case COMPLETION_COMPLETE:
+ $completionicon = 'auto-y'; break;
+ case COMPLETION_COMPLETE_PASS:
+ $completionicon = 'auto-pass'; break;
+ case COMPLETION_COMPLETE_FAIL:
+ $completionicon = 'auto-fail'; break;
+ }
+ }
+ if ($completionicon) {
+ $formattedname = $mod->get_formatted_name();
+ $imgalt = get_string('completion-alt-' . $completionicon, 'completion', $formattedname);
+ if ($completion == COMPLETION_TRACKING_MANUAL && !$this->page->user_is_editing()) {
+ $imgtitle = get_string('completion-title-' . $completionicon, 'completion', $formattedname);
+ $newstate =
+ $completiondata->completionstate == COMPLETION_COMPLETE
+ ? COMPLETION_INCOMPLETE
+ : COMPLETION_COMPLETE;
+ // In manual mode the icon is a toggle form...
+
+ // If this completion state is used by the
+ // conditional activities system, we need to turn
+ // off the JS.
+ $extraclass = '';
+ if (!empty($CFG->enableavailability) &&
+ condition_info::completion_value_used_as_condition($course, $mod)) {
+ $extraclass = ' preventjs';
+ }
+ $output .= html_writer::start_tag('form', array('method' => 'post',
+ 'action' => new moodle_url('/course/togglecompletion.php'),
+ 'class' => 'togglecompletion'. $extraclass));
+ $output .= html_writer::start_tag('div');
+ $output .= html_writer::empty_tag('input', array(
+ 'type' => 'hidden', 'name' => 'id', 'value' => $mod->id));
+ $output .= html_writer::empty_tag('input', array(
+ 'type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()));
+ $output .= html_writer::empty_tag('input', array(
+ 'type' => 'hidden', 'name' => 'modulename', 'value' => $mod->name));
+ $output .= html_writer::empty_tag('input', array(
+ 'type' => 'hidden', 'name' => 'completionstate', 'value' => $newstate));
+ $output .= html_writer::empty_tag('input', array(
+ 'type' => 'image',
+ 'src' => $this->output->pix_url('i/completion-'.$completionicon),
+ 'alt' => $imgalt, 'title' => $imgtitle));
+ $output .= html_writer::end_tag('div');
+ $output .= html_writer::end_tag('form');
+ } else {
+ // In auto mode, or when editing, the icon is just an image
+ $completionpixicon = new pix_icon('i/completion-'.$completionicon, $imgalt, '',
+ array('title' => $imgalt));
+ $output .= html_writer::tag('span', $this->output->render($completionpixicon),
+ array('class' => 'autocompletion'));
+ }
+ }
+ return $output;
+ }
+
+ /**
+ * Checks if course module has any conditions that may make it unavailable for
+ * all or some of the students
+ *
+ * This function is internal and is only used to create CSS classes for the module name/text
+ *
+ * @param cm_info $mod
+ * @return bool
+ */
+ protected function is_cm_conditionally_hidden(cm_info $mod) {
+ global $CFG;
+ $conditionalhidden = false;
+ if (!empty($CFG->enableavailability)) {
+ $conditionalhidden = $mod->availablefrom > time() ||
+ ($mod->availableuntil && $mod->availableuntil < time()) ||
+ count($mod->conditionsgrade) > 0 ||
+ count($mod->conditionscompletion) > 0;
+ }
+ return $conditionalhidden;
+ }
+
+ /**
+ * Renders html to display a name with the link to the course module on a course page
+ *
+ * If module is unavailable for user but still needs to be displayed
+ * in the list, just the name is returned without a link
+ *
+ * Note, that for course modules that never have separate pages (i.e. labels)
+ * this function return an empty string
+ *
+ * @param cm_info $mod
+ * @param array $displayoptions
+ * @return string
+ */
+ public function course_section_cm_name(cm_info $mod, $displayoptions = array()) {
+ global $CFG;
+ $output = '';
+ if (!$mod->uservisible &&
+ (empty($mod->showavailability) || empty($mod->availableinfo))) {
+ // nothing to be displayed to the user
+ return $output;
+ }
+ $url = $mod->get_url();
+ if (!$url) {
+ return $output;
+ }
+
+ //Accessibility: for files get description via icon, this is very ugly hack!
+ $instancename = $mod->get_formatted_name();
+ $altname = '';
+ $altname = $mod->modfullname;
+ // Avoid unnecessary duplication: if e.g. a forum name already
+ // includes the word forum (or Forum, etc) then it is unhelpful
+ // to include that in the accessible description that is added.
+ if (false !== strpos(textlib::strtolower($instancename),
+ textlib::strtolower($altname))) {
+ $altname = '';
+ }
+ // File type after name, for alphabetic lists (screen reader).
+ if ($altname) {
+ $altname = get_accesshide(' '.$altname);
+ }
+
+ $conditionalhidden = $this->is_cm_conditionally_hidden($mod);
+ $accessiblebutdim = !$mod->visible || $conditionalhidden;
+
+ $linkclasses = '';
+ $accesstext = '';
+ $textclasses = '';
+ if ($accessiblebutdim) {
+ $linkclasses .= ' dimmed';
+ $textclasses .= ' dimmed_text';
+ if ($conditionalhidden) {
+ $linkclasses .= ' conditionalhidden';
+ $textclasses .= ' conditionalhidden';
+ }
+ if ($mod->uservisible) {
+ // show accessibility note only if user can access the module himself
+ $accesstext = get_accesshide(get_string('hiddenfromstudents').': ');
+ }
+ }
+
+ // Get on-click attribute value if specified and decode the onclick - it
+ // has already been encoded for display (puke).
+ $onclick = htmlspecialchars_decode($mod->get_on_click(), ENT_QUOTES);
+
+ $groupinglabel = '';
+ if (!empty($mod->groupingid) && has_capability('moodle/course:managegroups', context_course::instance($mod->course))) {
+ $groupings = groups_get_all_groupings($mod->course);
+ $groupinglabel = html_writer::tag('span', '('.format_string($groupings[$mod->groupingid]->name).')',
+ array('class' => 'groupinglabel '.$textclasses));
+ }
+
+ // Display link itself.
+ $activitylink = html_writer::empty_tag('img', array('src' => $mod->get_icon_url(),
+ 'class' => 'iconlarge activityicon', 'alt' => $mod->modfullname)) . $accesstext .
+ html_writer::tag('span', $instancename . $altname, array('class' => 'instancename'));
+ if ($mod->uservisible) {
+ $output .= html_writer::link($url, $activitylink, array('class' => $linkclasses, 'onclick' => $onclick)) .
+ $groupinglabel;
+ } else {
+ // We may be displaying this just in order to show information
+ // about visibility, without the actual link ($mod->uservisible)
+ $output .= html_writer::tag('div', $activitylink, array('class' => $textclasses)) .
+ $groupinglabel;
+ }
+ return $output;
+ }
+
+ /**
+ * Renders html to display the module content on the course page (i.e. text of the labels)
+ *
+ * @param cm_info $mod
+ * @param array $displayoptions
+ * @return string
+ */
+ public function course_section_cm_text(cm_info $mod, $displayoptions = array()) {
+ $output = '';
+ if (!$mod->uservisible &&
+ (empty($mod->showavailability) || empty($mod->availableinfo))) {
+ // nothing to be displayed to the user
+ return $output;
+ }
+ $content = $mod->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
+ $conditionalhidden = $this->is_cm_conditionally_hidden($mod);
+ $accessiblebutdim = !$mod->visible || $conditionalhidden;
+ $textclasses = '';
+ $accesstext = '';
+ if ($accessiblebutdim) {
+ $textclasses .= ' dimmed_text';
+ if ($conditionalhidden) {
+ $textclasses .= ' conditionalhidden';
+ }
+ if ($mod->uservisible) {
+ // show accessibility note only if user can access the module himself
+ $accesstext = get_accesshide(get_string('hiddenfromstudents').': ');
+ }
+ }
+ if ($mod->get_url()) {
+ if ($content) {
+ // If specified, display extra content after link.
+ $output = html_writer::tag('div', $content, array('class' =>
+ trim('contentafterlink ' . $textclasses)));
+ }
+ } else {
+ // No link, so display only content.
+ $output = html_writer::tag('div', $accesstext . $content, array('class' => $textclasses));
+ }
+ return $output;
+ }
+
+ /**
+ * Renders HTML to show course module availability information (for someone who isn't allowed
+ * to see the activity itself, or for staff)
+ *
+ * @param cm_info $mod
+ * @param array $displayoptions
+ * @return string
+ */
+ public function course_section_cm_availability(cm_info $mod, $displayoptions = array()) {
+ global $CFG;
+ if (!$mod->uservisible) {
+ // this is a student who is not allowed to see the module but might be allowed
+ // to see availability info (i.e. "Available from ...")
+ if (!empty($mod->showavailability) && !empty($mod->availableinfo)) {
+ $output = html_writer::tag('div', $mod->availableinfo, array('class' => 'availabilityinfo'));
+ }
+ return $output;
+ }
+ // this is a teacher who is allowed to see module but still should see the
+ // information that module is not available to all/some students
+ $modcontext = context_module::instance($mod->id);
+ $canviewhidden = has_capability('moodle/course:viewhiddenactivities', $modcontext);
+ if ($canviewhidden && !empty($CFG->enableavailability)) {
+ // Don't add availability information if user is not editing and activity is hidden.
+ if ($mod->visible || $this->page->user_is_editing()) {
+ $hidinfoclass = '';
+ if (!$mod->visible) {
+ $hidinfoclass = 'hide';
+ }
+ $ci = new condition_info($mod);
+ $fullinfo = $ci->get_full_information();
+ if($fullinfo) {
+ echo ''.get_string($mod->showavailability
+ ? 'userrestriction_visible'
+ : 'userrestriction_hidden','condition',
+ $fullinfo).'
';
+ }
+ }
+ }
+ 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;
+ }
}
diff --git a/course/togglecompletion.php b/course/togglecompletion.php
index 3773890099a..2977f7179f1 100644
--- a/course/togglecompletion.php
+++ b/course/togglecompletion.php
@@ -123,7 +123,7 @@ switch($targetstate) {
}
// Get course-modules entry
-$cm = get_coursemodule_from_id(null, $cmid, null, false, MUST_EXIST);
+$cm = get_coursemodule_from_id(null, $cmid, null, true, MUST_EXIST);
$course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
// Check user is logged in
@@ -152,8 +152,12 @@ if ($fromajax) {
} else {
// In case of use in other areas of code we allow a 'backto' parameter,
// otherwise go back to course page
- $backto = optional_param('backto', 'view.php?id='.$course->id, PARAM_URL);
- redirect($backto);
+
+ if ($backto = optional_param('backto', null, PARAM_URL)) {
+ redirect($backto);
+ } else {
+ redirect(course_get_url($course, $cm->sectionnum));
+ }
}
// utility functions
diff --git a/course/view.php b/course/view.php
index 6f40c365a52..0b1facaf833 100644
--- a/course/view.php
+++ b/course/view.php
@@ -279,10 +279,6 @@
echo html_writer::end_tag('div');
// Include course AJAX
- if (include_course_ajax($course, $modnamesused)) {
- // Add the module chooser
- $renderer = $PAGE->get_renderer('core', 'course');
- echo $renderer->course_modchooser(get_module_metadata($course, $modnames, $displaysection), $course);
- }
+ include_course_ajax($course, $modnamesused);
echo $OUTPUT->footer();
diff --git a/course/yui/modchooser/modchooser.js b/course/yui/modchooser/modchooser.js
index 10fddedd122..377e5aed5ab 100644
--- a/course/yui/modchooser/modchooser.js
+++ b/course/yui/modchooser/modchooser.js
@@ -161,6 +161,6 @@ YUI.add('moodle-course-modchooser', function(Y) {
}
},
'@VERSION@', {
- requires:['base', 'overlay', 'moodle-core-chooserdialogue', 'transition']
+ requires:['base', 'overlay', 'moodle-core-chooserdialogue', 'transition', 'moodle-course-coursebase']
}
);
diff --git a/index.php b/index.php
index 35c8eeb5e84..10a199fa12b 100644
--- a/index.php
+++ b/index.php
@@ -142,20 +142,15 @@
" class=\"iconsmall\" alt=\"$streditsummary\" />
";
}
- print_section($SITE, $section, $mods, $modnamesused, true);
+ $courserenderer = $PAGE->get_renderer('core', 'course');
+ echo $courserenderer->course_section_cm_list($SITE, $section);
- if ($editing) {
- print_section_add_menus($SITE, $section->section, $modnames);
- }
+ echo $courserenderer->course_section_add_cm_control($SITE, $section->section);
echo $OUTPUT->box_end();
}
}
// Include course AJAX
- if (include_course_ajax($SITE, $modnamesused)) {
- // Add the module chooser
- $renderer = $PAGE->get_renderer('core', 'course');
- echo $renderer->course_modchooser(get_module_metadata($SITE, $modnames), $SITE);
- }
+ include_course_ajax($SITE, $modnamesused);
if (isloggedin() and !isguestuser() and isset($CFG->frontpageloggedin)) {
$frontpagelayout = $CFG->frontpageloggedin;
diff --git a/lib/deprecatedlib.php b/lib/deprecatedlib.php
index 4ace5edf3cc..47ec83831fe 100644
--- a/lib/deprecatedlib.php
+++ b/lib/deprecatedlib.php
@@ -3084,3 +3084,134 @@ function format_weeks_get_section_dates($section, $course) {
}
return null;
}
+
+/**
+ * Obtains shared data that is used in print_section when displaying a
+ * course-module entry.
+ *
+ * Deprecated. Instead of:
+ * list($content, $name) = get_print_section_cm_text($cm, $course);
+ * use:
+ * $content = $cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
+ * $name = $cm->get_formatted_name();
+ *
+ * @deprecated since 2.5
+ * @see cm_info::get_formatted_content()
+ * @see cm_info::get_formatted_name()
+ *
+ * This data is also used in other areas of the code.
+ * @param cm_info $cm Course-module data (must come from get_fast_modinfo)
+ * @param object $course (argument not used)
+ * @return array An array with the following values in this order:
+ * $content (optional extra content for after link),
+ * $instancename (text of link)
+ */
+function get_print_section_cm_text(cm_info $cm, $course) {
+ debugging('Function get_print_section_cm_text() is deprecated. Please use '.
+ 'cm_info::get_formatted_content() and cm_info::get_formatted_name()',
+ DEBUG_DEVELOPER);
+ return array($cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true)),
+ $cm->get_formatted_name());
+}
+
+/**
+ * Prints the menus to add activities and resources.
+ *
+ * Deprecated. Please use:
+ * $courserenderer = $PAGE->get_renderer('core', 'course');
+ * $output = $courserenderer->course_section_add_cm_control($course, $section, $sectionreturn,
+ * array('inblock' => $vertical));
+ * echo $output; // if $return argument in print_section_add_menus() set to false
+ *
+ * @deprecated since 2.5
+ * @see core_course_renderer::course_section_add_cm_control()
+ *
+ * @param stdClass $course course object, must be the same as set on the page
+ * @param int $section relative section number (field course_sections.section)
+ * @param null|array $modnames (argument ignored) get_module_types_names() is used instead of argument
+ * @param bool $vertical Vertical orientation
+ * @param bool $return Return the menus or send them to output
+ * @param int $sectionreturn The section to link back to
+ * @return void|string depending on $return
+ */
+function print_section_add_menus($course, $section, $modnames = null, $vertical=false, $return=false, $sectionreturn=null) {
+ global $PAGE;
+ debugging('Function print_section_add_menus() is deprecated. Please use course renderer '.
+ 'function course_section_add_cm_control()', DEBUG_DEVELOPER);
+ $output = '';
+ $courserenderer = $PAGE->get_renderer('core', 'course');
+ $output = $courserenderer->course_section_add_cm_control($course, $section, $sectionreturn,
+ array('inblock' => $vertical));
+ if ($return) {
+ return $output;
+ } else {
+ echo $output;
+ return !empty($output);
+ }
+}
+
+/**
+ * Produces the editing buttons for a module
+ *
+ * Deprecated. Please use:
+ * $courserenderer = $PAGE->get_renderer('core', 'course');
+ * $actions = course_get_cm_edit_actions($mod, $indent, $section);
+ * return ' ' . $courserenderer->course_section_cm_edit_actions($actions);
+ *
+ * @deprecated since 2.5
+ * @see course_get_cm_edit_actions()
+ * @see core_course_renderer->course_section_cm_edit_actions()
+ *
+ * @param stdClass $mod The module to produce editing buttons for
+ * @param bool $absolute_ignored (argument ignored) - all links are absolute
+ * @param bool $moveselect (argument ignored)
+ * @param int $indent The current indenting
+ * @param int $section The section to link back to
+ * @return string XHTML for the editing buttons
+ */
+function make_editing_buttons(stdClass $mod, $absolute_ignored = true, $moveselect = true, $indent=-1, $section=null) {
+ global $PAGE;
+ debugging('Function make_editing_buttons() is deprecated, please see PHPdocs in '.
+ 'lib/deprecatedlib.php on how to replace it', DEBUG_DEVELOPER);
+ if (!($mod instanceof cm_info)) {
+ $modinfo = get_fast_modinfo($mod->course);
+ $mod = $modinfo->get_cm($mod->id);
+ }
+ $actions = course_get_cm_edit_actions($mod, $indent, $section);
+
+ $courserenderer = $PAGE->get_renderer('core', 'course');
+ // The space added before the is a ugly hack but required to set the CSS property white-space: nowrap
+ // and having it to work without attaching the preceding text along with it. Hopefully the refactoring of
+ // the course page HTML will allow this to be removed.
+ return ' ' . $courserenderer->course_section_cm_edit_actions($actions);
+}
+
+/**
+ * Prints a section full of activity modules
+ *
+ * Deprecated. Please use:
+ * $courserenderer = $PAGE->get_renderer('core', 'course');
+ * echo $courserenderer->course_section_cm_list($course, $section, $sectionreturn,
+ * array('hidecompletion' => $hidecompletion));
+ *
+ * @deprecated since 2.5
+ * @see core_course_renderer::course_section_cm_list()
+ *
+ * @param stdClass $course The course
+ * @param stdClass|section_info $section The section object containing properties id and section
+ * @param array $mods (argument not used)
+ * @param array $modnamesused (argument not used)
+ * @param bool $absolute (argument not used)
+ * @param string $width (argument not used)
+ * @param bool $hidecompletion Hide completion status
+ * @param int $sectionreturn The section to return to
+ * @return void
+ */
+function print_section($course, $section, $mods, $modnamesused, $absolute=false, $width="100%", $hidecompletion=false, $sectionreturn=null) {
+ global $PAGE;
+ debugging('Function print_section() is deprecated. Please use course renderer function '.
+ 'course_section_cm_list() instead.', DEBUG_DEVELOPER);
+ $displayoptions = array('hidecompletion' => $hidecompletion);
+ $courserenderer = $PAGE->get_renderer('core', 'course');
+ echo $courserenderer->course_section_cm_list($course, $section, $sectionreturn, $displayoptions);
+}
diff --git a/lib/modinfolib.php b/lib/modinfolib.php
index a9f4b241270..c40efc7ebaf 100644
--- a/lib/modinfolib.php
+++ b/lib/modinfolib.php
@@ -500,6 +500,22 @@ class cm_info extends stdClass {
*/
public $groupmembersonly;
+ /**
+ * Indicates whether the course containing the module has forced the groupmode
+ * This means that cm_info::$groupmode should be ignored and cm_info::$coursegroupmode be
+ * used instead
+ * @var bool
+ */
+ public $coursegroupmodeforce;
+
+ /**
+ * Group mode (one of the constants NONE, SEPARATEGROUPS, or VISIBLEGROUPS) - from
+ * course table - as specified for the course containing the module
+ * Effective only if cm_info::$coursegroupmodeforce is set
+ * @var int
+ */
+ public $coursegroupmode;
+
/**
* Indent level on course page (0 = no indent) - from course_modules table
* @var int
@@ -756,6 +772,52 @@ class cm_info extends stdClass {
return $this->content;
}
+ /**
+ * Returns the content to display on course/overview page, formatted and passed through filters
+ *
+ * if $options['context'] is not specified, the module context is used
+ *
+ * @param array|stdClass $options formatting options, see {@link format_text()}
+ * @return string
+ */
+ public function get_formatted_content($options = array()) {
+ $this->obtain_view_data();
+ if (empty($this->content)) {
+ return '';
+ }
+ if ($this->modname === 'label') {
+ // special case, label returns already formatted content, see cm_info::__construct()
+ // and label_get_coursemodule_info()
+ return $this->content;
+ }
+ // Improve filter performance by preloading filter setttings for all
+ // activities on the course (this does nothing if called multiple
+ // times)
+ filter_preload_activities($this->get_modinfo());
+
+ $options = (array)$options;
+ if (!isset($options['context'])) {
+ $options['context'] = context_module::instance($this->id);
+ }
+ return format_text($this->content, FORMAT_HTML, $options);
+ }
+
+ /**
+ * Returns the name to display on course/overview page, formatted and passed through filters
+ *
+ * if $options['context'] is not specified, the module context is used
+ *
+ * @param array|stdClass $options formatting options, see {@link format_string()}
+ * @return string
+ */
+ public function get_formatted_name($options = array()) {
+ $options = (array)$options;
+ if (!isset($options['context'])) {
+ $options['context'] = context_module::instance($this->id);
+ }
+ return format_string($this->name, true, $options);
+ }
+
/**
* Note: Will collect view data, if not already obtained.
* @return string Extra CSS classes to add to html output for this activity on main page
@@ -1017,6 +1079,8 @@ class cm_info extends stdClass {
$this->groupmode = isset($mod->groupmode) ? $mod->groupmode : 0;
$this->groupingid = isset($mod->groupingid) ? $mod->groupingid : 0;
$this->groupmembersonly = isset($mod->groupmembersonly) ? $mod->groupmembersonly : 0;
+ $this->coursegroupmodeforce = $course->groupmodeforce;
+ $this->coursegroupmode = $course->groupmode;
$this->indent = isset($mod->indent) ? $mod->indent : 0;
$this->extra = isset($mod->extra) ? $mod->extra : '';
$this->extraclasses = isset($mod->extraclasses) ? $mod->extraclasses : '';
diff --git a/lib/upgrade.txt b/lib/upgrade.txt
index 783300bc320..468691fad16 100644
--- a/lib/upgrade.txt
+++ b/lib/upgrade.txt
@@ -1,6 +1,13 @@
This files describes API changes in core lbraries and APIs,
information provided here is intended especially for developers.
+=== 2.5 ===
+
+* Functions responsible for output in course/lib.php are deprecated, the code is moved to
+ appropriate renderers: print_section_add_menus()
+ See functions' phpdocs in lib/deprecatedlib.php
+* Function get_print_section_cm_text() is deprecated, replaced with methods in cm_info
+
=== 2.4 ===
* Pagelib: Numerous deprecated functions were removed as classes page_base, page_course
diff --git a/theme/base/style/core.css b/theme/base/style/core.css
index 65f6a271949..f9bf057c1aa 100644
--- a/theme/base/style/core.css
+++ b/theme/base/style/core.css
@@ -55,6 +55,8 @@ a.dimmed_text:visited,
.block .list li,
.sitetopic .section li.activity,
.course-content .section li.activity,
+.sitetopic .section li.movehere,
+.course-content .section li.movehere,
.tabtree li {list-style: none;margin:0;padding:0;}
.course-content .current {background:#E3E3E3;}
diff --git a/theme/formal_white/style/course.css b/theme/formal_white/style/course.css
index 623149447a7..f4e6b6ae31f 100644
--- a/theme/formal_white/style/course.css
+++ b/theme/formal_white/style/course.css
@@ -30,6 +30,7 @@
.path-course-view .section .activity a {line-height:1em;}
.path-course-view .section .weekdates {margin:0;font-weight:normal;font-size:100%;}
.path-course-view .section .groupinglabel {color:#666666;}
+.path-course-view .section .groupinglabel.dimmed_text {color: #AAA;}
.path-course-view .section .left {font-weight:bold;}
.path-course-view .weeks .section,
diff --git a/theme/standard/style/course.css b/theme/standard/style/course.css
index c20c07a79bd..e09c032c603 100644
--- a/theme/standard/style/course.css
+++ b/theme/standard/style/course.css
@@ -27,6 +27,7 @@
.path-course-view .section {font-size:1em;line-height:1.2em;}
.path-course-view .section .weekdates {margin: 0;font-weight: normal;font-size: 1em;}
.path-course-view .section .groupinglabel {color: #666666;}
+.path-course-view .section .groupinglabel.dimmed_text {color: #AAA;}
.path-course-view .section .left {font-weight:bold;}
.path-course-view .weeks .section,