| 1 | 
           efrain | 
           1 | 
           <?php
  | 
        
        
            | 
            | 
           2 | 
           // This file is part of Moodle - http://moodle.org/
  | 
        
        
            | 
            | 
           3 | 
           //
  | 
        
        
            | 
            | 
           4 | 
           // Moodle is free software: you can redistribute it and/or modify
  | 
        
        
            | 
            | 
           5 | 
           // it under the terms of the GNU General Public License as published by
  | 
        
        
            | 
            | 
           6 | 
           // the Free Software Foundation, either version 3 of the License, or
  | 
        
        
            | 
            | 
           7 | 
           // (at your option) any later version.
  | 
        
        
            | 
            | 
           8 | 
           //
  | 
        
        
            | 
            | 
           9 | 
           // Moodle is distributed in the hope that it will be useful,
  | 
        
        
            | 
            | 
           10 | 
           // but WITHOUT ANY WARRANTY; without even the implied warranty of
  | 
        
        
            | 
            | 
           11 | 
           // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  | 
        
        
            | 
            | 
           12 | 
           // GNU General Public License for more details.
  | 
        
        
            | 
            | 
           13 | 
           //
  | 
        
        
            | 
            | 
           14 | 
           // You should have received a copy of the GNU General Public License
  | 
        
        
            | 
            | 
           15 | 
           // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  | 
        
        
            | 
            | 
           16 | 
              | 
        
        
            | 
            | 
           17 | 
           /**
  | 
        
        
            | 
            | 
           18 | 
            * Contains the default section controls output class.
  | 
        
        
            | 
            | 
           19 | 
            *
  | 
        
        
            | 
            | 
           20 | 
            * @package   format_topics
  | 
        
        
            | 
            | 
           21 | 
            * @copyright 2020 Ferran Recio <ferran@moodle.com>
  | 
        
        
            | 
            | 
           22 | 
            * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  | 
        
        
            | 
            | 
           23 | 
            */
  | 
        
        
            | 
            | 
           24 | 
              | 
        
        
            | 
            | 
           25 | 
           namespace format_topics\output\courseformat\content\section;
  | 
        
        
            | 
            | 
           26 | 
              | 
        
        
           | 1441 | 
           ariadna | 
           27 | 
           use core\output\action_menu\link as action_menu_link;
  | 
        
        
            | 
            | 
           28 | 
           use core\output\action_menu\link_secondary as action_menu_link_secondary;
  | 
        
        
            | 
            | 
           29 | 
           use core\output\pix_icon;
  | 
        
        
           | 1 | 
           efrain | 
           30 | 
           use core_courseformat\output\local\content\section\controlmenu as controlmenu_base;
  | 
        
        
           | 1441 | 
           ariadna | 
           31 | 
           use core\url;
  | 
        
        
           | 1 | 
           efrain | 
           32 | 
              | 
        
        
            | 
            | 
           33 | 
           /**
  | 
        
        
            | 
            | 
           34 | 
            * Base class to render a course section menu.
  | 
        
        
            | 
            | 
           35 | 
            *
  | 
        
        
            | 
            | 
           36 | 
            * @package   format_topics
  | 
        
        
            | 
            | 
           37 | 
            * @copyright 2020 Ferran Recio <ferran@moodle.com>
  | 
        
        
            | 
            | 
           38 | 
            * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  | 
        
        
            | 
            | 
           39 | 
            */
  | 
        
        
            | 
            | 
           40 | 
           class controlmenu extends controlmenu_base {
  | 
        
        
            | 
            | 
           41 | 
              | 
        
        
            | 
            | 
           42 | 
               /** @var \core_courseformat\base the course format class */
  | 
        
        
            | 
            | 
           43 | 
               protected $format;
  | 
        
        
            | 
            | 
           44 | 
              | 
        
        
            | 
            | 
           45 | 
               /** @var \section_info the course section class */
  | 
        
        
            | 
            | 
           46 | 
               protected $section;
  | 
        
        
            | 
            | 
           47 | 
              | 
        
        
            | 
            | 
           48 | 
               /**
  | 
        
        
            | 
            | 
           49 | 
                * Generate the edit control items of a section.
  | 
        
        
            | 
            | 
           50 | 
                *
  | 
        
        
            | 
            | 
           51 | 
                * This method must remain public until the final deprecation of section_edit_control_items.
  | 
        
        
            | 
            | 
           52 | 
                *
  | 
        
        
            | 
            | 
           53 | 
                * @return array of edit control items
  | 
        
        
            | 
            | 
           54 | 
                */
  | 
        
        
            | 
            | 
           55 | 
               public function section_control_items() {
  | 
        
        
            | 
            | 
           56 | 
                   $section = $this->section;
  | 
        
        
           | 1441 | 
           ariadna | 
           57 | 
                   $parentcontrols = parent::section_control_items();
  | 
        
        
           | 1 | 
           efrain | 
           58 | 
              | 
        
        
           | 1441 | 
           ariadna | 
           59 | 
                   if ($section->is_orphan() || !$section->sectionnum) {
  | 
        
        
            | 
            | 
           60 | 
                       return $parentcontrols;
  | 
        
        
           | 1 | 
           efrain | 
           61 | 
                   }
  | 
        
        
            | 
            | 
           62 | 
              | 
        
        
           | 1441 | 
           ariadna | 
           63 | 
                   if (!has_capability('moodle/course:setcurrentsection', $this->coursecontext)) {
  | 
        
        
            | 
            | 
           64 | 
                       return $parentcontrols;
  | 
        
        
            | 
            | 
           65 | 
                   }
  | 
        
        
           | 1 | 
           efrain | 
           66 | 
              | 
        
        
           | 1441 | 
           ariadna | 
           67 | 
                   return $this->add_control_after($parentcontrols, 'edit', 'highlight', $this->get_section_highlight_item());
  | 
        
        
           | 1 | 
           efrain | 
           68 | 
               }
  | 
        
        
            | 
            | 
           69 | 
              | 
        
        
            | 
            | 
           70 | 
               /**
  | 
        
        
            | 
            | 
           71 | 
                * Return the course url.
  | 
        
        
            | 
            | 
           72 | 
                *
  | 
        
        
           | 1441 | 
           ariadna | 
           73 | 
                * @return url
  | 
        
        
           | 1 | 
           efrain | 
           74 | 
                */
  | 
        
        
           | 1441 | 
           ariadna | 
           75 | 
               #[\core\attribute\deprecated(
  | 
        
        
            | 
            | 
           76 | 
                   since: '5.0',
  | 
        
        
            | 
            | 
           77 | 
                   mdl: 'MDL-82767',
  | 
        
        
            | 
            | 
           78 | 
                   reason: 'Not used anymore, use $this->format->get_update_url instead',
  | 
        
        
            | 
            | 
           79 | 
               )]
  | 
        
        
            | 
            | 
           80 | 
               protected function get_course_url(): url {
  | 
        
        
            | 
            | 
           81 | 
                   \core\deprecation::emit_deprecation([self::class, __FUNCTION__]);
  | 
        
        
           | 1 | 
           efrain | 
           82 | 
                   $format = $this->format;
  | 
        
        
            | 
            | 
           83 | 
                   $section = $this->section;
  | 
        
        
            | 
            | 
           84 | 
                   $course = $format->get_course();
  | 
        
        
            | 
            | 
           85 | 
                   $sectionreturn = $format->get_sectionnum();
  | 
        
        
            | 
            | 
           86 | 
              | 
        
        
            | 
            | 
           87 | 
                   if ($sectionreturn) {
  | 
        
        
           | 1441 | 
           ariadna | 
           88 | 
                       $url = course_get_url($course, $section->sectionnum);
  | 
        
        
           | 1 | 
           efrain | 
           89 | 
                   } else {
  | 
        
        
            | 
            | 
           90 | 
                       $url = course_get_url($course);
  | 
        
        
            | 
            | 
           91 | 
                   }
  | 
        
        
            | 
            | 
           92 | 
                   $url->param('sesskey', sesskey());
  | 
        
        
            | 
            | 
           93 | 
                   return $url;
  | 
        
        
            | 
            | 
           94 | 
               }
  | 
        
        
            | 
            | 
           95 | 
              | 
        
        
            | 
            | 
           96 | 
               /**
  | 
        
        
           | 1441 | 
           ariadna | 
           97 | 
                * Retrieves the view item for the section control menu.
  | 
        
        
            | 
            | 
           98 | 
                *
  | 
        
        
            | 
            | 
           99 | 
                * @return action_menu_link|null The menu item if applicable, otherwise null.
  | 
        
        
            | 
            | 
           100 | 
                */
  | 
        
        
            | 
            | 
           101 | 
               protected function get_section_highlight_item(): action_menu_link_secondary {
  | 
        
        
            | 
            | 
           102 | 
                   $format = $this->format;
  | 
        
        
            | 
            | 
           103 | 
                   $section = $this->section;
  | 
        
        
            | 
            | 
           104 | 
                   $course = $format->get_course();
  | 
        
        
            | 
            | 
           105 | 
                   $sectionreturn = $format->get_sectionnum();
  | 
        
        
            | 
            | 
           106 | 
              | 
        
        
            | 
            | 
           107 | 
                   $highlightoff = get_string('highlightoff');
  | 
        
        
            | 
            | 
           108 | 
                   $highlightofficon = 'i/marked';
  | 
        
        
            | 
            | 
           109 | 
              | 
        
        
            | 
            | 
           110 | 
                   $highlighton = get_string('highlight');
  | 
        
        
            | 
            | 
           111 | 
                   $highlightonicon = 'i/marker';
  | 
        
        
            | 
            | 
           112 | 
              | 
        
        
            | 
            | 
           113 | 
                   if ($course->marker == $section->sectionnum) {  // Show the "light globe" on/off.
  | 
        
        
            | 
            | 
           114 | 
                       $action = 'section_unhighlight';
  | 
        
        
            | 
            | 
           115 | 
                       $icon = $highlightofficon;
  | 
        
        
            | 
            | 
           116 | 
                       $name = $highlightoff;
  | 
        
        
            | 
            | 
           117 | 
                       $attributes = [
  | 
        
        
            | 
            | 
           118 | 
                           'class' => 'editing_highlight',
  | 
        
        
            | 
            | 
           119 | 
                           'data-action' => 'sectionUnhighlight',
  | 
        
        
            | 
            | 
           120 | 
                           'data-sectionreturn' => $sectionreturn,
  | 
        
        
            | 
            | 
           121 | 
                           'data-id' => $section->id,
  | 
        
        
            | 
            | 
           122 | 
                           'data-icon' => $highlightofficon,
  | 
        
        
            | 
            | 
           123 | 
                           'data-swapname' => $highlighton,
  | 
        
        
            | 
            | 
           124 | 
                           'data-swapicon' => $highlightonicon,
  | 
        
        
            | 
            | 
           125 | 
                       ];
  | 
        
        
            | 
            | 
           126 | 
                   } else {
  | 
        
        
            | 
            | 
           127 | 
                       $action = 'section_highlight';
  | 
        
        
            | 
            | 
           128 | 
                       $icon = $highlightonicon;
  | 
        
        
            | 
            | 
           129 | 
                       $name = $highlighton;
  | 
        
        
            | 
            | 
           130 | 
                       $attributes = [
  | 
        
        
            | 
            | 
           131 | 
                           'class' => 'editing_highlight',
  | 
        
        
            | 
            | 
           132 | 
                           'data-action' => 'sectionHighlight',
  | 
        
        
            | 
            | 
           133 | 
                           'data-sectionreturn' => $sectionreturn,
  | 
        
        
            | 
            | 
           134 | 
                           'data-id' => $section->id,
  | 
        
        
            | 
            | 
           135 | 
                           'data-icon' => $highlightonicon,
  | 
        
        
            | 
            | 
           136 | 
                           'data-swapname' => $highlightoff,
  | 
        
        
            | 
            | 
           137 | 
                           'data-swapicon' => $highlightofficon,
  | 
        
        
            | 
            | 
           138 | 
                       ];
  | 
        
        
            | 
            | 
           139 | 
                   }
  | 
        
        
            | 
            | 
           140 | 
              | 
        
        
            | 
            | 
           141 | 
                   $url = $this->format->get_update_url(
  | 
        
        
            | 
            | 
           142 | 
                       action: $action,
  | 
        
        
            | 
            | 
           143 | 
                       ids: [$section->id],
  | 
        
        
            | 
            | 
           144 | 
                       returnurl: $this->baseurl,
  | 
        
        
            | 
            | 
           145 | 
                   );
  | 
        
        
            | 
            | 
           146 | 
              | 
        
        
            | 
            | 
           147 | 
                   return new action_menu_link_secondary(
  | 
        
        
            | 
            | 
           148 | 
                           url: $url,
  | 
        
        
            | 
            | 
           149 | 
                           icon: new pix_icon($icon, ''),
  | 
        
        
            | 
            | 
           150 | 
                           text: $name,
  | 
        
        
            | 
            | 
           151 | 
                           attributes: $attributes,
  | 
        
        
            | 
            | 
           152 | 
                   );
  | 
        
        
            | 
            | 
           153 | 
               }
  | 
        
        
            | 
            | 
           154 | 
              | 
        
        
            | 
            | 
           155 | 
               /**
  | 
        
        
           | 1 | 
           efrain | 
           156 | 
                * Return the specific section highlight action.
  | 
        
        
            | 
            | 
           157 | 
                *
  | 
        
        
           | 1441 | 
           ariadna | 
           158 | 
                * @deprecated since Moodle 5.0
  | 
        
        
            | 
            | 
           159 | 
                * @todo Remove this method in Moodle 6.0 (MDL-83530).
  | 
        
        
           | 1 | 
           efrain | 
           160 | 
                * @return array the action element.
  | 
        
        
            | 
            | 
           161 | 
                */
  | 
        
        
           | 1441 | 
           ariadna | 
           162 | 
               #[\core\attribute\deprecated(
  | 
        
        
            | 
            | 
           163 | 
                   replacement: 'get_section_highlight_item',
  | 
        
        
            | 
            | 
           164 | 
                   since: '5.0',
  | 
        
        
            | 
            | 
           165 | 
                   mdl: 'MDL-83527',
  | 
        
        
            | 
            | 
           166 | 
                   reason: 'Wrong return type',
  | 
        
        
            | 
            | 
           167 | 
               )]
  | 
        
        
           | 1 | 
           efrain | 
           168 | 
               protected function get_highlight_control(): array {
  | 
        
        
           | 1441 | 
           ariadna | 
           169 | 
                   \core\deprecation::emit_deprecation([self::class, __FUNCTION__]);
  | 
        
        
           | 1 | 
           efrain | 
           170 | 
                   $format = $this->format;
  | 
        
        
            | 
            | 
           171 | 
                   $section = $this->section;
  | 
        
        
            | 
            | 
           172 | 
                   $course = $format->get_course();
  | 
        
        
            | 
            | 
           173 | 
                   $sectionreturn = $format->get_sectionnum();
  | 
        
        
            | 
            | 
           174 | 
                   $url = $this->get_course_url();
  | 
        
        
            | 
            | 
           175 | 
                   if (!is_null($sectionreturn)) {
  | 
        
        
            | 
            | 
           176 | 
                       $url->param('sectionid', $format->get_sectionid());
  | 
        
        
            | 
            | 
           177 | 
                   }
  | 
        
        
            | 
            | 
           178 | 
              | 
        
        
            | 
            | 
           179 | 
                   $highlightoff = get_string('highlightoff');
  | 
        
        
           | 11 | 
           efrain | 
           180 | 
                   $highlightofficon = 'i/marked';
  | 
        
        
            | 
            | 
           181 | 
              | 
        
        
           | 1 | 
           efrain | 
           182 | 
                   $highlighton = get_string('highlight');
  | 
        
        
           | 11 | 
           efrain | 
           183 | 
                   $highlightonicon = 'i/marker';
  | 
        
        
           | 1 | 
           efrain | 
           184 | 
              | 
        
        
            | 
            | 
           185 | 
                   if ($course->marker == $section->section) {  // Show the "light globe" on/off.
  | 
        
        
            | 
            | 
           186 | 
                       $url->param('marker', 0);
  | 
        
        
            | 
            | 
           187 | 
                       $result = [
  | 
        
        
            | 
            | 
           188 | 
                           'url' => $url,
  | 
        
        
           | 11 | 
           efrain | 
           189 | 
                           'icon' => $highlightofficon,
  | 
        
        
           | 1 | 
           efrain | 
           190 | 
                           'name' => $highlightoff,
  | 
        
        
            | 
            | 
           191 | 
                           'pixattr' => ['class' => ''],
  | 
        
        
            | 
            | 
           192 | 
                           'attr' => [
  | 
        
        
            | 
            | 
           193 | 
                               'class' => 'editing_highlight',
  | 
        
        
            | 
            | 
           194 | 
                               'data-action' => 'sectionUnhighlight',
  | 
        
        
            | 
            | 
           195 | 
                               'data-sectionreturn' => $sectionreturn,
  | 
        
        
            | 
            | 
           196 | 
                               'data-id' => $section->id,
  | 
        
        
           | 11 | 
           efrain | 
           197 | 
                               'data-icon' => $highlightofficon,
  | 
        
        
           | 1 | 
           efrain | 
           198 | 
                               'data-swapname' => $highlighton,
  | 
        
        
           | 11 | 
           efrain | 
           199 | 
                               'data-swapicon' => $highlightonicon,
  | 
        
        
           | 1 | 
           efrain | 
           200 | 
                           ],
  | 
        
        
            | 
            | 
           201 | 
                       ];
  | 
        
        
            | 
            | 
           202 | 
                   } else {
  | 
        
        
            | 
            | 
           203 | 
                       $url->param('marker', $section->section);
  | 
        
        
            | 
            | 
           204 | 
                       $result = [
  | 
        
        
            | 
            | 
           205 | 
                           'url' => $url,
  | 
        
        
           | 11 | 
           efrain | 
           206 | 
                           'icon' => $highlightonicon,
  | 
        
        
           | 1 | 
           efrain | 
           207 | 
                           'name' => $highlighton,
  | 
        
        
            | 
            | 
           208 | 
                           'pixattr' => ['class' => ''],
  | 
        
        
            | 
            | 
           209 | 
                           'attr' => [
  | 
        
        
            | 
            | 
           210 | 
                               'class' => 'editing_highlight',
  | 
        
        
            | 
            | 
           211 | 
                               'data-action' => 'sectionHighlight',
  | 
        
        
            | 
            | 
           212 | 
                               'data-sectionreturn' => $sectionreturn,
  | 
        
        
            | 
            | 
           213 | 
                               'data-id' => $section->id,
  | 
        
        
           | 11 | 
           efrain | 
           214 | 
                               'data-icon' => $highlightonicon,
  | 
        
        
           | 1 | 
           efrain | 
           215 | 
                               'data-swapname' => $highlightoff,
  | 
        
        
           | 11 | 
           efrain | 
           216 | 
                               'data-swapicon' => $highlightofficon,
  | 
        
        
           | 1 | 
           efrain | 
           217 | 
                           ],
  | 
        
        
            | 
            | 
           218 | 
                       ];
  | 
        
        
            | 
            | 
           219 | 
                   }
  | 
        
        
            | 
            | 
           220 | 
                   return $result;
  | 
        
        
            | 
            | 
           221 | 
               }
  | 
        
        
            | 
            | 
           222 | 
           }
  |