src/Entity/AdMapping.php line 13

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\AdMappingRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Gedmo\Timestampable\Traits\TimestampableEntity;
  8. #[ORM\Entity(repositoryClassAdMappingRepository::class)]
  9. #[ORM\UniqueConstraint(name'unique_user'columns: ['user_id'])]
  10. class AdMapping
  11. {
  12.     use TimestampableEntity;
  13.     #[ORM\Id]
  14.     #[ORM\GeneratedValue]
  15.     #[ORM\Column]
  16.     private ?int $id null;
  17.     #[ORM\ManyToOne(inversedBy'adMappings')]
  18.     private ?User $user null;
  19.     #[ORM\OneToMany(mappedBy'adMapping'targetEntityAdMappingCustomer::class, cascade: ['all'])]
  20.     private Collection $adMappingCustomers;
  21.     public function __construct()
  22.     {
  23.         $this->adMappingCustomers = new ArrayCollection();
  24.     }
  25.     public function getId(): ?int
  26.     {
  27.         return $this->id;
  28.     }
  29.     public function getUser(): ?User
  30.     {
  31.         return $this->user;
  32.     }
  33.     public function setUser(?User $user): static
  34.     {
  35.         $this->user $user;
  36.         return $this;
  37.     }
  38.     /**
  39.      * @return Collection<int, AdMappingCustomer>
  40.      */
  41.     public function getAdMappingCustomers(): Collection
  42.     {
  43.         return $this->adMappingCustomers;
  44.     }
  45.     public function addAdMappingCustomer(AdMappingCustomer $adMappingCustomer): static
  46.     {
  47.         if (!$this->adMappingCustomers->contains($adMappingCustomer)) {
  48.             $this->adMappingCustomers->add($adMappingCustomer);
  49.             $adMappingCustomer->setAdMapping($this);
  50.         }
  51.         return $this;
  52.     }
  53.     public function removeAdMappingCustomer(AdMappingCustomer $adMappingCustomer): static
  54.     {
  55.         if ($this->adMappingCustomers->removeElement($adMappingCustomer)) {
  56.             // set the owning side to null (unless already changed)
  57.             if ($adMappingCustomer->getAdMapping() === $this) {
  58.                 $adMappingCustomer->setAdMapping(null);
  59.             }
  60.         }
  61.         return $this;
  62.     }
  63.     public function getTotalCustomers()
  64.     {
  65.         return $this->adMappingCustomers->count();
  66.     }
  67.     public function __toString()
  68.     {
  69.         return (string)$this->getUser();
  70.     }
  71. }