src/Entity/Image.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ImageRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. /**
  6.  * @ORM\Entity(repositoryClass=ImageRepository::class)
  7.  */
  8. class Image
  9. {
  10.     /**
  11.      * @ORM\Id
  12.      * @ORM\GeneratedValue
  13.      * @ORM\Column(type="integer")
  14.      */
  15.     private $id;
  16.     /**
  17.      * @ORM\Column(type="text")
  18.      */
  19.     private $path;
  20.     /**
  21.      * @ORM\Column(type="text", nullable=true)
  22.      */
  23.     private $storageKey;
  24.     /**
  25.      * @ORM\Column(type="datetime")
  26.      */
  27.     private $createdAt;
  28.     /**
  29.      * @ORM\ManyToOne(targetEntity=Recommendation::class, inversedBy="images")
  30.      */
  31.     private $recommendation;
  32.     public function __construct()
  33.     {
  34.         if(is_null($this->id)){
  35.             $this->createdAt = new \DateTime();
  36.         }
  37.     }
  38.     public function getId(): ?int
  39.     {
  40.         return $this->id;
  41.     }
  42.     public function getPath(): ?string
  43.     {
  44.         return $this->path;
  45.     }
  46.     public function setPath(string $path): self
  47.     {
  48.         $this->path $path;
  49.         return $this;
  50.     }
  51.     public function getStorageKey(): ?string
  52.     {
  53.         return $this->storageKey;
  54.     }
  55.     public function setStorageKey(?string $storageKey): self
  56.     {
  57.         $this->storageKey $storageKey;
  58.         return $this;
  59.     }
  60.     public function getCreatedAt(): ?\DateTimeInterface
  61.     {
  62.         return $this->createdAt;
  63.     }
  64.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  65.     {
  66.         $this->createdAt $createdAt;
  67.         return $this;
  68.     }
  69.     public function getRecommendation(): ?Recommendation
  70.     {
  71.         return $this->recommendation;
  72.     }
  73.     public function setRecommendation(?Recommendation $recommendation): self
  74.     {
  75.         $this->recommendation $recommendation;
  76.         return $this;
  77.     }
  78.     public function getImage(): ?string
  79.     {
  80.         if(!empty($this->getStorageKey()) && strpos($this->getStorageKey(),'http') === false){
  81.             return $_ENV['SELECTEL_STORAGE_PUBLIC_DOMAIN']."/".$this->getStorageKey();
  82.         } else {
  83.             return "https://".$_SERVER['SERVER_NAME']."/".$this->getPath();
  84.         }
  85.     }
  86. }