mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-05 21:26:14 +01:00
61b178f44e
Summary: Use `PhutilInvalidStateException`. Depends on D12803. Test Plan: Unit tests pass. Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: Korvin, epriestley Differential Revision: https://secure.phabricator.com/D12829
61 lines
1.6 KiB
PHP
61 lines
1.6 KiB
PHP
<?php
|
|
|
|
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 PhutilInvalidStateException('setMock');
|
|
}
|
|
$mock = $this->mock;
|
|
|
|
$images_to_show = array();
|
|
$thumbnail = null;
|
|
if (!empty($this->images)) {
|
|
$images_to_show = array_intersect_key(
|
|
$this->mock->getImages(), array_flip($this->images));
|
|
}
|
|
|
|
$xform = PhabricatorFileTransform::getTransformByKey(
|
|
PhabricatorFileThumbnailTransform::TRANSFORM_PINBOARD);
|
|
|
|
if ($images_to_show) {
|
|
$image = head($images_to_show);
|
|
$thumbfile = $image->getFile();
|
|
$header = 'M'.$mock->getID().' '.$mock->getName().
|
|
' (#'.$image->getID().')';
|
|
$uri = '/M'.$this->mock->getID().'/'.$image->getID().'/';
|
|
} else {
|
|
$thumbfile = $mock->getCoverFile();
|
|
$header = 'M'.$mock->getID().' '.$mock->getName();
|
|
$uri = '/M'.$this->mock->getID();
|
|
}
|
|
|
|
$thumbnail = $thumbfile->getURIForTransform($xform);
|
|
list($x, $y) = $xform->getTransformedDimensions($thumbfile);
|
|
|
|
$item = id(new PHUIPinboardItemView())
|
|
->setHeader($header)
|
|
->setURI($uri)
|
|
->setImageURI($thumbnail)
|
|
->setImageSize($x, $y)
|
|
->setDisabled($mock->isClosed())
|
|
->addIconCount('fa-picture-o', count($mock->getImages()))
|
|
->addIconCount('fa-trophy', $mock->getTokenCount());
|
|
|
|
return $item;
|
|
}
|
|
|
|
}
|