src/Entity/Product.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ProductRepository;
  4. use Cofondateur\SocleTechniqueBundle\Annotation\CrudField;
  5. use Cofondateur\SocleTechniqueBundle\Traits\SEOInterface;
  6. use Cofondateur\SocleTechniqueBundle\Traits\SEOTrait;
  7. use Cofondateur\SocleTechniqueBundle\Traits\SluggableInterface;
  8. use Cofondateur\SocleTechniqueBundle\Traits\SluggableTrait;
  9. use Cofondateur\SocleTechniqueBundle\Traits\SortableInterface;
  10. use Cofondateur\SocleTechniqueBundle\Traits\SortableTrait;
  11. use Doctrine\ORM\Mapping as ORM;
  12. use Symfony\Component\HttpFoundation\File\File;
  13. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  14. use Symfony\Component\Validator\Constraints as Assert;
  15. use Doctrine\Common\Collections\ArrayCollection;
  16. use Doctrine\Common\Collections\Collection;
  17. use App\Form\ParagraphFormType;
  18. /**
  19.  * @Vich\Uploadable
  20.  * @ORM\Entity(repositoryClass=ProductRepository::class)
  21.  */
  22. class Product implements SEOInterfaceSluggableInterfaceSortableInterface
  23. {
  24.     
  25.     use SEOTrait;
  26.     use SortableTrait;
  27.     use SluggableTrait;
  28.     
  29.     /**
  30.      * @ORM\Id
  31.      * @ORM\GeneratedValue
  32.      * @ORM\Column(type="integer")
  33.      */
  34.     private $id;
  35.     /**
  36.      * @ORM\Column(type="string", length=255, nullable=true)
  37.      * @CrudField(label="Titre", index=true)
  38.      */
  39.     private $title;
  40.     /**
  41.      * @ORM\Column(type="text", nullable=true)
  42.      * @CrudField(label="Introduction", ckeditor=true)
  43.      */
  44.     private $intro;
  45.     /**
  46.      * @ORM\ManyToOne(targetEntity=Category::class, inversedBy="products")
  47.      * @CrudField(label="Catégorie", index=true)
  48.      */
  49.     private $category;
  50.     /**
  51.      * @ORM\OneToMany(targetEntity=Paragraph::class, mappedBy="product", cascade={"persist", "remove"})
  52.      * @CrudField(label="Paragraphes", formType=ParagraphFormType::class, tab="Paragraphes")
  53.      */
  54.     private $paragraphs;
  55.     /**
  56.      * @ORM\OneToMany(targetEntity=Achievement::class, mappedBy="product")
  57.      */
  58.     private $achievements;
  59.     /**
  60.      * NOTE: This is not a mapped field of entity metadata, just a simple property.
  61.      * @Vich\UploadableField(mapping="default", fileNameProperty="productName", size="productSize")
  62.      * @Assert\Expression("this.getProductFile() or this.getProductName()", message = "Veuillez sélectionner un fichier")
  63.      * @Assert\File(
  64.      *     maxSize = "1200k"
  65.      * )
  66.      * @CrudField(label="Visuel principal")
  67.      * @var File
  68.      */
  69.     private $productFile;
  70.     /**
  71.      * @ORM\Column(type="string", length=255, nullable=true)
  72.      *
  73.      * @var string
  74.      */
  75.     private $productName;
  76.     /**
  77.      * @ORM\Column(type="integer", nullable=true)
  78.      *
  79.      * @var integer
  80.      */
  81.     private $productSize;
  82.     /**
  83.      * @ORM\Column(type="datetime", nullable=true)
  84.      *
  85.      * @var \DateTime
  86.      */
  87.     private $productFileUpdatedAt;
  88.     /**
  89.      * @ORM\Column(type="boolean")
  90.      * @CrudField(label="Affiché", index=true)
  91.      */
  92.     private $display 1;
  93.     public function __construct()
  94.     {
  95.         $this->paragraphs = new ArrayCollection();
  96.         $this->achievements = new ArrayCollection();
  97.     }
  98.     public function __toString(): string
  99.     {
  100.         return $this->getTitle() ?? $this->getId() ?? "N/A";
  101.     }
  102.     public function getId(): ?int
  103.     {
  104.         return $this->id;
  105.     }
  106.     /**
  107.      * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
  108.      * of 'UploadedFile' is injected into this setter to trigger the  update. If this
  109.      * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
  110.      * must be able to accept an instance of 'File' as the bundle will inject one here
  111.      * during Doctrine hydration.
  112.      *
  113.      * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $image
  114.      */
  115.     public function setProductFile(File $image null)
  116.     {
  117.         $this->productFile $image;
  118.         if (null !== $image) {
  119.             // It is required that at least one field changes if you are using doctrine
  120.             // otherwise the event listeners won't be called and the file is lost
  121.             $this->productFileUpdatedAt = new \DateTimeImmutable();
  122.         }
  123.     }
  124.     public function getProductFile()
  125.     {
  126.         return $this->productFile;
  127.     }
  128.     public function getProductName(): ?string
  129.     {
  130.         return $this->productName;
  131.     }
  132.     public function setProductName(?string $productName): self
  133.     {
  134.         $this->productName $productName;
  135.         return $this;
  136.     }
  137.     public function getProductSize(): ?int
  138.     {
  139.         return $this->productSize;
  140.     }
  141.     public function setProductSize(?int $productSize): self
  142.     {
  143.         $this->productSize $productSize;
  144.         return $this;
  145.     }
  146.     public function getProductFileUpdatedAt(): ?\DateTimeInterface
  147.     {
  148.         return $this->productFileUpdatedAt;
  149.     }
  150.     public function setProductFileUpdatedAt(?\DateTimeInterface $productFileUpdatedAt): self
  151.     {
  152.         $this->productFileUpdatedAt $productFileUpdatedAt;
  153.         return $this;
  154.     }
  155.     public function getTitle(): ?string
  156.     {
  157.         return $this->title;
  158.     }
  159.     public function setTitle(?string $title): self
  160.     {
  161.         $this->title $title;
  162.         return $this;
  163.     }
  164.     public function getIntro(): ?string
  165.     {
  166.         return $this->intro;
  167.     }
  168.     public function setIntro(?string $intro): self
  169.     {
  170.         $this->intro $intro;
  171.         return $this;
  172.     }
  173.     public function getCategory(): ?Category
  174.     {
  175.         return $this->category;
  176.     }
  177.     public function setCategory(?Category $category): self
  178.     {
  179.         $this->category $category;
  180.         return $this;
  181.     }
  182.     /**
  183.      * @return Collection|Paragraph[]
  184.      */
  185.     public function getParagraphs(): Collection
  186.     {
  187.         return $this->paragraphs;
  188.     }
  189.     public function addParagraph(Paragraph $paragraph): self
  190.     {
  191.         if (!$this->paragraphs->contains($paragraph)) {
  192.             $this->paragraphs[] = $paragraph;
  193.             $paragraph->setProduct($this);
  194.         }
  195.         return $this;
  196.     }
  197.     public function removeParagraph(Paragraph $paragraph): self
  198.     {
  199.         if ($this->paragraphs->removeElement($paragraph)) {
  200.             // set the owning side to null (unless already changed)
  201.             if ($paragraph->getProduct() === $this) {
  202.                 $paragraph->setProduct(null);
  203.             }
  204.         }
  205.         return $this;
  206.     }
  207.     /**
  208.      * @return Collection|Achievement[]
  209.      */
  210.     public function getAchievements(): Collection
  211.     {
  212.         return $this->achievements;
  213.     }
  214.     public function addAchievement(Achievement $achievement): self
  215.     {
  216.         if (!$this->achievements->contains($achievement)) {
  217.             $this->achievements[] = $achievement;
  218.             $achievement->setProduct($this);
  219.         }
  220.         return $this;
  221.     }
  222.     public function removeAchievement(Achievement $achievement): self
  223.     {
  224.         if ($this->achievements->removeElement($achievement)) {
  225.             // set the owning side to null (unless already changed)
  226.             if ($achievement->getProduct() === $this) {
  227.                 $achievement->setProduct(null);
  228.             }
  229.         }
  230.         return $this;
  231.     }
  232.     public function getDisplay(): ?bool
  233.     {
  234.         return $this->display;
  235.     }
  236.     public function setDisplay(bool $display): self
  237.     {
  238.         $this->display $display;
  239.         return $this;
  240.     }
  241. }