src/AtechNet/CoreBundle/Entity/ShipmentNotificationPreference.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\AtechNet\CoreBundle\Entity;
  3. use Doctrine\DBAL\Types\Types;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Doctrine\ORM\Mapping\Column;
  6. use Doctrine\ORM\Mapping\Entity;
  7. use Doctrine\ORM\Mapping\ManyToOne;
  8. use Doctrine\ORM\Mapping\JoinColumn;
  9. use Doctrine\ORM\Mapping\Table as Table;
  10. use Doctrine\ORM\Mapping\UniqueConstraint;
  11. /**
  12.  * Shipment notification preferencese table
  13.  *
  14.  * @Table(name="shipment_notification_preferences")
  15.  * @Entity
  16.  */
  17. class ShipmentNotificationPreference extends AbstractEntity
  18. {
  19.     /**
  20.      * @var User|null
  21.      *
  22.      * @ManyToOne(
  23.      *     targetEntity="User",
  24.      *     inversedBy="shipmentNotificationPreferences"
  25.      * )
  26.      * @JoinColumn(name="user_id", referencedColumnName="id", nullable=false)
  27.      */
  28.     private ?User $user = null;
  29.     /**
  30.      * @var array
  31.      * @Column(name="fields", type="json")
  32.      */
  33.     private array $fields = [];
  34.     /**
  35.      * @return User
  36.      */
  37.     public function getUser(): User
  38.     {
  39.         return $this->user;
  40.     }
  41.     /**
  42.      * @param ?User $user
  43.      * @return $this
  44.      */
  45.     public function setUser(?User $user): self
  46.     {
  47.         $this->user = $user;
  48.         return $this;
  49.     }
  50.     /**
  51.      * @return array
  52.      */
  53.     public function getFields(): array
  54.     {
  55.         return $this->fields;
  56.     }
  57.     /**
  58.      * @param array $fields
  59.      * @return $this
  60.      */
  61.     public function setFields(array $fields): self
  62.     {
  63.         $this->fields = array_values(array_unique($fields));
  64.         return $this;
  65.     }
  66.     /**
  67.      * @param string $field
  68.      * @return $this
  69.      */
  70.     public function addField(string $field): self
  71.     {
  72.         if (!in_array($field, $this->fields, true)) {
  73.             $this->fields[] = $field;
  74.         }
  75.         return $this;
  76.     }
  77.     /**
  78.      * @param string $field
  79.      * @return $this
  80.      */
  81.     public function removeField(string $field): self
  82.     {
  83.         $this->fields = array_values(
  84.             array_filter($this->fields, fn ($f) => $f !== $field)
  85.         );
  86.         return $this;
  87.     }
  88. }