Skip to content

Commit

Permalink
Content scripts loading order #38 (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
qunabu authored Jun 28, 2021
1 parent 874a09f commit 1720fea
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 23 deletions.
6 changes: 6 additions & 0 deletions src/Repositories/H5PContentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ public function upload($file, $content = null, $only_upgrade = null, $disable_h5
$this->hh5pService->getStorage()->savePackage();
// $this->hh5pService->getRepository()->deleteLibraryUsage($content['id']);
$id = $this->hh5pService->getStorage()->contentId;

$content = $this->hh5pService->getCore()->loadContent($id);
$content['metadata']['title'] = $content['title'];

$safe_parameters = $this->hh5pService->getCore()->filterParameters($content);

return H5PContent::findOrFail($id);
} else {
@unlink($this->hh5pService->getRepository()->getUploadedH5pPath());
Expand Down
6 changes: 3 additions & 3 deletions src/Repositories/H5PRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ public function saveLibraryData(&$libraryData, $new = true)
];

$libObj = H5PLibrary::firstOrCreate($library);

$library['libraryId'] = $libObj->id;
$this->deleteLibraryDependencies($library['libraryId']);

Expand Down Expand Up @@ -519,7 +519,7 @@ public function updateContent($content, $contentMainId = null)
} else {
unset($content['params']);
unset($content['library']);

$newContent = H5PContent::create($content);
return $newContent->id;
}
Expand Down Expand Up @@ -889,7 +889,7 @@ public function loadContentDependencies($id, $type = null)
{
$where = $type ? [['content_id', $id], ['dependency_type', $type]] : [['content_id', $id]] ;

$libs = H5PContentLibrary::with('library')->where($where)->get();
$libs = H5PContentLibrary::with('library')->where($where)->orderBy('weight')->get();

return array_map(function ($value) {
return [
Expand Down
41 changes: 21 additions & 20 deletions src/Services/HeadlessH5PService.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class HeadlessH5PService implements HeadlessH5PServiceContract
private H5PEditorAjaxInterface $editorAjaxRepository;
private H5PContentValidator $contentValidator;
private array $config;

public function __construct(
H5PFrameworkInterface $repository,
H5PFileStorage $fileStorage,
Expand All @@ -60,32 +60,32 @@ public function __construct(
$this->editor = $editor;
$this->contentValidator = $contentValidator;
}

public function getEditor():H5peditor
{
return $this->editor;
}

public function getRepository():H5PFrameworkInterface
{
return $this->repository;
}

public function getFileStorage():H5PFileStorage
{
return $this->fileStorage;
}

public function getCore():H5PCore
{
return $this->core;
}

public function getValidator():H5PValidator
{
return $this->validator;
}

public function getStorage():H5PStorage
{
return $this->storage;
Expand All @@ -95,7 +95,7 @@ public function getEditorStorage():H5peditorStorage
{
return $this->editorStorage;
}

public function getContentValidator():H5PContentValidator
{
return $this->contentValidator;
Expand Down Expand Up @@ -281,8 +281,8 @@ public function getEditorSettings($content = null):array
}, $files['styles']);

// Error with scripts order


$settings['contents']["cid-$content"]['scripts'] = $scripts;
$settings['contents']["cid-$content"]['styles'] = $styles;

Expand All @@ -308,7 +308,7 @@ public function getEditorSettings($content = null):array

//$settings = self::get_content_files($settings, $content);
}

return $settings;
}

Expand Down Expand Up @@ -349,10 +349,10 @@ public function getContentSettings($id):array
//$settings['core']['scripts'][] = $config['get_h5peditor_url'].'/language/en.js'; // TODO this lang should vary depending on config

// get settings start

$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'];
Expand Down Expand Up @@ -381,11 +381,12 @@ public function getContentSettings($id):array
// get settings stop

$settings['nonce'] = $settings['contents']["cid-$id"]['nonce'];

$language_script = '/language/'.$config['get_language'].'.js';

$preloaded_dependencies = $this->getCore()->loadContentDependencies($id, 'preloaded');
$files = $this->getCore()->getDependenciesFiles($preloaded_dependencies);

$cid = $settings['contents']["cid-$id"];
$embed = H5PCore::determineEmbedType($cid ['content']['embed_type'] ?? "div", $cid['content']['library']['embedTypes']);

Expand Down Expand Up @@ -419,13 +420,13 @@ public function getContentSettings($id):array
, "http://localhost:1000/h5p/libraries/H5P.Transition-1.0/transition.js?ver=1.0.4"
, "http://localhost:1000/h5p/libraries/H5P.Image-1.1/image.js?ver=1.1.10"
, "http://localhost:1000/h5p/libraries/H5P.Agamotto-1.5/dist/h5p-agamotto.js?ver=1.5.2"];

$settings['contents']["cid-$id"]['scripts'] = $scripts;
$settings['contents']["cid-$id"]['styles'] = $styles;

return $settings;
}


public function deleteLibrary($id):bool
{
Expand Down Expand Up @@ -454,7 +455,7 @@ public function getSettingsForContent($id)
{
$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'];
Expand Down Expand Up @@ -497,7 +498,7 @@ public function uploadFile($contentId, $field, $token, $nonce = null)
if (!$file->isLoaded()) {
throw new H5PException(H5PException::FILE_NOT_FOUND);
}

// Make sure file is valid and mark it for cleanup at a later time
if ($file->validate()) {
$file_id = $this->getFileStorage()->saveFile($file, $contentId);
Expand Down

0 comments on commit 1720fea

Please sign in to comment.