Skip to content

Commit

Permalink
bug fixes (#180)
Browse files Browse the repository at this point in the history
* fixes

* json fix

* fixes

Co-authored-by: Tomasz Smolarek <tomasz.smolarek@escolasoft.com>
  • Loading branch information
dyfero and dyfero authored Nov 16, 2022
1 parent 31122bd commit 4b4184e
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 13 deletions.
2 changes: 1 addition & 1 deletion config/hh5p.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

// Content screen setting

'h5p_show_display_option' => true,
'h5p_show_display_option' => false,
'h5p_frame' => true,
'h5p_export' => false,
'h5p_embed' => false,
Expand Down
4 changes: 2 additions & 2 deletions database/factories/H5PLibraryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public function definition()
'runnable' => 1,
'restricted' => 0,
'fullscreen' => 1,
'embed_types' => '',
'embed_types' => 'div',
'preloaded_js' => '',
'preloaded_css' => '',
'drop_library_css' => '',
'semantics' => '',
'semantics' => '[]',
'tutorial_url' => '',
'has_icon' => 0,
'add_to' => ''
Expand Down
2 changes: 1 addition & 1 deletion src/HeadlessH5PServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private function bindH5P(): void
$languageRepository = new H5PLibraryLanguageRepository();
$repository = new H5PRepository($languageRepository);
$fileStorage = new H5PFileStorageRepository(storage_path('app/h5p'));
$core = new H5PCore($repository, $fileStorage, url('h5p'), config('hh5p.language'), true);
$core = new H5PCore($repository, $fileStorage, url('h5p'), config('hh5p.language'), config('hh5p.h5p_export'));
$core->aggregateAssets = true;
$validator = new H5PValidator($repository, $core);
$storage = new H5PStorage($repository, $core);
Expand Down
19 changes: 17 additions & 2 deletions src/Repositories/H5PContentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace EscolaLms\HeadlessH5P\Repositories;

use EscolaLms\Auth\Events\Auth;
use EscolaLms\Core\Repositories\Criteria\Criterion;
use EscolaLms\HeadlessH5P\Dtos\ContentFilterCriteriaDto;
use EscolaLms\HeadlessH5P\Exceptions\H5PException;
Expand All @@ -13,9 +12,11 @@
use EscolaLms\HeadlessH5P\Repositories\Contracts\H5PContentRepositoryContract;
use EscolaLms\HeadlessH5P\Services\Contracts\HeadlessH5PServiceContract;
use EscolaLms\HeadlessH5P\Traits\QueryExtendable;
use H5PCore;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;


class H5PContentRepository implements H5PContentRepositoryContract
Expand All @@ -38,6 +39,7 @@ public function create(string $library, string $params, string $nonce): int
['major_version', $libNames['majorVersion']],
['minor_version', $libNames['minorVersion']],
])->first();

if ($libDb === null) {
throw new H5PException(H5PException::LIBRARY_NOT_FOUND);
}
Expand All @@ -57,6 +59,7 @@ public function create(string $library, string $params, string $nonce): int
'author' => $user->email,
]);

$this->filterParameters(H5PContent::findOrFail($content), $libDb);
$this->moveTmpFilesToContentFolders($nonce, $content);

return $content;
Expand Down Expand Up @@ -93,7 +96,7 @@ public function edit(int $id, string $library, string $params, string $nonce): i
'library_id' => $libDb->id,
'library' => $library,
'parameters' => $params,
//'nonce'=>$nonce
'filtered' => isset($json->params) ? json_encode($json->params) : $content['filtered']
], $id);

$this->moveTmpFilesToContentFolders($nonce, $id);
Expand Down Expand Up @@ -267,4 +270,16 @@ private function getUnused(): Collection
->whereRaw('(SELECT COUNT(*) FROM topic_h5ps WHERE hh5p_contents.id = topic_h5ps.value) <= 0')
->get();
}

private function filterParameters(H5PContent $h5pContent, H5PLibrary $h5pLibrary): void
{
$content = $h5pContent->toArray();
$content['library'] = $h5pLibrary->toArray();
$content['params'] = json_encode($content['params']);
$content['metadata'] = json_decode(json_encode($content['metadata']), true);
$content['slug'] = Str::slug($content['title']);
$content['embedType'] = H5PCore::determineEmbedType($h5pContent->embededType ?? 'div', $h5pLibrary->embedTypes);

$this->hh5pService->getCore()->filterParameters($content);
}
}
1 change: 1 addition & 0 deletions src/Repositories/H5PEditorStorageRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public function getLibraries($libraries = null)
['minor_version', $library->minorVersion]
])->first())
->reject(fn($library) => !$library)
->values()
->all();
}

Expand Down
11 changes: 4 additions & 7 deletions src/Services/HeadlessH5PService.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,16 +424,14 @@ public function getContentSettings($id, ?string $token = null): array
$content = $this->getCore()->loadContent($id);
$content['metadata']['title'] = $content['title'];

$safe_parameters = $this->getCore()->filterParameters($content); // TODO: actually this is inserting stuff in Database, it shouldn'e instert anything since this is a GET

$library = $content['library'];

$uberName = $library['name'] . ' ' . $library['majorVersion'] . '.' . $library['minorVersion'];

$settings['contents']["cid-$id"] = [
'library' => $uberName,
'content' => $content,
'jsonContent' => $safe_parameters,
'jsonContent' => $content['filtered'],
'fullScreen' => $content['library']['fullscreen'],
// TODO check all of those endpointis are working fine
'exportUrl' => config('hh5p.h5p_export') && $token ? route('hh5p.content.export', [$content['id'], '_token' => $token]) : '',
Expand Down Expand Up @@ -502,8 +500,6 @@ public function getSettingsForContent($id): array
$content = $this->getCore()->loadContent($id);
$content['metadata']['title'] = $content['title'];

$safe_parameters = $this->getCore()->filterParameters($content); // TODO: actually this is inserting stuff in Database, it shouldn'e instert anything since this is a GET

$library = $content['library'];

$uberName = $library['name'] . ' ' . $library['majorVersion'] . '.' . $library['minorVersion'];
Expand All @@ -512,9 +508,9 @@ public function getSettingsForContent($id): array
'library' => $uberName,
'content' => $content,
'jsonContent' => json_encode([
'params' => json_decode($safe_parameters),
'params' => json_decode($content['filtered']),
'metadata' => $content['metadata'],
]),
], JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE),
'fullScreen' => $content['library']['fullscreen'],
'exportUrl' => config('hh5p.h5p_export') ? route('hh5p.content.export', [$content['id']]) : '',
//'embedCode' => '<iframe src="'.route('h5p.embed', ['id' => $content['id']]).'" width=":w" height=":h" frameborder="0" allowfullscreen="allowfullscreen"></iframe>',
Expand All @@ -534,6 +530,7 @@ public function getSettingsForContent($id): array
'nonce' => $content['nonce'],
];


return $settings;
}

Expand Down
1 change: 1 addition & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ protected function getEnvironmentSetUp($app)
$app['config']->set('auth.providers.users.model', User::class);
$app['config']->set('passport.client_uuids', true);
$app['config']->set('hh5p.guzzle', ['handler' => $handlerStack]);
$app['config']->set('hh5p.h5p_export', true);
}

protected function authenticateAsAdmin(): void
Expand Down

0 comments on commit 4b4184e

Please sign in to comment.