<?php
namespace App\Entity;
use App\Service\Helper\DateTimeHelper;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
use Exception;
/**
* @ORM\Table(name="products__images", uniqueConstraints={
* @ORM\UniqueConstraint(columns={"src", "product_id"})
* })
* @ORM\Entity(repositoryClass="App\Repository\ProductImageRepository")
*
*/
class ProductImage
{
use IdTrait;
/**
* @ORM\Column(name="created_at", type="datetime", nullable=false)
*/
private DateTime $createdAt;
/**
* @ORM\ManyToOne(targetEntity="Product")
* @ORM\JoinColumn(name="product_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
*/
private Product $product;
/**
* @ORM\Column(name="src", type="string")
*/
private string $src;
/**
* @ORM\Column(name="hash", type="string")
*/
private string $hash;
/**
* @ORM\Column(name="published", type="boolean", nullable=false, options={"default":1})
*/
private bool $published = true;
/**
* @throws Exception
*/
public function __construct(Product $product, string $src, string $hash)
{
$this->product = $product;
$this->src = $src;
$this->hash = $hash;
$this->createdAt = DateTimeHelper::getNowDateTime();
}
public function getProduct(): Product
{
return $this->product;
}
public function getSrc(): string
{
return $this->src;
}
public function isPublished(): bool
{
return $this->published;
}
public function setPublished(bool $published): void
{
$this->published = $published;
}
public function getHash(): string
{
return $this->hash;
}
}