src/Entity/TvUser.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Annotation\SerializedNameGroups;
  4. use App\Repository\TvUserRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Doctrine\ORM\Mapping\Index;
  9. use Doctrine\ORM\Mapping\Table;
  10. use Gedmo\Mapping\Annotation as Gedmo;
  11. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  12. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  13. use Symfony\Component\Security\Core\User\UserInterface;
  14. use Symfony\Component\Serializer\Annotation\Groups;
  15. use Symfony\Component\Validator\Constraints as Assert;
  16. /**
  17.  * @ORM\Entity(repositoryClass=TvUserRepository::class)
  18.  * @ORM\HasLifecycleCallbacks
  19.  * @Table(indexes={@Index(name="search_idx", columns={"id", "code"})})
  20.  * @UniqueEntity("username", message="user.username_unique")
  21.  */
  22. class TvUser implements UserInterfacePasswordAuthenticatedUserInterface
  23. {
  24.     const QUOTA_DAY 'daily';
  25.     const QUOTA_WEEK 'weekly';
  26.     const QUOTA_MONTH 'monthly';
  27.     const QUOTA_NONE 'unset';
  28.     const STATUS_ACTIVE 'active';
  29.     const STATUS_SUSPENDED 'suspended';
  30.     const STATUSES = [
  31.         self::STATUS_ACTIVE,
  32.         self::STATUS_SUSPENDED,
  33.     ];
  34.     const QUOTAS = [
  35.         self::QUOTA_DAY,
  36.         self::QUOTA_WEEK,
  37.         self::QUOTA_MONTH,
  38.     ];
  39.     /**
  40.      * Associative array, keys are the quotas types (none excluded)
  41.      * values are the string to pass to a datetime object
  42.      */
  43.     const QUOTAS_VAlUES = [
  44.         self::QUOTA_DAY => '1 day',
  45.         self::QUOTA_WEEK => '1 week',
  46.         self::QUOTA_MONTH => '1 month',
  47.     ];
  48.     const ROLE_USER 'ROLE_USER';
  49.     const ROLE_ADMIN 'ROLE_ADMIN';
  50.     const ROLE_GOD 'ROLE_GOD';
  51.     const ROLE_MANAGER 'ROLE_MANAGER';
  52.     const ROLE_COMPANY_MANAGER 'ROLE_COMPANY_MANAGER';
  53.     const ROLES = [
  54.         self::ROLE_ADMIN,
  55.         self::ROLE_GOD,
  56.         self::ROLE_USER,
  57.         self::ROLE_MANAGER,
  58.         self::ROLE_COMPANY_MANAGER,
  59.     ];
  60.     /**
  61.      * @ORM\Id
  62.      * @ORM\GeneratedValue
  63.      * @ORM\Column(type="integer")
  64.      * @Groups({"tv_user_read", "tv_company_read", "export_tv_user_csv", "team_read", "team_user_read", "tv_user:read:form", "notification_read"})
  65.      */
  66.     private $id;
  67.     /**
  68.      * @ORM\Column(type="string", length=255, nullable=false, unique=true)
  69.      * @Groups({"tv_user_read", "tv_company_read", "tv_user_creation", "export_tv_user_csv", "message_read", "tv_user_read_creation"})
  70.      * @SerializedNameGroups(name="Identifiant", groups={"tv_user_read_creation"})
  71.      */
  72.     private $code;
  73.     /**
  74.      * @ORM\Column(type="string", length=180, unique=true)
  75.      * @Groups({"tv_user_read", "tv_user_creation", "tv_user_write", "team_read", "team_user_read", "tv_user:read:form", "notification_read"})
  76.      */
  77.     private $username;
  78.     /**
  79.      * @ORM\Column(type="json")
  80.      */
  81.     private $roles = [];
  82.     /**
  83.      * @var string The hashed password
  84.      * @ORM\Column(type="string")
  85.      */
  86.     private $password;
  87.     /**
  88.      * @ORM\Column(type="string", length=255, nullable=true)
  89.      * @Groups({"tv_user_read", "tv_user_write", "team_read", "team_user_read"})
  90.      * @Assert\Email(message="user.email")
  91.      */
  92.     private $email;
  93.     /**
  94.      * @ORM\Column(type="integer")
  95.      * @Groups({"tv_user_read", "tv_user_write", "export_tv_user_csv"})
  96.      */
  97.     private $quotas 0;
  98.     /**
  99.      * @ORM\Column(type="string", length=255)
  100.      * @Groups({"tv_user_read", "tv_user_write", "export_tv_user_csv"})
  101.      */
  102.     private $quotasType self::QUOTA_NONE;
  103.     /**
  104.      * @ORM\Column(type="boolean", options={"default": 1})
  105.      * @Groups({"tv_user_read", "tv_company_read", "export_tv_user_csv", "notification_read"})
  106.      */
  107.     private $active true;
  108.     /**
  109.      * @ORM\Column(type="datetime")
  110.      * @Gedmo\Timestampable(on="create")
  111.      * @Groups({"tv_user_read"})
  112.      */
  113.     private $createdAt;
  114.     /**
  115.      * @ORM\Column(type="datetime")
  116.      * @Groups({"tv_user_read"})
  117.      * @Gedmo\Timestampable(on="update")
  118.      */
  119.     private $updatedAt;
  120.     /**
  121.      * @ORM\Column(type="string", length=255, nullable=true)
  122.      */
  123.     private $recoveryToken;
  124.     /**
  125.      * Property rendered public to use in security precept
  126.      * @var TvCompany
  127.      * @ORM\ManyToOne(targetEntity=TvCompany::class, inversedBy="tvUsers")
  128.      * @Groups({"tv_user_read", "tv_user_creation", "message_read", "tv_user_read_creation", "team_user_read"})
  129.      * @SerializedNameGroups(name="Entreprise", groups={"tv_user_read_creation"})
  130.      */
  131.     public $tvCompany;
  132.     /**
  133.      * @ORM\OneToMany(targetEntity=Log::class, mappedBy="tvUser", orphanRemoval=true, cascade={"persist", "refresh", "remove"})
  134.      */
  135.     private $logs;
  136.     /**
  137.      * Sent messages by the tvUser to web admins
  138.      * @ORM\OneToMany(targetEntity=Message::class, mappedBy="tvUser", orphanRemoval=true, cascade={"persist", "refresh", "remove"})
  139.      */
  140.     private $messages;
  141.     /**
  142.      * @ORM\Column(type="datetime", nullable=true)
  143.      * @Groups({"tv_user_read", "tv_company_read"})
  144.      */
  145.     private $lastLogin;
  146.     /**
  147.      * @var string|null
  148.      * @Groups({"tv_user_creation", "tv_user_write", "tv_user_read_creation"})
  149.      * @Assert\Regex("/(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}/", message="user.password")
  150.      * @SerializedNameGroups(name="Mot-de-passe", groups={"tv_user_read_creation"})
  151.      */
  152.     private $plainPassword null;
  153.     /**
  154.      * @var string|null
  155.      * @Groups({"tv_user_creation", "tv_user_write"})
  156.      * @Assert\IdenticalTo(propertyPath="plainPassword", message="user.repeat_password")
  157.      */
  158.     private $passwordConfirm null;
  159.     /**
  160.      * @var bool
  161.      */
  162.     public $isPopulated false;
  163.     /**
  164.      * @ORM\OneToMany(targetEntity=VideoEvent::class, mappedBy="tvUser", orphanRemoval=true, cascade={"persist", "refresh", "remove"})
  165.      */
  166.     private $videoEvents;
  167.     /**
  168.      * @ORM\Column(type="boolean", options={"default": 0})
  169.      * @Groups({"tv_user_read", "tv_company_read", "tv_user_write"})
  170.      */
  171.     private $newsletter false;
  172.     /**
  173.      * @ORM\Column(type="boolean", options={"default": 1})
  174.      * @Groups({"tv_user_read", "tv_company_read", "tv_user_write"})
  175.      */
  176.     private $firstLogin true;
  177.     /**
  178.      * @ORM\Column(type="boolean", options={"default": 1})
  179.      * @Groups({"tv_user_read", "tv_company_read", "tv_user_write"})
  180.      */
  181.     private $homeSurvey true;
  182.     /**
  183.      * @ORM\Column(type="datetime", nullable=true)
  184.      * @Groups({"tv_user_read", "tv_company_read"})
  185.      * @Gedmo\Timestampable(on="change", field="newsletter", value=true)
  186.      */
  187.     private $newsletterDate;
  188.     /**
  189.      * @ORM\OneToMany(targetEntity=UserResponse::class, mappedBy="tvUser", orphanRemoval=true, cascade={"persist", "refresh", "remove"})
  190.      */
  191.     private $userResponses;
  192.     /**
  193.      * @ORM\Column(type="datetime", nullable=true)
  194.      * @Gedmo\Timestampable(on="change", field="email")
  195.      */
  196.     private $emailUpdatedAt;
  197.     /**
  198.      * @ORM\Column(type="datetime", nullable=true)
  199.      */
  200.     private $emailValidatedAt;
  201.     /**
  202.      * @ORM\OneToMany(targetEntity=Favorite::class, mappedBy="tvUser", orphanRemoval=true, cascade={"persist", "refresh", "remove"})
  203.      */
  204.     private $favorites;
  205.     /**
  206.      * @ORM\Column(type="string", length=255)
  207.      * @Groups({"tv_user_read", "tv_company_read", "export_tv_user_csv"})
  208.      * @Assert\Choice(choices=self::STATUSES)
  209.      */
  210.     private $status;
  211.     /**
  212.      * @ORM\ManyToOne(targetEntity=Department::class, inversedBy="tvUsers")
  213.      * @Groups({"tv_user_read", "tv_user_write"})
  214.      */
  215.     private $department;
  216.     /**
  217.      * @ORM\OneToMany(targetEntity=LogEmail::class, mappedBy="tvUser", orphanRemoval=true, cascade={"persist", "refresh", "remove"})
  218.      */
  219.     private $logEmails;
  220.     /**
  221.      * @ORM\OneToMany(targetEntity=Channel::class, mappedBy="tvUser", orphanRemoval=true, cascade={"persist", "refresh", "remove"})
  222.      */
  223.     private $channels;
  224.     /**
  225.      * @ORM\ManyToMany(targetEntity=Objective::class, mappedBy="tvUsers")
  226.      */
  227.     private $objectives;
  228.     /**
  229.      * @ORM\ManyToOne(targetEntity=Association::class, inversedBy="tvUsers")
  230.      * @Groups({"tv_user_read", "tv_user_write", "tv_company_read"})
  231.      */
  232.     private $association;
  233.     /**
  234.      * @ORM\OneToMany(targetEntity=TeamUser::class, mappedBy="tvUser", orphanRemoval=true, cascade={"persist", "refresh", "remove"})
  235.      */
  236.     private $teamUsers;
  237.     /**
  238.      * @ORM\Column(type="boolean", nullable=true, options={"default": "1"})
  239.      * @Groups({"tv_user_read", "tv_user_write", "tuto_only"})
  240.      */
  241.     private $displayTeamplayTuto true;
  242.     /**
  243.      * @ORM\OneToMany(targetEntity=TeamplayLog::class, mappedBy="tvUser", orphanRemoval=true, cascade={"persist", "refresh", "remove"})
  244.      */
  245.     private $teamplayLogs;
  246.     /**
  247.      * @ORM\OneToMany(targetEntity=PedometerLog::class, mappedBy="tvUser", orphanRemoval=true, cascade={"persist", "refresh", "remove"})
  248.      */
  249.     private $pedometerLogs;
  250.     /**
  251.      * @ORM\Column(type="string", length=255, nullable=true)
  252.      * @Groups({"tv_user_read", "tv_user_write"})
  253.      */
  254.     private $deviceOs;
  255.     /**
  256.      * @ORM\Column(type="text", nullable=true)
  257.      * @Groups({"tv_user_read", "tv_user_write"})
  258.      */
  259.     private $deviceToken;
  260.     /**
  261.      * @ORM\Column(type="string", length=255, nullable=true)
  262.      * @Groups({"tv_user_read", "tv_user_write"})
  263.      */
  264.     private $deviceName;
  265.     /**
  266.      * @ORM\Column(type="boolean", nullable=true, options={"default": 1})
  267.      * @Groups({"tv_user_read", "tv_user_write"})
  268.      */
  269.     private $deviceActive true;
  270.     /**
  271.      * @ORM\Column(type="datetime", nullable=true)
  272.      * @Gedmo\Timestampable(on="change", field={"deviceOs", "deviceToken", "deviceName", "deviceActive"})
  273.      * @Groups({"tv_user_read", "tv_user_write"})
  274.      */
  275.     private $deviceUpdate;
  276.     /**
  277.      * @ORM\OneToMany(targetEntity=UserNotification::class, mappedBy="tvUser", orphanRemoval=true, cascade={"persist", "refresh", "remove"})
  278.      */
  279.     private $userNotifications;
  280.     /**
  281.      * @ORM\OneToMany(targetEntity=UserDevice::class, mappedBy="tvUser", orphanRemoval=true, cascade={"persist", "refresh", "remove"})
  282.      */
  283.     private $devices;
  284.     /**
  285.      * @ORM\OneToMany(targetEntity=AwardLog::class, mappedBy="tvUser", orphanRemoval=true, cascade={"persist", "refresh", "remove"})
  286.      */
  287.     private $awardLogs;
  288.     /**
  289.      * @ORM\OneToMany(targetEntity=UserVideoTimecode::class, mappedBy="tvUser", orphanRemoval=true, cascade={"persist", "refresh", "remove"})
  290.      */
  291.     private $userVideoTimecodes;
  292.     /**
  293.      * @ORM\OneToMany(targetEntity=Notation::class, mappedBy="tvUser", cascade={"persist", "refresh", "remove"}, orphanRemoval=true)
  294.      */
  295.     private $notations;
  296.     /**
  297.      * @ORM\OneToMany(targetEntity=VideoLastValidate::class, mappedBy="tvUser", cascade={"persist", "refresh", "remove"}, orphanRemoval=true)
  298.      */
  299.     private $videoLastValidates;
  300.     /**
  301.      * @ORM\OneToMany(targetEntity=VideoLastSeen::class, mappedBy="tvUser", cascade={"persist", "refresh", "remove"}, orphanRemoval=true)
  302.      */
  303.     private $videoLastSeens;
  304.     /**
  305.      * @ORM\OneToMany(targetEntity=MoodResponse::class, mappedBy="tvUser", cascade={"persist", "refresh", "remove"}, orphanRemoval=true)
  306.      */
  307.     private $moodResponses;
  308.     /**
  309.      * @ORM\OneToMany(targetEntity=ProgramEvent::class, mappedBy="tvUser", cascade={"persist", "refresh", "remove"}, orphanRemoval=true)
  310.      */
  311.     private $programEvents;
  312.     /**
  313.      * @ORM\OneToMany(targetEntity=DayEvent::class, mappedBy="tvUser", cascade={"persist", "refresh", "remove"}, orphanRemoval=true)
  314.      */
  315.     private $dayEvents;
  316.     /**
  317.      * @ORM\OneToOne(targetEntity=User::class, inversedBy="tvUser")
  318.      */
  319.     private $user;
  320.     public function __construct()
  321.     {
  322.         $this->logs = new ArrayCollection();
  323.         $this->messages = new ArrayCollection();
  324.         $this->videoEvents = new ArrayCollection();
  325.         $this->roles = [self::ROLE_USER];
  326.         $this->userResponses = new ArrayCollection();
  327.         $this->favorites = new ArrayCollection();
  328.         $this->logEmails = new ArrayCollection();
  329.         $this->channels = new ArrayCollection();
  330.         $this->objectives = new ArrayCollection();
  331.         $this->teamUsers = new ArrayCollection();
  332.         $this->teams = new ArrayCollection();
  333.         $this->teamplayLogs = new ArrayCollection();
  334.         $this->pedometerLogs = new ArrayCollection();
  335.         $this->userNotifications = new ArrayCollection();
  336.         $this->devices = new ArrayCollection();
  337.         $this->awardLogs = new ArrayCollection();
  338.         $this->userVideoTimecodes = new ArrayCollection();
  339.         $this->notations = new ArrayCollection();
  340.         $this->videoLastValidates = new ArrayCollection();
  341.         $this->videoLastSeens = new ArrayCollection();
  342.         $this->moodResponses = new ArrayCollection();
  343.         $this->programEvents = new ArrayCollection();
  344.         $this->dayEvents = new ArrayCollection();
  345.     }
  346.     public function __toString(): string
  347.     {
  348.         return "#{$this->getId()} - {$this->getUsername()}";
  349.     }
  350.     public function getId(): ?int
  351.     {
  352.         return $this->id;
  353.     }
  354.     /**
  355.      * A visual identifier that represents this user.
  356.      *
  357.      * @see UserInterface
  358.      */
  359.     public function getUserIdentifier(): string
  360.     {
  361.         return (string)$this->getUsername();
  362.     }
  363.     /**
  364.      * A visual identifier that represents this tvUser.
  365.      *
  366.      * @see UserInterface
  367.      */
  368.     public function getUsername(): string
  369.     {
  370.         return (string)$this->username;
  371.     }
  372.     public function setUsername(string $username): self
  373.     {
  374.         $this->username $username;
  375.         return $this;
  376.     }
  377.     /**
  378.      * @see UserInterface
  379.      */
  380.     public function getRoles(): array
  381.     {
  382.         $roles $this->roles;
  383.         // guarantee every tvUser at least has ROLE_USER
  384.         $roles[] = 'ROLE_USER';
  385.         return array_unique($roles);
  386.     }
  387.     public function setRoles(array $roles): self
  388.     {
  389.         $this->roles $roles;
  390.         return $this;
  391.     }
  392.     /**
  393.      * @see UserInterface
  394.      */
  395.     public function getPassword(): string
  396.     {
  397.         return (string)$this->password;
  398.     }
  399.     public function setPassword(string $password): self
  400.     {
  401.         $this->password $password;
  402.         return $this;
  403.     }
  404.     /**
  405.      * @see UserInterface
  406.      */
  407.     public function getSalt()
  408.     {
  409.         // not needed when using the "bcrypt" algorithm in security.yaml
  410.     }
  411.     /**
  412.      * @see UserInterface
  413.      */
  414.     public function eraseCredentials()
  415.     {
  416.         // If you store any temporary, sensitive data on the tvUser, clear it here
  417.         $this->plainPassword null;
  418.     }
  419.     public function getEmail(): ?string
  420.     {
  421.         return $this->email;
  422.     }
  423.     public function setEmail(?string $email): self
  424.     {
  425.         $this->email $email;
  426.         return $this;
  427.     }
  428.     public function getQuotas(): ?int
  429.     {
  430.         return $this->quotas;
  431.     }
  432.     public function setQuotas(int $quotas): self
  433.     {
  434.         $this->quotas $quotas;
  435.         return $this;
  436.     }
  437.     public function getQuotasType(): ?string
  438.     {
  439.         return $this->quotasType;
  440.     }
  441.     public function setQuotasType(string $quotasType): self
  442.     {
  443.         $this->quotasType $quotasType;
  444.         return $this;
  445.     }
  446.     public function getActive(): ?bool
  447.     {
  448.         return $this->active;
  449.     }
  450.     public function setActive(bool $active): self
  451.     {
  452.         $this->active $active;
  453.         if ($this->active){
  454.             $this->status self::STATUS_ACTIVE;
  455.         }else{
  456.             $this->status self::STATUS_SUSPENDED;
  457.         }
  458.         return $this;
  459.     }
  460.     public function getCreatedAt(): ?\DateTimeInterface
  461.     {
  462.         return $this->createdAt;
  463.     }
  464.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  465.     {
  466.         $this->createdAt $createdAt;
  467.         return $this;
  468.     }
  469.     public function getUpdatedAt(): ?\DateTimeInterface
  470.     {
  471.         return $this->updatedAt;
  472.     }
  473.     public function setUpdatedAt(\DateTimeInterface $updatedAt): self
  474.     {
  475.         $this->updatedAt $updatedAt;
  476.         return $this;
  477.     }
  478.     public function getRecoveryToken(): ?string
  479.     {
  480.         return $this->recoveryToken;
  481.     }
  482.     public function setRecoveryToken(?string $recoveryToken): self
  483.     {
  484.         $this->recoveryToken $recoveryToken;
  485.         return $this;
  486.     }
  487.     public function getTvCompany(): ?TvCompany
  488.     {
  489.         return $this->tvCompany;
  490.     }
  491.     public function setTvCompany(?TvCompany $tvCompany): self
  492.     {
  493.         $this->tvCompany $tvCompany;
  494.         return $this;
  495.     }
  496.     /**
  497.      * @ORM\PrePersist
  498.      * @ORM\PreUpdate
  499.      */
  500.     public function updatedTimestamps(): void
  501.     {
  502.         $this->setUpdatedAt(new \DateTime('now'));
  503.         if ($this->getCreatedAt() === null) {
  504.             $this->setCreatedAt(new \DateTime('now'));
  505.         }
  506.     }
  507.     /**
  508.      * @return Collection|Log[]
  509.      */
  510.     public function getLogs(): Collection
  511.     {
  512.         return $this->logs;
  513.     }
  514.     public function addLog(Log $log): self
  515.     {
  516.         if (!$this->logs->contains($log)) {
  517.             $this->logs[] = $log;
  518.             $log->setTvUser($this);
  519.         }
  520.         return $this;
  521.     }
  522.     public function removeLog(Log $log): self
  523.     {
  524.         if ($this->logs->removeElement($log)) {
  525.             // set the owning side to null (unless already changed)
  526.             if ($log->getTvUser() === $this) {
  527.                 $log->setTvUser(null);
  528.             }
  529.         }
  530.         return $this;
  531.     }
  532.     /**
  533.      * @return Collection|Message[]
  534.      */
  535.     public function getMessages(): Collection
  536.     {
  537.         return $this->messages;
  538.     }
  539.     public function addMessage(Message $message): self
  540.     {
  541.         if (!$this->messages->contains($message)) {
  542.             $this->messages[] = $message;
  543.             $message->setTvUser($this);
  544.         }
  545.         return $this;
  546.     }
  547.     public function removeMessage(Message $message): self
  548.     {
  549.         if ($this->messages->removeElement($message)) {
  550.             // set the owning side to null (unless already changed)
  551.             if ($message->getTvUser() === $this) {
  552.                 $message->setTvUser(null);
  553.             }
  554.         }
  555.         return $this;
  556.     }
  557.     /**
  558.      * @return \DateTime|null
  559.      */
  560.     public function getLastLogin(): ?\DateTime
  561.     {
  562.         return $this->lastLogin;
  563.     }
  564.     /**
  565.      * @param string|null $code
  566.      * @return TvUser
  567.      */
  568.     public function setCode(?string $code): TvUser
  569.     {
  570.         $this->code $code;
  571.         return $this;
  572.     }
  573.     /**
  574.      * @return string|null
  575.      */
  576.     public function getCode(): ?string
  577.     {
  578.         return $this->code;
  579.     }
  580.     /**
  581.      * @param string $role
  582.      * @return bool
  583.      */
  584.     public function hasRole(string $role)
  585.     {
  586.         return in_array($role$this->roles);
  587.     }
  588.     /**
  589.      * Updates the tvCompany according to the status of the order
  590.      * @return TvUser
  591.      * @ORM\PrePersist
  592.      */
  593.     public function updateTvCompany(): self
  594.     {
  595.         if ($this->tvCompany instanceof TvCompany) {
  596.             $this->tvCompany->setTvUsersCount($this->tvCompany->getTvUsersCount() + 1);
  597.         }
  598.         return $this;
  599.     }
  600.     public function setLastLogin(?\DateTimeInterface $lastLogin): self
  601.     {
  602.         $this->lastLogin $lastLogin;
  603.         return $this;
  604.     }
  605.     /**
  606.      * If persisted this password will be encoded into the password field
  607.      * @param string $password
  608.      * @return $this
  609.      */
  610.     public function setPlainPassword(string $password): TvUser
  611.     {
  612.         $this->plainPassword $password;
  613.         return $this;
  614.     }
  615.     /**
  616.      * @return string
  617.      */
  618.     public function getPlainPassword(): ?string
  619.     {
  620.         return $this->plainPassword;
  621.     }
  622.     /**
  623.      * @return Collection|VideoEvent[]
  624.      */
  625.     public function getVideoEvents(): Collection
  626.     {
  627.         return $this->videoEvents;
  628.     }
  629.     public function addVideoEvent(VideoEvent $videoEvent): self
  630.     {
  631.         if (!$this->videoEvents->contains($videoEvent)) {
  632.             $this->videoEvents[] = $videoEvent;
  633.             $videoEvent->setTvUser($this);
  634.         }
  635.         return $this;
  636.     }
  637.     public function removeVideoEvent(VideoEvent $videoEvent): self
  638.     {
  639.         if ($this->videoEvents->removeElement($videoEvent)) {
  640.             // set the owning side to null (unless already changed)
  641.             if ($videoEvent->getTvUser() === $this) {
  642.                 $videoEvent->setTvUser(null);
  643.             }
  644.         }
  645.         return $this;
  646.     }
  647.     /**
  648.      * Checks the quotas of a tvUser
  649.      * @return bool true if ok, false if not ok
  650.      */
  651.     public function checkQuotas(): bool
  652.     {
  653.         $result true;
  654.         if ($this->getQuotasType() != self::QUOTA_NONE){
  655.             $span self::QUOTAS_VAlUES[$this->getQuotasType()];
  656.             $limit = new \DateTime("-$span");
  657.             $count 0;
  658.             foreach ($this->getVideoEvents() as $videoEvent) {
  659.                 if ($limit->diff($videoEvent->getCreatedAt())->invert == 0){
  660.                     $count += $videoEvent->getValue();
  661.                 }
  662.             }
  663.             if ($count $this->getQuotas()){
  664.                 $result false;
  665.             }
  666.         }
  667.         return $result;
  668.     }
  669.     public function getNewsletter(): ?bool
  670.     {
  671.         return $this->newsletter;
  672.     }
  673.     public function setNewsletter(bool $newsletter): self
  674.     {
  675.         $this->newsletter $newsletter;
  676.         return $this;
  677.     }
  678.     public function getNewsletterDate(): ?\DateTimeInterface
  679.     {
  680.         return $this->newsletterDate;
  681.     }
  682.     public function setNewsletterDate(?\DateTimeInterface $newsletterDate): self
  683.     {
  684.         $this->newsletterDate $newsletterDate;
  685.         return $this;
  686.     }
  687.     /**
  688.      * @return Collection|UserResponse[]
  689.      */
  690.     public function getUserResponses(): Collection
  691.     {
  692.         return $this->userResponses;
  693.     }
  694.     public function addUserResponse(UserResponse $userResponse): self
  695.     {
  696.         if (!$this->userResponses->contains($userResponse)) {
  697.             $this->userResponses[] = $userResponse;
  698.             $userResponse->setTvUser($this);
  699.         }
  700.         return $this;
  701.     }
  702.     public function removeUserResponse(UserResponse $userResponse): self
  703.     {
  704.         if ($this->userResponses->removeElement($userResponse)) {
  705.             // set the owning side to null (unless already changed)
  706.             if ($userResponse->getTvUser() === $this) {
  707.                 $userResponse->setTvUser(null);
  708.             }
  709.         }
  710.         return $this;
  711.     }
  712.     public function getEmailUpdatedAt(): ?\DateTimeInterface
  713.     {
  714.         return $this->emailUpdatedAt;
  715.     }
  716.     public function setEmailUpdatedAt(?\DateTimeInterface $emailUpdatedAt): self
  717.     {
  718.         $this->emailUpdatedAt $emailUpdatedAt;
  719.         return $this;
  720.     }
  721.     public function getEmailValidatedAt(): ?\DateTimeInterface
  722.     {
  723.         return $this->emailValidatedAt;
  724.     }
  725.     public function setEmailValidatedAt(?\DateTimeInterface $emailValidatedAt): self
  726.     {
  727.         $this->emailValidatedAt $emailValidatedAt;
  728.         return $this;
  729.     }
  730.     /**
  731.      * Checks if the email is validated
  732.      * @return bool
  733.      */
  734.     public function isEmailValidated(): bool
  735.     {
  736.         return ($this->emailValidatedAt !== null);
  737.     }
  738.     /**
  739.      * @param bool $firstLogin
  740.      * @return TvUser
  741.      */
  742.     public function setFirstLogin(bool $firstLogin): TvUser
  743.     {
  744.         $this->firstLogin $firstLogin;
  745.         return $this;
  746.     }
  747.     /**
  748.      * @return bool
  749.      */
  750.     public function isFirstLogin(): bool
  751.     {
  752.         return $this->firstLogin;
  753.     }
  754.     /**
  755.      * @param bool $homeSurvey
  756.      * @return TvUser
  757.      */
  758.     public function setHomeSurvey(bool $homeSurvey): TvUser
  759.     {
  760.         $this->homeSurvey $homeSurvey;
  761.         return $this;
  762.     }
  763.     /**
  764.      * @return bool
  765.      */
  766.     public function isHomeSurvey(): bool
  767.     {
  768.         return $this->homeSurvey;
  769.     }
  770.     /**
  771.      * @return Collection|Favorite[]
  772.      */
  773.     public function getFavorites(): Collection
  774.     {
  775.         return $this->favorites;
  776.     }
  777.     public function addFavorite(Favorite $favorite): self
  778.     {
  779.         if (!$this->favorites->contains($favorite)) {
  780.             $this->favorites[] = $favorite;
  781.         }
  782.         return $this;
  783.     }
  784.     public function removeFavorite(Favorite $favorite): self
  785.     {
  786.         $this->favorites->removeElement($favorite);
  787.         return $this;
  788.     }
  789.     public function getStatus(): ?string
  790.     {
  791.         return $this->status;
  792.     }
  793.     public function setStatus(string $status): self
  794.     {
  795.         $this->status $status;
  796.         return $this;
  797.     }
  798.     /**
  799.      * @return string|null
  800.      */
  801.     public function getPasswordConfirm(): ?string
  802.     {
  803.         return $this->passwordConfirm;
  804.     }
  805.     /**
  806.      * @param string|null $passwordConfirm
  807.      * @return TvUser
  808.      */
  809.     public function setPasswordConfirm(?string $passwordConfirm): TvUser
  810.     {
  811.         $this->passwordConfirm $passwordConfirm;
  812.         return $this;
  813.     }
  814.     public function getDepartment(): ?Department
  815.     {
  816.         return $this->department;
  817.     }
  818.     public function setDepartment(?Department $department): self
  819.     {
  820.         $this->department $department;
  821.         return $this;
  822.     }
  823.     /**
  824.      * @return Collection|LogEmail[]
  825.      */
  826.     public function getLogEmails(): Collection
  827.     {
  828.         return $this->logEmails;
  829.     }
  830.     public function addLogEmail(LogEmail $logEmail): self
  831.     {
  832.         if (!$this->logEmails->contains($logEmail)) {
  833.             $this->logEmails[] = $logEmail;
  834.             $logEmail->setTvUser($this);
  835.         }
  836.         return $this;
  837.     }
  838.     public function removeLogEmail(LogEmail $logEmail): self
  839.     {
  840.         if ($this->logEmails->removeElement($logEmail)) {
  841.             // set the owning side to null (unless already changed)
  842.             if ($logEmail->getTvUser() === $this) {
  843.                 $logEmail->setTvUser(null);
  844.             }
  845.         }
  846.         return $this;
  847.     }
  848.     /**
  849.      * @return Collection|Channel[]
  850.      */
  851.     public function getChannels(): Collection
  852.     {
  853.         return $this->channels;
  854.     }
  855.     public function addChannel(Channel $channel): self
  856.     {
  857.         if (!$this->channels->contains($channel)) {
  858.             $this->channels[] = $channel;
  859.             $channel->setTvUser($this);
  860.         }
  861.         return $this;
  862.     }
  863.     public function removeChannel(Channel $channel): self
  864.     {
  865.         if ($this->channels->removeElement($channel)) {
  866.             // set the owning side to null (unless already changed)
  867.             if ($channel->getTvUser() === $this) {
  868.                 $channel->setTvUser(null);
  869.             }
  870.         }
  871.         return $this;
  872.     }
  873.     
  874.     /**
  875.      * @return Collection|Objective[]
  876.      */
  877.     public function getObjectives(): Collection
  878.     {
  879.         return $this->objectives;
  880.     }
  881.     /**
  882.      * @return Collection|Objective[]
  883.      * @Groups({"tv_user_write"})
  884.      */
  885.     public function setObjectives(Collection $objectives): self
  886.     {
  887.         $this->objectives $objectives;
  888.         return $this;
  889.     }
  890.     public function addObjective(Objective $objective): self
  891.     {
  892.         if (!$this->objectives->contains($objective)) {
  893.             $this->objectives[] = $objective;
  894.             $objective->addTvUser($this);
  895.         }
  896.         return $this;
  897.     }
  898.     
  899.     public function removeObjective(Objective $objective): self
  900.     {
  901.         if ($this->objectives->removeElement($objective)) {
  902.             $objective->removeTvUser($this);
  903.         }
  904.         return $this;
  905.     }
  906.     public function getAssociation(): ?Association
  907.     {
  908.         return $this->association;
  909.     }
  910.     public function setAssociation(?Association $association): self
  911.     {
  912.         $this->association $association;
  913.         return $this;
  914.     }
  915.     /**
  916.      * @return Collection|TeamUser[]
  917.      */
  918.     public function getTeamUsers(): Collection
  919.     {
  920.         return $this->teamUsers;
  921.     }
  922.     public function addTeamUser(TeamUser $teamUser): self
  923.     {
  924.         if (!$this->teamUsers->contains($teamUser)) {
  925.             $this->teamUsers[] = $teamUser;
  926.             $teamUser->setTvUser($this);
  927.         }
  928.         return $this;
  929.     }
  930.     public function removeTeamUser(TeamUser $teamUser): self
  931.     {
  932.         if ($this->teamUsers->removeElement($teamUser)) {
  933.             // set the owning side to null (unless already changed)
  934.             if ($teamUser->getTvUser() === $this) {
  935.                 $teamUser->setTvUser(null);
  936.             }
  937.         }
  938.         return $this;
  939.     }
  940.     /**
  941.      * Récupére un tableau de Team
  942.      * @return Collection|Team[]|null
  943.      */
  944.     public function getTeams(): ?Collection
  945.     {
  946.         $teams null;
  947.         if(!$this->teamUsers->isEmpty()) {
  948.             $teams = new ArrayCollection([]);
  949.             foreach ($this->teamUsers->toArray() as $teamUser) {
  950.                 if($teamUser->getTeam() instanceof Team) {
  951.                     $teams->add($teamUser->getTeam());
  952.                 }
  953.             }
  954.         }
  955.         return $teams;
  956.     }
  957.     public function getDisplayTeamplayTuto(): ?bool
  958.     {
  959.         return $this->displayTeamplayTuto;
  960.     }
  961.     public function setDisplayTeamplayTuto(?bool $displayTeamplayTuto): self
  962.     {
  963.         $this->displayTeamplayTuto $displayTeamplayTuto;
  964.         return $this;
  965.     }
  966.     /**
  967.      * @return Collection|TeamplayLog[]
  968.      */
  969.     public function getTeamplayLogs(): Collection
  970.     {
  971.         return $this->teamplayLogs;
  972.     }
  973.     public function addTeamplayLog(TeamplayLog $teamplayLog): self
  974.     {
  975.         if (!$this->teamplayLogs->contains($teamplayLog)) {
  976.             $this->teamplayLogs[] = $teamplayLog;
  977.             $teamplayLog->setTvUser($this);
  978.         }
  979.         return $this;
  980.     }
  981.     public function removeTeamplayLog(TeamplayLog $teamplayLog): self
  982.     {
  983.         if ($this->teamplayLogs->removeElement($teamplayLog)) {
  984.             // set the owning side to null (unless already changed)
  985.             if ($teamplayLog->getTvUser() === $this) {
  986.                 $teamplayLog->setTvUser(null);
  987.             }
  988.         }
  989.         return $this;
  990.     }
  991.     /**
  992.      * @return Collection|PedometerLog[]
  993.      */
  994.     public function getPedometerLogs(): Collection
  995.     {
  996.         return $this->pedometerLogs;
  997.     }
  998.     public function addPedometerLog(PedometerLog $pedometerLog): self
  999.     {
  1000.         if (!$this->pedometerLogs->contains($pedometerLog)) {
  1001.             $this->pedometerLogs[] = $pedometerLog;
  1002.             $pedometerLog->setTvUser($this);
  1003.         }
  1004.         return $this;
  1005.     }
  1006.     public function removePedometerLog(PedometerLog $pedometerLog): self
  1007.     {
  1008.         if ($this->pedometerLogs->removeElement($pedometerLog)) {
  1009.             // set the owning side to null (unless already changed)
  1010.             if ($pedometerLog->getTvUser() === $this) {
  1011.                 $pedometerLog->setTvUser(null);
  1012.             }
  1013.         }
  1014.         return $this;
  1015.     }
  1016.     public function getDeviceOs(): ?string
  1017.     {
  1018.         return $this->deviceOs;
  1019.     }
  1020.     public function setDeviceOs(?string $deviceOs): self
  1021.     {
  1022.         $this->deviceOs $deviceOs;
  1023.         return $this;
  1024.     }
  1025.     public function getDeviceToken(): ?string
  1026.     {
  1027.         return $this->deviceToken;
  1028.     }
  1029.     public function setDeviceToken(?string $deviceToken): self
  1030.     {
  1031.         $this->deviceToken $deviceToken;
  1032.         return $this;
  1033.     }
  1034.     public function getDeviceName(): ?string
  1035.     {
  1036.         return $this->deviceName;
  1037.     }
  1038.     public function setDeviceName(?string $deviceName): self
  1039.     {
  1040.         $this->deviceName $deviceName;
  1041.         return $this;
  1042.     }
  1043.     public function isDeviceActive(): ?bool
  1044.     {
  1045.         return $this->deviceActive;
  1046.     }
  1047.     public function setDeviceActive(?bool $deviceActive): self
  1048.     {
  1049.         $this->deviceActive $deviceActive;
  1050.         return $this;
  1051.     }
  1052.     public function getDeviceUpdate(): ?\DateTimeInterface
  1053.     {
  1054.         return $this->deviceUpdate;
  1055.     }
  1056.     public function setDeviceUpdate(?\DateTimeInterface $deviceUpdate): self
  1057.     {
  1058.         $this->deviceUpdate $deviceUpdate;
  1059.         return $this;
  1060.     }
  1061.     /**
  1062.      * @return Collection<int, UserNotification>
  1063.      */
  1064.     public function getUserNotifications(): Collection
  1065.     {
  1066.         return $this->userNotifications;
  1067.     }
  1068.     public function addUserNotification(UserNotification $userNotification): self
  1069.     {
  1070.         if (!$this->userNotifications->contains($userNotification)) {
  1071.             $this->userNotifications[] = $userNotification;
  1072.             $userNotification->setTvUser($this);
  1073.         }
  1074.         return $this;
  1075.     }
  1076.     public function removeUserNotification(UserNotification $userNotification): self
  1077.     {
  1078.         if ($this->userNotifications->removeElement($userNotification)) {
  1079.             // set the owning side to null (unless already changed)
  1080.             if ($userNotification->getTvUser() === $this) {
  1081.                 $userNotification->setTvUser(null);
  1082.             }
  1083.         }
  1084.         return $this;
  1085.     }
  1086.     /**
  1087.      * @return Collection<int, UserDevice>
  1088.      */
  1089.     public function getDevices(): Collection
  1090.     {
  1091.         return $this->devices;
  1092.     }
  1093.     public function addDevice(UserDevice $device): self
  1094.     {
  1095.         if (!$this->devices->contains($device)) {
  1096.             $this->devices[] = $device;
  1097.             $device->setTvUser($this);
  1098.         }
  1099.         return $this;
  1100.     }
  1101.     public function removeDevice(UserDevice $device): self
  1102.     {
  1103.         if ($this->devices->removeElement($device)) {
  1104.             // set the owning side to null (unless already changed)
  1105.             if ($device->getTvUser() === $this) {
  1106.                 $device->setTvUser(null);
  1107.             }
  1108.         }
  1109.         return $this;
  1110.     }
  1111.     /**
  1112.      * @return Collection|AwardLog[]
  1113.      */
  1114.     public function getAwardLogs(): Collection
  1115.     {
  1116.         return $this->awardLogs;
  1117.     }
  1118.     public function addAwardLog(AwardLog $awardLog): self
  1119.     {
  1120.         if (!$this->awardLogs->contains($awardLog)) {
  1121.             $this->awardLogs[] = $awardLog;
  1122.             $awardLog->setTvUser($this);
  1123.         }
  1124.         return $this;
  1125.     }
  1126.     public function removeAwardLog(AwardLog $awardLog): self
  1127.     {
  1128.         if ($this->awardLogs->removeElement($awardLog)) {
  1129.             // set the owning side to null (unless already changed)
  1130.             if ($awardLog->getTvUser() === $this) {
  1131.                 $awardLog->setTvUser(null);
  1132.             }
  1133.         }
  1134.         return $this;
  1135.     }
  1136.     /**
  1137.      * @return Collection|UserVideoTimecode[]
  1138.      */
  1139.     public function getUserVideoTimecodes(): Collection
  1140.     {
  1141.         return $this->userVideoTimecodes;
  1142.     }
  1143.     public function addUserVideoTimecode(UserVideoTimecode $userVideoTimecode): self
  1144.     {
  1145.         if (!$this->userVideoTimecodes->contains($userVideoTimecode)) {
  1146.             $this->userVideoTimecodes[] = $userVideoTimecode;
  1147.             $userVideoTimecode->setTvUser($this);
  1148.         }
  1149.         return $this;
  1150.     }
  1151.     public function removeUserVideoTimecode(UserVideoTimecode $userVideoTimecode): self
  1152.     {
  1153.         if ($this->userVideoTimecodes->removeElement($userVideoTimecode)) {
  1154.             // set the owning side to null (unless already changed)
  1155.             if ($userVideoTimecode->getTvUser() === $this) {
  1156.                 $userVideoTimecode->setTvUser(null);
  1157.             }
  1158.         }
  1159.         return $this;
  1160.     }
  1161.     /**
  1162.      * @return Collection|Notation[]
  1163.      */
  1164.     public function getNotations(): Collection
  1165.     {
  1166.         return $this->notations;
  1167.     }
  1168.     public function addNotation(Notation $notation): self
  1169.     {
  1170.         if (!$this->notations->contains($notation)) {
  1171.             $this->notations[] = $notation;
  1172.             $notation->setTvUser($this);
  1173.         }
  1174.         return $this;
  1175.     }
  1176.     public function removeNotation(Notation $notation): self
  1177.     {
  1178.         if ($this->notations->removeElement($notation)) {
  1179.             // set the owning side to null (unless already changed)
  1180.             if ($notation->getTvUser() === $this) {
  1181.                 $notation->setTvUser(null);
  1182.             }
  1183.         }
  1184.         return $this;
  1185.     }
  1186.     
  1187.     /**
  1188.      * @return Collection|VideoLastValidate[]
  1189.      */
  1190.     public function getVideoLastValidates(): Collection
  1191.     {
  1192.         return $this->videoLastValidates;
  1193.     }
  1194.     public function addVideoLastValidate(VideoLastValidate $videoLastValidate): self
  1195.     {
  1196.         if (!$this->videoLastValidates->contains($videoLastValidate)) {
  1197.             $this->videoLastValidates[] = $videoLastValidate;
  1198.             $videoLastValidate->setTvUser($this);
  1199.         }
  1200.         return $this;
  1201.     }
  1202.     public function removeVideoLastValidate(VideoLastValidate $videoLastValidate): self
  1203.     {
  1204.         if ($this->videoLastValidates->removeElement($videoLastValidate)) {
  1205.             // set the owning side to null (unless already changed)
  1206.             if ($videoLastValidate->getTvUser() === $this) {
  1207.                 $videoLastValidate->setTvUser(null);
  1208.             }
  1209.         }
  1210.         return $this;
  1211.     }
  1212.     /**
  1213.      * @return Collection|VideoLastSeen[]
  1214.      */
  1215.     public function getVideoLastSeens(): Collection
  1216.     {
  1217.         return $this->videoLastSeens;
  1218.     }
  1219.     public function addVideoLastSeen(VideoLastSeen $videoLastSeen): self
  1220.     {
  1221.         if (!$this->videoLastSeens->contains($videoLastSeen)) {
  1222.             $this->videoLastSeens[] = $videoLastSeen;
  1223.             $videoLastSeen->setTvUser($this);
  1224.         }
  1225.         return $this;
  1226.     }
  1227.     public function removeVideoLastSeen(VideoLastSeen $videoLastSeen): self
  1228.     {
  1229.         if ($this->videoLastSeens->removeElement($videoLastSeen)) {
  1230.             // set the owning side to null (unless already changed)
  1231.             if ($videoLastSeen->getTvUser() === $this) {
  1232.                 $videoLastSeen->setTvUser(null);
  1233.             }
  1234.         }
  1235.         return $this;
  1236.     }
  1237.     /**
  1238.      * @return Collection|MoodResponse[]
  1239.      */
  1240.     public function getMoodResponses(): Collection
  1241.     {
  1242.         return $this->moodResponses;
  1243.     }
  1244.     public function addMoodResponse(MoodResponse $moodResponse): self
  1245.     {
  1246.         if (!$this->moodResponses->contains($moodResponse)) {
  1247.             $this->moodResponses[] = $moodResponse;
  1248.             $moodResponse->setTvUser($this);
  1249.         }
  1250.         return $this;
  1251.     }
  1252.     public function removeMoodResponse(MoodResponse $moodResponse): self
  1253.     {
  1254.         if ($this->moodResponses->removeElement($moodResponse)) {
  1255.             // set the owning side to null (unless already changed)
  1256.             if ($moodResponse->getTvUser() === $this) {
  1257.                 $moodResponse->setTvUser(null);
  1258.             }
  1259.         }
  1260.         return $this;
  1261.     }
  1262.     /**
  1263.      * @return Collection|ProgramEvent[]
  1264.      */
  1265.     public function getProgramEvents(): Collection
  1266.     {
  1267.         return $this->programEvents;
  1268.     }
  1269.     public function addProgramEvent(ProgramEvent $programEvent): self
  1270.     {
  1271.         if (!$this->programEvents->contains($programEvent)) {
  1272.             $this->programEvents[] = $programEvent;
  1273.             $programEvent->setTvUser($this);
  1274.         }
  1275.         return $this;
  1276.     }
  1277.     public function removeProgramEvent(ProgramEvent $programEvent): self
  1278.     {
  1279.         if ($this->programEvents->removeElement($programEvent)) {
  1280.             // set the owning side to null (unless already changed)
  1281.             if ($programEvent->getTvUser() === $this) {
  1282.                 $programEvent->setTvUser(null);
  1283.             }
  1284.         }
  1285.         return $this;
  1286.     }
  1287.     /**
  1288.      * @return Collection|DayEvent[]
  1289.      */
  1290.     public function getDayEvents(): Collection
  1291.     {
  1292.         return $this->dayEvents;
  1293.     }
  1294.     public function addDayEvent(DayEvent $dayEvent): self
  1295.     {
  1296.         if (!$this->dayEvents->contains($dayEvent)) {
  1297.             $this->dayEvents[] = $dayEvent;
  1298.             $dayEvent->setTvUser($this);
  1299.         }
  1300.         return $this;
  1301.     }
  1302.     public function removeDayEvent(DayEvent $dayEvent): self
  1303.     {
  1304.         if ($this->dayEvents->removeElement($dayEvent)) {
  1305.             // set the owning side to null (unless already changed)
  1306.             if ($dayEvent->getTvUser() === $this) {
  1307.                 $dayEvent->setTvUser(null);
  1308.             }
  1309.         }
  1310.         return $this;
  1311.     }
  1312.     public function getUser(): ?User
  1313.     {
  1314.         return $this->user;
  1315.     }
  1316.     public function setUser(?User $user): self
  1317.     {
  1318.         $this->user $user;
  1319.         return $this;
  1320.     }
  1321. }