125 lines
2.3 KiB
PHP
125 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Entity;
|
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
|
|
|
use DateTime;
|
|
/**
|
|
* @ORM\Entity
|
|
* @ORM\Table(name="customer_tag")
|
|
*/
|
|
class CustomerTag
|
|
{
|
|
/**
|
|
* @ORM\Id
|
|
* @ORM\Column(type="string", length=200, nullable=false, unique=true)
|
|
* @Assert\NotBlank()
|
|
*/
|
|
protected $id;
|
|
|
|
// name of tag
|
|
/**
|
|
* @ORM\Column(type="string", length=200)
|
|
* @Assert\NotBlank()
|
|
*/
|
|
protected $name;
|
|
|
|
// customers
|
|
/**
|
|
* @ORM\ManyToMany(targetEntity="Customer", mappedBy="customer_tags", fetch="EXTRA_LAZY")
|
|
*/
|
|
protected $customers;
|
|
|
|
// tag details
|
|
/**
|
|
* @ORM\Column(type="json")
|
|
*/
|
|
protected $tag_details;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->date_create = new DateTime();
|
|
$this->customers = new ArrayCollection();
|
|
$this->tag_details = [];
|
|
}
|
|
|
|
public function getID()
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function setID($id)
|
|
{
|
|
$this->id = $id;
|
|
return $this;
|
|
}
|
|
|
|
public function setName($name)
|
|
{
|
|
$this->name = $name;
|
|
return $this;
|
|
}
|
|
|
|
public function getName()
|
|
{
|
|
return $this->name;
|
|
}
|
|
|
|
public function getDateCreate()
|
|
{
|
|
return $this->date_create;
|
|
}
|
|
|
|
public function addCustomer(Customer $customer)
|
|
{
|
|
$this->customers[$customer->getID()] = $customer;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function clearCustomers()
|
|
{
|
|
$this->customers->clear();
|
|
return $this;
|
|
}
|
|
|
|
public function getCustomers()
|
|
{
|
|
return $this->customers;
|
|
}
|
|
|
|
public function removeCustomer(Customer $customer)
|
|
{
|
|
$this->customers->removeElement($customer);
|
|
}
|
|
|
|
public function addTagDetails($id, $value)
|
|
{
|
|
$this->tag_details[$id] = $value;
|
|
return $this;
|
|
}
|
|
|
|
public function setTagDetails($tag_details)
|
|
{
|
|
$this->tag_details = $tag_details;
|
|
return $this;
|
|
}
|
|
|
|
public function getTagDetails($id)
|
|
{
|
|
// return null if we don't have it
|
|
if (!isset($this->tag_details[$id]))
|
|
return null;
|
|
|
|
return $this->tag_details[$id];
|
|
}
|
|
|
|
public function getAllTagDetails()
|
|
{
|
|
return json_encode($this->tag_details);
|
|
}
|
|
}
|
|
|