diff --git a/h5p.classes.php b/h5p.classes.php index 73eb1ed..c2efea0 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -102,7 +102,7 @@ interface H5PFrameworkInterface { * @param int $contentMainId * Any contentMainId defined by the framework, for instance to support revisioning */ - public function saveContentData($contentId, $contentJson, $mainJsonData, $contentMainId = NULL); + public function saveContentData($contentId, $contentJson, $mainJsonData, $mainLibraryId, $contentMainId = NULL); /** * Copies content data @@ -686,17 +686,30 @@ class H5PStorage { $this->h5pC->delTree($destination_path); rename($current_path, $destination_path); } + foreach ($this->h5pC->librariesJsonData as $key => &$library) { + // All libraries have been saved, we now save all the dependencies + if (isset($library['preloadedDependencies'])) { + $this->h5pF->saveLibraryDependencies($library['libraryId'], $library['preloadedDependencies'], 'preloaded'); + } + if (isset($library['dynamicDependencies'])) { + $this->h5pF->saveLibraryDependencies($library['libraryId'], $library['dynamicDependencies'], 'dynamic'); + } + if (isset($library['editorDependencies'])) { + $this->h5pF->saveLibraryDependencies($library['libraryId'], $library['editorDependencies'], 'editor'); + } + } $current_path = $this->h5pF->getUploadedH5pFolderPath() . DIRECTORY_SEPARATOR . 'content'; $destination_path = $this->h5pF->getH5pPath() . DIRECTORY_SEPARATOR . 'content' . DIRECTORY_SEPARATOR . $contentId; rename($current_path, $destination_path); - - $contentJson = file_get_contents($destination_path . DIRECTORY_SEPARATOR . 'content.json'); - $this->h5pF->saveContentData($contentId, $contentJson, $this->h5pC->mainJsonData, $contentMainId); $librariesInUse = array(); $this->getLibraryUsage($librariesInUse, $this->h5pC->mainJsonData); $this->h5pF->saveLibraryUsage($contentId, $librariesInUse); $this->h5pC->delTree($this->h5pF->getUploadedH5pFolderPath()); + + $contentJson = file_get_contents($destination_path . DIRECTORY_SEPARATOR . 'content.json'); + $mainLibraryId = $librariesInUse[$this->h5pC->mainJsonData['mainLibrary']]['library']['libraryId']; + $this->h5pF->saveContentData($contentId, $contentJson, $this->h5pC->mainJsonData, $mainLibraryId, $contentMainId); } public function deletePackage($contentId) { diff --git a/js/h5p.js b/js/h5p.js index 0cd835c..ec21e24 100644 --- a/js/h5p.js +++ b/js/h5p.js @@ -58,6 +58,27 @@ H5P.Coords = function(x, y, w, h) { return this; }; +/** + *@param {string} library + * library in the format machineName majorVersion.minorVersion + * @returns + * library as an object with machineName, majorVersion and minorVersion properties + * return false if the library parameter is invalid + */ +H5P.libraryFromString = function (library) { + var regExp = /(.+)\s(\d)+\.(\d)$/g; + var res = regExp.exec(library); + if (res !== null) { + return { + 'machineName': res[1], + 'majorVersion': res[2], + 'minorVersion': res[3] + }; + } + else { + return false; + } +}; // Play a video. $target is jQuery object to attach video to. (Appended). // Params are video-params from content. cp is content path. onEnded is // function to call when finished.