src/Flexy/ShopBundle/Entity/Customer/CustomerGroup.php line 19
<?php
namespace App\Flexy\ShopBundle\Entity\Customer;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Flexy\ShopBundle\Entity\Vendor\Vendor;
use App\Flexy\ShopBundle\Repository\Customer\CustomerGroupRepository;
use Doctrine\Common\Collections\ArrayCollection;
use App\Flexy\ShopBundle\Entity\Shipping\ShippingMethod;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
#[ApiResource(
normalizationContext: ['groups' => ['read']],
denormalizationContext: ['groups' => ['write']],
)]
#[ORM\Entity(repositoryClass: CustomerGroupRepository::class)]
class CustomerGroup implements \Stringable
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
private ?\DateTimeImmutable $createdAt = null;
#[ORM\OneToMany(targetEntity: Customer::class, mappedBy: 'customerGroup')]
private \Doctrine\Common\Collections\Collection|array $customers;
#[ORM\OneToMany(targetEntity: ShippingMethod::class, mappedBy: 'customerGroup')]
#[Groups(["write","read"])]
private \Doctrine\Common\Collections\Collection|array $shippingMethods;
#[ORM\Column(type: 'string', length: 255)]
#[Groups(["write","read"])]
private ?string $name = null;
#[ORM\Column(type: 'string', length: 255, unique: true)]
private $code;
#[ORM\ManyToMany(targetEntity: Vendor::class, mappedBy: 'customerGroups')]
private Collection $vendors;
public function __toString(): string{
return (string)$this->name;
}
public function __construct()
{
$this->customers = new ArrayCollection();
$this->vendors = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(?\DateTimeImmutable $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
/**
* @return Collection|Customer[]
*/
public function getCustomers(): Collection
{
return $this->customers;
}
public function addCustomer(Customer $customer): self
{
if (!$this->customers->contains($customer)) {
$this->customers[] = $customer;
$customer->setCustomerGroup($this);
}
return $this;
}
public function removeCustomer(Customer $customer): self
{
if ($this->customers->removeElement($customer)) {
// set the owning side to null (unless already changed)
if ($customer->getCustomerGroup() === $this) {
$customer->setCustomerGroup(null);
}
}
return $this;
}
/**
* @return Collection|ShippingMethod[]
*/
public function getShippingMethods(): Collection
{
return $this->shippingMethods;
}
public function addShippingMethod(ShippingMethod $shippingMethod): self
{
if (!$this->shippingMethods->contains($shippingMethod)) {
$this->shippingMethods[] = $shippingMethod;
$shippingMethod->setCustomerGroup($this);
}
return $this;
}
public function removeShippingMethod(ShippingMethod $shippingMethod): self
{
if ($this->shippingMethods->removeElement($shippingMethod)) {
// set the owning side to null (unless already changed)
if ($shippingMethod->getCustomerGroup() === $this) {
$shippingMethod->setCustomerGroup(null);
}
}
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): self
{
$this->name = $name;
return $this;
}
/**
* Get the value of code
*/
public function getCode()
{
return $this->code;
}
/**
* Set the value of code
*
* @return self
*/
public function setCode($code)
{
$this->code = $code;
return $this;
}
/**
* @return Collection<int, Vendor>
*/
public function getVendors(): Collection
{
return $this->vendors;
}
public function addVendor(Vendor $vendor): self
{
if (!$this->vendors->contains($vendor)) {
$this->vendors->add($vendor);
$vendor->addCustomerGroup($this);
}
return $this;
}
public function removeVendor(Vendor $vendor): self
{
if ($this->vendors->removeElement($vendor)) {
$vendor->removeCustomerGroup($this);
}
return $this;
}
}