[ENTITY] Add utils to Attachment and AttachmentThumbnail to get the corresponding URL and html representation parameters

This commit is contained in:
Hugo Sales 2021-04-25 21:26:53 +00:00
parent 2a74dced22
commit 9a7f1358c2
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
2 changed files with 24 additions and 0 deletions

View File

@ -233,6 +233,11 @@ class Attachment extends Entity
return Common::config('attachments', 'dir') . $this->getFilename(); return Common::config('attachments', 'dir') . $this->getFilename();
} }
public function getAttachmentUrl()
{
return Router::url('attachment_thumbnail', ['id' => $this->getAttachmentId(), 'w' => Common::config('attachment', 'width'), 'h' => Common::config('attachment', 'height')]);
}
public static function schemaDef(): array public static function schemaDef(): array
{ {
return [ return [

View File

@ -27,6 +27,7 @@ use App\Core\Entity;
use App\Core\Event; use App\Core\Event;
use App\Core\GSFile; use App\Core\GSFile;
use App\Core\Log; use App\Core\Log;
use App\Core\Router;
use App\Util\Common; use App\Util\Common;
use App\Util\Exception\NotFoundException; use App\Util\Exception\NotFoundException;
use App\Util\Exception\ServerException; use App\Util\Exception\ServerException;
@ -149,6 +150,24 @@ class AttachmentThumbnail extends Entity
return Common::config('thumbnail', 'dir') . $this->getFilename(); return Common::config('thumbnail', 'dir') . $this->getFilename();
} }
public function getUrl()
{
return Router::url('attachment_thumbnail', ['id' => $this->getAttachmentId(), 'w' => $this->getWidth(), 'h' => $this->getHeight()]);
}
/**
* Get the HTML attributes for this thumbnail
*/
public function getHTMLAttributes(array $orig = [], bool $overwrite = true)
{
$attrs = [
'height' => $this->getHeight(),
'width' => $this->getWidth(),
'src' => $this->getUrl(),
];
return $overwrite ? array_merge($orig, $attrs) : array_merge($attrs, $orig);
}
/** /**
* Delete a attachment thumbnail. This table doesn't own all the attachments, only itself * Delete a attachment thumbnail. This table doesn't own all the attachments, only itself
*/ */