2013-03-07 17:23:40 +01:00
|
|
|
<?php
|
|
|
|
|
2013-07-16 22:31:20 +02:00
|
|
|
/**
|
|
|
|
* @group pholio
|
|
|
|
*/
|
2013-03-07 17:23:40 +01:00
|
|
|
final class PholioMockEmbedView extends AphrontView {
|
|
|
|
|
|
|
|
private $mock;
|
2013-03-14 17:38:56 +01:00
|
|
|
private $images = array();
|
2013-03-07 17:23:40 +01:00
|
|
|
|
|
|
|
public function setMock(PholioMock $mock) {
|
|
|
|
$this->mock = $mock;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-03-14 17:38:56 +01:00
|
|
|
public function setImages(array $images) {
|
|
|
|
$this->images = $images;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-03-07 17:23:40 +01:00
|
|
|
public function render() {
|
|
|
|
if (!$this->mock) {
|
2014-06-09 20:36:49 +02:00
|
|
|
throw new Exception('Call setMock() before render()!');
|
2013-03-07 17:23:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2013-03-14 17:38:56 +01:00
|
|
|
$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);
|
|
|
|
}
|
|
|
|
|
2013-03-07 17:23:40 +01:00
|
|
|
$thumbnails = array();
|
2013-03-14 17:38:56 +01:00
|
|
|
foreach ($images_to_show as $image) {
|
2013-03-07 17:23:40 +01:00
|
|
|
$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(
|
2014-05-12 19:08:32 +02:00
|
|
|
'fa-picture-o' => count($this->mock->getImages()),
|
|
|
|
'fa-trophy' => $this->mock->getTokenCount());
|
2013-03-07 17:23:40 +01:00
|
|
|
|
|
|
|
$icon_list = array();
|
|
|
|
foreach ($icons_data as $icon_name => $icon_value) {
|
2014-05-12 19:08:32 +02:00
|
|
|
$icon = id(new PHUIIconView())
|
|
|
|
->setIconFont($icon_name.' white')
|
|
|
|
->addClass('pholio-mock-embed-icon');
|
|
|
|
|
2013-03-07 17:23:40 +01:00
|
|
|
$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);
|
|
|
|
|
|
|
|
|
2013-03-09 22:52:41 +01:00
|
|
|
return phutil_tag(
|
2013-03-07 17:23:40 +01:00
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'pholio-mock-embed'
|
|
|
|
),
|
|
|
|
array($mock_header, $mock_body, $mock_footer));
|
|
|
|
}
|
|
|
|
}
|