MDL-66609: core_h5p: Add <component>_get_path_from_pluginfile method

This method has been added to all the components having some exceptions
with the way they treat the itemid in the pluginfile paths.
This commit is contained in:
Sara Arjona 2019-10-17 22:20:13 +02:00 committed by Andrew Nicols
parent 9e67f5e366
commit 810d7a3d2e
8 changed files with 177 additions and 0 deletions

View file

@ -584,3 +584,28 @@ function mod_resource_core_calendar_provide_event_action(calendar_event $event,
true
);
}
/**
* Given an array with a file path, it returns the itemid and the filepath for the defined filearea.
*
* @param string $filearea The filearea.
* @param array $args The path (the part after the filearea and before the filename).
* @return array The itemid and the filepath inside the $args path, for the defined filearea.
*/
function mod_resource_get_path_from_pluginfile(string $filearea, array $args) : array {
// Resource never has an itemid (the number represents the revision but it's not stored in database).
array_shift($args);
// Get the filepath.
if (empty($args)) {
$filepath = '/';
} else {
$filepath = '/' . implode('/', $args) . '/';
}
return [
'itemid' => 0,
'filepath' => $filepath,
];
}