Passed
Push — master ( 2e08f5...71c5af )
by Anthony
03:28
created
Service/Globals.php 2 patches
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -11,11 +11,11 @@  discard block
 block discarded – undo
11 11
 	 */
12 12
 	private $container;
13 13
 
14
-    /**
15
-     * Globals constructor.
16
-     * @param ContainerInterface $container
17
-     */
18
-    public function __construct(ContainerInterface $container)
14
+				/**
15
+				 * Globals constructor.
16
+				 * @param ContainerInterface $container
17
+				 */
18
+				public function __construct(ContainerInterface $container)
19 19
 	{
20 20
 		$this->container = $container;
21 21
 	}
@@ -38,23 +38,23 @@  discard block
 block discarded – undo
38 38
 		return $package_name;
39 39
 	}
40 40
 
41
-    /**
42
-     * this method send base bundle path related to ribs-admin
43
-     * @param string|null $package
44
-     * @param bool $dev_mode
45
-     * @return string
46
-     */
41
+				/**
42
+				 * this method send base bundle path related to ribs-admin
43
+				 * @param string|null $package
44
+				 * @param bool $dev_mode
45
+				 * @return string
46
+				 */
47 47
 	public function getBaseBundlePath(string $package = "piou-piou/ribs-admin-bundle", bool $dev_mode = false): string
48 48
 	{
49 49
 		$path = $this->container->get('kernel')->getProjectDir();
50 50
 
51
-        $dev_mode = $package === "piou-piou/ribs-admin-bundle" ? $this->container->getParameter("ribs_admin.dev_mode"): $dev_mode;
51
+								$dev_mode = $package === "piou-piou/ribs-admin-bundle" ? $this->container->getParameter("ribs_admin.dev_mode"): $dev_mode;
52 52
 
53 53
 		if ($dev_mode === true) {
54 54
 			$package = "/lib/".$this->getPackageDevName($package);
55 55
 		} else {
56
-            $package = "/vendor/" . $package;
57
-        }
56
+												$package = "/vendor/" . $package;
57
+								}
58 58
 		
59 59
 		return $path . $package;
60 60
 	}
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -48,10 +48,10 @@
 block discarded – undo
48 48
 	{
49 49
 		$path = $this->container->get('kernel')->getProjectDir();
50 50
 
51
-        $dev_mode = $package === "piou-piou/ribs-admin-bundle" ? $this->container->getParameter("ribs_admin.dev_mode"): $dev_mode;
51
+        $dev_mode = $package === "piou-piou/ribs-admin-bundle" ? $this->container->getParameter("ribs_admin.dev_mode") : $dev_mode;
52 52
 
53 53
 		if ($dev_mode === true) {
54
-			$package = "/lib/".$this->getPackageDevName($package);
54
+			$package = "/lib/" . $this->getPackageDevName($package);
55 55
 		} else {
56 56
             $package = "/vendor/" . $package;
57 57
         }
Please login to merge, or discard this patch.
Entity/UserLogs.php 1 patch
Indentation   +202 added lines, -202 removed lines patch added patch discarded remove patch
@@ -13,207 +13,207 @@
 block discarded – undo
13 13
  */
14 14
 class UserLogs
15 15
 {
16
-    use GuidTrait;
17
-    use CreatedUpdatedTrait;
18
-
19
-    /**
20
-     * @var integer
21
-     *
22
-     * @ORM\Column(name="id", type="integer", nullable=false)
23
-     * @ORM\Id
24
-     * @ORM\GeneratedValue(strategy="IDENTITY")
25
-     */
26
-    private $id;
27
-
28
-    /**
29
-     * @ORM\ManyToOne(targetEntity="PiouPiou\RibsAdminBundle\Entity\User")
30
-     * @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false)
31
-     */
32
-    private $user;
33
-
34
-    /**
35
-     * @var string
36
-     *
37
-     * @ORM\Column(name="method", type="string", length=255, nullable=false)
38
-     */
39
-    private $method;
40
-
41
-    /**
42
-     * @var string
43
-     *
44
-     * @ORM\Column(name="route", type="string", length=255, nullable=false)
45
-     */
46
-    private $route;
47
-
48
-    /**
49
-     * @var string
50
-     *
51
-     * @ORM\Column(name="url", type="string", length=255, nullable=false)
52
-     */
53
-    private $url;
54
-
55
-    /**
56
-     * @var string
57
-     *
58
-     * @ORM\Column(name="full_url", type="string", length=255, nullable=false)
59
-     */
60
-    private $full_url;
61
-
62
-    /**
63
-     * @var string
64
-     *
65
-     * @ORM\Column(name="request_format", type="string", length=255, nullable=false)
66
-     */
67
-    private $request_format;
68
-
69
-    /**
70
-     * @var string
71
-     *
72
-     * @ORM\Column(name="equest_parameters", type="json", nullable=true)
73
-     */
74
-    private $request_parameters;
75
-
76
-    /**
77
-     * @return int
78
-     */
79
-    public function getId()
80
-    {
81
-        return $this->id;
82
-    }
83
-
84
-    /**
85
-     * @param int $id
86
-     */
87
-    public function setId($id)
88
-    {
89
-        $this->id = $id;
90
-    }
91
-
92
-    /**
93
-     * @return User
94
-     */
95
-    public function getUser(): User
96
-    {
97
-        return $this->user;
98
-    }
99
-
100
-    /**
101
-     * @param \User $user
102
-     */
103
-    public function setUser($user)
104
-    {
105
-        $this->user = $user;
106
-    }
107
-
108
-    /**
109
-     * @return string
110
-     */
111
-    public function getMethod(): string
112
-    {
113
-        return $this->method;
114
-    }
115
-
116
-    /**
117
-     * @param string $method
118
-     * @return UserLogs
119
-     */
120
-    public function setMethod(string $method): UserLogs
121
-    {
122
-        $this->method = $method;
123
-
124
-        return $this;
125
-    }
126
-
127
-    /**
128
-     * @return string
129
-     */
130
-    public function getRoute(): string
131
-    {
132
-        return $this->route;
133
-    }
134
-
135
-    /**
136
-     * @param string $route
137
-     * @return UserLogs
138
-     */
139
-    public function setRoute(string $route): UserLogs
140
-    {
141
-        $this->route = $route;
142
-
143
-        return $this;
144
-    }
145
-
146
-    /**
147
-     * @return string
148
-     */
149
-    public function getUrl(): string
150
-    {
151
-        return $this->url;
152
-    }
153
-
154
-    /**
155
-     * @param string $url
156
-     * @return UserLogs
157
-     */
158
-    public function setUrl(string $url): UserLogs
159
-    {
160
-        $this->url = $url;
161
-
162
-        return $this;
163
-    }
164
-
165
-    /**
166
-     * @return string
167
-     */
168
-    public function getFullUrl(): string
169
-    {
170
-        return $this->full_url;
171
-    }
172
-
173
-    /**
174
-     * @param string $full_url
175
-     * @return UserLogs
176
-     */
177
-    public function setFullUrl(string $full_url): UserLogs
178
-    {
179
-        $this->full_url = $full_url;
180
-
181
-        return $this;
182
-    }
183
-
184
-    /**
185
-     * @return string
186
-     */
187
-    public function getRequestFormat(): string
188
-    {
189
-        return $this->request_format;
190
-    }
191
-
192
-    /**
193
-     * @param string $request_format
194
-     * @return UserLogs
195
-     */
196
-    public function setRequestFormat(string $request_format): UserLogs
197
-    {
198
-        $this->request_format = $request_format;
199
-
200
-        return $this;
201
-    }
202
-
203
-    public function getRequestParameters()
204
-    {
205
-        return $this->request_parameters;
206
-    }
207
-
208
-    /**
209
-     * @param $request_parameters
210
-     * @return UserLogs
211
-     */
212
-    public function setRequestParameters($request_parameters): UserLogs
213
-    {
214
-        $this->request_parameters = $request_parameters;
215
-
216
-        return $this;
217
-    }
16
+				use GuidTrait;
17
+				use CreatedUpdatedTrait;
18
+
19
+				/**
20
+				 * @var integer
21
+				 *
22
+				 * @ORM\Column(name="id", type="integer", nullable=false)
23
+				 * @ORM\Id
24
+				 * @ORM\GeneratedValue(strategy="IDENTITY")
25
+				 */
26
+				private $id;
27
+
28
+				/**
29
+				 * @ORM\ManyToOne(targetEntity="PiouPiou\RibsAdminBundle\Entity\User")
30
+				 * @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false)
31
+				 */
32
+				private $user;
33
+
34
+				/**
35
+				 * @var string
36
+				 *
37
+				 * @ORM\Column(name="method", type="string", length=255, nullable=false)
38
+				 */
39
+				private $method;
40
+
41
+				/**
42
+				 * @var string
43
+				 *
44
+				 * @ORM\Column(name="route", type="string", length=255, nullable=false)
45
+				 */
46
+				private $route;
47
+
48
+				/**
49
+				 * @var string
50
+				 *
51
+				 * @ORM\Column(name="url", type="string", length=255, nullable=false)
52
+				 */
53
+				private $url;
54
+
55
+				/**
56
+				 * @var string
57
+				 *
58
+				 * @ORM\Column(name="full_url", type="string", length=255, nullable=false)
59
+				 */
60
+				private $full_url;
61
+
62
+				/**
63
+				 * @var string
64
+				 *
65
+				 * @ORM\Column(name="request_format", type="string", length=255, nullable=false)
66
+				 */
67
+				private $request_format;
68
+
69
+				/**
70
+				 * @var string
71
+				 *
72
+				 * @ORM\Column(name="equest_parameters", type="json", nullable=true)
73
+				 */
74
+				private $request_parameters;
75
+
76
+				/**
77
+				 * @return int
78
+				 */
79
+				public function getId()
80
+				{
81
+								return $this->id;
82
+				}
83
+
84
+				/**
85
+				 * @param int $id
86
+				 */
87
+				public function setId($id)
88
+				{
89
+								$this->id = $id;
90
+				}
91
+
92
+				/**
93
+				 * @return User
94
+				 */
95
+				public function getUser(): User
96
+				{
97
+								return $this->user;
98
+				}
99
+
100
+				/**
101
+				 * @param \User $user
102
+				 */
103
+				public function setUser($user)
104
+				{
105
+								$this->user = $user;
106
+				}
107
+
108
+				/**
109
+				 * @return string
110
+				 */
111
+				public function getMethod(): string
112
+				{
113
+								return $this->method;
114
+				}
115
+
116
+				/**
117
+				 * @param string $method
118
+				 * @return UserLogs
119
+				 */
120
+				public function setMethod(string $method): UserLogs
121
+				{
122
+								$this->method = $method;
123
+
124
+								return $this;
125
+				}
126
+
127
+				/**
128
+				 * @return string
129
+				 */
130
+				public function getRoute(): string
131
+				{
132
+								return $this->route;
133
+				}
134
+
135
+				/**
136
+				 * @param string $route
137
+				 * @return UserLogs
138
+				 */
139
+				public function setRoute(string $route): UserLogs
140
+				{
141
+								$this->route = $route;
142
+
143
+								return $this;
144
+				}
145
+
146
+				/**
147
+				 * @return string
148
+				 */
149
+				public function getUrl(): string
150
+				{
151
+								return $this->url;
152
+				}
153
+
154
+				/**
155
+				 * @param string $url
156
+				 * @return UserLogs
157
+				 */
158
+				public function setUrl(string $url): UserLogs
159
+				{
160
+								$this->url = $url;
161
+
162
+								return $this;
163
+				}
164
+
165
+				/**
166
+				 * @return string
167
+				 */
168
+				public function getFullUrl(): string
169
+				{
170
+								return $this->full_url;
171
+				}
172
+
173
+				/**
174
+				 * @param string $full_url
175
+				 * @return UserLogs
176
+				 */
177
+				public function setFullUrl(string $full_url): UserLogs
178
+				{
179
+								$this->full_url = $full_url;
180
+
181
+								return $this;
182
+				}
183
+
184
+				/**
185
+				 * @return string
186
+				 */
187
+				public function getRequestFormat(): string
188
+				{
189
+								return $this->request_format;
190
+				}
191
+
192
+				/**
193
+				 * @param string $request_format
194
+				 * @return UserLogs
195
+				 */
196
+				public function setRequestFormat(string $request_format): UserLogs
197
+				{
198
+								$this->request_format = $request_format;
199
+
200
+								return $this;
201
+				}
202
+
203
+				public function getRequestParameters()
204
+				{
205
+								return $this->request_parameters;
206
+				}
207
+
208
+				/**
209
+				 * @param $request_parameters
210
+				 * @return UserLogs
211
+				 */
212
+				public function setRequestParameters($request_parameters): UserLogs
213
+				{
214
+								$this->request_parameters = $request_parameters;
215
+
216
+								return $this;
217
+				}
218 218
 }
219 219
 
Please login to merge, or discard this patch.
Controller/UserLogsController.php 1 patch
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -10,44 +10,44 @@
 block discarded – undo
10 10
 
11 11
 class UserLogsController extends AbstractController
12 12
 {
13
-    /**
14
-     * list all user logs
15
-     * @Route("/user-logs/{page}", requirements={"page" = "\d+"}, name="ribsadmin_userlogs")
16
-     * @param ParameterBagInterface $parameterBag
17
-     * @param int $page
18
-     * @return Response
19
-     */
20
-    public function list(ParameterBagInterface $parameterBag, int $page = 1): Response
21
-    {
22
-        $em = $this->getDoctrine()->getManager();
23
-        $max_per_page = $parameterBag->get("ribs_admin.paginator_element_per_page");
13
+				/**
14
+				 * list all user logs
15
+				 * @Route("/user-logs/{page}", requirements={"page" = "\d+"}, name="ribsadmin_userlogs")
16
+				 * @param ParameterBagInterface $parameterBag
17
+				 * @param int $page
18
+				 * @return Response
19
+				 */
20
+				public function list(ParameterBagInterface $parameterBag, int $page = 1): Response
21
+				{
22
+								$em = $this->getDoctrine()->getManager();
23
+								$max_per_page = $parameterBag->get("ribs_admin.paginator_element_per_page");
24 24
 
25
-        $logs = $em->getRepository(UserLogs::class)->findAllPaginated($page, $max_per_page);
26
-        $pagination = array(
27
-            "page" => $page,
28
-            "page_number" => ceil(count($logs) / 20),
29
-            "route" => "ribsadmin_userlogs",
30
-            "parameters" => array()
31
-        );
25
+								$logs = $em->getRepository(UserLogs::class)->findAllPaginated($page, $max_per_page);
26
+								$pagination = array(
27
+												"page" => $page,
28
+												"page_number" => ceil(count($logs) / 20),
29
+												"route" => "ribsadmin_userlogs",
30
+												"parameters" => array()
31
+								);
32 32
 
33
-        return $this->render("@RibsAdmin/userlogs/list.html.twig", [
34
-            "logs" => $logs,
35
-            "pagination" => $pagination
36
-        ]);
37
-    }
33
+								return $this->render("@RibsAdmin/userlogs/list.html.twig", [
34
+												"logs" => $logs,
35
+												"pagination" => $pagination
36
+								]);
37
+				}
38 38
 
39
-    /**
40
-     * show detail of a user log
41
-     * @Route("/user-logs/show/{guid}", name="ribsadmin_userlogs_show")
42
-     * @param string $guid
43
-     * @return Response
44
-     */
45
-    public function show(string $guid): Response
46
-    {
47
-        $log = $this->getDoctrine()->getRepository(UserLogs::class)->findOneByGuid($guid);
39
+				/**
40
+				 * show detail of a user log
41
+				 * @Route("/user-logs/show/{guid}", name="ribsadmin_userlogs_show")
42
+				 * @param string $guid
43
+				 * @return Response
44
+				 */
45
+				public function show(string $guid): Response
46
+				{
47
+								$log = $this->getDoctrine()->getRepository(UserLogs::class)->findOneByGuid($guid);
48 48
 
49
-        return $this->render("@RibsAdmin/userlogs/show.html.twig", [
50
-            "log" => $log,
51
-        ]);
52
-    }
49
+								return $this->render("@RibsAdmin/userlogs/show.html.twig", [
50
+												"log" => $log,
51
+								]);
52
+				}
53 53
 }
Please login to merge, or discard this patch.
Form/Type/UploaderType.php 1 patch
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -9,41 +9,41 @@
 block discarded – undo
9 9
 
10 10
 class UploaderType extends AbstractType
11 11
 {
12
-    /**
13
-     * @param FormBuilderInterface $builder
14
-     * @param array $options
15
-     */
16
-    public function buildForm(FormBuilderInterface $builder, array $options)
17
-    {
18
-        $builder
19
-            ->add($options["uploader_name"], FileType::class, [
20
-                "label" => false,
21
-                "attr" => [
22
-                    "class" => "input-autocomplete",
23
-                    "data-ribs-fileuploader" => "",
24
-                    "data-url-param" => $options["data_url_param"],
25
-                    "data-retrieve-url-param" => $options["data_retrieve_url_param"],
26
-                    "data-delete-url-param" => $options["data_delete_url_param"],
27
-                    "accept" => $options["accept"],
28
-                    "multiple" => $options["multiple"],
29
-                    "autocomplete" => "off",
30
-                ],
31
-                "mapped" => false
32
-            ]);
33
-    }
12
+				/**
13
+				 * @param FormBuilderInterface $builder
14
+				 * @param array $options
15
+				 */
16
+				public function buildForm(FormBuilderInterface $builder, array $options)
17
+				{
18
+								$builder
19
+												->add($options["uploader_name"], FileType::class, [
20
+																"label" => false,
21
+																"attr" => [
22
+																				"class" => "input-autocomplete",
23
+																				"data-ribs-fileuploader" => "",
24
+																				"data-url-param" => $options["data_url_param"],
25
+																				"data-retrieve-url-param" => $options["data_retrieve_url_param"],
26
+																				"data-delete-url-param" => $options["data_delete_url_param"],
27
+																				"accept" => $options["accept"],
28
+																				"multiple" => $options["multiple"],
29
+																				"autocomplete" => "off",
30
+																],
31
+																"mapped" => false
32
+												]);
33
+				}
34 34
 
35
-    /**
36
-     * @param OptionsResolver $resolver
37
-     */
38
-    public function configureOptions(OptionsResolver $resolver)
39
-    {
40
-        $resolver->setDefaults([
41
-            "uploader_name" => null,
42
-            "data_url_param" => null,
43
-            "data_retrieve_url_param" => null,
44
-            "data_delete_url_param" => null,
45
-            "accept" => "*",
46
-            "multiple" => false,
47
-        ]);
48
-    }
35
+				/**
36
+				 * @param OptionsResolver $resolver
37
+				 */
38
+				public function configureOptions(OptionsResolver $resolver)
39
+				{
40
+								$resolver->setDefaults([
41
+												"uploader_name" => null,
42
+												"data_url_param" => null,
43
+												"data_retrieve_url_param" => null,
44
+												"data_delete_url_param" => null,
45
+												"accept" => "*",
46
+												"multiple" => false,
47
+								]);
48
+				}
49 49
 }
Please login to merge, or discard this patch.
Controller/UploaderController.php 1 patch
Indentation   +121 added lines, -121 removed lines patch added patch discarded remove patch
@@ -14,125 +14,125 @@
 block discarded – undo
14 14
 
15 15
 class UploaderController extends AbstractController
16 16
 {
17
-    /**
18
-     * @Route("/upload", name="ribsadmin_upload")
19
-     * @param Request $request
20
-     * @param ParameterBagInterface $parameter
21
-     * @return JsonResponse
22
-     * @throws Exception
23
-     */
24
-    public function upload(Request $request, ParameterBagInterface $parameter): JsonResponse
25
-    {
26
-        $success = false;
27
-        $new_filename = null;
28
-        $file = null;
29
-        $upload_dir = null;
30
-
31
-        if ($request->files && $request->files->has("file")) {
32
-            $upload_dir = $parameter->get("ribs_admin.upload_dir");
33
-            /** @var UploadedFile $file */
34
-            $file = $request->files->get("file");
35
-            $date = new \DateTime();
36
-            $extension = explode(".", $file->getFilename());
37
-            $new_filename = uniqid() . "-" . $date->getTimestamp() . "." . end($extension);
38
-
39
-            if (!is_dir($upload_dir)) {
40
-                $this->createRecursiveDirFromRoot($upload_dir);
41
-            }
42
-
43
-            if ($file->move($upload_dir, $new_filename)) {
44
-                $success = true;
45
-            }
46
-        }
47
-
48
-        return new JsonResponse([
49
-            "original_filename" => $file ? $file->getClientOriginalName() : null,
50
-            "new_filename" => $new_filename,
51
-            "file_path" => $upload_dir . "/" . $new_filename,
52
-            "success" => $success
53
-        ]);
54
-    }
55
-
56
-    /**
57
-     * @Route("/delete-uploaded-file", name="ribsadmin_delete_uploaded_file")
58
-     * @param Request $request
59
-     * @param ParameterBagInterface $parameter
60
-     * @return JsonResponse
61
-     */
62
-    public function deleteUploadedFile(Request $request, ParameterBagInterface $parameter): JsonResponse
63
-    {
64
-        $success = false;
65
-        if ($request->get("file_path") && $request->get("file_name")) {
66
-            $fs = new Filesystem();
67
-            $upload_dir = $parameter->get("ribs_admin.upload_dir");
68
-
69
-            if (is_file($request->get("file_path"))) {
70
-                $fs->remove($request->get("file_path"));
71
-            } elseif (is_file($upload_dir . "/" . $request->get("file_name"))) {
72
-                $fs->remove($upload_dir . "/" . $request->get("file_name"));
73
-            }
74
-            $success = true;
75
-        }
76
-
77
-        return new JsonResponse([
78
-            "success" => $success
79
-        ]);
80
-    }
81
-
82
-    /**
83
-     * @Route("/retrieve-uploaded-files", name="ribsadmin_retrieve_uploaded_file")
84
-     * @param Request $request
85
-     * @param ParameterBagInterface $parameter
86
-     * @return JsonResponse
87
-     */
88
-    public function retrieveUploadedFile(Request $request, ParameterBagInterface $parameter): JsonResponse
89
-    {
90
-        $success = true;
91
-        $fs = new Filesystem();
92
-        $finder = new Finder();
93
-        $finder->files()->in($parameter->get("ribs_admin.upload_dir"));
94
-        $files = [];
95
-        $index = 0;
96
-
97
-        foreach ($finder as $file) {
98
-            $files[] = [
99
-                "file_path" => $parameter->get("ribs_admin.base_upload_url") . $file->getFilename(),
100
-                "filename" => $file->getFilename(),
101
-                "index" => $index
102
-            ];
103
-
104
-            $index++;
105
-        }
106
-
107
-        return new JsonResponse([
108
-            "success" => $success,
109
-            "files" => $files
110
-        ]);
111
-    }
112
-
113
-    /**
114
-     * method that create a tree of folders on each slash
115
-     * @param $path
116
-     * @return string
117
-     */
118
-    private function createRecursiveDirFromRoot($path)
119
-    {
120
-        $fs = new Filesystem();
121
-        $new_path = $path;
122
-        $folders = explode("/", $path);
123
-
124
-        foreach ($folders as $index => $folder) {
125
-            $new_path .= $folder;
126
-
127
-            if (!$fs->exists($new_path)) {
128
-                $fs->mkdir($new_path);
129
-            }
130
-
131
-            if ($index + 1 < count($folders)) {
132
-                $new_path .= "/";
133
-            }
134
-        }
135
-
136
-        return $new_path;
137
-    }
17
+				/**
18
+				 * @Route("/upload", name="ribsadmin_upload")
19
+				 * @param Request $request
20
+				 * @param ParameterBagInterface $parameter
21
+				 * @return JsonResponse
22
+				 * @throws Exception
23
+				 */
24
+				public function upload(Request $request, ParameterBagInterface $parameter): JsonResponse
25
+				{
26
+								$success = false;
27
+								$new_filename = null;
28
+								$file = null;
29
+								$upload_dir = null;
30
+
31
+								if ($request->files && $request->files->has("file")) {
32
+												$upload_dir = $parameter->get("ribs_admin.upload_dir");
33
+												/** @var UploadedFile $file */
34
+												$file = $request->files->get("file");
35
+												$date = new \DateTime();
36
+												$extension = explode(".", $file->getFilename());
37
+												$new_filename = uniqid() . "-" . $date->getTimestamp() . "." . end($extension);
38
+
39
+												if (!is_dir($upload_dir)) {
40
+																$this->createRecursiveDirFromRoot($upload_dir);
41
+												}
42
+
43
+												if ($file->move($upload_dir, $new_filename)) {
44
+																$success = true;
45
+												}
46
+								}
47
+
48
+								return new JsonResponse([
49
+												"original_filename" => $file ? $file->getClientOriginalName() : null,
50
+												"new_filename" => $new_filename,
51
+												"file_path" => $upload_dir . "/" . $new_filename,
52
+												"success" => $success
53
+								]);
54
+				}
55
+
56
+				/**
57
+				 * @Route("/delete-uploaded-file", name="ribsadmin_delete_uploaded_file")
58
+				 * @param Request $request
59
+				 * @param ParameterBagInterface $parameter
60
+				 * @return JsonResponse
61
+				 */
62
+				public function deleteUploadedFile(Request $request, ParameterBagInterface $parameter): JsonResponse
63
+				{
64
+								$success = false;
65
+								if ($request->get("file_path") && $request->get("file_name")) {
66
+												$fs = new Filesystem();
67
+												$upload_dir = $parameter->get("ribs_admin.upload_dir");
68
+
69
+												if (is_file($request->get("file_path"))) {
70
+																$fs->remove($request->get("file_path"));
71
+												} elseif (is_file($upload_dir . "/" . $request->get("file_name"))) {
72
+																$fs->remove($upload_dir . "/" . $request->get("file_name"));
73
+												}
74
+												$success = true;
75
+								}
76
+
77
+								return new JsonResponse([
78
+												"success" => $success
79
+								]);
80
+				}
81
+
82
+				/**
83
+				 * @Route("/retrieve-uploaded-files", name="ribsadmin_retrieve_uploaded_file")
84
+				 * @param Request $request
85
+				 * @param ParameterBagInterface $parameter
86
+				 * @return JsonResponse
87
+				 */
88
+				public function retrieveUploadedFile(Request $request, ParameterBagInterface $parameter): JsonResponse
89
+				{
90
+								$success = true;
91
+								$fs = new Filesystem();
92
+								$finder = new Finder();
93
+								$finder->files()->in($parameter->get("ribs_admin.upload_dir"));
94
+								$files = [];
95
+								$index = 0;
96
+
97
+								foreach ($finder as $file) {
98
+												$files[] = [
99
+																"file_path" => $parameter->get("ribs_admin.base_upload_url") . $file->getFilename(),
100
+																"filename" => $file->getFilename(),
101
+																"index" => $index
102
+												];
103
+
104
+												$index++;
105
+								}
106
+
107
+								return new JsonResponse([
108
+												"success" => $success,
109
+												"files" => $files
110
+								]);
111
+				}
112
+
113
+				/**
114
+				 * method that create a tree of folders on each slash
115
+				 * @param $path
116
+				 * @return string
117
+				 */
118
+				private function createRecursiveDirFromRoot($path)
119
+				{
120
+								$fs = new Filesystem();
121
+								$new_path = $path;
122
+								$folders = explode("/", $path);
123
+
124
+								foreach ($folders as $index => $folder) {
125
+												$new_path .= $folder;
126
+
127
+												if (!$fs->exists($new_path)) {
128
+																$fs->mkdir($new_path);
129
+												}
130
+
131
+												if ($index + 1 < count($folders)) {
132
+																$new_path .= "/";
133
+												}
134
+								}
135
+
136
+								return $new_path;
137
+				}
138 138
 }
Please login to merge, or discard this patch.