MDL-28207 Course: Showing/hiding/marking a section respect capabilities
This commit is contained in:
+18
-18
@@ -205,9 +205,7 @@ abstract class format_section_renderer_base extends plugin_renderer_base {
|
||||
return array();
|
||||
}
|
||||
|
||||
if (!has_capability('moodle/course:update', context_course::instance($course->id))) {
|
||||
return array();
|
||||
}
|
||||
$coursecontext = context_course::instance($course->id);
|
||||
|
||||
if ($onsectionpage) {
|
||||
$baseurl = course_get_url($course, $section->section);
|
||||
@@ -219,23 +217,25 @@ abstract class format_section_renderer_base extends plugin_renderer_base {
|
||||
$controls = array();
|
||||
|
||||
$url = clone($baseurl);
|
||||
if ($section->visible) { // Show the hide/show eye.
|
||||
$strhidefromothers = get_string('hidefromothers', 'format_'.$course->format);
|
||||
$url->param('hide', $section->section);
|
||||
$controls[] = html_writer::link($url,
|
||||
html_writer::empty_tag('img', array('src' => $this->output->pix_url('i/hide'),
|
||||
'class' => 'icon hide', 'alt' => $strhidefromothers)),
|
||||
array('title' => $strhidefromothers, 'class' => 'editing_showhide'));
|
||||
} else {
|
||||
$strshowfromothers = get_string('showfromothers', 'format_'.$course->format);
|
||||
$url->param('show', $section->section);
|
||||
$controls[] = html_writer::link($url,
|
||||
html_writer::empty_tag('img', array('src' => $this->output->pix_url('i/show'),
|
||||
'class' => 'icon hide', 'alt' => $strshowfromothers)),
|
||||
array('title' => $strshowfromothers, 'class' => 'editing_showhide'));
|
||||
if (has_capability('moodle/course:sectionvisibility', $coursecontext)) {
|
||||
if ($section->visible) { // Show the hide/show eye.
|
||||
$strhidefromothers = get_string('hidefromothers', 'format_'.$course->format);
|
||||
$url->param('hide', $section->section);
|
||||
$controls[] = html_writer::link($url,
|
||||
html_writer::empty_tag('img', array('src' => $this->output->pix_url('i/hide'),
|
||||
'class' => 'icon hide', 'alt' => $strhidefromothers)),
|
||||
array('title' => $strhidefromothers, 'class' => 'editing_showhide'));
|
||||
} else {
|
||||
$strshowfromothers = get_string('showfromothers', 'format_'.$course->format);
|
||||
$url->param('show', $section->section);
|
||||
$controls[] = html_writer::link($url,
|
||||
html_writer::empty_tag('img', array('src' => $this->output->pix_url('i/show'),
|
||||
'class' => 'icon hide', 'alt' => $strshowfromothers)),
|
||||
array('title' => $strshowfromothers, 'class' => 'editing_showhide'));
|
||||
}
|
||||
}
|
||||
|
||||
if (!$onsectionpage) {
|
||||
if (!$onsectionpage && has_capability('moodle/course:update', $coursecontext)) {
|
||||
$url = clone($baseurl);
|
||||
if ($section->section > 1) { // Add a arrow to move section up.
|
||||
$url->param('section', $section->section);
|
||||
|
||||
@@ -74,9 +74,7 @@ class format_topics_renderer extends format_section_renderer_base {
|
||||
return array();
|
||||
}
|
||||
|
||||
if (!has_capability('moodle/course:update', context_course::instance($course->id))) {
|
||||
return array();
|
||||
}
|
||||
$coursecontext = context_course::instance($course->id);
|
||||
|
||||
if ($onsectionpage) {
|
||||
$url = course_get_url($course, $section->section);
|
||||
@@ -86,18 +84,20 @@ class format_topics_renderer extends format_section_renderer_base {
|
||||
$url->param('sesskey', sesskey());
|
||||
|
||||
$controls = array();
|
||||
if ($course->marker == $section->section) { // Show the "light globe" on/off.
|
||||
$url->param('marker', 0);
|
||||
$controls[] = html_writer::link($url,
|
||||
html_writer::empty_tag('img', array('src' => $this->output->pix_url('i/marked'),
|
||||
'class' => 'icon ', 'alt' => get_string('markedthistopic'))),
|
||||
array('title' => get_string('markedthistopic'), 'class' => 'editing_highlight'));
|
||||
} else {
|
||||
$url->param('marker', $section->section);
|
||||
$controls[] = html_writer::link($url,
|
||||
html_writer::empty_tag('img', array('src' => $this->output->pix_url('i/marker'),
|
||||
'class' => 'icon', 'alt' => get_string('markthistopic'))),
|
||||
array('title' => get_string('markthistopic'), 'class' => 'editing_highlight'));
|
||||
if (has_capability('moodle/course:setcurrentsection', $coursecontext)) {
|
||||
if ($course->marker == $section->section) { // Show the "light globe" on/off.
|
||||
$url->param('marker', 0);
|
||||
$controls[] = html_writer::link($url,
|
||||
html_writer::empty_tag('img', array('src' => $this->output->pix_url('i/marked'),
|
||||
'class' => 'icon ', 'alt' => get_string('markedthistopic'))),
|
||||
array('title' => get_string('markedthistopic'), 'class' => 'editing_highlight'));
|
||||
} else {
|
||||
$url->param('marker', $section->section);
|
||||
$controls[] = html_writer::link($url,
|
||||
html_writer::empty_tag('img', array('src' => $this->output->pix_url('i/marker'),
|
||||
'class' => 'icon', 'alt' => get_string('markthistopic'))),
|
||||
array('title' => get_string('markthistopic'), 'class' => 'editing_highlight'));
|
||||
}
|
||||
}
|
||||
|
||||
return array_merge($controls, parent::section_edit_controls($course, $section, $onsectionpage));
|
||||
|
||||
+3
-2
@@ -75,7 +75,6 @@ switch($requestmethod) {
|
||||
|
||||
switch ($class) {
|
||||
case 'section':
|
||||
require_capability('moodle/course:update', $coursecontext);
|
||||
|
||||
if (!$DB->record_exists('course_sections', array('course'=>$course->id, 'section'=>$id))) {
|
||||
throw new moodle_exception('AJAX commands.php: Bad Section ID '.$id);
|
||||
@@ -83,11 +82,13 @@ switch($requestmethod) {
|
||||
|
||||
switch ($field) {
|
||||
case 'visible':
|
||||
require_capability('moodle/course:sectionvisibility', $coursecontext);
|
||||
$resourcestotoggle = set_section_visible($course->id, $id, $value);
|
||||
echo json_encode(array('resourcestotoggle' => $resourcestotoggle));
|
||||
break;
|
||||
|
||||
case 'move':
|
||||
require_capability('moodle/course:update', $coursecontext);
|
||||
move_section_to($course, $id, $value);
|
||||
// See if format wants to do something about it
|
||||
$libfile = $CFG->dirroot.'/course/format/'.$course->format.'/lib.php';
|
||||
@@ -178,7 +179,7 @@ switch($requestmethod) {
|
||||
case 'course':
|
||||
switch($field) {
|
||||
case 'marker':
|
||||
require_capability('moodle/course:update', $coursecontext);
|
||||
require_capability('moodle/course:setcurrentsection', $coursecontext);
|
||||
course_set_marker($course->id, $value);
|
||||
break;
|
||||
}
|
||||
|
||||
+3
-1
@@ -162,7 +162,7 @@
|
||||
set_user_preference('usemodchooser', $modchooser);
|
||||
}
|
||||
|
||||
if (has_capability('moodle/course:update', $context)) {
|
||||
if (has_capability('moodle/course:sectionvisibility', $context)) {
|
||||
if ($hide && confirm_sesskey()) {
|
||||
set_section_visible($course->id, $hide, '0');
|
||||
redirect($PAGE->url);
|
||||
@@ -172,7 +172,9 @@
|
||||
set_section_visible($course->id, $show, '1');
|
||||
redirect($PAGE->url);
|
||||
}
|
||||
}
|
||||
|
||||
if (has_capability('moodle/course:update', $context)) {
|
||||
if (!empty($section)) {
|
||||
if (!empty($move) and confirm_sesskey()) {
|
||||
$destsection = $section + $move;
|
||||
|
||||
Reference in New Issue
Block a user