Created
January 11, 2023 12:58
-
-
Save radynsade/0ff93fe3bb59090c0fada78821376561 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Modules\Upload\Images; | |
use Core\Models\BaseModel; | |
use Modules\Upload\Files\DbFile; | |
class Image extends BaseModel { | |
public const IMAGES_DIR_NAME = 'images'; | |
/** | |
* @var boolean | |
*/ | |
protected bool $isVector; | |
/** | |
* @var integer | |
*/ | |
protected int $dbFileId; | |
public function initialize(): void { | |
parent::initialize(); | |
$this->belongsTo( | |
'db_file_id', | |
DbFile::class, | |
'id', | |
[ | |
'alias' => 'dbFile', | |
'foreignKey' => true, | |
'reusable' => true | |
] | |
); | |
$this->hasMany( | |
'id', | |
Thumbnail::class, | |
'image_id', | |
[ | |
'alias' => 'Thumbnails', | |
'reusable' => true | |
] | |
); | |
} | |
/** | |
* @return boolean | |
*/ | |
public function getIsVector() { | |
return $this->isVector; | |
} | |
/** | |
* @param boolean $isVector | |
* @return static | |
*/ | |
public function setIsVector(bool $isVector): static { | |
$this->isVector = $isVector; | |
return $this; | |
} | |
/** | |
* @return integer | |
*/ | |
public function getDbFileId(): int { | |
return $this->dbFileId; | |
} | |
/** | |
* @param integer $dbFileId | |
* @return static | |
*/ | |
public function setDbFileId(int $dbFileId): static { | |
$this->dbFileId = $dbFileId; | |
return $this; | |
} | |
/** | |
* @return DbFile | |
*/ | |
public function getDbFile(): DbFile { | |
return $this->dbFile; | |
} | |
/** | |
* @param DbFile $dbFile | |
* @return static | |
*/ | |
public function setDbFile(DbFile $dbFile): static { | |
$this->dbFile = $dbFile; | |
if ($dbFile->getMimeType() === 'image/svg+xml') { | |
$this->isVector = true; | |
} else { | |
$this->isVector = false; | |
} | |
return $this; | |
} | |
/** | |
* @return Thumbnail[] | |
*/ | |
public function getThumbnails(): array { | |
return $this->thumbnails; | |
} | |
/** | |
* @param Thumbnail[] $thumbnails | |
* @return static | |
*/ | |
public function setThumbnails(iterable $thumbnails): static { | |
$this->thumbnails = [...$thumbnails]; | |
return $this; | |
} | |
/** | |
* @param Thumbnail $thumbnail | |
* @return static | |
*/ | |
public function addThumbnail(Thumbnail $thumbnail): static { | |
$this->thumbnails = [ | |
...$this->thumbnails, | |
$thumbnail | |
]; | |
return $this; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment