src/Entity/Achievement.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\AchievementRepository;
  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\SortableTrait;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Doctrine\Common\Collections\Collection;
  12. use Doctrine\ORM\Mapping as ORM;
  13. use Symfony\Component\HttpFoundation\File\File;
  14. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  15. use Symfony\Component\Validator\Constraints as Assert;
  16. use App\Form\PhotoFormType;
  17. /**
  18.  * @Vich\Uploadable
  19.  * @ORM\Entity(repositoryClass=AchievementRepository::class)
  20.  */
  21. class Achievement implements SEOInterfaceSluggableInterface
  22. {
  23.     
  24.     use SEOTrait;
  25.     use SortableTrait;
  26.     use SluggableTrait;
  27.     
  28.     /**
  29.      * @ORM\Id
  30.      * @ORM\GeneratedValue
  31.      * @ORM\Column(type="integer")
  32.      */
  33.     private $id;
  34.      /**
  35.      * @ORM\ManyToOne(targetEntity=Product::class, inversedBy="achievements")
  36.      * @ORM\JoinColumn(nullable=false)
  37.      * @CrudField(label="Produit", index=true)
  38.      */
  39.     private $product;
  40.     /**
  41.      * @ORM\Column(type="string", length=255)
  42.      * @CrudField(label="Titre", index=true)
  43.      */
  44.     private $title;
  45.     /**
  46.      * @ORM\Column(type="text", nullable=true)
  47.      * @CrudField(label="Description", ckeditor=true)
  48.      */
  49.     private $description;
  50.     /**
  51.      * NOTE: This is not a mapped field of entity metadata, just a simple property.
  52.      * @Vich\UploadableField(mapping="default", fileNameProperty="achievementName", size="achievementSize")
  53.      * @Assert\Expression("this.getAchievementFile() or this.getAchievementName()", message = "Veuillez sélectionner un fichier")
  54.      * @Assert\File(
  55.      *     maxSize = "1200k"
  56.      * )
  57.      * @CrudField(label="Fichier")
  58.      * @var File
  59.      */
  60.     private $achievementFile;
  61.     /**
  62.      * @ORM\Column(type="string", length=255, nullable=true)
  63.      *
  64.      * @var string
  65.      */
  66.     private $achievementName;
  67.     /**
  68.      * @ORM\Column(type="integer", nullable=true)
  69.      *
  70.      * @var integer
  71.      */
  72.     private $achievementSize;
  73.     /**
  74.      * @ORM\Column(type="datetime", nullable=true)
  75.      *
  76.      * @var \DateTime
  77.      */
  78.     private $achievementFileUpdatedAt;
  79.     /**
  80.      * @ORM\OneToMany(targetEntity=Photo::class, mappedBy="achievement", cascade={"persist", "remove"})
  81.      * @CrudField(label="Photos", formType=PhotoFormType::class, tab="Photos")
  82.      * @ORM\OrderBy({"position" = "ASC"})
  83.      */
  84.     private $photos;
  85.     /**
  86.      * @ORM\Column(type="datetime")
  87.      */
  88.     private $updatedAt;
  89.     public function __construct()
  90.     {
  91.         $this->photos = new ArrayCollection();
  92.         $this->updatedAt = new \DateTime();
  93.     }
  94.     public function __toString(): string
  95.     {
  96.         return $this->getId() ?? "N/A";
  97.     }
  98.     public function getId(): ?int
  99.     {
  100.         return $this->id;
  101.     }
  102.     /**
  103.      * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
  104.      * of 'UploadedFile' is injected into this setter to trigger the  update. If this
  105.      * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
  106.      * must be able to accept an instance of 'File' as the bundle will inject one here
  107.      * during Doctrine hydration.
  108.      *
  109.      * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $image
  110.      */
  111.     public function setAchievementFile(File $image null)
  112.     {
  113.         $this->achievementFile $image;
  114.         if (null !== $image) {
  115.             // It is required that at least one field changes if you are using doctrine
  116.             // otherwise the event listeners won't be called and the file is lost
  117.             $this->achievementFileUpdatedAt = new \DateTimeImmutable();
  118.         }
  119.         $this->updatedAt = new \DateTime();
  120.     }
  121.     public function getAchievementFile()
  122.     {
  123.         return $this->achievementFile;
  124.     }
  125.     public function getAchievementName(): ?string
  126.     {
  127.         return $this->achievementName;
  128.     }
  129.     public function setAchievementName(?string $achievementName): self
  130.     {
  131.         $this->achievementName $achievementName;
  132.         $this->updatedAt = new \DateTime();
  133.         return $this;
  134.     }
  135.     public function getAchievementSize(): ?int
  136.     {
  137.         return $this->achievementSize;
  138.     }
  139.     public function setAchievementSize(?int $achievementSize): self
  140.     {
  141.         $this->achievementSize $achievementSize;
  142.         $this->updatedAt = new \DateTime();
  143.         return $this;
  144.     }
  145.     public function getAchievementFileUpdatedAt(): ?\DateTimeInterface
  146.     {
  147.         return $this->achievementFileUpdatedAt;
  148.     }
  149.     public function setAchievementFileUpdatedAt(?\DateTimeInterface $achievementFileUpdatedAt): self
  150.     {
  151.         $this->achievementFileUpdatedAt $achievementFileUpdatedAt;
  152.         $this->updatedAt = new \DateTime();
  153.         return $this;
  154.     }
  155.     public function getProduct(): ?Product
  156.     {
  157.         return $this->product;
  158.     }
  159.     public function setProduct(?Product $product): self
  160.     {
  161.         $this->product $product;
  162.         $this->updatedAt = new \DateTime();
  163.         return $this;
  164.     }
  165.     public function getTitle(): ?string
  166.     {
  167.         return $this->title;
  168.     }
  169.     public function setTitle(?string $title): self
  170.     {
  171.         $this->title $title;
  172.         $this->updatedAt = new \DateTime();
  173.         return $this;
  174.     }
  175.     public function getDescription(): ?string
  176.     {
  177.         return $this->description;
  178.     }
  179.     public function setDescription(?string $description): self
  180.     {
  181.         $this->description $description;
  182.         $this->updatedAt = new \DateTime();
  183.         return $this;
  184.     }
  185.     /**
  186.      * @return Collection|Photo[]
  187.      */
  188.     public function getPhotos(): Collection
  189.     {
  190.         return $this->photos;
  191.     }
  192.     public function addPhoto(Photo $photo): self
  193.     {
  194.         if (!$this->photos->contains($photo)) {
  195.             $this->photos[] = $photo;
  196.             $photo->setAchievement($this);
  197.         }
  198.         $this->updatedAt = new \DateTime();
  199.         return $this;
  200.     }
  201.     public function removePhoto(Photo $photo): self
  202.     {
  203.         if ($this->photos->removeElement($photo)) {
  204.             // set the owning side to null (unless already changed)
  205.             if ($photo->getAchievement() === $this) {
  206.                 $photo->setAchievement(null);
  207.             }
  208.         }
  209.         return $this;
  210.     }
  211.     public function getUpdatedAt(): ?\DateTimeInterface
  212.     {
  213.         return $this->updatedAt;
  214.     }
  215.     public function setUpdatedAt(\DateTimeInterface $updatedAt): self
  216.     {
  217.         $this->updatedAt $updatedAt;
  218.         return $this;
  219.     }
  220. }