Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F96120366
PholioMockEmbedView.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Dec 22, 20:38
Size
2 KB
Mime Type
text/x-php
Expires
Tue, Dec 24, 20:38 (2 d)
Engine
blob
Format
Raw Data
Handle
23126405
Attached To
rPH Phabricator
PholioMockEmbedView.php
View Options
<?php
/**
* @group pholio
*/
final
class
PholioMockEmbedView
extends
AphrontView
{
private
$mock
;
private
$images
=
array
();
public
function
setMock
(
PholioMock
$mock
)
{
$this
->
mock
=
$mock
;
return
$this
;
}
public
function
setImages
(
array
$images
)
{
$this
->
images
=
$images
;
return
$this
;
}
public
function
render
()
{
if
(!
$this
->
mock
)
{
throw
new
Exception
(
"Call setMock() before render()!"
);
}
require_celerity_resource
(
'pholio-css'
);
$mock_link
=
phutil_tag
(
'a'
,
array
(
'href'
=>
'/M'
.
$this
->
mock
->
getID
(),
),
'M'
.
$this
->
mock
->
getID
().
' '
.
$this
->
mock
->
getName
());
$mock_header
=
phutil_tag
(
'div'
,
array
(
'class'
=>
'pholio-mock-embed-head'
,
),
$mock_link
);
$images_to_show
=
array
();
if
(!
empty
(
$this
->
images
))
{
$images_to_show
=
array_intersect_key
(
$this
->
mock
->
getImages
(),
array_flip
(
$this
->
images
));
}
if
(
empty
(
$images_to_show
))
{
$images_to_show
=
array_slice
(
$this
->
mock
->
getImages
(),
0
,
4
);
}
$thumbnails
=
array
();
foreach
(
$images_to_show
as
$image
)
{
$thumbfile
=
$image
->
getFile
();
$dimensions
=
PhabricatorImageTransformer
::
getPreviewDimensions
(
$thumbfile
,
140
);
$tag
=
phutil_tag
(
'img'
,
array
(
'width'
=>
$dimensions
[
'sdx'
],
'height'
=>
$dimensions
[
'sdy'
],
'class'
=>
'pholio-mock-carousel-thumbnail'
,
'src'
=>
$thumbfile
->
getPreview140URI
(),
'style'
=>
'top: '
.
floor
((
140
-
$dimensions
[
'sdy'
]
)
/
2
).
'px'
,
));
$thumbnails
[]
=
javelin_tag
(
'a'
,
array
(
'class'
=>
'pholio-mock-carousel-thumb-item'
,
'href'
=>
'/M'
.
$this
->
mock
->
getID
().
'/'
.
$image
->
getID
().
'/'
,
),
$tag
);
}
$mock_body
=
phutil_tag
(
'div'
,
array
(),
$thumbnails
);
$icons_data
=
array
(
'fa-picture-o'
=>
count
(
$this
->
mock
->
getImages
()),
'fa-trophy'
=>
$this
->
mock
->
getTokenCount
());
$icon_list
=
array
();
foreach
(
$icons_data
as
$icon_name
=>
$icon_value
)
{
$icon
=
id
(
new
PHUIIconView
())
->
setIconFont
(
$icon_name
.
' white'
)
->
addClass
(
'pholio-mock-embed-icon'
);
$count
=
phutil_tag
(
'span'
,
array
(),
$icon_value
);
$icon_list
[]
=
phutil_tag
(
'span'
,
array
(
'class'
=>
'pholio-mock-embed-icons'
),
array
(
$icon
,
$count
));
}
$mock_footer
=
phutil_tag
(
'div'
,
array
(
'class'
=>
'pholio-mock-embed-footer'
,
),
$icon_list
);
return
phutil_tag
(
'div'
,
array
(
'class'
=>
'pholio-mock-embed'
),
array
(
$mock_header
,
$mock_body
,
$mock_footer
));
}
}
Event Timeline
Log In to Comment