From 0c649e4ee2a5de7baf10122eb22051155ef8b33a Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Fri, 22 Nov 2019 15:30:33 +0100 Subject: [PATCH] WIP: Fix course illustration using resources --- src/CoreBundle/Entity/Illustration.php | 19 +++++++++++++++++ .../Repository/IllustrationRepository.php | 21 +++++++++++++------ .../Repository/ResourceRepository.php | 1 + 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/CoreBundle/Entity/Illustration.php b/src/CoreBundle/Entity/Illustration.php index efd294dffd..18a645e205 100644 --- a/src/CoreBundle/Entity/Illustration.php +++ b/src/CoreBundle/Entity/Illustration.php @@ -42,11 +42,19 @@ class Illustration extends AbstractResource implements ResourceInterface $this->name = 'illustration'; } + /** + * @return int + */ public function getId(): int { return $this->id; } + /** + * @param int $id + * + * @return Illustration + */ public function setId(int $id): Illustration { $this->id = $id; @@ -54,11 +62,19 @@ class Illustration extends AbstractResource implements ResourceInterface return $this; } + /** + * @return string + */ public function getName(): string { return $this->name; } + /** + * @param string $name + * + * @return Illustration + */ public function setName(string $name): Illustration { $this->name = $name; @@ -74,6 +90,9 @@ class Illustration extends AbstractResource implements ResourceInterface return $this->getId(); } + /** + * @return string + */ public function getResourceName(): string { return $this->getName(); diff --git a/src/CoreBundle/Repository/IllustrationRepository.php b/src/CoreBundle/Repository/IllustrationRepository.php index ca89aad4ec..b61c1d632c 100644 --- a/src/CoreBundle/Repository/IllustrationRepository.php +++ b/src/CoreBundle/Repository/IllustrationRepository.php @@ -16,9 +16,11 @@ use Symfony\Component\HttpFoundation\File\UploadedFile; class IllustrationRepository extends ResourceRepository { /** - * @param UploadedFile $uploadFile + * @param AbstractResource $resource + * @param User $user + * @param $uploadFile * - * @return ResourceFile + * @return ResourceFile|null */ public function addIllustration(AbstractResource $resource, User $user, $uploadFile): ?ResourceFile { @@ -28,15 +30,19 @@ class IllustrationRepository extends ResourceRepository if ($illustrationNode === null) { $illustration = new Illustration(); $em->persist($illustration); - $illustrationNode = $this->addResourceNode($illustration, $user, $resource); - //$this->addResourceToEveryone($illustrationNode); + $this->addResourceNode($illustration, $user, $resource); + } else { + $illustration = $this->repository->findOneBy(['resourceNode' => $illustrationNode]); } - return $this->addFile($illustrationNode, $uploadFile); + //$this->addResourceToEveryone($illustrationNode); + return $this->addFile($illustration, $uploadFile); } /** - * @return ResourceNode + * @param AbstractResource $resource + * + * @return ResourceNode|null */ public function getIllustrationNodeFromResource(AbstractResource $resource): ?ResourceNode { @@ -51,6 +57,9 @@ class IllustrationRepository extends ResourceRepository return $node; } + /** + * @param AbstractResource $resource + */ public function deleteIllustration(AbstractResource $resource) { $node = $this->getIllustrationNodeFromResource($resource); diff --git a/src/CoreBundle/Repository/ResourceRepository.php b/src/CoreBundle/Repository/ResourceRepository.php index c551cfd413..a7057748d8 100644 --- a/src/CoreBundle/Repository/ResourceRepository.php +++ b/src/CoreBundle/Repository/ResourceRepository.php @@ -262,6 +262,7 @@ class ResourceRepository extends EntityRepository $resourceFile->setFile($file); $resourceFile->setName($resource->getResourceName()); $em->persist($resourceFile); + $resourceNode->setResourceFile($resourceFile); $em->persist($resourceNode); $em->flush();