Resources: Update entities

Change getIllustrationUrl signature to allow user in illustrationRepo
pull/3733/head
Julio Montoya 4 years ago
parent 3d75e664e8
commit 33021ff34b
  1. 10
      src/CoreBundle/Controller/AccountController.php
  2. 1
      src/CoreBundle/Controller/ResourceApiController.php
  3. 9
      src/CoreBundle/Controller/ResourceController.php
  4. 2
      src/CoreBundle/Entity/AbstractResource.php
  5. 6
      src/CoreBundle/Entity/ResourceInterface.php
  6. 839
      src/CoreBundle/Entity/User.php
  7. 4
      src/CoreBundle/Repository/Node/IllustrationRepository.php

@ -41,7 +41,7 @@ class AccountController extends BaseController
/**
* @Route("/edit", methods={"GET", "POST"}, name="chamilo_core_account_edit")
*/
public function editAction(Request $request, UserRepository $userRepository, IllustrationRepository $illustrationRepository)
public function editAction(Request $request, UserRepository $userRepository, IllustrationRepository $illustrationRepo)
{
$user = $this->getUser();
@ -51,20 +51,14 @@ class AccountController extends BaseController
$form = $this->createForm(ProfileType::class, $user);
$form->setData($user);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$illustration = $form['illustration']->getData();
if ($illustration) {
$file = $illustrationRepository->addIllustrationToUser($this->getUser(), $illustration);
$em = $illustrationRepository->getEntityManager();
$em->persist($file);
$em->flush();
$illustrationRepo->addIllustrationToUser($this->getUser(), $illustration);
}
$userRepository->updateUser($user);
$this->addFlash('success', $this->trans('Updated'));
$url = $this->generateUrl('chamilo_core_account_home', ['username' => $user->getUsername()]);

@ -22,6 +22,7 @@ use Symfony\Component\HttpFoundation\Response;
* Class ResourceApiController.
* RouteResource("Resource").
*
* @deprecated experimental code
* debug api routes with: bin/console debug:router | grep api
*/
class ResourceApiController extends AbstractController implements CourseControllerInterface

@ -215,7 +215,7 @@ class ResourceController extends AbstractResourceController implements CourseCon
*
* @Route("/{tool}/{type}/{id}/edit", methods={"GET", "POST"})
*/
public function editAction(Request $request, IllustrationRepository $illustrationRepository): Response
public function editAction(Request $request, IllustrationRepository $illustrationRepo): Response
{
$resourceNodeId = $request->get('id');
@ -271,15 +271,12 @@ class ResourceController extends AbstractResourceController implements CourseCon
if ($form->has('illustration')) {
$illustration = $form->get('illustration')->getData();
if ($illustration) {
$file = $illustrationRepository->addIllustration($newResource, $this->getUser(), $illustration);
$em = $illustrationRepository->getEntityManager();
$em->persist($file);
$em->flush();
$file = $illustrationRepo->addIllustration($newResource, $this->getUser(), $illustration);
$illustrationRepo->update($file);
}
}
$this->addFlash('success', $this->trans('Updated'));
$resourceNodeParentId = $newResource->getResourceNode()->getParent()->getId();
$routeParams['id'] = $resourceNodeParentId;

@ -331,7 +331,7 @@ abstract class AbstractResource
return $this;
}
public function setResourceNode(ResourceNode $resourceNode): self
public function setResourceNode(ResourceNode $resourceNode): ResourceInterface
{
$this->resourceNode = $resourceNode;

@ -4,8 +4,6 @@
namespace Chamilo\CoreBundle\Entity;
use Chamilo\CourseBundle\Entity\CGroup;
/**
* Interface ResourceInterface.
*/
@ -23,9 +21,9 @@ interface ResourceInterface
public function getResourceNode(): ResourceNode;
public function setResourceNode(ResourceNode $resourceNode): AbstractResource;
public function setResourceNode(ResourceNode $resourceNode): ResourceInterface;
public function setParent(AbstractResource $parent);
public function addCourseLink(Course $course, Session $session = null, CGroup $group = null, int $visibility);
//public function addCourseLink(Course $course, Session $session = null, CGroup $group = null, int $visibility);
}

File diff suppressed because it is too large Load Diff

@ -8,6 +8,7 @@ use Chamilo\CoreBundle\Entity\AbstractResource;
use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Entity\Illustration;
use Chamilo\CoreBundle\Entity\ResourceFile;
use Chamilo\CoreBundle\Entity\ResourceInterface;
use Chamilo\CoreBundle\Entity\ResourceNode;
use Chamilo\CoreBundle\Entity\Session;
use Chamilo\CoreBundle\Entity\User;
@ -105,6 +106,7 @@ final class IllustrationRepository extends ResourceRepository implements GridInt
}
$file = $this->addFile($illustration, $uploadFile);
$em->persist($file);
$em->flush();
return $file;
@ -142,7 +144,7 @@ final class IllustrationRepository extends ResourceRepository implements GridInt
/**
* @param string $filter See: services.yaml parameter "glide_media_filters" to see the list of filters.
*/
public function getIllustrationUrl(AbstractResource $resource, string $filter = ''): string
public function getIllustrationUrl(ResourceInterface $resource, string $filter = ''): string
{
return $this->getIllustrationUrlFromNode($resource->getResourceNode(), $filter);
}

Loading…
Cancel
Save