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
|
|
|
}
|
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-06-14 21:11:19 +02:00
|
|
|
foreach ($images_to_show as $image) {
|
|
|
|
$thumbfile = $image->getFile();
|
|
|
|
$thumbnail = $thumbfile->getThumb280x210URI();
|
|
|
|
}
|
|
|
|
$header = 'M'.$mock->getID().' '.$mock->getName().
|
|
|
|
' (#'.$image->getID().')';
|
|
|
|
$uri = '/M'.$this->mock->getID().'/'.$image->getID().'/';
|
|
|
|
} else {
|
|
|
|
$thumbnail = $mock->getCoverFile()->getThumb280x210URI();
|
|
|
|
$header = 'M'.$mock->getID().' '.$mock->getName();
|
|
|
|
$uri = '/M'.$this->mock->getID();
|
2013-03-14 17:38:56 +01:00
|
|
|
}
|
|
|
|
|
2014-06-14 21:11:19 +02:00
|
|
|
$item = id(new PHUIPinboardItemView())
|
|
|
|
->setHeader($header)
|
|
|
|
->setURI($uri)
|
|
|
|
->setImageURI($thumbnail)
|
|
|
|
->setImageSize(280, 210)
|
|
|
|
->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
|
|
|
}
|
|
|
|
}
|