<?php
namespace App\AtechNet\CoreBundle\Entity;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\Table as Table;
use Doctrine\ORM\Mapping\UniqueConstraint;
/**
* Shipment notification preferencese table
*
* @Table(name="shipment_notification_preferences")
* @Entity
*/
class ShipmentNotificationPreference extends AbstractEntity
{
/**
* @var User|null
*
* @ManyToOne(
* targetEntity="User",
* inversedBy="shipmentNotificationPreferences"
* )
* @JoinColumn(name="user_id", referencedColumnName="id", nullable=false)
*/
private ?User $user = null;
/**
* @var array
* @Column(name="fields", type="json")
*/
private array $fields = [];
/**
* @return User
*/
public function getUser(): User
{
return $this->user;
}
/**
* @param ?User $user
* @return $this
*/
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
/**
* @return array
*/
public function getFields(): array
{
return $this->fields;
}
/**
* @param array $fields
* @return $this
*/
public function setFields(array $fields): self
{
$this->fields = array_values(array_unique($fields));
return $this;
}
/**
* @param string $field
* @return $this
*/
public function addField(string $field): self
{
if (!in_array($field, $this->fields, true)) {
$this->fields[] = $field;
}
return $this;
}
/**
* @param string $field
* @return $this
*/
public function removeField(string $field): self
{
$this->fields = array_values(
array_filter($this->fields, fn ($f) => $f !== $field)
);
return $this;
}
}