src/Entity/UserSetting.php line 25

Open in your IDE?
  1. <?php
  2. /**
  3.  * @license Silk Software House Sp. Z O. O.
  4.  */
  5. declare(strict_types=1);
  6. namespace App\Entity;
  7. use App\Entity\Traits\IdTrait;
  8. use App\Entity\Traits\TimePreUpdateTrait;
  9. use App\Entity\Traits\TimeTrait;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Doctrine\Common\Collections\Collection;
  12. use Doctrine\ORM\Mapping as ORM;
  13. use Symfony\Component\Validator\Constraints as Assert;
  14. /**
  15.  * Class UserSetting.
  16.  *
  17.  * @ORM\Entity(repositoryClass="App\Repository\UserSettingRepository")
  18.  * @ORM\Table(name="user_settings")
  19.  * @ORM\HasLifecycleCallbacks()
  20.  */
  21. class UserSetting
  22. {
  23.     use IdTrait;
  24.     use TimeTrait;
  25.     use TimePreUpdateTrait;
  26.     public const DEFAULT_TOKEN_DURATION_TIME 24;
  27.     /**
  28.      * User.
  29.      *
  30.      * @var User|null
  31.      *
  32.      * @ORM\OneToOne(targetEntity="App\Entity\User", inversedBy="setting", cascade={"persist","remove"})
  33.      * @ORM\JoinColumn(name="user_id", nullable=false, onDelete="CASCADE")
  34.      */
  35.     private ?User $user null;
  36.     /**
  37.      * Recipe.
  38.      *
  39.      * @var Recipe|null
  40.      *
  41.      * @Assert\NotBlank()
  42.      *
  43.      * @ORM\ManyToOne(targetEntity="App\Entity\Recipe")
  44.      * @ORM\JoinColumn(name="standard_recipe_id", nullable=true)
  45.      */
  46.     private ?Recipe $standardRecipe null;
  47.     /**
  48.      * Language.
  49.      *
  50.      * @var string
  51.      *
  52.      * @Assert\NotBlank()
  53.      * @Assert\Choice({"en", "pl", "sv"})
  54.      *
  55.      * @ORM\Column(name="language", type="text", nullable=false, options={"default": "en", "comment": "Application language."})
  56.      */
  57.     private string $language 'en';
  58.     /**
  59.      * Used devices.
  60.      *
  61.      * @ORM\ManyToMany(targetEntity="App\Entity\Device", inversedBy="userSetting")
  62.      * @ORM\JoinTable(
  63.      *     name="devices_user_settings",
  64.      *     joinColumns={@ORM\JoinColumn(name="user_setting_id", referencedColumnName="id")},
  65.      *     inverseJoinColumns={@ORM\JoinColumn(name="device_id", referencedColumnName="id")}
  66.      * )
  67.      */
  68.     private $usedDevices;
  69.     /**
  70.      * @ORM\Column(type="integer", nullable=false, options={"default" : 7})
  71.      */
  72.     private int $fontSizeCoefficient 0;
  73.     /**
  74.      * @ORM\Column(type="integer", length=10, options={"default" : 24})
  75.      */
  76.     private ?int $tokenTimeDuration self::DEFAULT_TOKEN_DURATION_TIME;
  77.     /**
  78.      * UserSetting constructor.
  79.      */
  80.     public function __construct()
  81.     {
  82.         $this->usedDevices = new ArrayCollection();
  83.     }
  84.     /**
  85.      * Get user.
  86.      *
  87.      * @return User
  88.      */
  89.     public function getUser(): User
  90.     {
  91.         if (!isset($this->user)) {
  92.             throw new \LogicException('The User is not set, not expected.');
  93.         }
  94.         return $this->user;
  95.     }
  96.     /**
  97.      * Set user.
  98.      *
  99.      * @param User $user
  100.      *
  101.      * @return UserSetting
  102.      */
  103.     public function setUser(User $user): self
  104.     {
  105.         $this->user $user;
  106.         return $this;
  107.     }
  108.     /**
  109.      * Get a standard recipe.
  110.      *
  111.      * @return Recipe
  112.      */
  113.     public function getStandardRecipe(): ?Recipe
  114.     {
  115.         return $this->standardRecipe;
  116.     }
  117.     /**
  118.      * Set a standard recipe.
  119.      *
  120.      * @param Recipe $standardRecipe
  121.      *
  122.      * @return UserSetting
  123.      */
  124.     public function setStandardRecipe(Recipe $standardRecipe): self
  125.     {
  126.         $this->standardRecipe $standardRecipe;
  127.         return $this;
  128.     }
  129.     /**
  130.      * Get language.
  131.      *
  132.      * @return string
  133.      */
  134.     public function getLanguage(): string
  135.     {
  136.         return $this->language;
  137.     }
  138.     /**
  139.      * Set language.
  140.      *
  141.      * @param string $language
  142.      *
  143.      * @return UserSetting
  144.      */
  145.     public function setLanguage(string $language 'en'): self
  146.     {
  147.         if ('' !== $language) {
  148.             $this->language $language;
  149.         }
  150.         return $this;
  151.     }
  152.     /**
  153.      * Set active devices.
  154.      *
  155.      * @param Collection $activeDevices
  156.      *
  157.      * @return UserSetting
  158.      */
  159.     public function setUsedDevices(Collection $activeDevices): self
  160.     {
  161.         $this->usedDevices $activeDevices;
  162.         return $this;
  163.     }
  164.     /**
  165.      * Get active devices.
  166.      *
  167.      * @return Collection
  168.      */
  169.     public function getUsedDevices(): Collection
  170.     {
  171.         return $this->usedDevices;
  172.     }
  173.     /**
  174.      * Add a used device.
  175.      *
  176.      * @param Device $device
  177.      *
  178.      * @return UserSetting
  179.      */
  180.     public function addUsedDevice(Device $device): self
  181.     {
  182.         if (!$this->usedDevices->contains($device)) {
  183.             $this->usedDevices->add($device);
  184.         }
  185.         return $this;
  186.     }
  187.     /**
  188.      * Remove used device.
  189.      *
  190.      * @param Device $device
  191.      *
  192.      * @return UserSetting
  193.      */
  194.     public function removeUsedDevice(Device $device): self
  195.     {
  196.         if ($this->usedDevices->contains($device)) {
  197.             $this->usedDevices->removeElement($device);
  198.         }
  199.         return $this;
  200.     }
  201.     /**
  202.      * @return int|null
  203.      */
  204.     public function getFontSizeCoefficient(): ?int
  205.     {
  206.         return $this->fontSizeCoefficient;
  207.     }
  208.     /**
  209.      * @param int $fontSizeCoefficient
  210.      *
  211.      * @return UserSetting
  212.      */
  213.     public function setFontSizeCoefficient(int $fontSizeCoefficient): self
  214.     {
  215.         $this->fontSizeCoefficient $fontSizeCoefficient;
  216.         return $this;
  217.     }
  218.     /**
  219.      * @return int|null
  220.      */
  221.     public function getTokenTimeDuration(): ?int
  222.     {
  223.         return $this->tokenTimeDuration;
  224.     }
  225.     /**
  226.      * @param int $tokenTimeDuration
  227.      *
  228.      * @return UserSetting
  229.      */
  230.     public function setTokenTimeDuration(int $tokenTimeDuration): self
  231.     {
  232.         $this->tokenTimeDuration $tokenTimeDuration;
  233.         return $this;
  234.     }
  235. }