[ENTITY] Add utils to Attachment and AttachmentThumbnail to get the corresponding URL and html representation parameters
This commit is contained in:
parent
2a74dced22
commit
9a7f1358c2
|
@ -233,6 +233,11 @@ class Attachment extends Entity
|
|||
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
|
||||
{
|
||||
return [
|
||||
|
|
|
@ -27,6 +27,7 @@ use App\Core\Entity;
|
|||
use App\Core\Event;
|
||||
use App\Core\GSFile;
|
||||
use App\Core\Log;
|
||||
use App\Core\Router;
|
||||
use App\Util\Common;
|
||||
use App\Util\Exception\NotFoundException;
|
||||
use App\Util\Exception\ServerException;
|
||||
|
@ -149,6 +150,24 @@ class AttachmentThumbnail extends Entity
|
|||
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
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue
Block a user