Commit 41b46256 authored by Ferran Recio Calderó's avatar Ferran Recio Calderó
Browse files

MDL-72578 course: activity render to output classes

parent 70073fdc
...@@ -232,7 +232,8 @@ abstract class info { ...@@ -232,7 +232,8 @@ abstract class info {
* @return bool True if activity is available for all * @return bool True if activity is available for all
*/ */
public function is_available_for_all() { public function is_available_for_all() {
if (is_null($this->availability)) { global $CFG;
if (is_null($this->availability) || !empty($CFG->enableavailability)) {
return true; return true;
} else { } else {
try { try {
......
...@@ -48,12 +48,19 @@ class block_site_main_menu extends block_list { ...@@ -48,12 +48,19 @@ class block_site_main_menu extends block_list {
} }
$course = get_site(); $course = get_site();
$format = course_get_format($course);
$courserenderer = $format->get_renderer($this->page);
require_once($CFG->dirroot.'/course/lib.php'); require_once($CFG->dirroot.'/course/lib.php');
$context = context_course::instance($course->id); $context = context_course::instance($course->id);
$isediting = $this->page->user_is_editing() && has_capability('moodle/course:manageactivities', $context); $isediting = $this->page->user_is_editing() && has_capability('moodle/course:manageactivities', $context);
$courserenderer = $this->page->get_renderer('core', 'course');
/// extra fast view mode // Output classes.
$cmnameclass = $format->get_output_classname('content\\cm\\cmname');
$controlmenuclass = $format->get_output_classname('content\\cm\\controlmenu');
// Extra fast view mode.
if (!$isediting) { if (!$isediting) {
$modinfo = get_fast_modinfo($course); $modinfo = get_fast_modinfo($course);
if (!empty($modinfo->sections[0])) { if (!empty($modinfo->sections[0])) {
...@@ -69,13 +76,17 @@ class block_site_main_menu extends block_list { ...@@ -69,13 +76,17 @@ class block_site_main_menu extends block_list {
$indent = ''; $indent = '';
} }
if (!empty($cm->url)) { if (empty($cm->url)) {
$content = html_writer::div($courserenderer->course_section_cm_name($cm), 'activity'); $content = html_writer::div(
$cm->get_formatted_content(['overflowdiv' => true, 'noclean' => true]),
'contentwithoutlink'
);
} else { } else {
$content = $courserenderer->course_section_cm_text($cm); $cmname = new $cmnameclass($format, $cm->get_section_info(), $cm, $isediting);
$content = $courserenderer->render($cmname);
} }
$this->content->items[] = $indent . html_writer::div($content, 'main-menu-content'); $this->content->items[] = $indent . html_writer::div($content, 'main-menu-content activity');
} }
} }
return $this->content; return $this->content;
...@@ -106,18 +117,28 @@ class block_site_main_menu extends block_list { ...@@ -106,18 +117,28 @@ class block_site_main_menu extends block_list {
continue; continue;
} }
if (!$ismoving) { if (!$ismoving) {
$actions = course_get_cm_edit_actions($mod, $mod->indent);
$controlmenu = new $controlmenuclass(
// Prepend list of actions with the 'move' action. $format,
$actions = array('move' => new action_menu_link_primary( $mod->get_section_info(),
new moodle_url('/course/mod.php', array('sesskey' => sesskey(), 'copy' => $mod->id)), $mod
new pix_icon('t/move', $strmove, 'moodle', array('class' => 'iconsmall', 'title' => '')), );
$strmove
)) + $actions; $menu = $controlmenu->get_action_menu();
$editbuttons = html_writer::tag('div', // Add a move primary action.
$courserenderer->course_section_cm_edit_actions($actions, $mod, array('donotenhance' => true)), $menu->add(
array('class' => 'buttons') new action_menu_link_primary(
new moodle_url('/course/mod.php', ['sesskey' => sesskey(), 'copy' => $mod->id]),
new pix_icon('t/move', $strmove, 'moodle', ['class' => 'iconsmall', 'title' => '']),
$strmove
)
);
$editbuttons = html_writer::tag(
'div',
$courserenderer->render($controlmenu),
['class' => 'buttons']
); );
} else { } else {
$editbuttons = ''; $editbuttons = '';
...@@ -138,9 +159,13 @@ class block_site_main_menu extends block_list { ...@@ -138,9 +159,13 @@ class block_site_main_menu extends block_list {
$indent = ''; $indent = '';
} }
if (!$mod->url) { if (!$mod->url) {
$content = $courserenderer->course_section_cm_text($mod); $content = html_writer::div(
$mod->get_formatted_content(['overflowdiv' => true, 'noclean' => true]),
'contentwithoutlink'
);
} else { } else {
$content = html_writer::div($courserenderer->course_section_cm_name($mod), ' activity'); $cmname = new $cmnameclass($format, $mod->get_section_info(), $mod, $isediting);
$content = html_writer::div($courserenderer->render($cmname), 'activity');
} }
$this->content->items[] = $indent . html_writer::div($content . $editbuttons, 'main-menu-content'); $this->content->items[] = $indent . html_writer::div($content . $editbuttons, 'main-menu-content');
} }
...@@ -159,5 +184,3 @@ class block_site_main_menu extends block_list { ...@@ -159,5 +184,3 @@ class block_site_main_menu extends block_list {
return $this->content; return $this->content;
} }
} }
...@@ -48,7 +48,8 @@ class block_social_activities extends block_list { ...@@ -48,7 +48,8 @@ class block_social_activities extends block_list {
} }
$course = $this->page->course; $course = $this->page->course;
$courserenderer = $this->page->get_renderer('core', 'course'); $format = course_get_format($course);
$courserenderer = $format->get_renderer($this->page);
require_once($CFG->dirroot.'/course/lib.php'); require_once($CFG->dirroot.'/course/lib.php');
...@@ -56,7 +57,11 @@ class block_social_activities extends block_list { ...@@ -56,7 +57,11 @@ class block_social_activities extends block_list {
$isediting = $this->page->user_is_editing() && has_capability('moodle/course:manageactivities', $context); $isediting = $this->page->user_is_editing() && has_capability('moodle/course:manageactivities', $context);
$modinfo = get_fast_modinfo($course); $modinfo = get_fast_modinfo($course);
/// extra fast view mode // Output classes.
$cmnameclass = $format->get_output_classname('content\\cm\\cmname');
$controlmenuclass = $format->get_output_classname('content\\cm\\controlmenu');
// Extra fast view mode.
if (!$isediting) { if (!$isediting) {
if (!empty($modinfo->sections[0])) { if (!empty($modinfo->sections[0])) {
foreach($modinfo->sections[0] as $cmid) { foreach($modinfo->sections[0] as $cmid) {
...@@ -66,18 +71,21 @@ class block_social_activities extends block_list { ...@@ -66,18 +71,21 @@ class block_social_activities extends block_list {
} }
if (!$cm->url) { if (!$cm->url) {
$content = $courserenderer->course_section_cm_text($cm); $content = html_writer::div(
$cm->get_formatted_content(['overflowdiv' => true, 'noclean' => true]),
'contentwithoutlink'
);
$this->content->items[] = $content; $this->content->items[] = $content;
$this->content->icons[] = ''; $this->content->icons[] = '';
} else { } else {
$this->content->items[] = html_writer::div($courserenderer->course_section_cm_name($cm), 'activity'); $cmname = new $cmnameclass($format, $cm->get_section_info(), $cm, $isediting);
$this->content->items[] = html_writer::div($courserenderer->render($cmname), 'activity');
} }
} }
} }
return $this->content; return $this->content;
} }
// Slow & hacky editing mode. // Slow & hacky editing mode.
$ismoving = ismoving($course->id); $ismoving = ismoving($course->id);
$section = $modinfo->get_section_info(0); $section = $modinfo->get_section_info(0);
...@@ -102,18 +110,28 @@ class block_social_activities extends block_list { ...@@ -102,18 +110,28 @@ class block_social_activities extends block_list {
continue; continue;
} }
if (!$ismoving) { if (!$ismoving) {
$actions = course_get_cm_edit_actions($mod, -1);
// Prepend list of actions with the 'move' action. $controlmenu = new $controlmenuclass(
$actions = array('move' => new action_menu_link_primary( $format,
new moodle_url('/course/mod.php', array('sesskey' => sesskey(), 'copy' => $mod->id)), $mod->get_section_info(),
new pix_icon('t/move', $strmove, 'moodle', array('class' => 'iconsmall', 'title' => '')), $mod,
$strmove ['disableindentation' => true]
)) + $actions; );
$menu = $controlmenu->get_action_menu();
// Add a move primary action.
$menu->add(
new action_menu_link_primary(
new moodle_url('/course/mod.php', ['sesskey' => sesskey(), 'copy' => $mod->id]),
new pix_icon('t/move', $strmove, 'moodle', ['class' => 'iconsmall', 'title' => '']),
$strmove
)
);
$editbuttons = html_writer::tag('div', $editbuttons = html_writer::tag('div',
$courserenderer->course_section_cm_edit_actions($actions, $mod, array('donotenhance' => true)), $courserenderer->render($controlmenu),
array('class' => 'buttons') ['class' => 'buttons']
); );
} else { } else {
$editbuttons = ''; $editbuttons = '';
...@@ -129,12 +147,15 @@ class block_social_activities extends block_list { ...@@ -129,12 +147,15 @@ class block_social_activities extends block_list {
$this->content->icons[] = ''; $this->content->icons[] = '';
} }
if (!$mod->url) { if (!$mod->url) {
$content = $courserenderer->course_section_cm_text($mod); $content = html_writer::div(
$mod->get_formatted_content(['overflowdiv' => true, 'noclean' => true]),
'contentwithoutlink'
);
$this->content->items[] = $content . $editbuttons; $this->content->items[] = $content . $editbuttons;
$this->content->icons[] = ''; $this->content->icons[] = '';
} else { } else {
$this->content->items[] = html_writer::div($courserenderer->course_section_cm_name($mod), 'activity') . $cmname = new $cmnameclass($format, $mod->get_section_info(), $mod, $isediting);
$editbuttons; $this->content->items[] = html_writer::div($courserenderer->render($cmname), 'activity') . $editbuttons;
} }
} }
} }
......
...@@ -31,6 +31,7 @@ use cm_info; ...@@ -31,6 +31,7 @@ use cm_info;
/** /**
* Class to prepare a course module name for display and in-place editing * Class to prepare a course module name for display and in-place editing
* *
* @deprecated since Moodle 4.0
* @package core_course * @package core_course
* @copyright 2016 Marina Glancy * @copyright 2016 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
...@@ -51,6 +52,10 @@ class course_module_name extends \core\output\inplace_editable { ...@@ -51,6 +52,10 @@ class course_module_name extends \core\output\inplace_editable {
* @param array $displayoptions * @param array $displayoptions
*/ */
public function __construct(cm_info $cm, $editable, $displayoptions = array()) { public function __construct(cm_info $cm, $editable, $displayoptions = array()) {
debugging(
'course_section_cm_list is deprecated. Use core_courseformat\\output\\local\\cm\\cmname instead',
DEBUG_DEVELOPER
);
$this->cm = $cm; $this->cm = $cm;
$this->displayoptions = $displayoptions; $this->displayoptions = $displayoptions;
$value = $cm->name; $value = $cm->name;
......
...@@ -1109,7 +1109,7 @@ abstract class base { ...@@ -1109,7 +1109,7 @@ abstract class base {
} }
/** /**
* Returns instance of output compornent used by this plugin * Returns instance of output component used by this plugin
* *
* @throws coding_exception if the format class does not extends the original core one. * @throws coding_exception if the format class does not extends the original core one.
* @param string $outputname the element to render (section, activity...) * @param string $outputname the element to render (section, activity...)
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
namespace core_courseformat\output\local\content\section; namespace core_courseformat\output\local\content;
use cm_info; use cm_info;
use core\activity_dates; use core\activity_dates;
...@@ -33,6 +33,7 @@ use renderable; ...@@ -33,6 +33,7 @@ use renderable;
use section_info; use section_info;
use stdClass; use stdClass;
use templatable; use templatable;
use \core_availability\info_module;
/** /**
* Base class to render a course module inside a course format. * Base class to render a course module inside a course format.
...@@ -55,6 +56,21 @@ class cm implements renderable, templatable { ...@@ -55,6 +56,21 @@ class cm implements renderable, templatable {
/** @var array optional display options */ /** @var array optional display options */
protected $displayoptions; protected $displayoptions;
/** @var string activity link css classes */
protected $linkclasses = null;
/** @var string text css classes */
protected $textclasses = null;
/** @var string the activity name output class name */
protected $cmnameclass;
/** @var string the activity control menu class name */
protected $controlmenuclass;
/** @var string the activity availability class name */
protected $availabilityclass;
/** /**
* Constructor. * Constructor.
* *
...@@ -68,6 +84,13 @@ class cm implements renderable, templatable { ...@@ -68,6 +84,13 @@ class cm implements renderable, templatable {
$this->section = $section; $this->section = $section;
$this->mod = $mod; $this->mod = $mod;
$this->displayoptions = $displayoptions; $this->displayoptions = $displayoptions;
$this->load_classes();
// Get the necessary classes.
$this->cmnameclass = $format->get_output_classname('content\\cm\\cmname');
$this->controlmenuclass = $format->get_output_classname('content\\cm\\controlmenu');
$this->availabilityclass = $format->get_output_classname('content\\cm\\availability');
} }
/** /**
...@@ -80,6 +103,7 @@ class cm implements renderable, templatable { ...@@ -80,6 +103,7 @@ class cm implements renderable, templatable {
global $USER; global $USER;
$format = $this->format; $format = $this->format;
$section = $this->section;
$mod = $this->mod; $mod = $this->mod;
$displayoptions = $this->displayoptions; $displayoptions = $this->displayoptions;
$course = $mod->get_course(); $course = $mod->get_course();
...@@ -94,6 +118,12 @@ class cm implements renderable, templatable { ...@@ -94,6 +118,12 @@ class cm implements renderable, templatable {
$activitydates = activity_dates::get_dates_for_module($mod, $USER->id); $activitydates = activity_dates::get_dates_for_module($mod, $USER->id);
} }
$displayoptions['linkclasses'] = $this->get_link_classes();
$displayoptions['textclasses'] = $this->get_text_classes();
// Grouping activity.
$groupinglabel = $mod->get_grouping_label($displayoptions['textclasses']);
$activityinfodata = null; $activityinfodata = null;
// - There are activity dates to be shown; or // - There are activity dates to be shown; or
// - Completion info needs to be displayed // - Completion info needs to be displayed
...@@ -107,13 +137,32 @@ class cm implements renderable, templatable { ...@@ -107,13 +137,32 @@ class cm implements renderable, templatable {
$activityinfodata = $activityinfo->export_for_template($output); $activityinfodata = $activityinfo->export_for_template($output);
} }
// Mod inplace name editable.
$cmname = new $this->cmnameclass(
$format,
$this->section,
$mod,
$format->show_editor(),
$this->displayoptions
);
// Mod availability.
$availability = new $this->availabilityclass(
$format,
$this->section,
$mod,
$this->displayoptions
);
$data = (object)[ $data = (object)[
'cmname' => $output->course_section_cm_name($mod, $displayoptions), 'cmname' => $cmname->export_for_template($output),
'grouping' => $groupinglabel,
'afterlink' => $mod->afterlink, 'afterlink' => $mod->afterlink,
'altcontent' => $output->course_section_cm_text($mod, $displayoptions), 'altcontent' => $mod->get_formatted_content(['overflowdiv' => true, 'noclean' => true]),
'availability' => $output->course_section_cm_availability($mod, $displayoptions), 'modavailability' => $availability->export_for_template($output),
'url' => $mod->url, 'url' => $mod->url,
'activityinfo' => $activityinfodata, 'activityinfo' => $activityinfodata,
'textclasses' => $displayoptions['textclasses'],
]; ];
if (!empty($mod->indent)) { if (!empty($mod->indent)) {
...@@ -131,22 +180,80 @@ class cm implements renderable, templatable { ...@@ -131,22 +180,80 @@ class cm implements renderable, templatable {
} }
$returnsection = $format->get_section_number(); $returnsection = $format->get_section_number();
$data->extras = [];
if ($format->show_editor()) { if ($format->show_editor()) {
// Edit actions. // Edit actions.
$editactions = course_get_cm_edit_actions($mod, $mod->indent, $returnsection); $controlmenu = new $this->controlmenuclass(
$data->extras[] = $output->course_section_cm_edit_actions($editactions, $mod, $displayoptions); $format,
if (!empty($mod->afterediticons)) { $this->section,
$data->extras[] = $mod->afterediticons; $mod,
} $this->displayoptions
);
$data->controlmenu = $controlmenu->export_for_template($output);
// Move and select options. // Move and select options.
$data->moveicon = course_get_cm_move($mod, $returnsection); $data->moveicon = course_get_cm_move($mod, $returnsection);
} }
if (!empty($data->extras)) { return $data;
$data->hasextras = true; }
/**
* Returns the CSS classes for the activity name/content
*
* For items which are hidden, unavailable or stealth but should be displayed
* to current user ($mod->is_visible_on_course_page()), we show those as dimmed.
* Students will also see as dimmed activities names that are not yet available
* but should still be displayed (without link) with availability info.
*/
protected function load_classes() {
$mod = $this->mod;
$linkclasses = '';
$textclasses = '';
if ($mod->uservisible) {
$info = new info_module($mod);
$conditionalhidden = !$info->is_available_for_all();
$accessiblebutdim = (!$mod->visible || $conditionalhidden) &&
has_capability('moodle/course:viewhiddenactivities', $mod->context);
if ($accessiblebutdim) {
$linkclasses .= ' dimmed';
$textclasses .= ' dimmed_text';
if ($conditionalhidden) {
$linkclasses .= ' conditionalhidden';
$textclasses .= ' conditionalhidden';
}
}
if ($mod->is_stealth()) {
// Stealth activity is the one that is not visible on course page.
// It still may be displayed to the users who can manage it.
$linkclasses .= ' stealth';
$textclasses .= ' stealth';
}
} else {
$linkclasses .= ' dimmed';
$textclasses .= ' dimmed dimmed_text';
} }
$this->linkclasses = $linkclasses;
$this->textclasses = $textclasses;
}
return $data; /**
* Get the activity link classes.
*
* @return string the activity link classes.
*/
public function get_link_classes(): string {
return $this->linkclasses;
}
/**
* Get the activity text/description classes.
*
* @return string the activity text classes.
*/
public function get_text_classes(): string {
return $this->textclasses;
} }
} }
<?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 activity availability information.
*
* @package core_courseformat
* @copyright 2020 Ferran Recio <ferran@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_courseformat\output\local\content\cm;
use core_courseformat\output\local\content\section\availability as section_avalability;