<?php
namespace App\Database\Domain\Entity\User;
use App\Database\Domain\Entity\AbstractEntity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity()
*/
class UserAvatar extends AbstractEntity
{
/**
* @ORM\Column(type="string", nullable=true)
*/
private ?string $assetPath;
/**
* @ORM\Column(type="string", nullable=true)
*/
private ?string $url;
public function __construct(
string $id,
?string $assetPath = null,
?string $url = null
) {
$this->id = $id;
$this->assetPath = $assetPath;
$this->url = $url;
}
public function getAssetPath(): ?string
{
return $this->assetPath;
}
public function setAssetPath(?string $assetPath): self
{
$this->assetPath = $assetPath;
return $this;
}
public function getUrl(): ?string
{
return $this->url;
}
public function setUrl(?string $url): self
{
$this->url = $url;
return $this;
}
public function avatar(string $host, ?string $projectDir = null)
{
if ($this->getAssetPath() && file_exists("$projectDir/public{$this->getAssetPath()}")) {
return "$host{$this->getAssetPath()}";
}
if ($this->getUrl()) {
return $this->getUrl();
}
return "$host/img/user-photo.png";
}
}