Completed
Push — master ( 82664b...176635 )
by Julito
88:10 queued 58:03
created

ResourceController::getGroupFile()   A

Complexity

Conditions 2
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 3
nop 3
dl 12
loc 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
namespace Chamilo\CoreBundle\Controller;
5
6
use Symfony\Component\HttpFoundation\BinaryFileResponse;
7
8
/**
9
 * Class ResourceController
10
 * author Julio Montoya <[email protected]>
11
 * @package Chamilo\CoreBundle\Controller
12
 */
13
class ResourceController extends BaseController
14
{
15
    /**
16
     * Gets a document from the courses/MATHS/document/file.jpg to the user
17
     * @todo check permissions
18
     * @param string $course
19
     * @param string $file
20
     * @return \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
21
     */
22
    public function getDocumentAction($course, $file)
23
    {
24
        try {
25
            $fs = $this->container->get('oneup_flysystem.course_filesystem');
26
            $path = $course.'/document/'.$file;
27
28
            if (!$fs->has($path)) {
29
                return $this->abort();
30
            }
31
32
            /** @var \League\Flysystem\Adapter\Local $adapter */
33
            $adapter = $fs->getAdapter();
34
            $filePath = $adapter->getPathPrefix().$path;
35
36
            return new BinaryFileResponse($filePath);
37
38
        } catch (\InvalidArgumentException $e) {
39
            return $this->abort();
40
        }
41
    }
42
43
    /**
44
     * Gets a document from the data/courses/MATHS/document/file.jpg to the user
45
     * @todo check permissions
46
     * @param Application $app
47
     * @param string $courseCode
48
     * @param string $file
49
     * @return \Symfony\Component\HttpFoundation\BinaryFileResponse|void
50
     */
51
    public function getCourseUploadFileAction(
52
        Application $app,
53
        $courseCode,
54
        $file
55
    ) {
56
        try {
57
            $file = $app['chamilo.filesystem']->getCourseUploadFile(
58
                $courseCode,
59
                $file
60
            );
61
62
            return $app->sendFile($file->getPathname());
63
        } catch (\InvalidArgumentException $e) {
64
            return $app->abort(404, 'File not found');
65
        }
66
    }
67
68
    /**
69
     * Gets a document from the data/courses/MATHS/scorm/file.jpg to the user
70
     * @todo check permissions
71
     * @param Application $app
72
     * @param string $courseCode
73
     * @param string $file
74
     * @return \Symfony\Component\HttpFoundation\BinaryFileResponse|void
75
     */
76
    public function getScormDocumentAction(Application $app, $courseCode, $file)
77
    {
78
        try {
79
            $file = $app['chamilo.filesystem']->getCourseScormDocument(
80
                $courseCode,
81
                $file
82
            );
83
84
            return $app->sendFile($file->getPathname());
85
        } catch (\InvalidArgumentException $e) {
86
            return $app->abort(404, 'File not found');
87
        }
88
    }
89
90
    /**
91
     * Gets a document from the data/default_platform_document/* folder
92
     * @param Application $app
93
     * @param string $file
94
     * @return \Symfony\Component\HttpFoundation\BinaryFileResponse|void
95
     */
96 View Code Duplication
    public function getDefaultCourseDocumentAction(Application $app, $file)
97
    {
98
        try {
99
            $file = $app['chamilo.filesystem']->get(
100
                'default_course_document/'.$file
101
            );
102
103
            return $app->sendFile($file->getPathname());
104
        } catch (\InvalidArgumentException $e) {
105
            return $app->abort(404, 'File not found');
106
        }
107
    }
108
109
    /**
110
     * @param Application $app
111
     * @param $groupId
112
     * @param $file
113
     * @return \Symfony\Component\HttpFoundation\BinaryFileResponse|void
114
     */
115 View Code Duplication
    public function getGroupFile(Application $app, $groupId, $file)
116
    {
117
        try {
118
            $file = $app['chamilo.filesystem']->get(
119
                'upload/groups/'.$groupId.'/'.$file
120
            );
121
122
            return $app->sendFile($file->getPathname());
123
        } catch (\InvalidArgumentException $e) {
124
            return $app->abort(404, 'File not found');
125
        }
126
    }
127
128
    /**
129
     * @param Application $app
130
     * @param $file
131
     * @return \Symfony\Component\HttpFoundation\BinaryFileResponse|void
132
     */
133 View Code Duplication
    public function getUserFile(Application $app, $file)
134
    {
135
        try {
136
            $file = $app['chamilo.filesystem']->get('upload/users/'.$file);
137
138
            return $app->sendFile($file->getPathname());
139
        } catch (\InvalidArgumentException $e) {
140
            return $app->abort(404, 'File not found');
141
        }
142
    }
143
}
144