<?php
namespace App\Entity;
use App\Repository\TagRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\SerializedName;
use Symfony\Component\Validator\Constraints as Assert;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\Entity(repositoryClass=TagRepository::class)
* @Vich\Uploadable
*/
class Tag
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"tag:read:id", "search", "user_favorite:read", "event:read"})
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
* @Assert\NotBlank
* @Groups({"tag:read:name", "user_favorite:read", "event:read", "search"})
*/
private $name;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $description;
/**
* @ORM\Column(type="float", options={"default": "1"})
*/
private $coef = 1;
/**
* @ORM\Column(type="float", options={"default": "1"})
*/
private $visioCoef = 1;
/**
* @ORM\OneToMany(targetEntity=SpecialistTag::class, mappedBy="tag", orphanRemoval=true)
*/
private $specialistTags;
/**
* @ORM\OneToMany(targetEntity=CompanyTag::class, mappedBy="tag", orphanRemoval=true, cascade={"persist", "refresh", "remove"})
*/
private $companyTags;
/**
* @ORM\Column(type="datetime")
* @Gedmo\Timestampable(on="create")
*/
private $createdAt;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $linkedId;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $recommendedPriceHt;
/**
* @ORM\OneToMany(targetEntity=VisioEventPromotion::class, mappedBy="tag")
*/
private $visioEventPromotions;
/**
* @ORM\OneToMany(targetEntity=VisioEvent::class, mappedBy="tag")
*/
private $visioEvents;
/**
* @ORM\ManyToOne(targetEntity=Tag::class, inversedBy="children")
*/
private $parent;
/**
* @ORM\OneToMany(targetEntity=Tag::class, mappedBy="parent")
*/
private $children;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $image;
/**
* @Vich\UploadableField(mapping="tag_images", fileNameProperty="image")
* @Assert\File(
* mimeTypes={"image/jpeg", "image/gif", "image/png", "image/jpg"},
* maxSize="700Ki",
* )
* @var File|null
*/
private $imageFile;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $updatedAt;
public function __construct()
{
$this->specialistTags = new ArrayCollection();
$this->companyTags = new ArrayCollection();
$this->createdAt = new \DateTime();
$this->visioEventPromotions = new ArrayCollection();
$this->visioEvents = new ArrayCollection();
$this->children = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getCreatedAt(): ?\DateTime
{
return $this->createdAt;
}
public function setCreatedAt(\DateTime $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
/**
* @return Collection|SpecialistTag[]
*/
public function getSpecialistTags(): Collection
{
return $this->specialistTags;
}
public function setSpecialistTags(array $specialistTags): self
{
$this->specialistTags = new ArrayCollection();
if (is_array($specialistTags)){
$this->specialistTags = new ArrayCollection($specialistTags);
}
return $this;
}
public function addSpecialistTag(SpecialistTag $specialistTag): self
{
if (!$this->specialistTags->contains($specialistTag)) {
$this->specialistTags[] = $specialistTag;
$specialistTag->setTag($this);
}
return $this;
}
public function removeSpecialistTag(SpecialistTag $specialistTag): self
{
if ($this->specialistTags->removeElement($specialistTag)) {
// set the owning side to null (unless already changed)
if ($specialistTag->getTag() === $this) {
$specialistTag->setTag(null);
}
}
return $this;
}
public function __toString()
{
return $this->name;
}
public function getCoef(): ?float
{
return $this->coef;
}
public function setCoef(?float $coef): self
{
$this->coef = floatval($coef);
return $this;
}
/**
* @return Collection|CompanyTag[]
*/
public function getCompanyTags(): Collection
{
return $this->companyTags;
}
public function setCompanyTags(array $companyTags): self
{
$this->companyTags = new ArrayCollection();
if (is_array($companyTags)){
$this->companyTags = new ArrayCollection($companyTags);
}
return $this;
}
public function addCompanyTag(CompanyTag $companyTag): self
{
if (!$this->companyTags->contains($companyTag)) {
$this->companyTags[] = $companyTag;
$companyTag->setTag($this);
}
return $this;
}
public function removeCompanyTag(CompanyTag $companyTag): self
{
if ($this->companyTags->removeElement($companyTag)) {
// set the owning side to null (unless already changed)
if ($companyTag->getTag() === $this) {
$companyTag->setTag(null);
}
}
return $this;
}
public function getLinkedId(): ?string
{
return $this->linkedId;
}
public function setLinkedId(string $linkedId): self
{
$this->linkedId = $linkedId;
return $this;
}
public function getRecommendedPriceHt(): ?float
{
return $this->recommendedPriceHt;
}
public function setRecommendedPriceHt(?float $recommendedPriceHt): self
{
$this->recommendedPriceHt = $recommendedPriceHt;
return $this;
}
/**
* @return Collection<int, VisioEventPromotion>
*/
public function getVisioEventPromotions(): Collection
{
return $this->visioEventPromotions;
}
public function addVisioEventPromotion(VisioEventPromotion $visioEventPromotion): self
{
if (!$this->visioEventPromotions->contains($visioEventPromotion)) {
$this->visioEventPromotions[] = $visioEventPromotion;
$visioEventPromotion->setTag($this);
}
return $this;
}
public function removeVisioEventPromotion(VisioEventPromotion $visioEventPromotion): self
{
if ($this->visioEventPromotions->removeElement($visioEventPromotion)) {
// set the owning side to null (unless already changed)
if ($visioEventPromotion->getTag() === $this) {
$visioEventPromotion->setTag(null);
}
}
return $this;
}
/**
* @return Collection<int, VisioEvent>
*/
public function getVisioEvents(): Collection
{
return $this->visioEvents;
}
public function addVisioEvent(VisioEvent $visioEvent): self
{
if (!$this->visioEvents->contains($visioEvent)) {
$this->visioEvents[] = $visioEvent;
$visioEvent->setTag($this);
}
return $this;
}
public function removeVisioEvent(VisioEvent $visioEvent): self
{
if ($this->visioEvents->removeElement($visioEvent)) {
// set the owning side to null (unless already changed)
if ($visioEvent->getTag() === $this) {
$visioEvent->setTag(null);
}
}
return $this;
}
/**
* @param float $visioCoef
* @return Tag
*/
public function setVisioCoef(float $visioCoef): Tag
{
$this->visioCoef = $visioCoef;
return $this;
}
/**
* @return float
*/
public function getVisioCoef(): float
{
return $this->visioCoef;
}
public function getParent(): ?self
{
return $this->parent;
}
public function setParent(?self $parent): self
{
$this->parent = $parent;
return $this;
}
/**
* @return Collection<int, self>
*/
public function getChildren(): Collection
{
return $this->children;
}
public function addChild(self $child): self
{
if (!$this->children->contains($child)) {
$this->children[] = $child;
$child->setParent($this);
}
return $this;
}
public function removeChild(self $child): self
{
if ($this->children->removeElement($child)) {
// set the owning side to null (unless already changed)
if ($child->getParent() === $this) {
$child->setParent(null);
}
}
return $this;
}
public function getImage(): ?string
{
return $this->image;
}
public function setImage(?string $image): self
{
$this->image = $image;
return $this;
}
/**
* @return File|null
*/
public function getImageFile(): ?File
{
return $this->imageFile;
}
/**
* @param File|null $imageFile
* @return Tag
*/
public function setImageFile(?File $imageFile = null): self
{
$this->imageFile = $imageFile;
if ($imageFile) {
// if 'updatedAt' is not defined in your entity, use another property
$this->updatedAt = new \DateTime('now');
}
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
}