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
058707e2
Unverified
Commit
058707e2
authored
Sep 23, 2017
by
Nicolas Widart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding more info on the media transformer
parent
a2be11b2
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
1 deletion
+30
-1
MediaTransformer.php
Modules/Media/Transformers/MediaTransformer.php
+30
-1
No files found.
Modules/Media/Transformers/MediaTransformer.php
View file @
058707e2
...
@@ -3,8 +3,10 @@
...
@@ -3,8 +3,10 @@
namespace
Modules\Media\Transformers
;
namespace
Modules\Media\Transformers
;
use
Illuminate\Http\Resources\Json\Resource
;
use
Illuminate\Http\Resources\Json\Resource
;
use
Mcamara\LaravelLocalization\Facades\LaravelLocalization
;
use
Modules\Media\Helpers\FileHelper
;
use
Modules\Media\Helpers\FileHelper
;
use
Modules\Media\Image\Imagy
;
use
Modules\Media\Image\Imagy
;
use
Modules\Media\Image\ThumbnailManager
;
class
MediaTransformer
extends
Resource
class
MediaTransformer
extends
Resource
{
{
...
@@ -12,17 +14,22 @@ class MediaTransformer extends Resource
...
@@ -12,17 +14,22 @@ class MediaTransformer extends Resource
* @var Imagy
* @var Imagy
*/
*/
private
$imagy
;
private
$imagy
;
/**
* @var ThumbnailManager
*/
private
$thumbnailManager
;
public
function
__construct
(
$resource
)
public
function
__construct
(
$resource
)
{
{
parent
::
__construct
(
$resource
);
parent
::
__construct
(
$resource
);
$this
->
imagy
=
app
(
Imagy
::
class
);
$this
->
imagy
=
app
(
Imagy
::
class
);
$this
->
thumbnailManager
=
app
(
ThumbnailManager
::
class
);
}
}
public
function
toArray
(
$request
)
public
function
toArray
(
$request
)
{
{
return
[
$data
=
[
'id'
=>
$this
->
id
,
'id'
=>
$this
->
id
,
'filename'
=>
$this
->
filename
,
'filename'
=>
$this
->
filename
,
'path'
=>
$this
->
getPath
(),
'path'
=>
$this
->
getPath
(),
...
@@ -35,6 +42,28 @@ class MediaTransformer extends Resource
...
@@ -35,6 +42,28 @@ class MediaTransformer extends Resource
'small_thumb'
=>
$this
->
imagy
->
getThumbnail
(
$this
->
path
,
'smallThumb'
),
'small_thumb'
=>
$this
->
imagy
->
getThumbnail
(
$this
->
path
,
'smallThumb'
),
'medium_thumb'
=>
$this
->
imagy
->
getThumbnail
(
$this
->
path
,
'mediumThumb'
),
'medium_thumb'
=>
$this
->
imagy
->
getThumbnail
(
$this
->
path
,
'mediumThumb'
),
];
];
foreach
(
$this
->
thumbnailManager
->
all
()
as
$thumbnail
)
{
$thumbnailName
=
$thumbnail
->
name
();
$data
[
'thumbnails'
][]
=
[
'name'
=>
$thumbnailName
,
'path'
=>
$this
->
imagy
->
getThumbnail
(
$this
->
path
,
$thumbnailName
),
'size'
=>
$thumbnail
->
size
(),
];
}
foreach
(
LaravelLocalization
::
getSupportedLocales
()
as
$locale
=>
$supportedLocale
)
{
foreach
(
$this
->
translatedAttributes
as
$translatedAttribute
)
{
$data
[
$locale
][
$translatedAttribute
]
=
$this
->
translateOrNew
(
$locale
)
->
$translatedAttribute
;
}
}
foreach
(
$this
->
tags
as
$tag
)
{
$data
[
'tags'
][]
=
$tag
->
name
;
}
return
$data
;
}
}
private
function
getPath
()
private
function
getPath
()
...
...
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