Continued work on getter/setters: post dimensions

This commit is contained in:
Marcin Kurczewski 2014-05-07 17:57:17 +02:00
parent 509bf44619
commit 75704ef0da
5 changed files with 43 additions and 23 deletions

View file

@ -13,8 +13,8 @@ class PostEntity extends AbstractEntity implements IValidatable
protected $safety;
public $hidden;
public $uploadDate;
public $imageWidth;
public $imageHeight;
protected $imageWidth;
protected $imageHeight;
public $uploaderId;
protected $source;
public $commentCount = 0;
@ -187,6 +187,26 @@ class PostEntity extends AbstractEntity implements IValidatable
$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()
{
return $this->name;
@ -308,14 +328,14 @@ class PostEntity extends AbstractEntity implements IValidatable
case 'image/jpeg':
list ($imageWidth, $imageHeight) = getimagesize($srcPath);
$this->setType(new PostType(PostType::Image));
$this->imageWidth = $imageWidth;
$this->imageHeight = $imageHeight;
$this->setImageWidth($imageWidth);
$this->setImageHeight($imageHeight);
break;
case 'application/x-shockwave-flash':
list ($imageWidth, $imageHeight) = getimagesize($srcPath);
$this->setType(new PostType(PostType::Flash));
$this->imageWidth = $imageWidth;
$this->imageHeight = $imageHeight;
$this->setImageWidth($imageWidth);
$this->setImageHeight($imageHeight);
break;
case 'video/webm':
case 'video/mp4':
@ -325,8 +345,8 @@ class PostEntity extends AbstractEntity implements IValidatable
case 'video/3gpp':
list ($imageWidth, $imageHeight) = getimagesize($srcPath);
$this->setType(new PostType(PostType::Video));
$this->imageWidth = $imageWidth;
$this->imageHeight = $imageHeight;
$this->setImageWidth($imageWidth);
$this->setImageHeight($imageHeight);
break;
default:
throw new SimpleException('Invalid file type "%s"', $this->mimeType);
@ -363,8 +383,8 @@ class PostEntity extends AbstractEntity implements IValidatable
$this->mimeType = null;
$this->fileSize = null;
$this->fileHash = $youtubeId;
$this->imageWidth = null;
$this->imageHeight = null;
$this->setImageWidth(null);
$this->setImageHeight(null);
$thumbPath = $this->getThumbDefaultPath();
if (file_exists($thumbPath))

View file

@ -54,8 +54,8 @@ class PostModel extends AbstractCrudModel
'safety' => $post->getSafety()->toInteger(),
'hidden' => $post->hidden,
'upload_date' => $post->uploadDate,
'image_width' => $post->imageWidth,
'image_height' => $post->imageHeight,
'image_width' => $post->getImageWidth(),
'image_height' => $post->getImageHeight(),
'uploader_id' => $post->uploaderId,
'source' => $post->getSource(),
];

View file

@ -24,8 +24,8 @@ $post = $this->context->transport->post;
<object
type="<?= $post->mimeType ?>"
width="<?= $post->imageWidth ?>"
height="<?= $post->imageHeight ?>"
width="<?= $post->getImageWidth() ?>"
height="<?= $post->getImageHeight() ?>"
data="<?= \Chibi\Router::linkTo(
['PostController', 'fileView'],
['name' => $post->getName()]) ?>">

View file

@ -134,12 +134,12 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
</span>
</div>
<?php if ($this->context->transport->post->imageWidth > 0): ?>
<?php if ($this->context->transport->post->getImageWidth()): ?>
<div class="key-value dim">
<span class="key">Dimensions:</span>
<span class="value" title="<?= $val = sprintf('%dx%d',
$this->context->transport->post->imageWidth,
$this->context->transport->post->imageHeight) ?>">
$this->context->transport->post->getImageWidth(),
$this->context->transport->post->getImageHeight()) ?>">
<?= $val ?>
</span>
</div>

View file

@ -19,8 +19,8 @@ class EditPostContentJobTest extends AbstractTest
$post = $this->uploadFromFile('image.jpg');
$this->assert->areEqual('image/jpeg', $post->mimeType);
$this->assert->areEqual(PostType::Image, $post->getType()->toInteger());
$this->assert->areEqual(320, $post->imageWidth);
$this->assert->areEqual(240, $post->imageHeight);
$this->assert->areEqual(320, $post->getImageWidth());
$this->assert->areEqual(240, $post->getImageHeight());
$this->assert->doesNotThrow(function() use ($post)
{
$post->generateThumb();
@ -34,8 +34,8 @@ class EditPostContentJobTest extends AbstractTest
$post = $this->uploadFromFile('image.png');
$this->assert->areEqual('image/png', $post->mimeType);
$this->assert->areEqual(PostType::Image, $post->getType()->toInteger());
$this->assert->areEqual(320, $post->imageWidth);
$this->assert->areEqual(240, $post->imageHeight);
$this->assert->areEqual(320, $post->getImageWidth());
$this->assert->areEqual(240, $post->getImageHeight());
$this->assert->doesNotThrow(function() use ($post)
{
$post->generateThumb();
@ -49,8 +49,8 @@ class EditPostContentJobTest extends AbstractTest
$post = $this->uploadFromFile('image.gif');
$this->assert->areEqual('image/gif', $post->mimeType);
$this->assert->areEqual(PostType::Image, $post->getType()->toInteger());
$this->assert->areEqual(320, $post->imageWidth);
$this->assert->areEqual(240, $post->imageHeight);
$this->assert->areEqual(320, $post->getImageWidth());
$this->assert->areEqual(240, $post->getImageHeight());
$this->assert->doesNotThrow(function() use ($post)
{
$post->generateThumb();