src/Database/Domain/Entity/User/UserAvatar.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Database\Domain\Entity\User;
  3. use App\Database\Domain\Entity\AbstractEntity;
  4. use Doctrine\ORM\Mapping as ORM;
  5. /**
  6.  * @ORM\Entity()
  7.  */
  8. class UserAvatar extends AbstractEntity
  9. {
  10.     /**
  11.      * @ORM\Column(type="string", nullable=true)
  12.      */
  13.     private ?string $assetPath;
  14.     /**
  15.      * @ORM\Column(type="string", nullable=true)
  16.      */
  17.     private ?string $url;
  18.     public function __construct(
  19.         string $id,
  20.         ?string $assetPath null,
  21.         ?string $url null
  22.     ) {
  23.         $this->id $id;
  24.         $this->assetPath $assetPath;
  25.         $this->url $url;
  26.     }
  27.     public function getAssetPath(): ?string
  28.     {
  29.         return $this->assetPath;
  30.     }
  31.     public function setAssetPath(?string $assetPath): self
  32.     {
  33.         $this->assetPath $assetPath;
  34.         return $this;
  35.     }
  36.     public function getUrl(): ?string
  37.     {
  38.         return $this->url;
  39.     }
  40.     public function setUrl(?string $url): self
  41.     {
  42.         $this->url $url;
  43.         return $this;
  44.     }
  45.     public function avatar(string $host, ?string $projectDir null)
  46.     {
  47.         if ($this->getAssetPath() && file_exists("$projectDir/public{$this->getAssetPath()}")) {
  48.             return "$host{$this->getAssetPath()}";
  49.         }
  50.         if ($this->getUrl()) {
  51.             return $this->getUrl();
  52.         }
  53.         return "$host/img/user-photo.png";
  54.     }
  55. }