<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Contains the default section controls output class.
*
* @package format_topics
* @copyright 2020 Ferran Recio <ferran@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace format_topics\output\courseformat\content\section;
< use context_course;
use core_courseformat\output\local\content\section\controlmenu as controlmenu_base;
> use moodle_url;
/**
* Base class to render a course section menu.
*
* @package format_topics
* @copyright 2020 Ferran Recio <ferran@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class controlmenu extends controlmenu_base {
< /** @var course_format the course format class */
> /** @var \core_courseformat\base the course format class */
protected $format;
< /** @var section_info the course section class */
> /** @var \section_info the course section class */
protected $section;
/**
* Generate the edit control items of a section.
*
* This method must remain public until the final deprecation of section_edit_control_items.
*
* @return array of edit control items
*/
public function section_control_items() {
$format = $this->format;
$section = $this->section;
> $coursecontext = $format->get_context();
$course = $format->get_course();
>
$sectionreturn = $format->get_section_number();
> $controls = [];
> if ($section->section && has_capability('moodle/course:setcurrentsection', $coursecontext)) {
$coursecontext = context_course::instance($course->id);
> $controls['highlight'] = $this->get_highlight_control();
> }
if ($sectionreturn) {
>
$url = course_get_url($course, $section->section);
> $parentcontrols = parent::section_control_items();
} else {
>
$url = course_get_url($course);
> // If the edit key exists, we are going to insert our controls after it.
}
> if (array_key_exists("edit", $parentcontrols)) {
$url->param('sesskey', sesskey());
> $merged = [];
> // We can't use splice because we are using associative arrays.
$controls = [];
> // Step through the array and merge the arrays.
if ($section->section && has_capability('moodle/course:setcurrentsection', $coursecontext)) {
> foreach ($parentcontrols as $key => $action) {
if ($course->marker == $section->section) { // Show the "light globe" on/off.
> $merged[$key] = $action;
$url->param('marker', 0);
> if ($key == "edit") {
$highlightoff = get_string('highlightoff');
> // If we have come to the edit key, merge these controls here.
$controls['highlight'] = [
> $merged = array_merge($merged, $controls);
'url' => $url,
> }
'icon' => 'i/marked',
> }
'name' => $highlightoff,
>
'pixattr' => ['class' => ''],
> return $merged;
'attr' => [
> } else {
'class' => 'editing_highlight',
> return array_merge($controls, $parentcontrols);
'data-action' => 'removemarker'
> }
],
> }
];
>
} else {
> /**
$url->param('marker', $section->section);
> * Return the course url.
$highlight = get_string('highlight');
> *
$controls['highlight'] = [
> * @return moodle_url
'url' => $url,
> */
'icon' => 'i/marker',
> protected function get_course_url(): moodle_url {
'name' => $highlight,
> $format = $this->format;
'pixattr' => ['class' => ''],
> $section = $this->section;
< $coursecontext = context_course::instance($course->id);
<
'data-action' => 'setmarker'
> return $url;
],
> }
];
>
}
> /**
}
> * Return the specific section highlight action.
> *
$parentcontrols = parent::section_control_items();
> * @return array the action element.
> */
// If the edit key exists, we are going to insert our controls after it.
> protected function get_highlight_control(): array {
if (array_key_exists("edit", $parentcontrols)) {
> $format = $this->format;
$merged = [];
> $section = $this->section;
// We can't use splice because we are using associative arrays.
> $course = $format->get_course();
// Step through the array and merge the arrays.
> $url = $this->get_course_url();
foreach ($parentcontrols as $key => $action) {
>
$merged[$key] = $action;
> $highlightoff = get_string('highlightoff');
if ($key == "edit") {
> $highlighton = get_string('highlight');
< $controls = [];
< if ($section->section && has_capability('moodle/course:setcurrentsection', $coursecontext)) {
< $highlightoff = get_string('highlightoff');
< $controls['highlight'] = [
> $result = [
< 'data-action' => 'removemarker'
> 'data-action' => 'sectionUnhighlight',
> 'data-id' => $section->id,
> 'data-swapname' => $highlighton,
> 'data-swapicon' => 'i/marker',
< $highlight = get_string('highlight');
< $controls['highlight'] = [
> $result = [
< 'name' => $highlight,
> 'name' => $highlighton,
< 'data-action' => 'setmarker'
> 'data-action' => 'sectionHighlight',
> 'data-id' => $section->id,
> 'data-swapname' => $highlightoff,
> 'data-swapicon' => 'i/marked',
< }
<
< $parentcontrols = parent::section_control_items();
<
< // If the edit key exists, we are going to insert our controls after it.
< if (array_key_exists("edit", $parentcontrols)) {
< $merged = [];
< // We can't use splice because we are using associative arrays.
< // Step through the array and merge the arrays.
< foreach ($parentcontrols as $key => $action) {
< $merged[$key] = $action;
< if ($key == "edit") {
< // If we have come to the edit key, merge these controls here.
< $merged = array_merge($merged, $controls);
< }
< }
<
< return $merged;
< } else {
< return array_merge($controls, $parentcontrols);
< }
> return $result;