2013-03-07 17:23:40 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
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) {
|
2015-05-13 23:53:52 +02:00
|
|
|
throw new PhutilInvalidStateException('setMock');
|
2013-03-07 17:23:40 +01:00
|
|
|
}
|
2014-06-14 21:11:19 +02:00
|
|
|
$mock = $this->mock;
|
2013-03-07 17:23:40 +01:00
|
|
|
|
2013-03-14 17:38:56 +01:00
|
|
|
$images_to_show = array();
|
2014-06-14 21:11:19 +02:00
|
|
|
$thumbnail = null;
|
2013-03-14 17:38:56 +01:00
|
|
|
if (!empty($this->images)) {
|
|
|
|
$images_to_show = array_intersect_key(
|
|
|
|
$this->mock->getImages(), array_flip($this->images));
|
2014-07-31 00:10:22 +02:00
|
|
|
}
|
|
|
|
|
2015-05-13 00:50:46 +02:00
|
|
|
$xform = PhabricatorFileTransform::getTransformByKey(
|
|
|
|
PhabricatorFileThumbnailTransform::TRANSFORM_PINBOARD);
|
|
|
|
|
2014-07-31 00:10:22 +02:00
|
|
|
if ($images_to_show) {
|
2015-05-13 00:50:46 +02:00
|
|
|
$image = head($images_to_show);
|
|
|
|
$thumbfile = $image->getFile();
|
2014-06-14 21:11:19 +02:00
|
|
|
$header = 'M'.$mock->getID().' '.$mock->getName().
|
|
|
|
' (#'.$image->getID().')';
|
|
|
|
$uri = '/M'.$this->mock->getID().'/'.$image->getID().'/';
|
|
|
|
} else {
|
2015-05-13 00:50:46 +02:00
|
|
|
$thumbfile = $mock->getCoverFile();
|
2014-06-14 21:11:19 +02:00
|
|
|
$header = 'M'.$mock->getID().' '.$mock->getName();
|
|
|
|
$uri = '/M'.$this->mock->getID();
|
2013-03-14 17:38:56 +01:00
|
|
|
}
|
|
|
|
|
2015-05-13 00:50:46 +02:00
|
|
|
$thumbnail = $thumbfile->getURIForTransform($xform);
|
|
|
|
list($x, $y) = $xform->getTransformedDimensions($thumbfile);
|
|
|
|
|
2014-06-14 21:11:19 +02:00
|
|
|
$item = id(new PHUIPinboardItemView())
|
|
|
|
->setHeader($header)
|
|
|
|
->setURI($uri)
|
|
|
|
->setImageURI($thumbnail)
|
2015-05-13 00:50:46 +02:00
|
|
|
->setImageSize($x, $y)
|
2014-06-14 21:11:19 +02:00
|
|
|
->setDisabled($mock->isClosed())
|
|
|
|
->addIconCount('fa-picture-o', count($mock->getImages()))
|
|
|
|
->addIconCount('fa-trophy', $mock->getTokenCount());
|
2013-03-07 17:23:40 +01:00
|
|
|
|
2014-06-14 21:11:19 +02:00
|
|
|
return $item;
|
2013-03-07 17:23:40 +01:00
|
|
|
}
|
2014-07-10 00:12:48 +02:00
|
|
|
|
2013-03-07 17:23:40 +01:00
|
|
|
}
|