src/Entity/User.php line 364

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiFilter;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use ApiPlatform\Core\Annotation\ApiSubresource;
  6. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter;
  7. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  8. use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
  9. use App\Repository\UserRepository;
  10. use DateTimeImmutable;
  11. use DateTimeInterface;
  12. use Doctrine\Common\Collections\Collection;
  13. use Doctrine\ORM\PersistentCollection;
  14. use JsonSerializable;
  15. use Doctrine\ORM\Mapping as ORM;
  16. use Doctrine\Common\Collections\ArrayCollection;
  17. use Symfony\Component\Security\Core\User\UserInterface;
  18. use Symfony\Component\Serializer\Annotation\Groups;
  19. use Symfony\Component\Validator\Constraints as Assert;
  20. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  21. /**
  22.  * @ApiResource(
  23.  *     collectionOperations={"get", "post"},
  24.  *     itemOperations={
  25.  *          "get"={
  26.  *              "normalization_context"={"groups"={"user:read", "user:item:get", "api_token:read", "api_token:item:get"}},
  27.  *          },
  28.  *          "put",
  29.  *          "delete",
  30.  *     },
  31.  *     normalizationContext={"groups"={"user:read"}, "swagger_definition_name"="Read"},
  32.  *     denormalizationContext={"groups"={"user:write"}, "swagger_definition_name"="Write"},
  33.  *     attributes={
  34.  *         "formats"={"jsonld", "json", "html", "csv"}
  35.  *     }
  36.  * )
  37.  * @UniqueEntity(fields={"email"})
  38.  * @ApiFilter(BooleanFilter::class, properties={"isActive", "isEmailForgotten"})
  39.  * @ApiFilter(SearchFilter::class, properties={"name": "partial", "firstName": "partial", "lastName": "partial", "email": "partial", "username": "partial"})
  40.  * @ApiFilter(PropertyFilter::class)
  41.  * @ORM\Entity(repositoryClass=UserRepository::class)
  42.  * @ORM\Entity
  43.  * @ORM\Table(name="`users`")
  44.  * @ORM\HasLifecycleCallbacks()
  45.  */
  46. class User implements UserInterface\SerializableJsonSerializable
  47. {
  48.     private $roleTexts = array(
  49.         'ROLE_GUEST' => 'Guest',
  50.         'ROLE_CUSTOMER' => 'Customer',
  51.         'ROLE_USER' => 'User',
  52.         'ROLE_MANAGER' => 'Manager',
  53.         'ROLE_ADMIN' => 'Administrator',
  54.         'ROLE_SUPER_ADMIN' => 'Super Administrator',
  55.     );
  56.     /**
  57.      * todo: update all id columns to use strategy="IDENTITY"
  58.      */
  59.     /**
  60.      * @ORM\Id()
  61.      * @ORM\GeneratedValue() // should be ORM\GeneratedValue(strategy="IDENTITY")
  62.      * @ORM\Column(type="integer")
  63.      * @Groups({"user:read", "user:write", "network_installation:read", "network_installation:item:get", "api_token:item:get", "department:item:get", "department:read"})
  64.      */
  65.     private $id;
  66.     /**
  67.      * @ORM\Column(type="string", length=191, unique=true, nullable=true)
  68.      * @Groups({"user:read", "user:write"})
  69.      */
  70.     protected $email;
  71.     /**
  72.      * @ORM\Column(type="string", length=191)
  73.      * @Groups({"user:read", "user:write", "network_installation:read", "network_installation:item:get", "api_token:item:get", "department:read", "department:item:get"})
  74.      * @var string $name
  75.      *
  76.      */
  77.     protected $name;
  78.     /**
  79.      * @ORM\Column(type="string", length=16, nullable=true)
  80.      * @Groups({"user:read", "user:write"})
  81.      */
  82.     protected $firstName;
  83.     /**
  84.      * @ORM\Column(type="string", length=32, nullable=true)
  85.      * @Groups({"user:read", "user:write"})
  86.      */
  87.     protected $lastName;
  88.     /**
  89.      * @ORM\Column(type="string", length=32, nullable=true)
  90.      * @Groups({"user:read", "user:write"})
  91.      */
  92.     protected $phoneNumber;
  93.     /**
  94.      * @ORM\Column(type="string", length=191, nullable=true)
  95.      * @Groups({"user:read", "user:write"})
  96.      */
  97.     protected $dropboxUserId;
  98.     /**
  99.      * @ORM\Column(type="text", nullable=true)
  100.      */
  101.     protected $dropboxLatestCursor;
  102.     /**
  103.      * @ORM\Column(type="string", length=191, nullable=true)
  104.      */
  105.     protected $dropboxOauthToken;
  106.     /**
  107.      * @ORM\Column(type="string", length=191)
  108.      * @Groups({"user:read", "user:write"})
  109.      * @var string $role
  110.      * available roles:
  111.      *    ROLE_USER
  112.      *    ROLE_CUSTOMER
  113.      *    ROLE_ADMIN
  114.      *    ROLE_GUEST
  115.      *    ROLE_MANAGER
  116.      *    ROLE_SUPER_ADMIN
  117.      */
  118.     protected $role;
  119.     /**
  120.      * @ORM\Column(type="json", nullable=true)
  121.      * @Groups({"user:read", "user:write"})
  122.      */
  123.     protected $roles;
  124.     /**
  125.      *
  126.      */
  127.     protected $plainPassword;
  128.     /**
  129.      * @ORM\Column(type="string", length=64, nullable=true)
  130.      */
  131.     protected $password;
  132.     /**
  133.      * @ORM\Column(type="boolean", nullable=true, options={"default":false})
  134.      * @Groups({"user:read", "user:write"})
  135.      */
  136.     protected $isActive false;
  137.     /**
  138.      * @ORM\Column(type="boolean", nullable=true, options={"default":false})
  139.      * @Groups({"user:read", "user:write"})
  140.      */
  141.     protected $isEmailForgotten false;
  142.     /**
  143.      * @ORM\Column(type="string", length=64, nullable=true)
  144.      */
  145.     protected $emailKey;
  146.     /**
  147.      * @ORM\Column(type="datetime", nullable=true)
  148.      * @Groups({"user:read", "user:write"})
  149.      */
  150.     private $lastLoggedIn;
  151.     /**
  152.      * @ORM\Column(type="datetime", nullable=true)
  153.      */
  154.     private $dateAdded;
  155.     /**
  156.      * @ORM\Column(type="datetime", nullable=true)
  157.      */
  158.     private $dateModified;
  159.     /**
  160.      * @ORM\Column(type="boolean", nullable=true)
  161.      * @Groups({"user:read", "user:write"})
  162.      */
  163.     private $isEmailConfirmed;
  164.     /* ~~~~~~~~~~~~~~~~ OneToOne ~~~~~~~~~~~~~~~~ */
  165.     /**
  166.      * @ORM\OneToOne(targetEntity=ApiToken::class, inversedBy="tokenUser", cascade={"persist", "remove"})
  167.      * @Groups({"user:read", "user:write"})
  168.      * todo: add to point tracker
  169.      */
  170.     private $currentApiToken;
  171.     /* ~~~~~~~~~~~~~~~~ ManyToOne ~~~~~~~~~~~~~~~~ */
  172.     /**
  173.      * @ORM\ManyToOne(targetEntity=TecDepartment::class, inversedBy="Users", cascade={"persist"}, fetch="EXTRA_LAZY")
  174.      * @Groups({"user:read", "user:write"})
  175.      */
  176.     private $tecDepartment;
  177.     /* ~~~~~~~~~~~~~~~~ OneToMany ~~~~~~~~~~~~~~~~ */
  178.     /**
  179.      * @ORM\OneToMany(targetEntity=ApiToken::class, mappedBy="user", orphanRemoval=true)
  180.      * @Groups({"user:item:get", "user:write"})
  181.      * todo: add to point tracker
  182.      */
  183.     private $apiTokens;
  184.     /**
  185.      * @ORM\OneToMany(targetEntity=ApiToken::class, mappedBy="retiredBy")
  186.      * @Groups({"user:item:get", "user:write"})
  187.      * todo: add to point tracker
  188.      */
  189.     private $retiredTokens;
  190.     /**
  191.      * @ORM\OneToMany(targetEntity="App\Entity\UserMessageQueueResult", mappedBy="user", cascade={"all"}, fetch="EXTRA_LAZY")
  192.      * @ORM\OrderBy({"viewedAt" = "DESC"})
  193.      */
  194.     private $userMessageQueueResults;
  195.     /**
  196.      * @ORM\OneToMany(targetEntity="App\Entity\FacilityDetails", mappedBy="serviceAccountManagerUser", cascade={"persist"}, fetch="EXTRA_LAZY")
  197.      * @ORM\JoinTable(name="service_account_managers_facility_details")
  198.      * @ORM\JoinColumn( name="service_account_manager_id", referencedColumnName="id", onDelete="cascade" )
  199.      */
  200.     private $facilityDetailsServiceAccountManager;
  201.     /**
  202.      * @ORM\OneToMany(targetEntity="App\Entity\FacilityDetails", mappedBy="serviceCustomerManagerUser", cascade={"persist"}, fetch="EXTRA_LAZY")
  203.      * @ORM\JoinTable(name="service_customer_managers_facility_details")
  204.      * @ORM\JoinColumn( name="service_customer_manager_id", referencedColumnName="id", onDelete="cascade" )
  205.      */
  206.     private $facilityDetailsServiceCustomerManager;
  207.     /**
  208.      * @ORM\OneToMany(targetEntity="App\Entity\VerificationItem", mappedBy="verifyingUser", cascade={"persist"}, fetch="EXTRA_LAZY")
  209.      * @ORM\JoinTable(name="user_verification_items")
  210.      * @ORM\JoinColumn( name="verifying_user_id", referencedColumnName="id" )
  211.      */
  212.     private $verificationItems;
  213.     /* ~~~~~~~~~~~~~~~~ ManyToMany ~~~~~~~~~~~~~~~~ */
  214.     /**
  215.      * @ORM\ManyToMany(targetEntity="App\Entity\Facility", inversedBy="users", cascade={"persist"}, fetch="EXTRA_LAZY")
  216.      * @ORM\JoinTable(name="user_facility")
  217.      * @ORM\OrderBy({"name" = "ASC"})
  218.      * @ApiSubresource()
  219.      */
  220.     private $facilities;
  221.     /**
  222.      * @ORM\ManyToMany(targetEntity="App\Entity\NetworkInstallation", inversedBy="users", cascade={"persist"}, fetch="EXTRA_LAZY")
  223.      * @ORM\JoinTable(name="network_installations_users")
  224.      * @ORM\OrderBy({"name" = "ASC"})
  225.      * @ApiSubresource()
  226.      * @Groups({"user:read", "user:write", "user:item:get"})
  227.      */
  228.     private $networkInstallations;
  229.     /**
  230.      * @ORM\ManyToMany(targetEntity="App\Entity\FacilityDetails", inversedBy="customerContacts", cascade={"persist"}, fetch="EXTRA_LAZY")
  231.      */
  232.     private $customerFacilityDetails;
  233.     /**
  234.      * @ORM\ManyToMany(targetEntity=EquipmentGroup::class, mappedBy="users")
  235.      */
  236.     private $equipmentGroups;
  237.     /*
  238.      * @ORM\ManyToMany(targetEntity="App\Entity\Department", inversedBy="users", cascade={"persist"}, fetch="EXTRA_LAZY")
  239.      */
  240. //    private $departments;
  241.     /* ~~~~~~~~~~~~~~~~ Magic Methods> ~~~~~~~~~~~~~~~~ */
  242.     public function __construct( array $data null )
  243.     {
  244.         $this->isActive true;
  245.         $this->userMessageQueueResults = new ArrayCollection();
  246.         $this->facilityDetailsServiceAccountManager = new ArrayCollection();
  247.         $this->verificationItems = new ArrayCollection();
  248.         $this->customerFacilityDetails = new ArrayCollection();
  249.         $this->apiTokens = new ArrayCollection();
  250.         $this->retiredTokens = new ArrayCollection();
  251.         if( !is_null$data ) ){
  252.             foreach( $data as $key => $value ){
  253.                 $methodName 'set' ucfirst$key );
  254.                 if( method_exists$this$methodName ) ){
  255.                     $this->{$methodName}( $value );
  256.                 } else {
  257.                     $this->__set$key$value );
  258.                 }
  259.             }
  260.         }
  261.         $this->equipmentGroups = new ArrayCollection();
  262.     }
  263.     /**
  264.      * @return string
  265.      */
  266.     public function __toString(): string
  267.     {
  268.         return (string) $this->name;
  269.     }
  270.     /**
  271.      * @param string $property
  272.      * @return mixed
  273.      */
  274.     public function __get(string $property)
  275.     {
  276.         // attempt to use the method
  277.         $methodName 'get' ucfirst$property );
  278.         if( method_exists$this$methodName ) ){
  279.             return $this->{$methodName}( $property );
  280.         }
  281.         // attempt to use the property
  282.         if (property_exists($this$property)) {
  283.             return $this->$property;
  284.         }
  285.         return null;
  286.     }
  287.     /**
  288.      * @param string $property
  289.      * @param mixed $value
  290.      * @return bool
  291.      */
  292.     public function __set(string $property$value) {
  293.         // attempt to use the method
  294.         $methodName 'set' ucfirst$property );
  295.         if( method_exists$this$methodName ) ){
  296.             $this->{$methodName}( $value );
  297.             return true;
  298.         }
  299.         // attempt to use the property
  300.         if (property_exists($this$property)) {
  301.             $this->$property $value;
  302.             return true;
  303.         }
  304.         return false;
  305.     }
  306.     /**
  307.      * @return array|mixed
  308.      */
  309.     public function jsonSerialize()
  310.     {
  311.         return array(
  312.             'id' => $this->id,
  313.             'email' => $this->email,
  314.             'name' => $this->name,
  315.             'department' => !is_null($this->department) ? $this->department->getName() : '',
  316.             'firstName' => $this->firstName,
  317.             'lastName' => $this->lastName,
  318.             'phoneNumber' => $this->phoneNumber,
  319.             'role' => $this->role,
  320.             'roleText' => array_key_exists$this->role$this->roleTexts ) ? $this->roleTexts[$this->role] : 'None',
  321.             'isActive' => $this->isActive,
  322.             'dropboxUserId' => $this->dropboxUserId,
  323.             'dropboxOauthToken' => $this->dropboxOauthToken,
  324.             'dropboxLatestCursor' => $this->dropboxLatestCursor,
  325.         );
  326.     }
  327.     /**
  328.      * Gets triggered every time on update
  329.      * @ORM\PreUpdate
  330.      */
  331.     public function onPreUpdate()
  332.     {
  333.         $this->dateModified = new \DateTime("now");
  334.     }
  335.     /**
  336.      * get id
  337.      *
  338.      * @return integer
  339.      */
  340.     public function getId(): int
  341.     {
  342.         return $this->id;
  343.     }
  344.     /**
  345.      * @param $id
  346.      * @return $this
  347.      * @deprecated id should be immutable
  348.      */
  349.     public function setId($id): User
  350.     {
  351.         $this->id $id;
  352.         return $this;
  353.     }
  354.     /**
  355.      * @return $this
  356.      * @deprecated this is the user!
  357.      */
  358.     public function getUser(): User
  359.     {
  360.         return $this;
  361.     }
  362.     public function getFirstName(): ?string
  363.     {
  364.         return $this->firstName;
  365.     }
  366.     public function setFirstName(?string $firstName): self
  367.     {
  368.         $this->firstName $firstName;
  369.         $this->name      $this->firstName " " $this->lastName;
  370.         $this->username  $this->firstName " " $this->lastName;
  371.         return $this;
  372.     }
  373.     public function getLastName(): ?string
  374.     {
  375.         return $this->lastName;
  376.     }
  377.     public function setLastName(?string $lastName): self
  378.     {
  379.         $this->lastName $lastName;
  380.         $this->name     $this->firstName " " $this->lastName;
  381.         $this->username $this->firstName " " $this->lastName;
  382.         return $this;
  383.     }
  384.     public function getPhoneNumber(): ?string
  385.     {
  386.         return $this->phoneNumber;
  387.     }
  388.     public function setPhoneNumber(?string $phoneNumber): self
  389.     {
  390.         $this->phoneNumber $phoneNumber;
  391.         return $this;
  392.     }
  393.     public function getIsActive(): ?bool
  394.     {
  395.         return $this->isActive;
  396.     }
  397.     public function setIsActive(?bool $isActive): self
  398.     {
  399.         if( $this->isEmailConfirmed $this->isActive $isActive;
  400.         return $this;
  401.     }
  402.     public function getIsEmailForgotten(): ?bool
  403.     {
  404.         return $this->isEmailForgotten;
  405.     }
  406.     public function setIsEmailForgotten(?bool $isEmailForgotten): self
  407.     {
  408.         $this->isEmailForgotten $isEmailForgotten;
  409.         return $this;
  410.     }
  411.     public function getEmailKey(): ?string
  412.     {
  413.         return $this->emailKey;
  414.     }
  415.     public function setEmailKey(?string $emailKey): self
  416.     {
  417.         $this->emailKey $emailKey;
  418.         return $this;
  419.     }
  420.     public function getLastLoggedIn(): ?DateTimeInterface
  421.     {
  422.         return $this->lastLoggedIn;
  423.     }
  424.     public function setLastLoggedIn(): self
  425.     {
  426.         $this->lastLoggedIn = new DateTimeImmutable();
  427.         return $this;
  428.     }
  429.     public function getDropboxUserId(): ?string
  430.     {
  431.         return $this->dropboxUserId;
  432.     }
  433.     public function setDropboxUserId(?string $dropboxUserId): self
  434.     {
  435.         $this->dropboxUserId $dropboxUserId;
  436.         return $this;
  437.     }
  438.     public function getDropboxLatestCursor(): ?string
  439.     {
  440.         return $this->dropboxLatestCursor;
  441.     }
  442.     public function setDropboxLatestCursor(?string $dropboxLatestCursor): self
  443.     {
  444.         $this->dropboxLatestCursor $dropboxLatestCursor;
  445.         return $this;
  446.     }
  447.     public function getDropboxOauthToken(): ?string
  448.     {
  449.         return $this->dropboxOauthToken;
  450.     }
  451.     public function setDropboxOauthToken(?string $dropboxOauthToken): self
  452.     {
  453.         $this->dropboxOauthToken $dropboxOauthToken;
  454.         return $this;
  455.     }
  456.     public function getRole(): ?string
  457.     {
  458.         return $this->role;
  459.     }
  460.     public function setRole(?string $role): self
  461.     {
  462.         $this->role $role;
  463.         return $this;
  464.     }
  465.     /**
  466.      * @see UserInterface
  467.      */
  468.     public function getRoles(): array
  469.     {
  470.         $roles $this->roles;
  471.         // guarantee every user at least has ROLE_USER
  472.         if( (is_null($roles) || count($roles) === 0) && !is_null$this->role ) ) $roles[] = $this->role;
  473.         return array_unique($roles);
  474.     }
  475.     public function setRoles(array $roles): self
  476.     {
  477.         $this->roles $roles;
  478.         return $this;
  479.     }
  480.     public function setName(?string $name): self
  481.     {
  482.         $nameArray explode(' '$name);
  483.         $familyName array_pop($nameArray);
  484.         $givenName implode(' '$nameArray);
  485.         $this->name $name;
  486.         $this->firstName $givenName;
  487.         $this->lastName $familyName;
  488.         return $this;
  489.     }
  490.     public function getName(): ?string
  491.     {
  492.         return $this->name;
  493.     }
  494.     public function getUsername(): ?string
  495.     {
  496.         return $this->email;
  497.     }
  498.     /**
  499.      * Returning a salt is only needed, if you are not using a modern
  500.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  501.      *
  502.      * @see UserInterface
  503.      */
  504.     public function getSalt(): ?string
  505.     {
  506.         return null;
  507.     }
  508.     /**
  509.      * @see UserInterface
  510.      */
  511.     public function eraseCredentials()
  512.     {
  513.         // If you store any temporary, sensitive data on the user, clear it here
  514.         // $this->plainPassword = null;
  515.     }
  516.     public function getEmail()
  517.     {
  518.         $emailParts explode(':'$this->email);
  519.         if ($emailParts[0] == 'autogenerated') {
  520.             return null;
  521.         } else {
  522.             return $this->email;
  523.         }
  524.     }
  525.     public function setEmail($email)
  526.     {
  527.         $this->email $email;
  528.     }
  529.     /**
  530.      * @see PasswordAuthenticatedUserInterface
  531.      */
  532.     public function getPassword(): string
  533.     {
  534.         return $this->password;
  535.     }
  536.     public function setPassword(string $password): self
  537.     {
  538.         $this->password $password;
  539.         return $this;
  540.     }
  541.     public function getPlainPassword(): ?string
  542.     {
  543.         return $this->plainPassword;
  544.     }
  545.     public function setPlainPassword(?string $plainPassword): self
  546.     {
  547.         $this->plainPassword $plainPassword;
  548.         return $this;
  549.     }
  550.     public function getDateAdded(): ?DateTimeInterface
  551.     {
  552.         return $this->dateAdded;
  553.     }
  554.     public function getDateModified(): ?DateTimeInterface
  555.     {
  556.         return $this->dateModified;
  557.     }
  558.     public function setDateModified(): self
  559.     {
  560.         $this->dateModified = new DateTime("now");
  561.         return $this;
  562.     }
  563.     public function getIsEmailConfirmed(): ?bool
  564.     {
  565.         return $this->isEmailConfirmed;
  566.     }
  567.     public function setIsEmailConfirmed(?bool $isEmailConfirmed): self
  568.     {
  569.         $this->isEmailConfirmed $isEmailConfirmed;
  570.         return $this;
  571.     }
  572.     /* ~~~~~~~~~~~~~~~~ OneToOne ~~~~~~~~~~~~~~~~ */
  573.     public function getCurrentApiToken(): ?ApiToken
  574.     {
  575.         return $this->currentApiToken;
  576.     }
  577.     public function setCurrentApiToken(?ApiToken $currentApiToken): self
  578.     {
  579.         $this->currentApiToken $currentApiToken;
  580.         return $this;
  581.     }
  582.     /* ~~~~~~~~~~~~~~~~ ManyToOne ~~~~~~~~~~~~~~~~ */
  583.     public function getTecDepartment(): ?TecDepartment
  584.     {
  585.         return $this->tecDepartment;
  586.     }
  587.     public function setTecDepartment(?TecDepartment $tecDepartment): self
  588.     {
  589.         $this->tecDepartment $tecDepartment;
  590.         return $this;
  591.     }
  592.     /**
  593.      * @Groups({"user:read", "user:write"})
  594.      * @return TecDepartment|null
  595.      */
  596.     public function getDepartment(): ?TecDepartment
  597.     {
  598.         return $this->getTecDepartment();
  599.     }
  600.     /**
  601.      * @Groups({"user:read", "user:write"})
  602.      * @param TecDepartment|null $tecDepartment
  603.      * @return $this
  604.      */
  605.     public function setDepartment(?TecDepartment $tecDepartment): self
  606.     {
  607.         return $this->setTecDepartment($tecDepartment);
  608.     }
  609.     /* ~~~~~~~~~~~~~~~~ OneToMany ~~~~~~~~~~~~~~~~ */
  610.     public function getUserMessageQueueResults(): ArrayCollection
  611.     {
  612.         return $this->userMessageQueueResults;
  613.     }
  614.     public function addUserMessageQueueResult(UserMessageQueueResult $userMessageQueueResult): self
  615.     {
  616.         if (!$this->userMessageQueueResults->contains($userMessageQueueResult)) {
  617.             $this->userMessageQueueResults[] = $userMessageQueueResult;
  618.             $userMessageQueueResult->setUser($this);
  619.         }
  620.         return $this;
  621.     }
  622.     public function removeUserMessageQueueResult(UserMessageQueueResult $userMessageQueueResult): self
  623.     {
  624.         if ($this->userMessageQueueResults->contains($userMessageQueueResult)) {
  625.             $this->userMessageQueueResults->removeElement($userMessageQueueResult);
  626.             // set the owning side to null (unless already changed)
  627.             if ($userMessageQueueResult->getUser() === $this) {
  628.                 $userMessageQueueResult->setUser();
  629.             }
  630.         }
  631.         return $this;
  632.     }
  633.     public function getFacilityDetailsServiceAccountManager(): ArrayCollection
  634.     {
  635.         return $this->facilityDetailsServiceAccountManager;
  636.     }
  637.     public function addFacilityDetailsServiceAccountManager(UserMessageQueueResult $userMessageQueueResult): self
  638.     {
  639.         if (!$this->facilityDetailsServiceAccountManager->contains($userMessageQueueResult)) {
  640.             $this->facilityDetailsServiceAccountManager[] = $userMessageQueueResult;
  641.             $userMessageQueueResult->setUser($this);
  642.         }
  643.         return $this;
  644.     }
  645.     public function removeFacilityDetailsServiceAccountManager(UserMessageQueueResult $userMessageQueueResult): self
  646.     {
  647.         if ($this->facilityDetailsServiceAccountManager->contains($userMessageQueueResult)) {
  648.             $this->facilityDetailsServiceAccountManager->removeElement($userMessageQueueResult);
  649.             // set the owning side to null (unless already changed)
  650.             if ($userMessageQueueResult->getUser() === $this) {
  651.                 $userMessageQueueResult->setUser();
  652.             }
  653.         }
  654.         return $this;
  655.     }
  656.     
  657.     public function getFacilityDetailsServiceCustomerManager()
  658.     {
  659.         return $this->facilityDetailsServiceCustomerManager;
  660.     }
  661.     public function addFacilityDetailsServiceCustomerManager(UserMessageQueueResult $userMessageQueueResult): self
  662.     {
  663.         if (!$this->facilityDetailsServiceCustomerManager->contains($userMessageQueueResult)) {
  664.             $this->facilityDetailsServiceCustomerManager[] = $userMessageQueueResult;
  665.             $userMessageQueueResult->setUser($this);
  666.         }
  667.         return $this;
  668.     }
  669.     public function removeFacilityDetailsServiceCustomerManager(UserMessageQueueResult $userMessageQueueResult): self
  670.     {
  671.         if ($this->facilityDetailsServiceCustomerManager->contains($userMessageQueueResult)) {
  672.             $this->facilityDetailsServiceCustomerManager->removeElement($userMessageQueueResult);
  673.             // set the owning side to null (unless already changed)
  674.             if ($userMessageQueueResult->getUser() === $this) {
  675.                 $userMessageQueueResult->setUser();
  676.             }
  677.         }
  678.         return $this;
  679.     }
  680.     
  681.     public function getVerificationItems(): ArrayCollection
  682.     {
  683.         return $this->verificationItems;
  684.     }
  685.     public function addVerificationItem(VerificationItem $verificationItem): self
  686.     {
  687.         if (!$this->verificationItems->contains($verificationItem)) {
  688.             $this->verificationItems[] = $verificationItem;
  689.             $verificationItem->setVerifyingUser($this);
  690.         }
  691.         return $this;
  692.     }
  693.     public function removeVerificationItem(VerificationItem $verificationItem): self
  694.     {
  695.         if ($this->verificationItems->contains($verificationItem)) {
  696.             $this->verificationItems->removeElement($verificationItem);
  697.             // set the owning side to null (unless already changed)
  698.             if ($verificationItem->getVerifyingUser() === $this) {
  699.                 $verificationItem->setVerifyingUser(null);
  700.             }
  701.         }
  702.         return $this;
  703.     }
  704.     /**
  705.      * @return Collection|ApiToken[]
  706.      */
  707.     public function getApiTokens(): Collection
  708.     {
  709.         return $this->apiTokens;
  710.     }
  711.     public function addApiToken(ApiToken $apiToken): self
  712.     {
  713.         if (!$this->apiTokens->contains($apiToken)) {
  714.             $this->apiTokens[] = $apiToken;
  715.             $apiToken->setUser($this);
  716.         }
  717.         return $this;
  718.     }
  719.     public function removeApiToken(ApiToken $apiToken): self
  720.     {
  721.         if ($this->apiTokens->removeElement($apiToken)) {
  722.             // set the owning side to null (unless already changed)
  723.             if ($apiToken->getUser() === $this) {
  724.                 $apiToken->setUser(null);
  725.             }
  726.         }
  727.         return $this;
  728.     }
  729.     /**
  730.      * @return Collection|ApiToken[]
  731.      */
  732.     public function getRetiredTokens(): Collection
  733.     {
  734.         return $this->retiredTokens;
  735.     }
  736.     public function addRetiredToken(ApiToken $retiredToken): self
  737.     {
  738.         if (!$this->retiredTokens->contains($retiredToken)) {
  739.             $this->retiredTokens[] = $retiredToken;
  740.             $retiredToken->setRetiredBy($this);
  741.         }
  742.         return $this;
  743.     }
  744.     public function removeRetiredToken(ApiToken $retiredToken): self
  745.     {
  746.         if ($this->retiredTokens->removeElement($retiredToken)) {
  747.             // set the owning side to null (unless already changed)
  748.             if ($retiredToken->getRetiredBy() === $this) {
  749.                 $retiredToken->setRetiredBy(null);
  750.             }
  751.         }
  752.         return $this;
  753.     }
  754.     /* ~~~~~~~~~~~~~~~~ ManyToMany ~~~~~~~~~~~~~~~~ */
  755.     /**
  756.      * @return mixed
  757.      */
  758.     public function getFacilities()
  759.     {
  760.         return $this->facilities;
  761.     }
  762.     /**
  763.      * Add Facility
  764.      *
  765.      * @param Facility $facility
  766.      * @return User
  767.      */
  768.     public function addFacility(Facility $facility): User
  769.     {
  770.         if (!$this->facilities->contains($facility)) {
  771.             $this->facilities[] = $facility;
  772.             $facility->addUser($this);
  773.         }
  774.         return $this;
  775.     }
  776.     /**
  777.      * Remove Facility
  778.      *
  779.      * @param Facility $facility
  780.      * @return User
  781.      */
  782.     public function removeFacility(Facility $facility): User
  783.     {
  784.         if ($this->facilities->contains($facility)) {
  785.             $this->facilities->removeElement($facility);
  786.             // set the owning side to null (unless already changed)
  787.             if ($facility->getUsers()->contains($this)) {
  788.                 $facility->removeUser($this);
  789.             }
  790.         }
  791.         return $this;
  792.     }
  793.     /**
  794.      * Get networkInstallations
  795.      *
  796.      * @return mixed
  797.      */
  798.     public function getNetworkInstallations()
  799.     {
  800.         return $this->networkInstallations;
  801.     }
  802.     /**
  803.      * Add networkInstallation
  804.      *
  805.      * @param NetworkInstallation $networkInstallation
  806.      *
  807.      * @return User
  808.      */
  809.     public function addNetworkInstallation(NetworkInstallation $networkInstallation): User
  810.     {
  811.         if (!$this->networkInstallations->contains($networkInstallation)) {
  812.             $this->networkInstallations[] = $networkInstallation;
  813.             $networkInstallation->addUser($this);
  814.         }
  815.         return $this;
  816.     }
  817.     /**
  818.      * Remove networkInstallation
  819.      *
  820.      * @param NetworkInstallation $networkInstallation
  821.      * @return User
  822.      */
  823.     public function removeNetworkInstallation(NetworkInstallation $networkInstallation): User
  824.     {
  825.         if ($this->networkInstallations->contains($networkInstallation)) {
  826.             $this->networkInstallations->removeElement($networkInstallation);
  827.             // set the owning side to null (unless already changed)
  828.             if ($networkInstallation->getUsers()->contains($this)) {
  829.                 $networkInstallation->removeUser($this);
  830.             }
  831.         }
  832.         return $this;
  833.     }
  834.     /**
  835.      * Get customerFacilityDetails
  836.      *
  837.      * @return mixed
  838.      */
  839.     public function getCustomerFacilityDetails()
  840.     {
  841.         return $this->customerFacilityDetails;
  842.     }
  843.     /**
  844.      * Add customerFacilityDetails
  845.      *
  846.      * @param \App\Entity\FacilityDetails $customerFacilityDetails
  847.      *
  848.      * @return User
  849.      */
  850.     public function addCustomerFacilityDetail(\App\Entity\FacilityDetails $customerFacilityDetails): User
  851.     {
  852.         if (!$this->customerFacilityDetails->contains($customerFacilityDetails)) {
  853.             $this->customerFacilityDetails[] = $customerFacilityDetails;
  854.             $customerFacilityDetails->addCustomerContact($this);
  855.         }
  856.         return $this;
  857.     }
  858.     /**
  859.      * Remove customerFacilityDetails
  860.      *
  861.      * @param \App\Entity\FacilityDetails $customerFacilityDetails
  862.      *
  863.      * @return User
  864.      */
  865.     public function removeCustomerFacilityDetail(\App\Entity\FacilityDetails $customerFacilityDetails): User
  866.     {
  867.         if ($this->customerFacilityDetails->contains($customerFacilityDetails)) {
  868.             $this->customerFacilityDetails->removeElement($customerFacilityDetails);
  869.             // set the owning side to null (unless already changed)
  870.             if ($customerFacilityDetails->getCustomerContacts()->contains($this)) {
  871.                 $customerFacilityDetails->removeCustomerContact($this);
  872.             }
  873.         }
  874.         return $this;
  875.     }
  876.     /**
  877.      * @return PersistentCollection|ArrayCollection
  878.      */
  879.  /*   public function getDepartments()
  880.     {
  881.         return $this->departments;
  882.     }
  883.     */
  884.     /**
  885.      * @param array $departments
  886.      * @param bool $cascade
  887.      * @return User
  888.      */
  889.     /*   public function addDepartments(array $departments, bool $cascade = true): User
  890.        {
  891.            foreach( $departments as $department ){
  892.                $this->addDepartment( $department, $cascade );
  893.            }
  894.            return $this;
  895.        }
  896.     */
  897.        /**
  898.         * @param Department $department
  899.         * @param bool $cascade
  900.         * @return User
  901.         */
  902.     /*    public function addDepartment(Department $department, bool $cascade = true): User
  903.         {
  904.             if( !is_null( $department ) ){
  905.                 // update the inverse side
  906.                 if( $cascade ) {
  907.                     $department->addUser($this);
  908.                 }
  909.             } else {
  910.                 if ( $this->departments->contains($department) && $this->departments[$department]->getUsers()->contains( $this ) ) {
  911.                     $this->departments[$department]->removeUser($this);
  912.                 }
  913.             }
  914.             $this->departments[] = $department;
  915.             return $this;
  916.         }
  917.     */
  918.         /**
  919.          * @param Department $department
  920.          * @return User
  921.          */
  922.     /*    public function removeDepartment(Department $department): User
  923.         {
  924.             if ($this->departments->contains($department)) {
  925.                 $this->departments->removeElement($department);
  926.                 // set the owning side to null (unless already changed)
  927.                 if ($department->getUsers()->contains( $this )) {
  928.                     $department->removeUser($this);
  929.                 }
  930.             }
  931.             return $this;
  932.         }
  933.     */
  934.         /**
  935.          * @param array $departments
  936.          * @return bool
  937.          */
  938.     /*    public function removeDepartments(array $departments): User
  939.         {
  940.             foreach( $departments as $department ){
  941.                 if( $department instanceof Department ){
  942.                     $this->removeDepartment( $department );
  943.                 }
  944.             }
  945.             return $this;
  946.         }
  947.     */
  948.         /* ~~~~~~~~~~~~~~~~ UserInterface Implementation Methods ~~~~~~~~~~~~~~~~ */
  949.     public function isEnabled(): bool
  950.     {
  951.         return $this->getIsActive();
  952.     }
  953.     public function isAccountNonExpired(): bool
  954.     {
  955.         return true;
  956.     }
  957.     public function isAccountNonLocked(): bool
  958.     {
  959.         return true;
  960.     }
  961.     public function isCredentialsNonExpired(): bool
  962.     {
  963.         return true;
  964.     }
  965.     /** @see \Serializable::serialize() */
  966.     public function serialize(): ?string
  967.     {
  968.         return serialize(
  969.             array(
  970.                 $this->id,
  971.                 $this->email,
  972.                 $this->password,
  973.                 $this->isActive,
  974.                 // see section on salt below
  975.                 // $this->salt,
  976.             )
  977.         );
  978.     }
  979.     /** @see \Serializable::unserialize() */
  980.     public function unserialize($serialized)
  981.     {
  982.         list (
  983.             $this->id,
  984.             $this->email,
  985.             $this->password,
  986.             $this->isActive,
  987.             // see section on salt below
  988.             // $this->salt
  989.             ) = unserialize($serialized, array('allowed_classes' => false));
  990.     }
  991.     /**
  992.      * @return Collection|EquipmentGroup[]
  993.      */
  994.     public function getEquipmentGroups(): Collection
  995.     {
  996.         return $this->equipmentGroups;
  997.     }
  998.     public function addEquipmentGroup(EquipmentGroup $equipmentGroup): self
  999.     {
  1000.         if (!$this->equipmentGroups->contains($equipmentGroup)) {
  1001.             $this->equipmentGroups[] = $equipmentGroup;
  1002.             $equipmentGroup->addUser($this);
  1003.         }
  1004.         return $this;
  1005.     }
  1006.     public function removeEquipmentGroup(EquipmentGroup $equipmentGroup): self
  1007.     {
  1008.         if ($this->equipmentGroups->removeElement($equipmentGroup)) {
  1009.             $equipmentGroup->removeUser($this);
  1010.         }
  1011.         return $this;
  1012.     }
  1013. }