2021-02-10 16:20:01 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @copyright 2021 Podlibre
|
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Entities;
|
|
|
|
|
|
|
|
use CodeIgniter\Entity;
|
|
|
|
|
|
|
|
class Person extends Entity
|
|
|
|
{
|
|
|
|
/**
|
2021-04-02 17:20:02 +00:00
|
|
|
* @var \App\Libraries\Image
|
2021-02-10 16:20:01 +00:00
|
|
|
*/
|
|
|
|
protected $image;
|
|
|
|
|
|
|
|
protected $casts = [
|
|
|
|
'id' => 'integer',
|
|
|
|
'full_name' => 'string',
|
|
|
|
'unique_name' => 'string',
|
|
|
|
'information_url' => '?string',
|
|
|
|
'image_uri' => 'string',
|
2021-04-02 17:20:02 +00:00
|
|
|
'image_mimetype' => 'string',
|
2021-02-10 16:20:01 +00:00
|
|
|
'created_by' => 'integer',
|
|
|
|
'updated_by' => 'integer',
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
2021-04-02 17:20:02 +00:00
|
|
|
* Saves a picture in `public/media/persons/`
|
2021-02-10 16:20:01 +00:00
|
|
|
*
|
|
|
|
* @param \CodeIgniter\HTTP\Files\UploadedFile|\CodeIgniter\Files\File $image
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function setImage($image = null)
|
|
|
|
{
|
|
|
|
if ($image) {
|
|
|
|
helper('media');
|
|
|
|
|
2021-04-02 17:20:02 +00:00
|
|
|
$this->attributes['image_mimetype'] = $image->getMimeType();
|
|
|
|
$this->attributes['image_uri'] = save_media(
|
2021-02-10 16:20:01 +00:00
|
|
|
$image,
|
2021-04-02 17:20:02 +00:00
|
|
|
'persons',
|
|
|
|
$this->attributes['unique_name'],
|
2021-02-10 16:20:01 +00:00
|
|
|
);
|
2021-04-02 17:20:02 +00:00
|
|
|
$this->image = new \App\Libraries\Image(
|
|
|
|
$this->attributes['image_uri'],
|
|
|
|
$this->attributes['image_mimetype'],
|
2021-02-10 16:20:01 +00:00
|
|
|
);
|
|
|
|
$this->image->saveSizes();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getImage()
|
|
|
|
{
|
2021-04-02 17:20:02 +00:00
|
|
|
return new \App\Libraries\Image(
|
|
|
|
$this->attributes['image_uri'],
|
|
|
|
$this->attributes['image_mimetype'],
|
|
|
|
);
|
2021-02-10 16:20:01 +00:00
|
|
|
}
|
|
|
|
}
|