src/Entity/Tag.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\TagRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Gedmo\Mapping\Annotation as Gedmo;
  8. use Symfony\Component\HttpFoundation\File\File;
  9. use Symfony\Component\Serializer\Annotation\Groups;
  10. use Symfony\Component\Serializer\Annotation\SerializedName;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  13. /**
  14.  * @ORM\Entity(repositoryClass=TagRepository::class)
  15.  * @Vich\Uploadable
  16.  */
  17. class Tag
  18. {
  19.     /**
  20.      * @ORM\Id
  21.      * @ORM\GeneratedValue
  22.      * @ORM\Column(type="integer")
  23.      * @Groups({"tag:read:id", "search", "user_favorite:read", "event:read"})
  24.      */
  25.     private $id;
  26.     /**
  27.      * @ORM\Column(type="string", length=255)
  28.      * @Assert\NotBlank
  29.      * @Groups({"tag:read:name", "user_favorite:read", "event:read", "search"})
  30.      */
  31.     private $name;
  32.     /**
  33.      * @ORM\Column(type="text", nullable=true)
  34.      */
  35.     private $description;
  36.     /**
  37.      * @ORM\Column(type="float", options={"default": "1"})
  38.      */
  39.     private $coef 1;
  40.     /**
  41.      * @ORM\Column(type="float", options={"default": "1"})
  42.      */
  43.     private $visioCoef 1;
  44.     /**
  45.      * @ORM\OneToMany(targetEntity=SpecialistTag::class, mappedBy="tag", orphanRemoval=true)
  46.      */
  47.     private $specialistTags;
  48.     /**
  49.      * @ORM\OneToMany(targetEntity=CompanyTag::class, mappedBy="tag", orphanRemoval=true, cascade={"persist", "refresh", "remove"})
  50.      */
  51.     private $companyTags;
  52.     /**
  53.      * @ORM\Column(type="datetime")
  54.      * @Gedmo\Timestampable(on="create")
  55.      */
  56.     private $createdAt;
  57.     /**
  58.      * @ORM\Column(type="string", length=255, nullable=true)
  59.      */
  60.     private $linkedId;
  61.     /**
  62.      * @ORM\Column(type="float", nullable=true)
  63.      */
  64.     private $recommendedPriceHt;
  65.     /**
  66.      * @ORM\OneToMany(targetEntity=VisioEventPromotion::class, mappedBy="tag")
  67.      */
  68.     private $visioEventPromotions;
  69.     /**
  70.      * @ORM\OneToMany(targetEntity=VisioEvent::class, mappedBy="tag")
  71.      */
  72.     private $visioEvents;
  73.     /**
  74.      * @ORM\ManyToOne(targetEntity=Tag::class, inversedBy="children")
  75.      */
  76.     private $parent;
  77.     /**
  78.      * @ORM\OneToMany(targetEntity=Tag::class, mappedBy="parent")
  79.      */
  80.     private $children;
  81.     /**
  82.      * @ORM\Column(type="string", length=255, nullable=true)
  83.      */
  84.     private $image;
  85.     /**
  86.      * @Vich\UploadableField(mapping="tag_images", fileNameProperty="image")
  87.      * @Assert\File(
  88.      *     mimeTypes={"image/jpeg", "image/gif", "image/png", "image/jpg"},
  89.      *     maxSize="700Ki",
  90.      * )
  91.      * @var File|null
  92.      */
  93.     private $imageFile;
  94.     /**
  95.      * @ORM\Column(type="datetime", nullable=true)
  96.      */
  97.     private $updatedAt;
  98.    
  99.     public function __construct()
  100.     {
  101.         $this->specialistTags = new ArrayCollection();
  102.         $this->companyTags = new ArrayCollection();
  103.         $this->createdAt = new \DateTime();
  104.         $this->visioEventPromotions = new ArrayCollection();
  105.         $this->visioEvents = new ArrayCollection();
  106.         $this->children = new ArrayCollection();
  107.     }
  108.     public function getId(): ?int
  109.     {
  110.         return $this->id;
  111.     }
  112.     public function getName(): ?string
  113.     {
  114.         return $this->name;
  115.     }
  116.     public function setName(string $name): self
  117.     {
  118.         $this->name $name;
  119.         return $this;
  120.     }
  121.     public function getDescription(): ?string
  122.     {
  123.         return $this->description;
  124.     }
  125.     public function setDescription(?string $description): self
  126.     {
  127.         $this->description $description;
  128.         return $this;
  129.     }
  130.     public function getCreatedAt(): ?\DateTime
  131.     {
  132.         return $this->createdAt;
  133.     }
  134.     public function setCreatedAt(\DateTime $createdAt): self
  135.     {
  136.         $this->createdAt $createdAt;
  137.         return $this;
  138.     }
  139.     /**
  140.      * @return Collection|SpecialistTag[]
  141.      */
  142.     public function getSpecialistTags(): Collection
  143.     {
  144.         return $this->specialistTags;
  145.     }
  146.     public function setSpecialistTags(array $specialistTags): self
  147.     {
  148.         $this->specialistTags = new ArrayCollection();
  149.         if (is_array($specialistTags)){
  150.             $this->specialistTags = new ArrayCollection($specialistTags);
  151.         }
  152.         return $this;
  153.     }
  154.     public function addSpecialistTag(SpecialistTag $specialistTag): self
  155.     {
  156.         if (!$this->specialistTags->contains($specialistTag)) {
  157.             $this->specialistTags[] = $specialistTag;
  158.             $specialistTag->setTag($this);
  159.         }
  160.         return $this;
  161.     }
  162.     public function removeSpecialistTag(SpecialistTag $specialistTag): self
  163.     {
  164.         if ($this->specialistTags->removeElement($specialistTag)) {
  165.             // set the owning side to null (unless already changed)
  166.             if ($specialistTag->getTag() === $this) {
  167.                 $specialistTag->setTag(null);
  168.             }
  169.         }
  170.         return $this;
  171.     }
  172.     public function __toString()
  173.     {
  174.         return $this->name;
  175.     }
  176.     public function getCoef(): ?float
  177.     {
  178.         return $this->coef;
  179.     }
  180.     public function setCoef(?float $coef): self
  181.     {
  182.         $this->coef floatval($coef);
  183.         return $this;
  184.     }
  185.     /**
  186.      * @return Collection|CompanyTag[]
  187.      */
  188.     public function getCompanyTags(): Collection
  189.     {
  190.         return $this->companyTags;
  191.     }
  192.     public function setCompanyTags(array $companyTags): self
  193.     {
  194.         $this->companyTags = new ArrayCollection();
  195.         if (is_array($companyTags)){
  196.             $this->companyTags = new ArrayCollection($companyTags);
  197.         }
  198.         return $this;
  199.     }
  200.     public function addCompanyTag(CompanyTag $companyTag): self
  201.     {
  202.         if (!$this->companyTags->contains($companyTag)) {
  203.             $this->companyTags[] = $companyTag;
  204.             $companyTag->setTag($this);
  205.         }
  206.         return $this;
  207.     }
  208.     public function removeCompanyTag(CompanyTag $companyTag): self
  209.     {
  210.         if ($this->companyTags->removeElement($companyTag)) {
  211.             // set the owning side to null (unless already changed)
  212.             if ($companyTag->getTag() === $this) {
  213.                 $companyTag->setTag(null);
  214.             }
  215.         }
  216.         return $this;
  217.     }
  218.     public function getLinkedId(): ?string
  219.     {
  220.         return $this->linkedId;
  221.     }
  222.     public function setLinkedId(string $linkedId): self
  223.     {
  224.         $this->linkedId $linkedId;
  225.         return $this;
  226.     }
  227.     public function getRecommendedPriceHt(): ?float
  228.     {
  229.         return $this->recommendedPriceHt;
  230.     }
  231.     public function setRecommendedPriceHt(?float $recommendedPriceHt): self
  232.     {
  233.         $this->recommendedPriceHt $recommendedPriceHt;
  234.         return $this;
  235.     }
  236.     /**
  237.      * @return Collection<int, VisioEventPromotion>
  238.      */
  239.     public function getVisioEventPromotions(): Collection
  240.     {
  241.         return $this->visioEventPromotions;
  242.     }
  243.     public function addVisioEventPromotion(VisioEventPromotion $visioEventPromotion): self
  244.     {
  245.         if (!$this->visioEventPromotions->contains($visioEventPromotion)) {
  246.             $this->visioEventPromotions[] = $visioEventPromotion;
  247.             $visioEventPromotion->setTag($this);
  248.         }
  249.         return $this;
  250.     }
  251.     public function removeVisioEventPromotion(VisioEventPromotion $visioEventPromotion): self
  252.     {
  253.         if ($this->visioEventPromotions->removeElement($visioEventPromotion)) {
  254.             // set the owning side to null (unless already changed)
  255.             if ($visioEventPromotion->getTag() === $this) {
  256.                 $visioEventPromotion->setTag(null);
  257.             }
  258.         }
  259.         return $this;
  260.     }
  261.     /**
  262.      * @return Collection<int, VisioEvent>
  263.      */
  264.     public function getVisioEvents(): Collection
  265.     {
  266.         return $this->visioEvents;
  267.     }
  268.     public function addVisioEvent(VisioEvent $visioEvent): self
  269.     {
  270.         if (!$this->visioEvents->contains($visioEvent)) {
  271.             $this->visioEvents[] = $visioEvent;
  272.             $visioEvent->setTag($this);
  273.         }
  274.         return $this;
  275.     }
  276.     public function removeVisioEvent(VisioEvent $visioEvent): self
  277.     {
  278.         if ($this->visioEvents->removeElement($visioEvent)) {
  279.             // set the owning side to null (unless already changed)
  280.             if ($visioEvent->getTag() === $this) {
  281.                 $visioEvent->setTag(null);
  282.             }
  283.         }
  284.         return $this;
  285.     }
  286.     /**
  287.      * @param float $visioCoef
  288.      * @return Tag
  289.      */
  290.     public function setVisioCoef(float $visioCoef): Tag
  291.     {
  292.         $this->visioCoef $visioCoef;
  293.         return $this;
  294.     }
  295.     /**
  296.      * @return float
  297.      */
  298.     public function getVisioCoef(): float
  299.     {
  300.         return $this->visioCoef;
  301.     }
  302.     public function getParent(): ?self
  303.     {
  304.         return $this->parent;
  305.     }
  306.     public function setParent(?self $parent): self
  307.     {
  308.         $this->parent $parent;
  309.         return $this;
  310.     }
  311.     /**
  312.      * @return Collection<int, self>
  313.      */
  314.     public function getChildren(): Collection
  315.     {
  316.         return $this->children;
  317.     }
  318.     public function addChild(self $child): self
  319.     {
  320.         if (!$this->children->contains($child)) {
  321.             $this->children[] = $child;
  322.             $child->setParent($this);
  323.         }
  324.         return $this;
  325.     }
  326.     public function removeChild(self $child): self
  327.     {
  328.         if ($this->children->removeElement($child)) {
  329.             // set the owning side to null (unless already changed)
  330.             if ($child->getParent() === $this) {
  331.                 $child->setParent(null);
  332.             }
  333.         }
  334.         return $this;
  335.     }
  336.     public function getImage(): ?string
  337.     {
  338.         return $this->image;
  339.     }
  340.     public function setImage(?string $image): self
  341.     {
  342.         $this->image $image;
  343.         return $this;
  344.     }
  345.     
  346.     /**
  347.      * @return File|null
  348.      */
  349.     public function getImageFile(): ?File
  350.     {
  351.         return $this->imageFile;
  352.     }
  353.     /**
  354.      * @param File|null $imageFile
  355.      * @return Tag
  356.      */
  357.     public function setImageFile(?File $imageFile null): self
  358.     {
  359.         $this->imageFile $imageFile;
  360.         if ($imageFile) {
  361.             // if 'updatedAt' is not defined in your entity, use another property
  362.             $this->updatedAt = new \DateTime('now');
  363.         }
  364.         return $this;
  365.     }
  366.     public function getUpdatedAt(): ?\DateTimeInterface
  367.     {
  368.         return $this->updatedAt;
  369.     }
  370.     public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  371.     {
  372.         $this->updatedAt $updatedAt;
  373.         return $this;
  374.     }
  375.    
  376. }