Skip to content

Commit

Permalink
Merge branch 'MDL-48947_v3' of https://github.com/Syxton/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
danpoltawski committed Sep 28, 2015
2 parents 5a06836 + 60cf074 commit ebadc15
Show file tree
Hide file tree
Showing 29 changed files with 512 additions and 126 deletions.
230 changes: 167 additions & 63 deletions course/format/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,46 @@ public function section_title($section, $course) {
return $title;
}

/**
* Generate the edit control action menu
*
* @param array $controls The edit control items from section_edit_control_items
* @param stdClass $course The course entry from DB
* @param stdClass $section The course_section entry from DB
* @return string HTML to output.
*/
protected function section_edit_control_menu($controls, $course, $section) {
$o = "";
if (!empty($controls)) {
$menu = new action_menu();
if ($section->section && get_string_manager()->string_exists('sectionmenu', 'format_'.$course->format)) {
$menu->set_menu_trigger(get_string('sectionmenu', 'format_'.$course->format));
} else {
$menu->set_menu_trigger(get_string('sectionmenu'));
}
$menu->attributes['class'] .= ' section-actions';
foreach ($controls as $value) {
$url = empty($value['url']) ? '' : $value['url'];
$icon = empty($value['icon']) ? '' : $value['icon'];
$name = empty($value['name']) ? '' : $value['name'];
$attr = empty($value['attr']) ? '' : $value['attr'];
$class = empty($item['pixattr']['class']) ? '' : $item['pixattr']['class'];
$alt = empty($item['pixattr']['alt']) ? '' : $item['pixattr']['alt'];
$al = new action_menu_link_secondary(
new moodle_url($url),
new pix_icon($icon, $name, null, array('class' => "smallicon " . $class, 'alt' => $alt)),
$name,
$attr
);
$menu->add($al);
}

$o .= html_writer::div($this->render($menu), 'section_action_menu');
}

return $o;
}

/**
* Generate the content to displayed on the right part of a section
* before course modules are included
Expand All @@ -98,12 +138,8 @@ public function section_title($section, $course) {
protected function section_right_content($section, $course, $onsectionpage) {
$o = $this->output->spacer();

if ($section->section != 0) {
$controls = $this->section_edit_controls($course, $section, $onsectionpage);
if (!empty($controls)) {
$o = implode('<br />', $controls);
}
}
$controls = $this->section_edit_control_items($course, $section, $onsectionpage);
$o .= $this->section_edit_control_menu($controls, $course, $section);

return $o;
}
Expand Down Expand Up @@ -160,6 +196,9 @@ protected function section_header($section, $course, $onsectionpage, $sectionret
'class' => 'section main clearfix'.$sectionstyle, 'role'=>'region',
'aria-label'=> get_section_name($course, $section)));

// Create a span that contains the section title to be used to create the keyboard section move menu.
$o .= html_writer::tag('span', $this->section_title($section, $course), array('class' => 'hidden sectionname'));

$leftcontent = $this->section_left_content($section, $course, $onsectionpage);
$o.= html_writer::tag('div', $leftcontent, array('class' => 'left side'));

Expand All @@ -181,17 +220,9 @@ protected function section_header($section, $course, $onsectionpage, $sectionret

$o.= html_writer::start_tag('div', array('class' => 'summary'));
$o.= $this->format_summary_text($section);

$context = context_course::instance($course->id);
if ($PAGE->user_is_editing() && has_capability('moodle/course:update', $context)) {
$url = new moodle_url('/course/editsection.php', array('id'=>$section->id, 'sr'=>$sectionreturn));
$o.= html_writer::link($url,
html_writer::empty_tag('img', array('src' => $this->output->pix_url('i/settings'),
'class' => 'iconsmall edit', 'alt' => get_string('edit'))),
array('title' => get_string('editsummary')));
}
$o.= html_writer::end_tag('div');

$context = context_course::instance($course->id);
$o .= $this->section_availability_message($section,
has_capability('moodle/course:viewhiddensections', $context));

Expand All @@ -217,6 +248,8 @@ protected function section_footer() {
* @param stdClass $section The course_section entry from DB
* @param bool $onsectionpage true if being printed on a section page
* @return array of links with edit controls
* @deprecated since Moodle 3.0 MDL-48947 - please do not use this function any more.
* @see format_section_renderer_base::section_edit_control_items()
*/
protected function section_edit_controls($course, $section, $onsectionpage = false) {
global $PAGE;
Expand All @@ -225,6 +258,45 @@ protected function section_edit_controls($course, $section, $onsectionpage = fal
return array();
}

$controls = array();
$items = $this->section_edit_control_items($course, $section, $onsectionpage);

foreach ($items as $key => $item) {
$url = empty($item['url']) ? '' : $item['url'];
$icon = empty($item['icon']) ? '' : $item['icon'];
$name = empty($item['name']) ? '' : $item['name'];
$attr = empty($item['attr']) ? '' : $item['attr'];
$class = empty($item['pixattr']['class']) ? '' : $item['pixattr']['class'];
$alt = empty($item['pixattr']['alt']) ? '' : $item['pixattr']['alt'];
$controls[$key] = html_writer::link(
new moodle_url($url),
html_writer::empty_tag('img', array(
'src' => $this->output->pix_url($icon),
'class' => "icon " . $class,
'alt' => $alt
)),
$attr);
}

debugging('section_edit_controls() is deprecated, please use section_edit_control_items() instead.', DEBUG_DEVELOPER);
return $controls;
}

/**
* Generate the edit control items of a section
*
* @param stdClass $course The course entry from DB
* @param stdClass $section The course_section entry from DB
* @param bool $onsectionpage true if being printed on a section page
* @return array of edit control items
*/
protected function section_edit_control_items($course, $section, $onsectionpage = false) {
global $PAGE;

if (!$PAGE->user_is_editing()) {
return array();
}

$coursecontext = context_course::instance($course->id);
$isstealth = isset($course->numsections) && ($section->section > $course->numsections);

Expand All @@ -237,62 +309,94 @@ protected function section_edit_controls($course, $section, $onsectionpage = fal

$controls = array();

$url = clone($baseurl);
if (!$isstealth && 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'));
if (!$isstealth && has_capability('moodle/course:update', $coursecontext)) {
if ($section->section > 0
&& get_string_manager()->string_exists('editsection', 'format_'.$course->format)) {
$streditsection = get_string('editsection', 'format_'.$course->format);
} 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'));
$streditsection = get_string('editsection');
}
}

if (course_can_delete_section($course, $section)) {
if (get_string_manager()->string_exists('deletesection', 'format_'.$course->format)) {
$strdelete = get_string('deletesection', 'format_'.$course->format);
} else {
$strdelete = get_string('deletesection');
}
$url = new moodle_url('/course/editsection.php', array('id' => $section->id,
'sr' => $onsectionpage ? $section->section : 0, 'delete' => 1));
$controls[] = html_writer::link($url,
html_writer::empty_tag('img', array('src' => $this->output->pix_url('t/delete'),
'class' => 'icon delete', 'alt' => $strdelete)),
array('title' => $strdelete));
$controls['edit'] = array(
'url' => new moodle_url('/course/editsection.php', array('id' => $section->id, 'sr' => $onsectionpage)),
'icon' => 'i/settings',
'name' => $streditsection,
'pixattr' => array('class' => '', 'alt' => $streditsection),
'attr' => array('class' => 'icon edit', 'title' => $streditsection));
}

if (!$isstealth && !$onsectionpage && has_capability('moodle/course:movesections', $coursecontext)) {
if ($section->section) {
$url = clone($baseurl);
if ($section->section > 1) { // Add a arrow to move section up.
$url->param('section', $section->section);
$url->param('move', -1);
$strmoveup = get_string('moveup');

$controls[] = html_writer::link($url,
html_writer::empty_tag('img', array('src' => $this->output->pix_url('i/up'),
'class' => 'icon up', 'alt' => $strmoveup)),
array('title' => $strmoveup, 'class' => 'moveup'));
if (!$isstealth) {
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['visiblity'] = array(
'url' => $url,
'icon' => 'i/hide',
'name' => $strhidefromothers,
'pixattr' => array('class' => '', 'alt' => $strhidefromothers),
'attr' => array('class' => 'icon editing_showhide', 'title' => $strhidefromothers));
} else {
$strshowfromothers = get_string('showfromothers', 'format_'.$course->format);
$url->param('show', $section->section);
$controls['visiblity'] = array(
'url' => $url,
'icon' => 'i/show',
'name' => $strshowfromothers,
'pixattr' => array('class' => '', 'alt' => $strshowfromothers),
'attr' => array('class' => 'icon editing_showhide', 'title' => $strshowfromothers));
}
}

if (!$onsectionpage) {
if (has_capability('moodle/course:movesections', $coursecontext)) {
$url = clone($baseurl);
if ($section->section > 1) { // Add a arrow to move section up.
$url->param('section', $section->section);
$url->param('move', -1);
$strmoveup = get_string('moveup');
$controls['moveup'] = array(
'url' => $url,
'icon' => 'i/up',
'name' => $strmoveup,
'pixattr' => array('class' => '', 'alt' => $strmoveup),
'attr' => array('class' => 'icon moveup', 'title' => $strmoveup));
}

$url = clone($baseurl);
if ($section->section < $course->numsections) { // Add a arrow to move section down.
$url->param('section', $section->section);
$url->param('move', 1);
$strmovedown = get_string('movedown');
$controls['movedown'] = array(
'url' => $url,
'icon' => 'i/down',
'name' => $strmovedown,
'pixattr' => array('class' => '', 'alt' => $strmovedown),
'attr' => array('class' => 'icon movedown', 'title' => $strmovedown));
}
}
}
}

$url = clone($baseurl);
if ($section->section < $course->numsections) { // Add a arrow to move section down.
$url->param('section', $section->section);
$url->param('move', 1);
$strmovedown = get_string('movedown');

$controls[] = html_writer::link($url,
html_writer::empty_tag('img', array('src' => $this->output->pix_url('i/down'),
'class' => 'icon down', 'alt' => $strmovedown)),
array('title' => $strmovedown, 'class' => 'movedown'));
if (course_can_delete_section($course, $section)) {
if (get_string_manager()->string_exists('deletesection', 'format_'.$course->format)) {
$strdelete = get_string('deletesection', 'format_'.$course->format);
} else {
$strdelete = get_string('deletesection');
}
$url = new moodle_url('/course/editsection.php', array(
'id' => $section->id,
'sr' => $onsectionpage ? $section->section : 0,
'delete' => 1));
$controls['delete'] = array(
'url' => $url,
'icon' => 'i/delete',
'name' => $strdelete,
'pixattr' => array('class' => '', 'alt' => $strdelete),
'attr' => array('class' => 'icon delete', 'title' => $strdelete));
}
}

Expand Down
2 changes: 1 addition & 1 deletion course/format/topics/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ M.course.format.process_sections = function(Y, sectionlist, response, sectionfro

for (var i = sectionfrom; i <= sectionto; i++) {
// Update section title.
sectionlist.item(i).one('.'+CSS.SECTIONNAME).setContent(response.sectiontitles[i]);
sectionlist.item(i).all('.'+CSS.SECTIONNAME).setContent(response.sectiontitles[i]);
// Update move icon.
ele = sectionlist.item(i).one(SELECTORS.SECTIONLEFTSIDE);
str = ele.getAttribute('alt');
Expand Down
2 changes: 2 additions & 0 deletions course/format/topics/lang/en/format_topics.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
*/

$string['currentsection'] = 'This topic';
$string['editsection'] = 'Edit topic';
$string['deletesection'] = 'Delete topic';
$string['sectionname'] = 'Topic';
$string['pluginname'] = 'Topics format';
$string['sectionmenu'] = 'Topic menu';
$string['section0name'] = 'General';
$string['page-course-view-topics'] = 'Any course main page in topics format';
$string['page-course-view-topics-x'] = 'Any course page in topics format';
Expand Down
30 changes: 17 additions & 13 deletions course/format/topics/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ protected function page_title() {
}

/**
* Generate the edit controls of a section
* Generate the edit control items of a section
*
* @param stdClass $course The course entry from DB
* @param stdClass $section The course_section entry from DB
* @param bool $onsectionpage true if being printed on a section page
* @return array of links with edit controls
* @return array of edit control items
*/
protected function section_edit_controls($course, $section, $onsectionpage = false) {
protected function section_edit_control_items($course, $section, $onsectionpage = false) {
global $PAGE;

if (!$PAGE->user_is_editing()) {
Expand All @@ -99,22 +99,26 @@ protected function section_edit_controls($course, $section, $onsectionpage = fal

$isstealth = $section->section > $course->numsections;
$controls = array();
if (!$isstealth && has_capability('moodle/course:setcurrentsection', $coursecontext)) {
if (!$isstealth && $section->section && 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'));
$markedthistopic = get_string('markedthistopic');
$highlightoff = get_string('highlightoff');
$controls[] = array("url" => $url, "icon" => 'i/marked',
"name" => $highlightoff,
'pixattr' => array('class' => '', 'alt' => $markedthistopic),
"attr" => array('class' => 'editing_highlight', 'title' => $markedthistopic));
} 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'));
$markthistopic = get_string('markthistopic');
$highlight = get_string('highlight');
$controls[] = array("url" => $url, "icon" => 'i/marker',
"name" => $highlight,
'pixattr' => array('class' => '', 'alt' => $markthistopic),
"attr" => array('class' => 'editing_highlight', 'title' => $markthistopic));
}
}

return array_merge($controls, parent::section_edit_controls($course, $section, $onsectionpage));
return array_merge($controls, parent::section_edit_control_items($course, $section, $onsectionpage));
}
}
Loading

0 comments on commit ebadc15

Please sign in to comment.