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

@ -2177,3 +2177,31 @@ function workshop_check_updates_since(cm_info $cm, $from, $filter = array()) {
}
return $updates;
}
/**
* 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|null The itemid and the filepath inside the $args path, for the defined filearea.
*/
function mod_workshop_get_path_from_pluginfile(string $filearea, array $args) : ?array {
if ($filearea !== 'instructauthors' && $filearea !== 'instructreviewers' && $filearea !== 'conclusion') {
return null;
}
// Workshop only has empty itemid for some of the fileareas.
array_shift($args);
// Get the filepath.
if (empty($args)) {
$filepath = '/';
} else {
$filepath = '/' . implode('/', $args) . '/';
}
return [
'itemid' => 0,
'filepath' => $filepath,
];
}