<?php
namespace App\Entity\Sms;
use App\Doctrine\Generator\DeliveryListIdGenerator;
use App\Entity\MiniAbstractBase;
use App\Entity\Traits\CreatedAtTrait;
use App\Entity\Traits\NameTrait;
use App\Entity\Traits\UpdatedAtTrait;
use App\Repository\Sms\DeliveryListRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table(name="vulco_delivery_list")
*
* @ORM\Entity(repositoryClass=DeliveryListRepository::class)
*/
class DeliveryList
{
use CreatedAtTrait;
use NameTrait;
use UpdatedAtTrait;
/**
* @ORM\Id
*
* @ORM\Column(type="delivery_list_id", length=255, nullable=false)
*
* @ORM\GeneratedValue(strategy="CUSTOM")
*
* @ORM\CustomIdGenerator(class=DeliveryListIdGenerator::class)
*/
private string $id;
/**
* @ORM\Column(type="string", nullable=false)
*/
private string $name;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Sms\DeliveryContact", mappedBy="deliveryList", cascade={"persist"}, orphanRemoval=true)
*
* @ORM\OrderBy({"name": "ASC"})
*/
private ?Collection $deliveryContacts;
public function __construct()
{
$this->deliveryContacts = new ArrayCollection();
}
public function getId(): string
{
return $this->id;
}
public function getDeliveryContacts(): ?Collection
{
return $this->deliveryContacts;
}
public function getDeliveryContactsAmount(): int
{
return count($this->getDeliveryContacts());
}
public function setDeliveryContacts(?Collection $deliveryContacts): self
{
$this->deliveryContacts = $deliveryContacts;
return $this;
}
public function addDeliveryContact(DeliveryContact $deliveryContact): self
{
if (!$this->deliveryContacts->contains($deliveryContact)) {
$this->deliveryContacts->add($deliveryContact);
$deliveryContact->setDeliveryList($this);
}
return $this;
}
public function removeDeliveryContact(DeliveryContact $deliveryContact): self
{
if ($this->deliveryContacts->contains($deliveryContact)) {
$this->deliveryContacts->removeElement($deliveryContact);
}
return $this;
}
public function __toString(): string
{
return $this->id ? $this->getName() : MiniAbstractBase::DEFAULT_EMPTY_STRING;
}
}