WIP: Fix course illustration using resources

pull/3064/head
Julio Montoya 5 years ago
parent 46c0b6f621
commit 0c649e4ee2
  1. 19
      src/CoreBundle/Entity/Illustration.php
  2. 21
      src/CoreBundle/Repository/IllustrationRepository.php
  3. 1
      src/CoreBundle/Repository/ResourceRepository.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();

@ -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);

@ -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();

Loading…
Cancel
Save