Continued work on getter/setters: post dimensions
This commit is contained in:
parent
509bf44619
commit
75704ef0da
5 changed files with 43 additions and 23 deletions
|
@ -13,8 +13,8 @@ class PostEntity extends AbstractEntity implements IValidatable
|
||||||
protected $safety;
|
protected $safety;
|
||||||
public $hidden;
|
public $hidden;
|
||||||
public $uploadDate;
|
public $uploadDate;
|
||||||
public $imageWidth;
|
protected $imageWidth;
|
||||||
public $imageHeight;
|
protected $imageHeight;
|
||||||
public $uploaderId;
|
public $uploaderId;
|
||||||
protected $source;
|
protected $source;
|
||||||
public $commentCount = 0;
|
public $commentCount = 0;
|
||||||
|
@ -187,6 +187,26 @@ class PostEntity extends AbstractEntity implements IValidatable
|
||||||
$this->hidden = boolval($hidden);
|
$this->hidden = boolval($hidden);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getImageWidth()
|
||||||
|
{
|
||||||
|
return $this->imageWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setImageWidth($imageWidth)
|
||||||
|
{
|
||||||
|
$this->imageWidth = $imageWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getImageHeight()
|
||||||
|
{
|
||||||
|
return $this->imageHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setImageHeight($imageHeight)
|
||||||
|
{
|
||||||
|
$this->imageHeight = $imageHeight;
|
||||||
|
}
|
||||||
|
|
||||||
public function getName()
|
public function getName()
|
||||||
{
|
{
|
||||||
return $this->name;
|
return $this->name;
|
||||||
|
@ -308,14 +328,14 @@ class PostEntity extends AbstractEntity implements IValidatable
|
||||||
case 'image/jpeg':
|
case 'image/jpeg':
|
||||||
list ($imageWidth, $imageHeight) = getimagesize($srcPath);
|
list ($imageWidth, $imageHeight) = getimagesize($srcPath);
|
||||||
$this->setType(new PostType(PostType::Image));
|
$this->setType(new PostType(PostType::Image));
|
||||||
$this->imageWidth = $imageWidth;
|
$this->setImageWidth($imageWidth);
|
||||||
$this->imageHeight = $imageHeight;
|
$this->setImageHeight($imageHeight);
|
||||||
break;
|
break;
|
||||||
case 'application/x-shockwave-flash':
|
case 'application/x-shockwave-flash':
|
||||||
list ($imageWidth, $imageHeight) = getimagesize($srcPath);
|
list ($imageWidth, $imageHeight) = getimagesize($srcPath);
|
||||||
$this->setType(new PostType(PostType::Flash));
|
$this->setType(new PostType(PostType::Flash));
|
||||||
$this->imageWidth = $imageWidth;
|
$this->setImageWidth($imageWidth);
|
||||||
$this->imageHeight = $imageHeight;
|
$this->setImageHeight($imageHeight);
|
||||||
break;
|
break;
|
||||||
case 'video/webm':
|
case 'video/webm':
|
||||||
case 'video/mp4':
|
case 'video/mp4':
|
||||||
|
@ -325,8 +345,8 @@ class PostEntity extends AbstractEntity implements IValidatable
|
||||||
case 'video/3gpp':
|
case 'video/3gpp':
|
||||||
list ($imageWidth, $imageHeight) = getimagesize($srcPath);
|
list ($imageWidth, $imageHeight) = getimagesize($srcPath);
|
||||||
$this->setType(new PostType(PostType::Video));
|
$this->setType(new PostType(PostType::Video));
|
||||||
$this->imageWidth = $imageWidth;
|
$this->setImageWidth($imageWidth);
|
||||||
$this->imageHeight = $imageHeight;
|
$this->setImageHeight($imageHeight);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new SimpleException('Invalid file type "%s"', $this->mimeType);
|
throw new SimpleException('Invalid file type "%s"', $this->mimeType);
|
||||||
|
@ -363,8 +383,8 @@ class PostEntity extends AbstractEntity implements IValidatable
|
||||||
$this->mimeType = null;
|
$this->mimeType = null;
|
||||||
$this->fileSize = null;
|
$this->fileSize = null;
|
||||||
$this->fileHash = $youtubeId;
|
$this->fileHash = $youtubeId;
|
||||||
$this->imageWidth = null;
|
$this->setImageWidth(null);
|
||||||
$this->imageHeight = null;
|
$this->setImageHeight(null);
|
||||||
|
|
||||||
$thumbPath = $this->getThumbDefaultPath();
|
$thumbPath = $this->getThumbDefaultPath();
|
||||||
if (file_exists($thumbPath))
|
if (file_exists($thumbPath))
|
||||||
|
|
|
@ -54,8 +54,8 @@ class PostModel extends AbstractCrudModel
|
||||||
'safety' => $post->getSafety()->toInteger(),
|
'safety' => $post->getSafety()->toInteger(),
|
||||||
'hidden' => $post->hidden,
|
'hidden' => $post->hidden,
|
||||||
'upload_date' => $post->uploadDate,
|
'upload_date' => $post->uploadDate,
|
||||||
'image_width' => $post->imageWidth,
|
'image_width' => $post->getImageWidth(),
|
||||||
'image_height' => $post->imageHeight,
|
'image_height' => $post->getImageHeight(),
|
||||||
'uploader_id' => $post->uploaderId,
|
'uploader_id' => $post->uploaderId,
|
||||||
'source' => $post->getSource(),
|
'source' => $post->getSource(),
|
||||||
];
|
];
|
||||||
|
|
|
@ -24,8 +24,8 @@ $post = $this->context->transport->post;
|
||||||
|
|
||||||
<object
|
<object
|
||||||
type="<?= $post->mimeType ?>"
|
type="<?= $post->mimeType ?>"
|
||||||
width="<?= $post->imageWidth ?>"
|
width="<?= $post->getImageWidth() ?>"
|
||||||
height="<?= $post->imageHeight ?>"
|
height="<?= $post->getImageHeight() ?>"
|
||||||
data="<?= \Chibi\Router::linkTo(
|
data="<?= \Chibi\Router::linkTo(
|
||||||
['PostController', 'fileView'],
|
['PostController', 'fileView'],
|
||||||
['name' => $post->getName()]) ?>">
|
['name' => $post->getName()]) ?>">
|
||||||
|
|
|
@ -134,12 +134,12 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php if ($this->context->transport->post->imageWidth > 0): ?>
|
<?php if ($this->context->transport->post->getImageWidth()): ?>
|
||||||
<div class="key-value dim">
|
<div class="key-value dim">
|
||||||
<span class="key">Dimensions:</span>
|
<span class="key">Dimensions:</span>
|
||||||
<span class="value" title="<?= $val = sprintf('%dx%d',
|
<span class="value" title="<?= $val = sprintf('%dx%d',
|
||||||
$this->context->transport->post->imageWidth,
|
$this->context->transport->post->getImageWidth(),
|
||||||
$this->context->transport->post->imageHeight) ?>">
|
$this->context->transport->post->getImageHeight()) ?>">
|
||||||
<?= $val ?>
|
<?= $val ?>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -19,8 +19,8 @@ class EditPostContentJobTest extends AbstractTest
|
||||||
$post = $this->uploadFromFile('image.jpg');
|
$post = $this->uploadFromFile('image.jpg');
|
||||||
$this->assert->areEqual('image/jpeg', $post->mimeType);
|
$this->assert->areEqual('image/jpeg', $post->mimeType);
|
||||||
$this->assert->areEqual(PostType::Image, $post->getType()->toInteger());
|
$this->assert->areEqual(PostType::Image, $post->getType()->toInteger());
|
||||||
$this->assert->areEqual(320, $post->imageWidth);
|
$this->assert->areEqual(320, $post->getImageWidth());
|
||||||
$this->assert->areEqual(240, $post->imageHeight);
|
$this->assert->areEqual(240, $post->getImageHeight());
|
||||||
$this->assert->doesNotThrow(function() use ($post)
|
$this->assert->doesNotThrow(function() use ($post)
|
||||||
{
|
{
|
||||||
$post->generateThumb();
|
$post->generateThumb();
|
||||||
|
@ -34,8 +34,8 @@ class EditPostContentJobTest extends AbstractTest
|
||||||
$post = $this->uploadFromFile('image.png');
|
$post = $this->uploadFromFile('image.png');
|
||||||
$this->assert->areEqual('image/png', $post->mimeType);
|
$this->assert->areEqual('image/png', $post->mimeType);
|
||||||
$this->assert->areEqual(PostType::Image, $post->getType()->toInteger());
|
$this->assert->areEqual(PostType::Image, $post->getType()->toInteger());
|
||||||
$this->assert->areEqual(320, $post->imageWidth);
|
$this->assert->areEqual(320, $post->getImageWidth());
|
||||||
$this->assert->areEqual(240, $post->imageHeight);
|
$this->assert->areEqual(240, $post->getImageHeight());
|
||||||
$this->assert->doesNotThrow(function() use ($post)
|
$this->assert->doesNotThrow(function() use ($post)
|
||||||
{
|
{
|
||||||
$post->generateThumb();
|
$post->generateThumb();
|
||||||
|
@ -49,8 +49,8 @@ class EditPostContentJobTest extends AbstractTest
|
||||||
$post = $this->uploadFromFile('image.gif');
|
$post = $this->uploadFromFile('image.gif');
|
||||||
$this->assert->areEqual('image/gif', $post->mimeType);
|
$this->assert->areEqual('image/gif', $post->mimeType);
|
||||||
$this->assert->areEqual(PostType::Image, $post->getType()->toInteger());
|
$this->assert->areEqual(PostType::Image, $post->getType()->toInteger());
|
||||||
$this->assert->areEqual(320, $post->imageWidth);
|
$this->assert->areEqual(320, $post->getImageWidth());
|
||||||
$this->assert->areEqual(240, $post->imageHeight);
|
$this->assert->areEqual(240, $post->getImageHeight());
|
||||||
$this->assert->doesNotThrow(function() use ($post)
|
$this->assert->doesNotThrow(function() use ($post)
|
||||||
{
|
{
|
||||||
$post->generateThumb();
|
$post->generateThumb();
|
||||||
|
|
Loading…
Reference in a new issue