2014-09-15 11:38:24 +02:00
|
|
|
<?php
|
|
|
|
namespace Szurubooru\Controllers\ViewProxies;
|
|
|
|
|
|
|
|
class PostViewProxy extends AbstractViewProxy
|
|
|
|
{
|
2014-09-25 23:53:47 +02:00
|
|
|
const FETCH_USER = 'fetchUser';
|
|
|
|
const FETCH_TAGS = 'fetchTags';
|
|
|
|
const FETCH_RELATIONS = 'fetchRelations';
|
|
|
|
|
2014-09-21 09:35:43 +02:00
|
|
|
private $tagViewProxy;
|
2014-09-21 18:21:54 +02:00
|
|
|
private $userViewProxy;
|
2014-09-21 09:35:43 +02:00
|
|
|
|
2014-09-21 18:21:54 +02:00
|
|
|
public function __construct(
|
|
|
|
TagViewProxy $tagViewProxy,
|
|
|
|
UserViewProxy $userViewProxy)
|
2014-09-21 09:35:43 +02:00
|
|
|
{
|
|
|
|
$this->tagViewProxy = $tagViewProxy;
|
2014-09-21 18:21:54 +02:00
|
|
|
$this->userViewProxy = $userViewProxy;
|
2014-09-21 09:35:43 +02:00
|
|
|
}
|
|
|
|
|
2014-09-25 23:53:47 +02:00
|
|
|
public function fromEntity($post, $config = [])
|
2014-09-15 11:38:24 +02:00
|
|
|
{
|
|
|
|
$result = new \StdClass;
|
|
|
|
if ($post)
|
|
|
|
{
|
|
|
|
$result->id = $post->getId();
|
2014-09-24 23:24:51 +02:00
|
|
|
$result->idMarkdown = $post->getIdMarkdown();
|
2014-09-15 11:38:24 +02:00
|
|
|
$result->name = $post->getName();
|
|
|
|
$result->uploadTime = $post->getUploadTime();
|
|
|
|
$result->lastEditTime = $post->getLastEditTime();
|
|
|
|
$result->safety = \Szurubooru\Helpers\EnumHelper::postSafetyToString($post->getSafety());
|
|
|
|
$result->contentType = \Szurubooru\Helpers\EnumHelper::postTypeToString($post->getContentType());
|
|
|
|
$result->contentChecksum = $post->getContentChecksum();
|
2014-09-18 19:30:12 +02:00
|
|
|
$result->contentMimeType = $post->getContentMimeType();
|
2014-09-23 19:00:40 +02:00
|
|
|
$result->contentExtension = \Szurubooru\Helpers\MimeHelper::getExtension($post->getContentMimeType());
|
2014-09-15 11:38:24 +02:00
|
|
|
$result->source = $post->getSource();
|
|
|
|
$result->imageWidth = $post->getImageWidth();
|
|
|
|
$result->imageHeight = $post->getImageHeight();
|
2014-09-24 23:24:51 +02:00
|
|
|
$result->featureCount = $post->getFeatureCount();
|
|
|
|
$result->lastFeatureTime = $post->getLastFeatureTime();
|
2014-09-15 11:38:24 +02:00
|
|
|
$result->originalFileSize = $post->getOriginalFileSize();
|
2014-09-28 11:33:25 +02:00
|
|
|
$result->favoriteCount = $post->getFavoriteCount();
|
2014-09-28 15:21:25 +02:00
|
|
|
$result->score = $post->getScore();
|
2014-09-25 23:53:47 +02:00
|
|
|
|
|
|
|
if (!empty($config[self::FETCH_TAGS]))
|
|
|
|
$result->tags = $this->tagViewProxy->fromArray($post->getTags());
|
|
|
|
|
|
|
|
if (!empty($config[self::FETCH_USER]))
|
|
|
|
$result->user = $this->userViewProxy->fromEntity($post->getUser());
|
|
|
|
|
|
|
|
if (!empty($config[self::FETCH_RELATIONS]))
|
|
|
|
$result->relations = $this->fromArray($post->getRelatedPosts());
|
2014-09-15 11:38:24 +02:00
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
}
|