Skip to content

Commit

Permalink
Get the newest library version
Browse files Browse the repository at this point in the history
  • Loading branch information
daVitekPL committed Mar 27, 2024
1 parent fbde2d5 commit 9a497e7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/Repositories/H5PContentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/Repositories/H5PEditorStorageRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down Expand Up @@ -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();
Expand Down
5 changes: 3 additions & 2 deletions src/Repositories/H5PRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -860,7 +860,7 @@ public function loadLibrary($machineName, $majorVersion, $minorVersion)
'minor_version' => $minorVersion,
])
->with('dependencies.requiredLibrary')
->first();
->latest()->first();

if (is_null($library)) {
return;
Expand Down Expand Up @@ -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);
Expand Down
17 changes: 16 additions & 1 deletion src/Services/HeadlessH5PService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Check warning on line 179 in src/Services/HeadlessH5PService.php

View check run for this annotation

Codecov / codecov/patch

src/Services/HeadlessH5PService.php#L179

Added line #L179 was not covered by tests

if (in_array($library->name, array('H5P.Questionnaire', 'H5P.FreeTextQuestion')) &&
!$this->h5p->h5pF->getOption('enable_lrs_content_types')) {
$library->restricted = TRUE;

Check warning on line 183 in src/Services/HeadlessH5PService.php

View check run for this annotation

Codecov / codecov/patch

src/Services/HeadlessH5PService.php#L181-L183

Added lines #L181 - L183 were not covered by tests
}
$this->addMoreHtmlTags($library->semantics);
$library
->append('contentsCount')
->append('requiredLibrariesCount');

Check warning on line 188 in src/Services/HeadlessH5PService.php

View check run for this annotation

Codecov / codecov/patch

src/Services/HeadlessH5PService.php#L185-L188

Added lines #L185 - L188 were not covered by tests

return collect([$library]);

Check warning on line 190 in src/Services/HeadlessH5PService.php

View check run for this annotation

Codecov / codecov/patch

src/Services/HeadlessH5PService.php#L190

Added line #L190 was not covered by tests
}

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);
Expand Down

0 comments on commit 9a497e7

Please sign in to comment.