|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* For licensing terms, see /license.txt */ |
|
4
|
|
|
|
|
5
|
|
|
namespace Chamilo\CoreBundle\Controller; |
|
6
|
|
|
|
|
7
|
|
|
use Chamilo\CoreBundle\Component\Utils\Glide; |
|
8
|
|
|
use Chamilo\CoreBundle\Entity\Resource\AbstractResource; |
|
9
|
|
|
use Chamilo\CoreBundle\Repository\ResourceFactory; |
|
10
|
|
|
use Chamilo\CoreBundle\Repository\ResourceRepository; |
|
11
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
12
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
|
13
|
|
|
use Vich\UploaderBundle\Storage\FlysystemStorage; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Class AbstractResourceController. |
|
17
|
|
|
*/ |
|
18
|
|
|
abstract class AbstractResourceController extends BaseController |
|
19
|
|
|
{ |
|
20
|
|
|
protected $resourceRepositoryFactory; |
|
21
|
|
|
|
|
22
|
|
|
public function __construct(ResourceFactory $resourceFactory) |
|
23
|
|
|
{ |
|
24
|
|
|
$this->resourceRepositoryFactory = $resourceFactory; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function getRepositoryFromRequest(Request $request): ResourceRepository |
|
28
|
|
|
{ |
|
29
|
|
|
$tool = $request->get('tool'); |
|
30
|
|
|
$type = $request->get('type'); |
|
31
|
|
|
|
|
32
|
|
|
return $this->resourceRepositoryFactory->createRepository($tool, $type); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public static function getSubscribedServices(): array |
|
36
|
|
|
{ |
|
37
|
|
|
$services = parent::getSubscribedServices(); |
|
38
|
|
|
$services['glide'] = Glide::class; |
|
39
|
|
|
//$services['storage'] = FlysystemStorage::class; |
|
40
|
|
|
|
|
41
|
|
|
return $services; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function denyAccessUnlessValidResource(AbstractResource $resource) |
|
45
|
|
|
{ |
|
46
|
|
|
if (null === $resource) { |
|
47
|
|
|
throw new NotFoundHttpException($this->trans('Resource doesn\'t exists.')); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
$resourceNode = $resource->getResourceNode(); |
|
51
|
|
|
|
|
52
|
|
|
if (null === $resourceNode) { |
|
53
|
|
|
throw new NotFoundHttpException($this->trans('Resource doesn\'t have a node.')); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @return Glide |
|
59
|
|
|
*/ |
|
60
|
|
|
public function getGlide() |
|
61
|
|
|
{ |
|
62
|
|
|
return $this->container->get('glide'); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|