Skip to content

Commit

Permalink
Merge branch 'jorisdugue:master' into upgrade-php-to-8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kdaniel95 authored Nov 11, 2021
2 parents 0ceacb7 + 8da2853 commit 558650e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ services:

studit_h5p.result_storage:
class: Studit\H5PBundle\Service\ResultService
arguments: ['@service_container']
arguments: ['@doctrine.orm.entity_manager']
Studit\H5PBundle\Service\ResultService: '@studit_h5p.result_storage'

Studit\H5PBundle\Command\H5pBundleIncludeAssetsCommand:
Expand Down
30 changes: 12 additions & 18 deletions Service/ResultService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,22 @@


use Doctrine\ORM\EntityManagerInterface;
use Psr\Container\ContainerInterface;
use Studit\H5PBundle\Entity\ContentResult;
use Symfony\Component\HttpFoundation\Request;

class ResultService
{
/**
* @var ContainerInterface
* @var EntityManagerInterface
*/
private $container;
private $em;

/**
* ResultService constructor.
* @param ContainerInterface $container
*/
public function __construct(ContainerInterface $container)
public function __construct(EntityManagerInterface $em)
{
$this->container = $container;
$this->em = $em;
}

/**
Expand All @@ -37,8 +35,8 @@ public function handleRequestFinished(Request $request, $userId)
\H5PCore::ajaxError('Invalid content');
}
// TODO: Fire 'h5p_alter_user_result' event here.
$contentRepo = $this->container->get('doctrine')->getRepository('StuditH5PBundle:Content');
$contentResultRepo = $this->container->get('doctrine')->getRepository('StuditH5PBundle:ContentResult');
$contentRepo = $this->em->getRepository('StuditH5PBundle:Content');
$contentResultRepo = $this->em->getRepository('StuditH5PBundle:ContentResult');
$result = $contentResultRepo->findOneBy(['userId' => $userId, 'content' => $contentId]);
if (!$result) {
$result = new ContentResult($userId);
Expand All @@ -61,11 +59,7 @@ public function handleRequestFinished(Request $request, $userId)
*/
public function removeData($contentId, $dataType, $user, $subContentId)
{
/**
* @var $em EntityManagerInterface
*/
$em = $this->container->get('doctrine');
$ContenUserData = $em->getRepository('StuditH5PBundle:ContentUserData')
$ContentUserData = $this->em->getRepository('StuditH5PBundle:ContentUserData')
->findBy(
[
'subContentId' => $subContentId,
Expand All @@ -74,11 +68,11 @@ public function removeData($contentId, $dataType, $user, $subContentId)
'user' => $user->getId()
]
);
if (count($ContenUserData) > 0){
foreach ($ContenUserData as $content){
$em->remove($content);
if (count($ContentUserData) > 0){
foreach ($ContentUserData as $content){
$this->em->remove($content);
}
$em->flush();
$this->em->flush();
}
}
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"require": {
"php": "^7.2.5 || ^8.0",
"doctrine/orm": "^2.7",
"guzzlehttp/guzzle": "^6.5",
"guzzlehttp/guzzle": "^7.3",
"h5p/h5p-core": "^1.24",
"h5p/h5p-editor": "^1.24",
"symfony/framework-bundle": "~4.0|~5.0",
Expand Down

0 comments on commit 558650e

Please sign in to comment.