Skip to content

Commit

Permalink
Merge pull request #23 from Emmedy/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
nieck authored Sep 16, 2024
2 parents f887ec4 + 1f036a8 commit 19f13db
Show file tree
Hide file tree
Showing 42 changed files with 741 additions and 403 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ public/index.php
.idea/*
.idea
composer.lock
.DS_Store
.thumbs
16 changes: 8 additions & 8 deletions Command/H5pBundleCleanUpFilesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

class H5pBundleCleanUpFilesCommand extends Command
{

/**
* @var H5POptions $h5POptions
*/
Expand All @@ -23,22 +22,23 @@ public function __construct(H5POptions $h5POptions)
}

protected static $defaultName = 'h5p-bundle:cleanup-files';
protected function configure()

protected function configure(): void
{
$this
->addArgument('location', InputArgument::OPTIONAL, 'The location of the files to clean up.')
->setDescription('Include the assets from the h5p vendor bundle in the public resources directory of this bundle.');
;
->setDescription(
'Include the assets from the h5p vendor bundle in the public resources directory of this bundle.'
);
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->cleanupFiles($input);

return 0;
$this->cleanupFiles($input);
return 0;
}

private function cleanupFiles(InputInterface $input)
private function cleanupFiles(InputInterface $input): void
{
$location = $input->getArgument('location');
if (!$location) {
Expand Down
26 changes: 12 additions & 14 deletions Command/H5pBundleIncludeAssetsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ class H5pBundleIncludeAssetsCommand extends Command
protected static $defaultName = 'h5p-bundle:IncludeAssetsCommand';
/** KernelInterface $appKernel */
private $appKernel;

/**
* @param KernelInterface $appKernel
*/
public function __construct(KernelInterface $appKernel)
{
$this->appKernel = $appKernel;
Expand All @@ -25,31 +29,26 @@ public function __construct(KernelInterface $appKernel)
protected function configure()
{
$this
->setDescription('Include the assets from the h5p vendor bundle in the public resources directory of this bundle.')
->setDescription(
'Include the assets from the h5p vendor bundle in the public resources directory of this bundle.'
)
->addOption('copy', 'c', InputOption::VALUE_NONE, 'Copy files')
;
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->includeAssets($input->getOption('copy') ?? false);

return 0;
}

private function includeAssets(bool $copy)
private function includeAssets(bool $copy): void
{
//get dir of vendor H5P

$fromDir = $this->appKernel->getProjectDir()."/vendor/h5p/";
$fromDir = $this->appKernel->getProjectDir() . "/vendor/h5p/";
//call service
//$toDir = $this->appKernel->getProjectDir().'/vendor/emmedy/h5p-bundle/public/h5p/';
$toDir = $this->appKernel->getProjectDir().'/public/bundles/emmedyh5p/h5p/';

//$toDir = new FileLocator($fromDir);
// $test = $fileLocator->locate('@EmmedyH5PBundle');

//$toDir = $fileLocator->locate();
$toDir = $this->appKernel->getProjectDir() . '/public/bundles/emmedyh5p/h5p/';

$coreSubDir = "h5p-core/";
$coreDirs = ["fonts", "images", "js", "styles"];
Expand All @@ -58,7 +57,6 @@ private function includeAssets(bool $copy)
$editorSubDir = "h5p-editor/";
$editorDirs = ["ckeditor", "images", "language", "libs", "scripts", "styles"];
$this->createFiles($fromDir, $toDir, $editorSubDir, $editorDirs, $copy);

}

private function createFiles($fromDir, $toDir, $subDir, $subDirs, $copy)
Expand All @@ -70,7 +68,7 @@ private function createFiles($fromDir, $toDir, $subDir, $subDirs, $copy)
$copy
? $this->recurseCopy($src, $dist)
: symlink($src, $dist);
}
}
}

private function recurseCopy($src, $dst)
Expand Down
50 changes: 30 additions & 20 deletions Controller/H5PAJAXController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Exception;
use Emmedy\H5PBundle\Core\H5POptions;
use Emmedy\H5PBundle\Event\H5PEvents;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -29,9 +28,9 @@ public function __construct(\H5peditor $h5peditor, H5POptions $h5poption)
*
* @Route("/libraries/")
* @param Request $request
* @return string
* @return JsonResponse
*/
public function librariesCallback(Request $request)
public function librariesCallback(Request $request): JsonResponse
{
ob_start();

Expand All @@ -50,16 +49,34 @@ public function librariesCallback(Request $request)

/**
* Callback that returns the content type cache
*
* @Route("/content-type-cache/")
*/
public function contentTypeCacheCallback()
public function contentTypeCacheCallback(): JsonResponse
{
ob_start();

$editor = $this->h5peditor;
$editor->ajax->action(\H5PEditorEndpoints::CONTENT_TYPE_CACHE);

$output = ob_get_contents();
ob_end_clean();
return $this->json(json_decode($output, true));
}

/**
* Callback that return the content hub metadata cache
* @Route("/content-hub-metadata-cache")
* @param Request $request
* @return JsonResponse
*/
public function contentHubMetadataCache(Request $request): JsonResponse
{
$locale = $request->getLocale() != null ? $request->getLocale() : 'en';
ob_start();

$editor = $this->h5peditor;
$editor->ajax->action(\H5PEditorEndpoints::CONTENT_HUB_METADATA_CACHE, $locale);

$output = ob_get_contents();
ob_end_clean();

Expand All @@ -74,16 +91,13 @@ public function contentTypeCacheCallback()
*
* @return JsonResponse
*/
public function TranslationsCallback(Request $request)
public function TranslationsCallback(Request $request): JsonResponse
{
ob_start();

$editor = $this->h5peditor;
$language = $request->get('language');
$editor->ajax->action(
\H5PEditorEndpoints::TRANSLATIONS,
$language
);
$editor->ajax->action(\H5PEditorEndpoints::TRANSLATIONS, $language);

$output = ob_get_contents();
ob_end_clean();
Expand All @@ -99,7 +113,7 @@ public function TranslationsCallback(Request $request)
* @return JsonResponse
* @Route("/library-install/")
*/
public function libraryInstallCallback(Request $request)
public function libraryInstallCallback(Request $request): JsonResponse
{
ob_start();

Expand All @@ -122,7 +136,7 @@ public function libraryInstallCallback(Request $request)
* @param Request $request
* @return JsonResponse
*/
private function libraryCallback(Request $request)
private function libraryCallback(Request $request): JsonResponse
{
ob_start();

Expand All @@ -135,14 +149,10 @@ private function libraryCallback(Request $request)
$request->get('majorVersion'),
$request->get('minorVersion'),
$locale,
$this->h5POptions->getOption('storage_dir'),
$this->h5POptions->getRelativeH5PPath(),
'',
$locale
);
/*new H5PEvents('library', NULL, NULL, NULL,
$request->get('machineName'), $request->get('majorVersion') . '.' . $request->get('minorVersion'),
$this->getUser() != null ? $this->getUser()->getId() : 0, $this->getDoctrine()->getManager()
);*/

$output = ob_get_contents();
ob_end_clean();
Expand All @@ -159,7 +169,7 @@ private function libraryCallback(Request $request)
* @throws Exception
* @Route("/library-upload/")
*/
public function libraryUploadCallback(Request $request)
public function libraryUploadCallback(Request $request): JsonResponse
{
ob_start();

Expand Down Expand Up @@ -192,7 +202,7 @@ public function libraryUploadCallback(Request $request)
* @return JsonResponse
* @Route("/files/")
*/
public function filesCallback(Request $request)
public function filesCallback(Request $request): JsonResponse
{
ob_start();

Expand All @@ -217,7 +227,7 @@ public function filesCallback(Request $request)
* @return JsonResponse
* @Route("/filter/")
*/
public function filterCallback(Request $request)
public function filterCallback(Request $request): JsonResponse
{
ob_start();

Expand Down
41 changes: 33 additions & 8 deletions Controller/H5PController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
*/
class H5PController extends AbstractController
{

protected $h5PIntegrations;
protected $libraryStorage;
protected $entityManager;
Expand All @@ -39,18 +38,21 @@ public function __construct(
* List of all H5P content
* @Route("list")
*/
public function listAction()
public function listAction(): Response
{
$contents = $this->entityManager->getRepository('Emmedy\H5PBundle\Entity\Content')->findAll();
return $this->render('@EmmedyH5P/list.html.twig', ['contents' => $contents]);
}

/**
* Show content of H5P created by user
* @Route("show/{content}")
* @param Content $content
* @param \H5PCore $h5PCore
* @param H5POptions $h5POptions
* @return Response
*/
public function showAction(Content $content, \H5PCore $h5PCore, H5POptions $h5POptions)
public function showAction(Content $content, \H5PCore $h5PCore, H5POptions $h5POptions): Response
{
$h5pIntegration = $this->h5PIntegrations->getGenericH5PIntegrationSettings();
$contentIdStr = 'cid-' . $content->getId();
Expand All @@ -70,7 +72,15 @@ public function showAction(Content $content, \H5PCore $h5PCore, H5POptions $h5PO
$h5pIntegration['contents'][$contentIdStr]['scripts'] = $jsFilePaths;
$h5pIntegration['contents'][$contentIdStr]['styles'] = $cssFilePaths;
}
return $this->render('@EmmedyH5P/show.html.twig', ['contentId' => $content->getId(), 'isFrame' => $content->getLibrary()->isFrame(), 'h5pIntegration' => $h5pIntegration, 'files' => $files]);
return $this->render(
'@EmmedyH5P/show.html.twig',
[
'contentId' => $content->getId(),
'isFrame' => $content->getLibrary()->isFrame(),
'h5pIntegration' => $h5pIntegration,
'files' => $files
]
);
}

/**
Expand All @@ -80,7 +90,7 @@ public function showAction(Content $content, \H5PCore $h5PCore, H5POptions $h5PO
*/
public function newAction(Request $request)
{
return $this->handleRequest($request );
return $this->handleRequest($request);
}

/**
Expand All @@ -93,6 +103,12 @@ public function editAction(Request $request, Content $content)
{
return $this->handleRequest($request, $content);
}

/**
* @param Request $request
* @param Content|null $content
* @return RedirectResponse|Response
*/
private function handleRequest(Request $request, Content $content = null)
{
$formData = null;
Expand All @@ -110,19 +126,28 @@ private function handleRequest(Request $request, Content $content = null)
return $this->redirectToRoute('emmedy_h5p_h5p_show', ['content' => $contentId]);
}
$h5pIntegration = $this->h5PIntegrations->getEditorIntegrationSettings($content ? $content->getId() : null);
return $this->render('@EmmedyH5P/edit.html.twig', ['form' => $form->createView(), 'h5pIntegration' => $h5pIntegration, 'h5pCoreTranslations' => $this->h5PIntegrations->getTranslationFilePath()]);
return $this->render(
'@EmmedyH5P/edit.html.twig',
[
'form' => $form->createView(),
'h5pIntegration' => $h5pIntegration,
'h5pCoreTranslations' => $this->h5PIntegrations->getTranslationFilePath()
]
);
}

/**
* @Route("delete/{contentId}")
* @param integer $contentId
* @param \H5PStorage $h5PStorage
* @return RedirectResponse
*/
public function deleteAction($contentId, \H5PStorage $h5PStorage)
public function deleteAction($contentId, \H5PStorage $h5PStorage): RedirectResponse
{
$h5PStorage->deletePackage([
'id' => $contentId,
'slug' => 'interactive-content'
]);
return $this->redirectToRoute('emmedy_h5p_h5p_list');
}
}
}
Loading

0 comments on commit 19f13db

Please sign in to comment.