MDL-68636 core_contentbank: added method to get H5P id from pathnamehash
authorVíctor Déniz Falcón <victor@moodle.com>
Fri, 1 May 2020 17:09:44 +0000 (18:09 +0100)
committerAmaia Anabitarte <amaia@moodle.com>
Fri, 15 May 2020 09:35:08 +0000 (11:35 +0200)
h5p/classes/api.php

index b86acad..81c7625 100644 (file)
@@ -487,4 +487,19 @@ class api {
         $pathnamehash = $fs->get_pathname_hash($contextid, $component, $filearea, $itemid, $filepath, $filename);
         return $pathnamehash;
     }
+
+    /**
+     * Returns the H5P content object corresponding to an H5P content file.
+     *
+     * @param string $pathnamehash The pathnamehash of the file associated to an H5P content.
+     *
+     * @return null|\stdClass H5P content object or null if not found.
+     */
+    public static function get_content_from_pathnamehash(string $pathnamehash): ?\stdClass {
+        global $DB;
+
+        $h5p = $DB->get_record('h5p', ['pathnamehash' => $pathnamehash]);
+
+        return ($h5p) ? $h5p : null;
+    }
 }