MDL-78291 core_courseformat: availability in activity action menu

This commit is contained in:
Ferran Recio
2023-08-22 09:39:13 +02:00
parent e998f14061
commit ee2e084e89
7 changed files with 38 additions and 83 deletions
@@ -153,7 +153,7 @@ class visibility implements named_templatable, renderable {
* Get the availability choice list.
* @return choicelist
*/
protected function get_choice_list(): choicelist {
public function get_choice_list(): choicelist {
$choice = $this->create_choice_list();
if (!$this->mod->visible) {
$selected = 'hide';
@@ -174,11 +174,14 @@ class visibility implements named_templatable, renderable {
global $CFG;
$choice = new choicelist();
$choice->add_option(
'show',
get_string('availability_show', 'core_courseformat'),
$this->get_option_data('show', 'cmShow')
);
if ($this->section->visible || $this->mod->has_view()) {
$label = $this->section->visible ? 'show' : 'stealth';
$choice->add_option(
'show',
get_string("availability_{$label}", 'core_courseformat'),
$this->get_option_data($label, 'cmShow')
);
}
$choice->add_option(
'hide',
get_string('availability_hide', 'core_courseformat'),
@@ -64,7 +64,7 @@
}
}}
{{#isInteractive}}
<div class="activity-badges my-1">
<div class="activity-badges my-1" data-region="visibility">
{{#dropwdown}}
{{< core/local/dropdown/status}}
{{$ buttonclasses }} badge badge-pill badge-secondary dropdown-toggle border-0 {{/ buttonclasses }}
@@ -74,12 +74,12 @@
{{/isInteractive}}
{{^isInteractive}}
{{#modhiddenfromstudents}}
<div class="activity-badges my-1 d-flex align-self-start align-items-center">
<div class="activity-badges my-1 d-flex align-self-start align-items-center" data-region="visibility">
<span class="badge badge-pill badge-secondary">{{#pix}}i/show, core{{/pix}}{{#str}}hiddenfromstudents{{/str}}</span>
</div>
{{/modhiddenfromstudents}}
{{#modstealth}}
<div class="activity-badges my-1 d-flex align-self-start align-items-center">
<div class="activity-badges my-1 d-flex align-self-start align-items-center" data-region="visibility">
<span class="badge badge-pill badge-secondary">{{#pix}}t/stealth, core{{/pix}}{{#str}}hiddenoncoursepage{{/str}}</span>
</div>
{{/modstealth}}
+2
View File
@@ -45,6 +45,8 @@ Some considerations about the activitybadge feature:
* New core_courseformat\base::get_format_string() to get strings that can be overridden by the format plugin.
The method will check first the string in the format_PLUGINNAME.php lang file and, if not, it will return the
core_courseformat string instead.
* New course format output classes:
- core_courseformat\output\local\content\cm\visibility to display the activity availability.
=== 4.1 ===
* New \core_courseformat\stateupdates methods add_section_remove() and add_cm_remove() have been added to replace
+12 -72
View File
@@ -1661,8 +1661,8 @@ function course_get_cm_edit_actions(cm_info $mod, $indent = -1, $sr = null) {
if (!isset($str)) {
$str = get_strings(
[
'delete', 'move', 'moveright', 'moveleft', 'editsettings', 'duplicate', 'modhide',
'makeavailable', 'makeunavailable', 'modshow', 'modshowcmtitle', 'makeavailablecmtitle',
'delete', 'move', 'moveright', 'moveleft', 'editsettings',
'duplicate', 'availability'
],
'moodle'
);
@@ -1759,76 +1759,16 @@ function course_get_cm_edit_actions(cm_info $mod, $indent = -1, $sr = null) {
// Hide/Show/Available/Unavailable.
if (has_capability('moodle/course:activityvisibility', $modcontext)) {
$allowstealth = !empty($CFG->allowstealth) && $courseformat->allow_stealth_module_visibility($mod, $sectioninfo);
$sectionvisible = $sectioninfo->visible;
// The module on the course page may be in one of the following states:
// - Available and displayed on the course page ($displayedoncoursepage);
// - Not available and not displayed on the course page ($unavailable);
// - Available but not displayed on the course page ($stealth) - this can also be a visible activity in a hidden section.
$displayedoncoursepage = $mod->visible && $mod->visibleoncoursepage && $sectionvisible;
$unavailable = !$mod->visible;
$stealth = $mod->visible && (!$mod->visibleoncoursepage || !$sectionvisible);
if ($displayedoncoursepage) {
$actions['hide'] = new action_menu_link_secondary(
new moodle_url($baseurl, array('hide' => $mod->id)),
new pix_icon('t/hide', '', 'moodle', array('class' => 'iconsmall')),
$str->modhide,
[
'class' => 'editing_hide',
'data-action' => ($usecomponents) ? 'cmHide' : 'hide',
'data-id' => $mod->id,
]
);
} else if (!$displayedoncoursepage && $sectionvisible) {
// Offer to "show" only if the section is visible.
$actions['show'] = new action_menu_link_secondary(
new moodle_url($baseurl, array('show' => $mod->id)),
new pix_icon('t/show', '', 'moodle', array('class' => 'iconsmall')),
$str->modshow,
[
'class' => 'editing_show',
'data-action' => ($usecomponents) ? 'cmShow' : 'show',
'data-id' => $mod->id,
// Title is needed mostly for behat tests. Otherwise it will follow any link with "show".
'title' => $str->modshowcmtitle,
]
);
}
if ($stealth) {
// When making the "stealth" module unavailable we perform the same action as hiding the visible module.
$actions['hide'] = new action_menu_link_secondary(
new moodle_url($baseurl, array('hide' => $mod->id)),
new pix_icon('t/unblock', '', 'moodle', array('class' => 'iconsmall')),
$str->makeunavailable,
[
'class' => 'editing_makeunavailable',
'data-action' => ($usecomponents) ? 'cmHide' : 'hide',
'data-sectionreturn' => $sr,
'data-id' => $mod->id,
]
);
} else if ($unavailable && (!$sectionvisible || $allowstealth) && $mod->has_view()) {
// Allow to make visually hidden module available in gradebook and other reports by making it a "stealth" module.
// When the section is hidden it is an equivalent of "showing" the module.
// Activities without the link (i.e. labels) can not be made available but hidden on course page.
$action = $sectionvisible ? 'stealth' : 'show';
if ($usecomponents) {
$action = 'cm' . ucfirst($action);
}
$actions[$action] = new action_menu_link_secondary(
new moodle_url($baseurl, array('stealth' => $mod->id)),
new pix_icon('t/block', '', 'moodle', array('class' => 'iconsmall')),
$str->makeavailable,
[
'class' => 'editing_makeavailable',
'data-action' => $action,
'data-sectionreturn' => $sr,
'data-id' => $mod->id,
// Title is needed mostly for behat tests. Otherwise it will follow any link with "make available".
'title' => $str->makeavailablecmtitle,
]
$availabilityclass = $courseformat->get_output_classname('content\\cm\\visibility');
/** @var core_courseformat\output\local\content\cm\visibility */
$availability = new $availabilityclass($courseformat, $sectioninfo, $mod);
$availabilitychoice = $availability->get_choice_list();
if ($availabilitychoice->count_options() > 1) {
$actions['availability'] = new action_menu_subpanel(
$str->availability,
$availabilitychoice,
['class' => 'editing_availability'],
new pix_icon('t/hide', '', 'moodle', array('class' => 'iconsmall'))
);
}
}
+2
View File
@@ -84,3 +84,5 @@ backpackemail,core_badges
backpackemail_help,core_badges
editcoursecompletionsettings,core_completion
clicktochangeinbrackets,core
modshowcmtitle,core
makeavailablecmtitle,core
+2 -2
View File
@@ -1248,7 +1248,6 @@ $string['mailteachers'] = 'Inform teachers';
$string['maincoursepage'] = 'Main course page';
$string['makeafolder'] = 'Create folder';
$string['makeavailable'] = 'Make available';
$string['makeavailablecmtitle'] = 'Make activity available';
$string['makeeditable'] = 'If you make \'{$a}\' editable by the web server process (eg apache) then you could edit this file directly from this page';
$string['makethismyhome'] = 'Make this my home page';
$string['makeunavailable'] = 'Make unavailable';
@@ -1350,7 +1349,6 @@ $string['missingusername'] = 'Missing username';
$string['moddoesnotsupporttype'] = 'Module {$a->modname} does not support uploads of type {$a->type}';
$string['modhide'] = 'Hide';
$string['modshow'] = 'Show';
$string['modshowcmtitle'] = 'Show activity';
$string['modvisible'] = 'Availability';
$string['modvisible_help'] = '* Show on course page: Available to students (subject to any access restrictions which may be set).
* Hide on course page: Not available to students.';
@@ -2452,3 +2450,5 @@ $string['supplyinfo'] = 'More details';
// Deprecated since Moodle 4.3.
$string['clicktochangeinbrackets'] = '{$a} (Click to change)';
$string['modshowcmtitle'] = 'Show activity';
$string['makeavailablecmtitle'] = 'Make activity available';
+8
View File
@@ -83,6 +83,14 @@ class choicelist implements renderable, named_templatable {
}
}
/**
* Get the number of options added to the choice list.
* @return int
*/
public function count_options(): int {
return count($this->options);
}
/**
* Set the selected option.
*