<?php
namespace App\Entity;
use App\Entity\Sale;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity()
*
* @ORM\Table(name="buyers_group")
*/
class BuyersGroup implements \Stringable
{
public const PUBLIC_GROUP = 'Tous B2C';
public const ONLINE_GROUP = 'Online';
/**
* @ORM\Id
*
* @ORM\GeneratedValue(strategy="AUTO")
*
* @ORM\Column(type="bigint")
*/
protected $id;
/**
* @ORM\Column(type="string", length=255, unique=true)
*/
protected $name;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\User", inversedBy="buyersGroups", cascade={"persist"})
*/
protected $users;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Sale", mappedBy="buyersGroups")
*/
protected $sales;
/**
* @ORM\Column(type="string", length=18, nullable=true)
*/
protected $salesforceId;
/**
* Constructor.
*/
public function __construct()
{
$this->users = new ArrayCollection();
$this->sales = new ArrayCollection();
}
/**
* __toString overriding.
*/
public function __toString(): string
{
return (string) $this->getName();
}
/**
* Set id.
*
* @param string $id
*/
public function setId($id): void
{
$this->id = $id;
}
/**
* Get id.
*
* @return string
*/
public function getId()
{
return $this->id;
}
/**
* Set name.
*
* @param string $name
*/
public function setName($name): void
{
$this->name = $name;
}
/**
* Get name.
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Add users.
*/
public function addUser(User $user): void
{
if (!$this->users->contains($user)) {
$user->addBuyersGroup($this);
$this->users[] = $user;
}
}
public function removeUser(User $user): void
{
if ($this->users->contains($user)) {
$user->removeBuyersGroup($this);
$this->users->removeElement($user);
}
}
/**
* Get users.
*
* @return Doctrine\Common\Collections\Collection
*/
public function getUsers()
{
return $this->users;
}
/**
* Add sale.
*/
public function addSale(Sale $sale): void
{
$this->sales[] = $sale;
}
/**
* Get sales.
*
* @return Doctrine\Common\Collections\Collection
*/
public function getSales()
{
return $this->sales;
}
/**
* Set the 15 or 18 characters long SF ID of this group.
*
* @param string $sfId The SF ID
*/
public function setSalesforceId($sfId): void
{
$this->salesforceId = $sfId;
}
/**
* Get the SF ID of this group.
*
* @return string The SF ID
*/
public function getSalesforceId()
{
return $this->salesforceId;
}
}