<?php
namespace App\Entity;
use App\Traits\CustomSlugify;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection as DoctrineCollection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use JsonSerializable;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass="App\Repository\CollectionRepository")
* @ORM\HasLifecycleCallbacks()
*/
class Collection implements JsonSerializable
{
use CustomSlugify;
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=50)
* @Assert\Length(min = 4, max = 20, allowEmptyString = false )
* @Assert\Regex("/[A-Za-z]/")
*/
private $name;
/**
* @Gedmo\Translatable
* @ORM\Column(type="string", length=512, nullable=true)
*/
private $description;
/**
* @ORM\Column(type="date", nullable=true)
*/
private $launchYear;
/**
* @ORM\Column(type="boolean")
*/
private $roll;
/**
* @ORM\Column(type="boolean")
*/
private $tile;
/**
* @ORM\Column(type="boolean")
*/
private $checkerboard;
/**
* @ORM\Column(type="boolean")
*/
private $monolithic;
/**
* @ORM\Column(type="boolean")
*/
private $brick;
/**
* @ORM\Column(type="boolean")
*/
private $ashlar;
/**
* @ORM\Column(type="smallint")
*/
private $orderAppearance;
/**
* @ORM\Column(type="boolean")
*/
private $actif;
/**
* @ORM\Column(type="string", length=50)
*/
private $slug;
/**
* @var DateTime
* @Gedmo\Timestampable(on="create")
* @ORM\Column(type="datetime", nullable=true)
*/
protected $createdAt;
/**
* @var DateTime
* @Gedmo\Timestampable(on="update")
* @ORM\Column(type="datetime", nullable=true)
*/
protected $updatedAt;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Attachment", mappedBy="collection", cascade={"persist", "remove"}, fetch="EAGER")
*/
private $attachments;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Product", mappedBy="collection")
*/
private $products;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $new;
public function __construct()
{
$this->attachments = new ArrayCollection();
$this->products = new ArrayCollection();
}
public function setTranslatableLocale($locale)
{
$this->locale = $locale;
}
public function __toString()
{
return $this->name.'';
}
public function jsonSerialize()
{
return [
'id' => $this->getId(),
'name' => $this->getName(),
'description' => $this->getDescription(),
'orderAppearance' => $this->getOrderAppearance(),
'slug' => $this->getSlug(),
'role' => $this->getRoll(),
'tile' => $this->getTile(),
'checkerboard' => $this->getCheckerboard(),
'monolithic' => $this->ismonolithic(),
'brick' => $this->isBrick(),
'ashlar' => $this->isAshlar(),
'lanchYear' => $this->getLaunchYear(),
'order' => $this->getOrderAppearance(),
'products' => $this->getProducts()->getValues(),
'attachments' => isset($this->attachmentsFile) ? $this->attachmentsFile : null,
'new' => $this->getNew()
];
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = ucfirst($name);
return $this;
}
/**
* @return mixed
*/
public function getDescription()
{
return $this->description;
}
/**
* @param mixed $description
*/
public function setDescription($description): void
{
$this->description = $description;
}
public function getLaunchYear(): ?\DateTimeInterface
{
return $this->launchYear;
}
public function setLaunchYear(?\DateTimeInterface $launchYear): self
{
$this->launchYear = $launchYear;
return $this;
}
public function getRoll(): ?bool
{
return $this->roll;
}
public function setRoll(bool $roll): self
{
$this->roll = $roll;
return $this;
}
public function getTile(): ?bool
{
return $this->tile;
}
public function setTile(bool $tile): self
{
$this->tile = $tile;
return $this;
}
public function getCheckerboard(): ?bool
{
return $this->checkerboard;
}
public function setCheckerboard(bool $checkerboard): self
{
$this->checkerboard = $checkerboard;
return $this;
}
public function ismonolithic(): ?bool
{
return $this->monolithic;
}
public function setmonolithic(bool $monolithic): self
{
$this->monolithic = $monolithic;
return $this;
}
public function isBrick(): ?bool
{
return $this->brick;
}
public function setBrick(bool $brick): self
{
$this->brick = $brick;
return $this;
}
public function isAshlar(): ?bool
{
return $this->ashlar;
}
public function setAshlar(bool $ashlar): self
{
$this->ashlar = $ashlar;
return $this;
}
public function getOrderAppearance(): ?int
{
return $this->orderAppearance;
}
public function setOrderAppearance(int $order_appearance): self
{
$this->orderAppearance = $order_appearance;
return $this;
}
public function getActif(): ?bool
{
return $this->actif;
}
public function setActif(bool $actif): self
{
$this->actif = $actif;
return $this;
}
/**
* @return mixed
*/
public function getSlug()
{
return $this->slug;
}
/**
* @param mixed $slug
*/
public function setSlug($slug): void
{
$this->slug = $slug;
}
/**
* @ORM\PrePersist
* @ORM\PreUpdate
*/
public function updateSlug()
{
$this->slug = $this->slugify($this->name);
}
/**
* @ORM\PrePersist
*/
public function initOrderApparearance()
{
$this->orderAppearance = 0;
$this->createdAt = new DateTime();
$this->updatedAt = new DateTime();
}
/**
* @return DateTime
*/
public function getCreatedAt(): DateTime
{
return $this->createdAt;
}
/**
* @param DateTime $createdAt
*/
public function setCreatedAt(DateTime $createdAt): void
{
$this->createdAt = $createdAt;
}
/**
* @return DateTime
*/
public function getUpdatedAt(): DateTime
{
return $this->updatedAt;
}
/**
* @param DateTime $updatedAt
*/
public function setUpdatedAt(DateTime $updatedAt): void
{
$this->updatedAt = $updatedAt;
}
/**
* @return DoctrineCollection|Attachment[]
*/
public function getAttachments(): ?DoctrineCollection
{
return $this->attachments;
}
public function addAttachment(Attachment $attachment): self
{
if (!$this->attachments->contains($attachment)) {
$this->attachments[] = $attachment;
$attachment->setCollection($this);
}
return $this;
}
public function removeAttachment(Attachment $attachment): self
{
if ($this->attachments->contains($attachment)) {
$this->attachments->removeElement($attachment);
// set the owning side to null (unless already changed)
if ($attachment->getCollection() === $this) {
$attachment->setCollection(null);
}
}
return $this;
}
/**
* @return DoctrineCollection|Product[]
*/
public function getProducts(): DoctrineCollection
{
return $this->products;
}
public function addProduct(Product $product): self
{
if (!$this->products->contains($product)) {
$this->products[] = $product;
$product->setCollection($this);
}
return $this;
}
public function removeProduct(Product $product): self
{
if ($this->products->contains($product)) {
$this->products->removeElement($product);
// set the owning side to null (unless already changed)
if ($product->getCollection() === $this) {
$product->setCollection(null);
}
}
return $this;
}
public function getNew(): ?bool
{
return $this->new;
}
public function setNew(?bool $new): self
{
$this->new = $new;
return $this;
}
}