src/Flexy/ShopBundle/Entity/Customer/CustomerGroup.php line 14
<?php
namespace App\Flexy\ShopBundle\Entity\Customer;
use ApiPlatform\Core\Annotation\ApiResource;
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;
#[ApiResource]
#[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')]
private \Doctrine\Common\Collections\Collection|array $shippingMethods;
#[ORM\Column(type: 'string', length: 255)]
private ?string $name = null;
#[ORM\Column(type: 'string', length: 255, unique: true)]
private $code;
public function __toString(): string{
return (string)$this->name;
}
public function __construct()
{
$this->customers = 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;
}
}