Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Improve documentation and functionality #53

Merged
merged 4 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions Core/H5PIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ public function getGenericH5PIntegrationSettings()
'l10n' => ['H5P' => $this->core->getLocalization()],
'hubIsEnabled' => $hubIsEnabled,
'siteUrl' => $this->requestStack->getMainRequest()->getUri(),
'librairyConfig' => $this->core->h5pF->getLibraryConfig()
'libraryConfig' => $this->core->h5pF->getLibraryConfig(),
'reportingIsEnabled' => $this->core->h5pF->getOption('enable_lrs_content_type', false) === 1
];
if (is_object($user)) {
$settings['user'] = [
Expand All @@ -126,10 +127,10 @@ public function getGenericH5PIntegrationSettings()
/**
* Get a list with prepared asset links that is used when JS loads components.
*
* @param null|array $keys [$keys] Optional keys, first for JS second for CSS.
* @param array|null $keys [$keys] Optional keys, first for JS second for CSS.
* @return array
*/
public function getCoreAssets($keys = null): array
public function getCoreAssets(?array $keys = null): array
{
if (empty($keys)) {
$keys = ['scripts', 'styles'];
Expand All @@ -141,11 +142,11 @@ public function getCoreAssets($keys = null): array
];
// Add all core scripts
foreach (\H5PCore::$scripts as $script) {
$assets[$keys[0]][] = "{$this->options->getH5PAssetPath()}/h5p-core/{$script}";
$assets[$keys[0]][] = "{$this->options->getH5PAssetPath()}/h5p-core/$script";
}
// and styles
foreach (\H5PCore::$styles as $style) {
$assets[$keys[1]][] = "{$this->options->getH5PAssetPath()}/h5p-core/{$style}";
$assets[$keys[1]][] = "{$this->options->getH5PAssetPath()}/h5p-core/$style";
}
return $assets;
}
Expand Down Expand Up @@ -284,7 +285,7 @@ private function getAssets($collection, $prefix, $exceptions = null): array
if ($exceptions && in_array($item, $exceptions)) {
continue;
}
$assets[] = "{$prefix}{$item}{$cacheBuster}";
$assets[] = "$prefix$item$cacheBuster";
}
return $assets;
}
Expand All @@ -297,7 +298,7 @@ private function getAssets($collection, $prefix, $exceptions = null): array
public function getCacheBuster(): string
{
$cache_buster = \H5PCore::$coreApi['majorVersion'] . '.' . \H5PCore::$coreApi['minorVersion'];
return $cache_buster ? "?={$cache_buster}" : '';
return $cache_buster ? "?=$cache_buster" : '';
}

/**
Expand Down
24 changes: 11 additions & 13 deletions Core/H5PSymfony.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,16 @@ class H5PSymfony implements \H5PFrameworkInterface
* @param RouterInterface $router
*/
public function __construct(
H5POptions $options,
EditorStorage $editorStorage,
TokenStorageInterface $tokenStorage,
EntityManagerInterface $manager,
?Session $session,
?RequestStack $requestStack,
H5POptions $options,
EditorStorage $editorStorage,
TokenStorageInterface $tokenStorage,
EntityManagerInterface $manager,
?Session $session,
?RequestStack $requestStack,
AuthorizationCheckerInterface $authorizationChecker,
EventDispatcherInterface $eventDispatcher,
RouterInterface $router
)
{
EventDispatcherInterface $eventDispatcher,
RouterInterface $router
) {
$this->options = $options;
$this->editorStorage = $editorStorage;
$this->tokenStorage = $tokenStorage;
Expand Down Expand Up @@ -158,8 +157,7 @@ public function fetchExternalData(
$headers = [],
$files = [],
$method = 'POST'
)
{
) {
$options = [];
if (!empty($data)) {
$options['headers'] = ['Content-Type' => 'application/x-www-form-urlencoded'];
Expand Down Expand Up @@ -893,7 +891,7 @@ public function getOption($name, $default = null)
try {
// return default if db/table still not created
return $this->options->getOption($name, $default);
} catch (ConnectionException|TableNotFoundException $e) {
} catch (ConnectionException | TableNotFoundException $e) {
return $default;
}
}
Expand Down
4 changes: 2 additions & 2 deletions Core/H5PUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct(TokenStorageInterface $tokenStorage)
* Fetch the current user if not present return the anonymous user
* @return string|UserInterface|null
*/
public function getCurrentOrAnonymousUser()
protected function getCurrentOrAnonymousUser()
{
$token = $this->tokenStorage->getToken();

Expand All @@ -36,7 +36,7 @@ public function getCurrentOrAnonymousUser()
* @param UserInterface|null $user
* @return string|null|integer
*/
public function getUserId(?UserInterface $user)
protected function getUserId(?UserInterface $user)
{
if ($user !== null) {
if (method_exists($user, 'getId')) {
Expand Down
4 changes: 2 additions & 2 deletions Entity/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ public function setParameters(string $parameters)
$this->parameters = $parameters;
}
/**
* @return string
* @return string|null
*/
public function getFilteredParameters(): string
public function getFilteredParameters(): ?string
{
return $this->filteredParameters;
}
Expand Down
17 changes: 8 additions & 9 deletions Service/ResultService.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,14 @@ public function handleRequestFinished(Request $request, $userId)
*/
public function removeData($contentId, $dataType, $user, $subContentId)
{
$ContentUserData = $this->em->getRepository('Studit\H5PBundle\Entity\ContentUserData')
->findBy(
[
'subContentId' => $subContentId,
'mainContent' => $contentId,
'dataId' => $dataType,
'user' => $user->getId()
]
);
$ContentUserData = $this->em->getRepository('Studit\H5PBundle\Entity\ContentUserData')->findBy(
[
'subContentId' => $subContentId,
'mainContent' => $contentId,
'dataId' => $dataType,
'user' => $user->getId()
]
);
if (count($ContentUserData) > 0) {
foreach ($ContentUserData as $content) {
$this->em->remove($content);
Expand Down
10 changes: 4 additions & 6 deletions Twig/H5PExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@ public function __construct(H5PIntegration $h5pIntegration)
$this->h5pIntegration = $h5pIntegration;
}

public function getFilters()
public function getFilters(): array
{
return array(
new TwigFilter('h5pCacheBuster', array($this, 'getH5PCacheBuster')),
);
return [new TwigFilter('h5pCacheBuster', [$this, 'getH5PCacheBuster'])];
}

public function getH5PCacheBuster($script)
public function getH5PCacheBuster($script): string
{
return $script . $this->h5pIntegration->getCacheBuster();
}
Expand All @@ -38,7 +36,7 @@ public function getH5PCacheBuster($script)
*
* @return string The extension name
*/
public function getName()
public function getName(): string
{
return 'h5p_extension';
}
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jorisdugue/h5p-bundle",
"version": "2.1.0",
"version": "2.2.0",
"type": "symfony-bundle",
"description": "H5P Bundle for Symfony 5, 6 and Symfony 7",
"keywords": [
Expand Down Expand Up @@ -31,7 +31,7 @@
"php": ">= 7.2.5",
"doctrine/orm": "^2.14.1",
"guzzlehttp/guzzle": "^7.8",
"h5p/h5p-core": "dev-master#6217d57",
"h5p/h5p-core": "1.26",
"h5p/h5p-editor": "^1.25",
"symfony/framework-bundle": "~5.0|~6.0|~7.0",
"symfony/serializer": "~5.0|~6.0|~7.0",
Expand Down
Loading