diff --git a/src/Repositories/H5PContentRepository.php b/src/Repositories/H5PContentRepository.php index 7feb8cd..535a3e9 100644 --- a/src/Repositories/H5PContentRepository.php +++ b/src/Repositories/H5PContentRepository.php @@ -39,7 +39,7 @@ public function create(string $library, string $params, string $nonce): int ['name', $libNames['machineName']], ['major_version', $libNames['majorVersion']], ['minor_version', $libNames['minorVersion']], - ])->first(); + ])->latest()->first(); if ($libDb === null) { throw new H5PException(H5PException::LIBRARY_NOT_FOUND); @@ -74,7 +74,7 @@ public function edit(int $id, string $library, string $params, string $nonce): i ['name', $libNames['machineName']], ['major_version', $libNames['majorVersion']], ['minor_version', $libNames['minorVersion']], - ])->first(); + ])->latest()->first(); if ($libDb === null) { throw new H5PException(H5PException::LIBRARY_NOT_FOUND); diff --git a/src/Repositories/H5PEditorStorageRepository.php b/src/Repositories/H5PEditorStorageRepository.php index dff19cf..89b87dc 100644 --- a/src/Repositories/H5PEditorStorageRepository.php +++ b/src/Repositories/H5PEditorStorageRepository.php @@ -45,7 +45,7 @@ public function getLanguage($machineName, $majorVersion, $minorVersion, $languag ['major_version', $majorVersion], ['minor_version', $minorVersion], ['name', $machineName], - ])->first(); + ])->latest()->first(); if ($library) { $libraryLanguage = H5PLibraryLanguage::where([ @@ -121,7 +121,7 @@ public function getLibraries($libraries = null) ['name', $library->name], ['major_version', $library->majorVersion], ['minor_version', $library->minorVersion] - ])->first()) + ])->latest()->first()) ->reject(fn($library) => !$library) ->values() ->all(); diff --git a/src/Repositories/H5PRepository.php b/src/Repositories/H5PRepository.php index 39dcf41..c3c5f1b 100644 --- a/src/Repositories/H5PRepository.php +++ b/src/Repositories/H5PRepository.php @@ -675,7 +675,7 @@ public function saveLibraryDependencies($libraryId, $dependencies, $dependency_t 'name' => $dependency['machineName'], 'major_version' => $dependency['majorVersion'], 'minor_version' => $dependency['minorVersion'], - ])->firstOrFail(); + ])->latest()->firstOrFail(); H5PLibraryDependency::firstOrCreate([ 'library_id' => $libraryId, @@ -860,7 +860,7 @@ public function loadLibrary($machineName, $majorVersion, $minorVersion) 'minor_version' => $minorVersion, ]) ->with('dependencies.requiredLibrary') - ->first(); + ->latest()->first(); if (is_null($library)) { return; @@ -899,6 +899,7 @@ public function loadLibrarySemantics($machineName, $majorVersion, $minorVersion) $library = H5PLibrary::where('name', $machineName) ->where('major_version', $majorVersion) ->where('minor_version', $minorVersion) + ->latest() ->first(); $semanticsFile = $this->getSemanticsFromFile($machineName, $majorVersion, $minorVersion); diff --git a/src/Services/HeadlessH5PService.php b/src/Services/HeadlessH5PService.php index 91b0aee..c980295 100644 --- a/src/Services/HeadlessH5PService.php +++ b/src/Services/HeadlessH5PService.php @@ -170,11 +170,26 @@ public function getConfig(): array /** * Calls editor ajax actions. */ - public function getLibraries(string $machineName = null, string $major_version = null, string $minor_version = null) + public function getLibraries(string $machineName = null, string $major_version = null, string $minor_version = null, int $library_id = null) { $lang = config('hh5p.language'); $libraries_url = url(config('hh5p.h5p_library_url')); + if ($library_id) { + $library = H5PLibrary::findOrFail($library_id); + + if (in_array($library->name, array('H5P.Questionnaire', 'H5P.FreeTextQuestion')) && + !$this->h5p->h5pF->getOption('enable_lrs_content_types')) { + $library->restricted = TRUE; + } + $this->addMoreHtmlTags($library->semantics); + $library + ->append('contentsCount') + ->append('requiredLibrariesCount'); + + return collect([$library]); + } + if ($machineName) { $defaultLang = $this->getEditor()->getLibraryLanguage($machineName, $major_version, $minor_version, $lang); $data = $this->getEditor()->getLibraryData($machineName, $major_version, $minor_version, $lang, '', $libraries_url, $defaultLang);