Commit 12f73788 authored by Jake Dallimore's avatar Jake Dallimore
Browse files

MDL-67585 core_course: deprecate get_module_metadata() from course/lib

parent 2f040002
......@@ -621,102 +621,6 @@ function set_section_visible($courseid, $sectionnumber, $visibility) {
return $resourcestotoggle;
}
/**
* Retrieve all metadata for the requested modules
*
* @param object $course The Course
* @param array $modnames An array containing the list of modules and their
* names
* @param int $sectionreturn The section to return to
* @return array A list of stdClass objects containing metadata about each
* module
*/
function get_module_metadata($course, $modnames, $sectionreturn = null) {
global $OUTPUT;
// get_module_metadata will be called once per section on the page and courses may show
// different modules to one another
static $modlist = array();
if (!isset($modlist[$course->id])) {
$modlist[$course->id] = array();
}
$return = array();
$urlbase = new moodle_url('/course/mod.php', array('id' => $course->id, 'sesskey' => sesskey()));
if ($sectionreturn !== null) {
$urlbase->param('sr', $sectionreturn);
}
foreach($modnames as $modname => $modnamestr) {
if (!course_allowed_module($course, $modname)) {
continue;
}
if (isset($modlist[$course->id][$modname])) {
// This module is already cached
$return += $modlist[$course->id][$modname];
continue;
}
$modlist[$course->id][$modname] = array();
// Create an object for a default representation of this module type in the activity chooser. It will be used
// if module does not implement callback get_shortcuts() and it will also be passed to the callback if it exists.
$defaultmodule = new stdClass();
$defaultmodule->title = $modnamestr;
$defaultmodule->name = $modname;
$defaultmodule->link = new moodle_url($urlbase, array('add' => $modname));
$defaultmodule->icon = $OUTPUT->pix_icon('icon', '', $defaultmodule->name, array('class' => 'icon'));
$sm = get_string_manager();
if ($sm->string_exists('modulename_help', $modname)) {
$defaultmodule->help = get_string('modulename_help', $modname);
if ($sm->string_exists('modulename_link', $modname)) { // Link to further info in Moodle docs.
$link = get_string('modulename_link', $modname);
$linktext = get_string('morehelp');
$defaultmodule->help .= html_writer::tag('div',
$OUTPUT->doc_link($link, $linktext, true), array('class' => 'helpdoclink'));
}
}
$defaultmodule->archetype = plugin_supports('mod', $modname, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER);
// Each module can implement callback modulename_get_shortcuts() in its lib.php and return the list
// of elements to be added to activity chooser.
$items = component_callback($modname, 'get_shortcuts', array($defaultmodule), null);
if ($items !== null) {
foreach ($items as $item) {
// Add all items to the return array. All items must have different links, use them as a key in the return array.
if (!isset($item->archetype)) {
$item->archetype = $defaultmodule->archetype;
}
if (!isset($item->icon)) {
$item->icon = $defaultmodule->icon;
}
// If plugin returned the only one item with the same link as default item - cache it as $modname,
// otherwise append the link url to the module name.
$item->name = (count($items) == 1 &&
$item->link->out() === $defaultmodule->link->out()) ? $modname : $modname . ':' . $item->link;
// If the module provides the helptext property, append it to the help text to match the look and feel
// of the default course modules.
if (isset($item->help) && isset($item->helplink)) {
$linktext = get_string('morehelp');
$item->help .= html_writer::tag('div',
$OUTPUT->doc_link($item->helplink, $linktext, true), array('class' => 'helpdoclink'));
}
$modlist[$course->id][$modname][$item->name] = $item;
}
$return += $modlist[$course->id][$modname];
// If get_shortcuts() callback is defined, the default module action is not added.
// It is a responsibility of the callback to add it to the return value unless it is not needed.
continue;
}
// The callback get_shortcuts() was not found, use the default item for the activity chooser.
$modlist[$course->id][$modname][$modname] = $defaultmodule;
$return[$modname] = $defaultmodule;
}
core_collator::asort_objects_by_property($return, 'title');
return $return;
}
/**
* Return the course category context for the category with id $categoryid, except
* that if $categoryid is 0, return the system context.
......
This files describes API changes in /course/*,
information provided here is intended especially for developers.
=== 3.9 ===
* The function get_module_metadata is now deprecated. Please use \core_course\local\service\content_item_service instead.
=== 3.8 ===
* The following functions have been finally deprecated and can not be used any more:
......
......@@ -3307,3 +3307,102 @@ function report_insights_context_insights(\context $context) {
return \core_analytics\manager::cached_models_with_insights($context);
}
/**
* Retrieve all metadata for the requested modules
*
* @deprecated since 3.9.
* @param object $course The Course
* @param array $modnames An array containing the list of modules and their
* names
* @param int $sectionreturn The section to return to
* @return array A list of stdClass objects containing metadata about each
* module
*/
function get_module_metadata($course, $modnames, $sectionreturn = null) {
global $OUTPUT;
debugging('get_module_metadata is deprecated. Please use \core_course\local\service\content_item_service instead.');
// get_module_metadata will be called once per section on the page and courses may show
// different modules to one another
static $modlist = array();
if (!isset($modlist[$course->id])) {
$modlist[$course->id] = array();
}
$return = array();
$urlbase = new moodle_url('/course/mod.php', array('id' => $course->id, 'sesskey' => sesskey()));
if ($sectionreturn !== null) {
$urlbase->param('sr', $sectionreturn);
}
foreach($modnames as $modname => $modnamestr) {
if (!course_allowed_module($course, $modname)) {
continue;
}
if (isset($modlist[$course->id][$modname])) {
// This module is already cached
$return += $modlist[$course->id][$modname];
continue;
}
$modlist[$course->id][$modname] = array();
// Create an object for a default representation of this module type in the activity chooser. It will be used
// if module does not implement callback get_shortcuts() and it will also be passed to the callback if it exists.
$defaultmodule = new stdClass();
$defaultmodule->title = $modnamestr;
$defaultmodule->name = $modname;
$defaultmodule->link = new moodle_url($urlbase, array('add' => $modname));
$defaultmodule->icon = $OUTPUT->pix_icon('icon', '', $defaultmodule->name, array('class' => 'icon'));
$sm = get_string_manager();
if ($sm->string_exists('modulename_help', $modname)) {
$defaultmodule->help = get_string('modulename_help', $modname);
if ($sm->string_exists('modulename_link', $modname)) { // Link to further info in Moodle docs.
$link = get_string('modulename_link', $modname);
$linktext = get_string('morehelp');
$defaultmodule->help .= html_writer::tag('div',
$OUTPUT->doc_link($link, $linktext, true), array('class' => 'helpdoclink'));
}
}
$defaultmodule->archetype = plugin_supports('mod', $modname, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER);
// Each module can implement callback modulename_get_shortcuts() in its lib.php and return the list
// of elements to be added to activity chooser.
$items = component_callback($modname, 'get_shortcuts', array($defaultmodule), null);
if ($items !== null) {
foreach ($items as $item) {
// Add all items to the return array. All items must have different links, use them as a key in the return array.
if (!isset($item->archetype)) {
$item->archetype = $defaultmodule->archetype;
}
if (!isset($item->icon)) {
$item->icon = $defaultmodule->icon;
}
// If plugin returned the only one item with the same link as default item - cache it as $modname,
// otherwise append the link url to the module name.
$item->name = (count($items) == 1 &&
$item->link->out() === $defaultmodule->link->out()) ? $modname : $modname . ':' . $item->link;
// If the module provides the helptext property, append it to the help text to match the look and feel
// of the default course modules.
if (isset($item->help) && isset($item->helplink)) {
$linktext = get_string('morehelp');
$item->help .= html_writer::tag('div',
$OUTPUT->doc_link($item->helplink, $linktext, true), array('class' => 'helpdoclink'));
}
$modlist[$course->id][$modname][$item->name] = $item;
}
$return += $modlist[$course->id][$modname];
// If get_shortcuts() callback is defined, the default module action is not added.
// It is a responsibility of the callback to add it to the return value unless it is not needed.
continue;
}
// The callback get_shortcuts() was not found, use the default item for the activity chooser.
$modlist[$course->id][$modname][$modname] = $defaultmodule;
$return[$modname] = $defaultmodule;
}
core_collator::asort_objects_by_property($return, 'title');
return $return;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment