src/Entity/Collection.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Traits\CustomSlugify;
  4. use DateTime;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection as DoctrineCollection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Gedmo\Mapping\Annotation as Gedmo;
  9. use JsonSerializable;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. /**
  12.  * @ORM\Entity(repositoryClass="App\Repository\CollectionRepository")
  13.  * @ORM\HasLifecycleCallbacks()
  14.  */
  15. class Collection implements JsonSerializable
  16. {
  17.     use CustomSlugify;
  18.     /**
  19.      * @ORM\Id()
  20.      * @ORM\GeneratedValue()
  21.      * @ORM\Column(type="integer")
  22.      */
  23.     private $id;
  24.     /**
  25.      * @ORM\Column(type="string", length=50)
  26.      * @Assert\Length(min = 4, max = 20, allowEmptyString = false )
  27.      * @Assert\Regex("/[A-Za-z]/")
  28.      */
  29.     private $name;
  30.     /**
  31.      * @Gedmo\Translatable
  32.      * @ORM\Column(type="string", length=512, nullable=true)
  33.      */
  34.     private $description;
  35.     /**
  36.      * @ORM\Column(type="date", nullable=true)
  37.      */
  38.     private $launchYear;
  39.     /**
  40.      * @ORM\Column(type="boolean")
  41.      */
  42.     private $roll;
  43.     /**
  44.      * @ORM\Column(type="boolean")
  45.      */
  46.     private $tile;
  47.     /**
  48.      * @ORM\Column(type="boolean")
  49.      */
  50.     private $checkerboard;
  51.     /**
  52.      * @ORM\Column(type="boolean")
  53.      */
  54.     private $monolithic;
  55.     /**
  56.      * @ORM\Column(type="boolean")
  57.      */
  58.     private $brick;
  59.     /**
  60.      * @ORM\Column(type="boolean")
  61.      */
  62.     private $ashlar;
  63.     /**
  64.      * @ORM\Column(type="smallint")
  65.      */
  66.     private $orderAppearance;
  67.     /**
  68.      * @ORM\Column(type="boolean")
  69.      */
  70.     private $actif;
  71.     /**
  72.      * @ORM\Column(type="string", length=50)
  73.      */
  74.     private $slug;
  75.     /**
  76.      * @var DateTime
  77.      * @Gedmo\Timestampable(on="create")
  78.      * @ORM\Column(type="datetime", nullable=true)
  79.      */
  80.     protected $createdAt;
  81.     /**
  82.      * @var DateTime
  83.      * @Gedmo\Timestampable(on="update")
  84.      * @ORM\Column(type="datetime", nullable=true)
  85.      */
  86.     protected $updatedAt;
  87.     /**
  88.      * @ORM\OneToMany(targetEntity="App\Entity\Attachment", mappedBy="collection", cascade={"persist", "remove"}, fetch="EAGER")
  89.      */
  90.     private $attachments;
  91.     /**
  92.      * @ORM\OneToMany(targetEntity="App\Entity\Product", mappedBy="collection")
  93.      */
  94.     private $products;
  95.     /**
  96.      * @ORM\Column(type="boolean", nullable=true)
  97.      */
  98.     private $new;
  99.     public function __construct()
  100.     {
  101.         $this->attachments = new ArrayCollection();
  102.         $this->products = new ArrayCollection();
  103.     }
  104.     public function setTranslatableLocale($locale)
  105.     {
  106.         $this->locale $locale;
  107.     }
  108.     public function __toString()
  109.     {
  110.         return $this->name.'';
  111.     }
  112.     public function jsonSerialize()
  113.     {
  114.         return [
  115.             'id' => $this->getId(),
  116.             'name' => $this->getName(),
  117.             'description' => $this->getDescription(),
  118.             'orderAppearance' => $this->getOrderAppearance(),
  119.             'slug' => $this->getSlug(),
  120.             'role' => $this->getRoll(),
  121.             'tile' => $this->getTile(),
  122.             'checkerboard' => $this->getCheckerboard(),
  123.             'monolithic' => $this->ismonolithic(),
  124.             'brick' => $this->isBrick(),
  125.             'ashlar' => $this->isAshlar(),
  126.             'lanchYear' => $this->getLaunchYear(),
  127.             'order' => $this->getOrderAppearance(),
  128.             'products' => $this->getProducts()->getValues(),
  129.             'attachments' => isset($this->attachmentsFile) ? $this->attachmentsFile null,
  130.             'new' => $this->getNew()
  131.         ];
  132.     }
  133.     public function getId(): ?int
  134.     {
  135.         return $this->id;
  136.     }
  137.     public function getName(): ?string
  138.     {
  139.         return $this->name;
  140.     }
  141.     public function setName(string $name): self
  142.     {
  143.         $this->name ucfirst($name);
  144.         return $this;
  145.     }
  146.     /**
  147.      * @return mixed
  148.      */
  149.     public function getDescription()
  150.     {
  151.         return $this->description;
  152.     }
  153.     /**
  154.      * @param mixed $description
  155.      */
  156.     public function setDescription($description): void
  157.     {
  158.         $this->description $description;
  159.     }
  160.     public function getLaunchYear(): ?\DateTimeInterface
  161.     {
  162.         return $this->launchYear;
  163.     }
  164.     public function setLaunchYear(?\DateTimeInterface $launchYear): self
  165.     {
  166.         $this->launchYear $launchYear;
  167.         return $this;
  168.     }
  169.     public function getRoll(): ?bool
  170.     {
  171.         return $this->roll;
  172.     }
  173.     public function setRoll(bool $roll): self
  174.     {
  175.         $this->roll $roll;
  176.         return $this;
  177.     }
  178.     public function getTile(): ?bool
  179.     {
  180.         return $this->tile;
  181.     }
  182.     public function setTile(bool $tile): self
  183.     {
  184.         $this->tile $tile;
  185.         return $this;
  186.     }
  187.     public function getCheckerboard(): ?bool
  188.     {
  189.         return $this->checkerboard;
  190.     }
  191.     public function setCheckerboard(bool $checkerboard): self
  192.     {
  193.         $this->checkerboard $checkerboard;
  194.         return $this;
  195.     }
  196.     public function ismonolithic(): ?bool
  197.     {
  198.         return $this->monolithic;
  199.     }
  200.     public function setmonolithic(bool $monolithic): self
  201.     {
  202.         $this->monolithic $monolithic;
  203.         return $this;
  204.     }
  205.     public function isBrick(): ?bool
  206.     {
  207.         return $this->brick;
  208.     }
  209.     public function setBrick(bool $brick): self
  210.     {
  211.         $this->brick $brick;
  212.         return $this;
  213.     }
  214.     public function isAshlar(): ?bool
  215.     {
  216.         return $this->ashlar;
  217.     }
  218.     public function setAshlar(bool $ashlar): self
  219.     {
  220.         $this->ashlar $ashlar;
  221.         return $this;
  222.     }
  223.     public function getOrderAppearance(): ?int
  224.     {
  225.         return $this->orderAppearance;
  226.     }
  227.     public function setOrderAppearance(int $order_appearance): self
  228.     {
  229.         $this->orderAppearance $order_appearance;
  230.         return $this;
  231.     }
  232.     public function getActif(): ?bool
  233.     {
  234.         return $this->actif;
  235.     }
  236.     public function setActif(bool $actif): self
  237.     {
  238.         $this->actif $actif;
  239.         return $this;
  240.     }
  241.     /**
  242.      * @return mixed
  243.      */
  244.     public function getSlug()
  245.     {
  246.         return $this->slug;
  247.     }
  248.     /**
  249.      * @param mixed $slug
  250.      */
  251.     public function setSlug($slug): void
  252.     {
  253.         $this->slug $slug;
  254.     }
  255.     /**
  256.      * @ORM\PrePersist
  257.      * @ORM\PreUpdate
  258.      */
  259.     public function updateSlug()
  260.     {
  261.         $this->slug $this->slugify($this->name);
  262.     }
  263.     /**
  264.      * @ORM\PrePersist
  265.      */
  266.     public function initOrderApparearance()
  267.     {
  268.         $this->orderAppearance 0;
  269.         $this->createdAt = new DateTime();
  270.         $this->updatedAt = new DateTime();
  271.     }
  272.     /**
  273.      * @return DateTime
  274.      */
  275.     public function getCreatedAt(): DateTime
  276.     {
  277.         return $this->createdAt;
  278.     }
  279.     /**
  280.      * @param DateTime $createdAt
  281.      */
  282.     public function setCreatedAt(DateTime $createdAt): void
  283.     {
  284.         $this->createdAt $createdAt;
  285.     }
  286.     /**
  287.      * @return DateTime
  288.      */
  289.     public function getUpdatedAt(): DateTime
  290.     {
  291.         return $this->updatedAt;
  292.     }
  293.     /**
  294.      * @param DateTime $updatedAt
  295.      */
  296.     public function setUpdatedAt(DateTime $updatedAt): void
  297.     {
  298.         $this->updatedAt $updatedAt;
  299.     }
  300.     /**
  301.      * @return DoctrineCollection|Attachment[]
  302.      */
  303.     public function getAttachments(): ?DoctrineCollection
  304.     {
  305.         return $this->attachments;
  306.     }
  307.     public function addAttachment(Attachment $attachment): self
  308.     {
  309.         if (!$this->attachments->contains($attachment)) {
  310.             $this->attachments[] = $attachment;
  311.             $attachment->setCollection($this);
  312.         }
  313.         return $this;
  314.     }
  315.     public function removeAttachment(Attachment $attachment): self
  316.     {
  317.         if ($this->attachments->contains($attachment)) {
  318.             $this->attachments->removeElement($attachment);
  319.             // set the owning side to null (unless already changed)
  320.             if ($attachment->getCollection() === $this) {
  321.                 $attachment->setCollection(null);
  322.             }
  323.         }
  324.         return $this;
  325.     }
  326.     /**
  327.      * @return DoctrineCollection|Product[]
  328.      */
  329.     public function getProducts(): DoctrineCollection
  330.     {
  331.         return $this->products;
  332.     }
  333.     public function addProduct(Product $product): self
  334.     {
  335.         if (!$this->products->contains($product)) {
  336.             $this->products[] = $product;
  337.             $product->setCollection($this);
  338.         }
  339.         return $this;
  340.     }
  341.     public function removeProduct(Product $product): self
  342.     {
  343.         if ($this->products->contains($product)) {
  344.             $this->products->removeElement($product);
  345.             // set the owning side to null (unless already changed)
  346.             if ($product->getCollection() === $this) {
  347.                 $product->setCollection(null);
  348.             }
  349.         }
  350.         return $this;
  351.     }
  352.     public function getNew(): ?bool
  353.     {
  354.         return $this->new;
  355.     }
  356.     public function setNew(?bool $new): self
  357.     {
  358.         $this->new $new;
  359.         return $this;
  360.     }
  361. }