Use resource node repository

pull/3741/head
Julio Montoya 4 years ago
parent 7d0dcff0b5
commit 0957e8c44b
  1. 15
      src/CoreBundle/Controller/ResourceController.php
  2. 5
      src/CoreBundle/Traits/ControllerTrait.php
  3. 8
      src/CoreBundle/Traits/ResourceControllerTrait.php

@ -495,7 +495,7 @@ class ResourceController extends AbstractResourceController implements CourseCon
$em = $this->getDoctrine();
/** @var ResourceNode $resourceNode */
$resourceNode = $em->getRepository(ResourceNode::class)->find($id);
$resourceNode = $this->getResourceNodeRepository()->find($id);
if (null === $resourceNode) {
throw new FileNotFoundException('Resource not found');
@ -536,7 +536,7 @@ class ResourceController extends AbstractResourceController implements CourseCon
$filter = $request->get('filter'); // See filters definitions in /config/services.yml
$em = $this->getDoctrine();
/** @var ResourceNode $resourceNode */
$resourceNode = $em->getRepository(ResourceNode::class)->find($id);
$resourceNode = $this->getResourceNodeRepository()->find($id);
if (null === $resourceNode) {
throw new FileNotFoundException('Resource not found');
@ -563,7 +563,7 @@ class ResourceController extends AbstractResourceController implements CourseCon
$id = $request->get('id');
$em = $this->getDoctrine();
/** @var ResourceNode $resourceNode */
$resourceNode = $em->getRepository(ResourceNode::class)->find($id);
$resourceNode = $this->getResourceNodeRepository()->find($id);
if (null === $resourceNode) {
throw new FileNotFoundException('Resource not found');
@ -591,7 +591,7 @@ class ResourceController extends AbstractResourceController implements CourseCon
$em = $this->getDoctrine();
/** @var ResourceNode $resourceNode */
$resourceNode = $em->getRepository(ResourceNode::class)->find($id);
$resourceNode = $this->getResourceNodeRepository()->find($id);
if (null === $resourceNode) {
throw new FileNotFoundException('Resource not found');
@ -701,7 +701,7 @@ class ResourceController extends AbstractResourceController implements CourseCon
$this->trans('Unauthorised view access to resource')
);
$repo = $this->getRepositoryFromRequest($request);
//$repo = $this->getRepositoryFromRequest($request);
$resourceFile = $resourceNode->getResourceFile();
if (!$resourceFile) {
@ -710,6 +710,7 @@ class ResourceController extends AbstractResourceController implements CourseCon
$fileName = $resourceNode->getResourceFile()->getOriginalName();
$mimeType = $resourceFile->getMimeType();
$resourceNodeRepo = $this->getResourceNodeRepository();
switch ($mode) {
case 'download':
@ -737,7 +738,7 @@ class ResourceController extends AbstractResourceController implements CourseCon
$params['crop'] = $crop;
}
$fileName = $repo->getResourceNodeRepository()->getFilename($resourceFile);
$fileName = $resourceNodeRepo->getFilename($resourceFile);
return $server->getImageResponse($fileName, $params);
}
@ -745,7 +746,7 @@ class ResourceController extends AbstractResourceController implements CourseCon
break;
}
$stream = $repo->getResourceNodeFileStream($resourceNode);
$stream = $resourceNodeRepo->getResourceNodeFileStream($resourceNode);
$response = new StreamedResponse(
function () use ($stream): void {

@ -8,6 +8,7 @@ use Chamilo\CoreBundle\Component\Utils\Glide;
use Chamilo\CoreBundle\Manager\SettingsManager;
use Chamilo\CoreBundle\Repository\Node\IllustrationRepository;
use Chamilo\CoreBundle\Repository\ResourceFactory;
use Chamilo\CoreBundle\Repository\ResourceNodeRepository;
use Chamilo\CourseBundle\Repository\CAnnouncementAttachmentRepository;
use Chamilo\CourseBundle\Repository\CAnnouncementRepository;
use Chamilo\CourseBundle\Repository\CAttendanceRepository;
@ -32,7 +33,6 @@ trait ControllerTrait
{
$services = parent::getSubscribedServices();
$services['translator'] = TranslatorInterface::class;
//$services['resource_factory'] = ResourceFactory::class;
$services['glide'] = Glide::class;
$services['chamilo.settings.manager'] = SettingsManager::class;
$services['chamilo_settings.form_factory.settings'] = SettingsFormFactory::class;
@ -41,7 +41,8 @@ trait ControllerTrait
The following classes are needed in order to load the resources files when using the /r/ path
For example: http://my.chamilomaster.net/r/agenda/event_attachments/96/download?cid=1&sid=0&gid=0
*/
$services[] = ResourceFactory::class;
$services[] = ResourceNodeRepository::class;
$services[] = CAnnouncementRepository::class;
$services[] = CAnnouncementAttachmentRepository::class;
$services[] = CAttendanceRepository::class;

@ -9,6 +9,7 @@ use Chamilo\CoreBundle\Entity\ResourceInterface;
use Chamilo\CoreBundle\Entity\ResourceNode;
use Chamilo\CoreBundle\Entity\User;
use Chamilo\CoreBundle\Repository\ResourceFactory;
use Chamilo\CoreBundle\Repository\ResourceNodeRepository;
use Chamilo\CoreBundle\Repository\ResourceRepository;
use Doctrine\ORM\EntityNotFoundException;
use Symfony\Component\HttpFoundation\Request;
@ -24,9 +25,14 @@ trait ResourceControllerTrait
return $this->getRepository($tool, $type);
}
public function getResourceNodeRepository(): ResourceNodeRepository
{
return $this->container->get(ResourceNodeRepository::class);
}
public function getResourceRepositoryFactory(): ResourceFactory
{
return $this->container->get('resource_factory');
return $this->container->get(ResourceFactory::class);
}
public function getRepository($tool, $type): ResourceRepository

Loading…
Cancel
Save