Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Platform
Commits
185736f9
Unverified
Commit
185736f9
authored
Sep 10, 2017
by
Nicolas Widart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Using return type hints
parent
71e1f9a8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
15 deletions
+16
-15
MediaController.php
Modules/Media/Http/Controllers/Api/MediaController.php
+16
-15
No files found.
Modules/Media/Http/Controllers/Api/MediaController.php
View file @
185736f9
...
@@ -2,10 +2,10 @@
...
@@ -2,10 +2,10 @@
namespace
Modules\Media\Http\Controllers\Api
;
namespace
Modules\Media\Http\Controllers\Api
;
use
Illuminate\Http\JsonResponse
;
use
Illuminate\Http\Request
;
use
Illuminate\Http\Request
;
use
Illuminate\Routing\Controller
;
use
Illuminate\Routing\Controller
;
use
Illuminate\Support\Facades\DB
;
use
Illuminate\Support\Facades\DB
;
use
Illuminate\Support\Facades\Response
;
use
Modules\Media\Entities\File
;
use
Modules\Media\Entities\File
;
use
Modules\Media\Events\FileWasLinked
;
use
Modules\Media\Events\FileWasLinked
;
use
Modules\Media\Events\FileWasUnlinked
;
use
Modules\Media\Events\FileWasUnlinked
;
...
@@ -54,29 +54,29 @@ class MediaController extends Controller
...
@@ -54,29 +54,29 @@ class MediaController extends Controller
* Store a newly created resource in storage.
* Store a newly created resource in storage.
*
*
* @param UploadMediaRequest $request
* @param UploadMediaRequest $request
* @return Response
* @return
\Illuminate\Http\Json
Response
*/
*/
public
function
store
(
UploadMediaRequest
$request
)
public
function
store
(
UploadMediaRequest
$request
)
:
JsonResponse
{
{
$savedFile
=
$this
->
fileService
->
store
(
$request
->
file
(
'file'
));
$savedFile
=
$this
->
fileService
->
store
(
$request
->
file
(
'file'
));
if
(
is_string
(
$savedFile
))
{
if
(
is_string
(
$savedFile
))
{
return
Response
::
json
([
return
response
()
->
json
([
'error'
=>
$savedFile
,
'error'
=>
$savedFile
,
],
409
);
],
409
);
}
}
event
(
new
FileWasUploaded
(
$savedFile
));
event
(
new
FileWasUploaded
(
$savedFile
));
return
Response
::
json
(
$savedFile
->
toArray
());
return
response
()
->
json
(
$savedFile
->
toArray
());
}
}
/**
/**
* Link the given entity with a media file
* Link the given entity with a media file
*
* @param Request $request
* @param Request $request
* @return \Illuminate\Http\JsonResponse
*/
*/
public
function
linkMedia
(
Request
$request
)
public
function
linkMedia
(
Request
$request
)
:
JsonResponse
{
{
$mediaId
=
$request
->
get
(
'mediaId'
);
$mediaId
=
$request
->
get
(
'mediaId'
);
$entityClass
=
$request
->
get
(
'entityClass'
);
$entityClass
=
$request
->
get
(
'entityClass'
);
...
@@ -102,7 +102,7 @@ class MediaController extends Controller
...
@@ -102,7 +102,7 @@ class MediaController extends Controller
event
(
new
FileWasLinked
(
$file
,
$entity
));
event
(
new
FileWasLinked
(
$file
,
$entity
));
return
Response
::
json
([
return
response
()
->
json
([
'error'
=>
false
,
'error'
=>
false
,
'message'
=>
'The link has been added.'
,
'message'
=>
'The link has been added.'
,
'result'
=>
[
'result'
=>
[
...
@@ -116,15 +116,15 @@ class MediaController extends Controller
...
@@ -116,15 +116,15 @@ class MediaController extends Controller
/**
/**
* Remove the record in the media__imageables table for the given id
* Remove the record in the media__imageables table for the given id
*
* @param Request $request
* @param Request $request
* @return \Illuminate\Http\JsonResponse
*/
*/
public
function
unlinkMedia
(
Request
$request
)
public
function
unlinkMedia
(
Request
$request
)
:
JsonResponse
{
{
$imageableId
=
$request
->
get
(
'imageableId'
);
$imageableId
=
$request
->
get
(
'imageableId'
);
$deleted
=
DB
::
table
(
'media__imageables'
)
->
whereId
(
$imageableId
)
->
delete
();
$deleted
=
DB
::
table
(
'media__imageables'
)
->
whereId
(
$imageableId
)
->
delete
();
if
(
!
$deleted
)
{
if
(
!
$deleted
)
{
return
Response
::
json
([
return
response
()
->
json
([
'error'
=>
true
,
'error'
=>
true
,
'message'
=>
'The file was not found.'
,
'message'
=>
'The file was not found.'
,
]);
]);
...
@@ -132,7 +132,7 @@ class MediaController extends Controller
...
@@ -132,7 +132,7 @@ class MediaController extends Controller
event
(
new
FileWasUnlinked
(
$imageableId
));
event
(
new
FileWasUnlinked
(
$imageableId
));
return
Response
::
json
([
return
response
()
->
json
([
'error'
=>
false
,
'error'
=>
false
,
'message'
=>
'The link has been removed.'
,
'message'
=>
'The link has been removed.'
,
]);
]);
...
@@ -141,8 +141,9 @@ class MediaController extends Controller
...
@@ -141,8 +141,9 @@ class MediaController extends Controller
/**
/**
* Sort the record in the media__imageables table for the given array
* Sort the record in the media__imageables table for the given array
* @param Request $request
* @param Request $request
* @return \Illuminate\Http\JsonResponse
*/
*/
public
function
sortMedia
(
Request
$request
)
public
function
sortMedia
(
Request
$request
)
:
JsonResponse
{
{
$imageableIdArray
=
$request
->
get
(
'sortable'
);
$imageableIdArray
=
$request
->
get
(
'sortable'
);
...
@@ -153,7 +154,7 @@ class MediaController extends Controller
...
@@ -153,7 +154,7 @@ class MediaController extends Controller
$order
++
;
$order
++
;
}
}
return
Response
::
json
([
'error'
=>
false
,
'message'
=>
'The items have been reorder.'
]);
return
response
()
->
json
([
'error'
=>
false
,
'message'
=>
'The items have been reorder.'
]);
}
}
/**
/**
...
@@ -162,7 +163,7 @@ class MediaController extends Controller
...
@@ -162,7 +163,7 @@ class MediaController extends Controller
* @param File $file
* @param File $file
* @return string
* @return string
*/
*/
private
function
getThumbnailPathFor
(
$mediaType
,
File
$file
)
private
function
getThumbnailPathFor
(
$mediaType
,
File
$file
)
:
string
{
{
if
(
$mediaType
===
'image'
)
{
if
(
$mediaType
===
'image'
)
{
return
$this
->
imagy
->
getThumbnail
(
$file
->
path
,
'mediumThumb'
);
return
$this
->
imagy
->
getThumbnail
(
$file
->
path
,
'mediumThumb'
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment