src/Entity/User.php line 53

Open in your IDE?
  1. <?php
  2. namespace MedBrief\MSR\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use DateTime;
  5. use DateTimeImmutable;
  6. use DH\Auditor\Provider\Doctrine\Auditing\Annotation as Audit;
  7. use Doctrine\Common\Collections\Collection as DoctrineCollection;
  8. use Doctrine\ORM\EntityManagerInterface;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Gedmo\Mapping\Annotation as Gedmo;
  11. use libphonenumber\PhoneNumber;
  12. use libphonenumber\PhoneNumberFormat;
  13. use libphonenumber\PhoneNumberUtil;
  14. use MedBrief\MSR\Entity\Analytics\AnalyticsUser;
  15. use MedBrief\MSR\Model\User\MultiFactorEnabledUser;
  16. use MedBrief\MSR\Repository\UserInternalRepository;
  17. use MedBrief\MSR\Repository\UserRepository;
  18. use MedBrief\MSR\Security\AdvancedUserInterface;
  19. use MedBrief\MSR\Traits\FilterableClassConstantsTrait;
  20. use Ramsey\Uuid\Uuid;
  21. use Symfony\Component\Security\Core\User\EquatableInterface;
  22. use Symfony\Component\Security\Core\User\UserInterface;
  23. use Symfony\Component\Serializer\Annotation\Groups;
  24. use Symfony\Component\Validator\Context\ExecutionContextInterface;
  25. /**
  26. * @ApiResource(
  27. * collectionOperations={
  28. * "get"={"access_control"="is_granted('ROLE_ADMIN')", "normalization_context"={"groups"={"user:list"}}}
  29. * },
  30. * itemOperations={
  31. * "get"={"access_control"="is_granted('READ', object)"}
  32. * },
  33. * attributes={
  34. * "normalization_context"={"groups"={"user:read"}}
  35. * }
  36. * )
  37. *
  38. * @ORM\Table(name="fos_user")
  39. *
  40. * @ORM\Entity(repositoryClass=UserRepository::class)
  41. *
  42. * @ORM\HasLifecycleCallbacks
  43. *
  44. * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false)
  45. *
  46. * @Audit\Auditable
  47. *
  48. * @Audit\Security(view={"ROLE_ALLOWED_TO_AUDIT"})
  49. */
  50. class User extends MultiFactorEnabledUser implements AdvancedUserInterface, EquatableInterface
  51. {
  52. use FilterableClassConstantsTrait;
  53. // CONSTANTS
  54. public const NOTIFICATION_STATUS_PENDING = 1;
  55. public const NOTIFICATION_STATUS_SENT = 2;
  56. public const NOTIFICATION_STATUS_FAILED = 3;
  57. public const NOTIFICATION_STATUS_UNSUBSCRIBE = 4;
  58. public const NOTIFICATION_FORMAT_PREFERENCE_EMAIL = UserNotification::NOTIFICATION_FORMAT_EMAIL;
  59. public const NOTIFICATION_FORMAT_PREFERENCE_SMS = UserNotification::NOTIFICATION_FORMAT_SMS;
  60. public const NOTIFICATION_FORMAT_PREFERENCE_PUSH = UserNotification::NOTIFICATION_FORMAT_PUSH;
  61. public const USER_TYPE_INTERNAL = 'internal';
  62. public const USER_TYPE_INTERNAL__LABEL = 'Internal';
  63. public const USER_TYPE_CLIENT = 'client';
  64. public const USER_TYPE_CLIENT__LABEL = 'Client';
  65. public const USER_TYPE_EXPERT = 'expert';
  66. public const USER_TYPE_EXPERT__LABEL = 'Expert';
  67. public const USER_TYPE_OTHER = 'other';
  68. public const USER_TYPE_OTHER__LABEL = 'Other';
  69. public const DEFAULT_ROLE_SUPER_ADMIN = 'ROLE_SUPER_ADMIN';
  70. public const DEFAULT_ROLE_SUPER_ADMIN__LABEL = 'MedBrief Super Administrator';
  71. public const DEFAULT_ROLE_ADMIN = 'ROLE_ADMIN';
  72. public const DEFAULT_ROLE_ADMIN__LABEL = 'MedBrief Administrator';
  73. // PROTECTED VARIABLES
  74. /**
  75. * @var int
  76. *
  77. * @ORM\Column(name="id", type="integer")
  78. *
  79. * @ORM\Id
  80. *
  81. * @ORM\GeneratedValue(strategy="IDENTITY")
  82. */
  83. protected $id;
  84. /**
  85. * @var string
  86. *
  87. * @ORM\Column(name="password", type="string", length=255)
  88. */
  89. protected $password;
  90. /**
  91. * @var string|null
  92. *
  93. * @ORM\Column(name="salt", type="string", length=255, nullable=true)
  94. */
  95. protected $salt;
  96. /**
  97. * @var bool
  98. *
  99. * @ORM\Column(name="enabled", type="boolean")
  100. */
  101. protected $enabled = false;
  102. /**
  103. * @var DateTime|null
  104. *
  105. * @ORM\Column(name="last_login", type="datetime", nullable=true)
  106. */
  107. protected $last_login;
  108. /**
  109. * @var array
  110. *
  111. * @ORM\Column(name="roles", type="array")
  112. */
  113. protected $roles = [];
  114. /**
  115. * @var string|null
  116. *
  117. * @ORM\Column(name="first_name", type="string", length=255, nullable=true)
  118. */
  119. protected $first_name;
  120. /**
  121. * @var string|null
  122. *
  123. * @ORM\Column(name="last_name", type="string", length=255, nullable=true)
  124. */
  125. protected $last_name;
  126. /**
  127. * @var DateTime
  128. *
  129. * @ORM\Column(name="created", type="datetime")
  130. *
  131. * @Gedmo\Timestampable(on="create")
  132. */
  133. protected $created;
  134. /**
  135. * @var DateTime
  136. *
  137. * @ORM\Column(name="updated", type="datetime")
  138. *
  139. * @Gedmo\Timestampable(on="update")
  140. */
  141. protected $updated;
  142. /**
  143. * @var DateTime|null
  144. *
  145. * @ORM\Column(name="deletedAt", type="datetime", nullable=true)
  146. */
  147. protected $deletedAt;
  148. /**
  149. * @var string
  150. *
  151. * @ORM\Column(name="search_index", type="text", nullable=false)
  152. */
  153. protected $search_index;
  154. /**
  155. * @var string|null
  156. *
  157. * @ORM\Column(name="phone_number", type="string", length=155, nullable=true)
  158. */
  159. protected $phoneNumber;
  160. /**
  161. * @var DateTime|null
  162. *
  163. * @ORM\Column(name="lastActivity", type="datetime", nullable=true)
  164. *
  165. * @Audit\Ignore
  166. */
  167. protected $lastActivity;
  168. /**
  169. * @var DateTime|null
  170. *
  171. * @ORM\Column(name="firstLoginDate", type="datetime", nullable=true)
  172. */
  173. protected $firstLoginDate;
  174. /**
  175. * Whether the user account is locked or not
  176. *
  177. * @var bool|null
  178. *
  179. * @ORM\Column(name="locked", type="boolean", nullable=true, options={"default"=false})
  180. */
  181. protected $locked = false;
  182. /**
  183. * @var string
  184. */
  185. protected $plainPassword;
  186. /**
  187. * mobileNumber - Used for SMS verification.
  188. *
  189. * @var PhoneNumber|null
  190. *
  191. * @ORM\Column(name="mobileNumber", type="phone_number", nullable=true)
  192. * @Audit\Ignore
  193. */
  194. private $mobileNumber;
  195. /** @ORM\Column(type="boolean", options={"default"=true}) */
  196. private bool $trustedDeviceEnabled = true;
  197. /**
  198. * @ORM\Column(type="integer", options={"default"=1, "unsigned"=true})
  199. * @Audit\Ignore
  200. */
  201. private int $trustedDeviceGeneration = 1;
  202. /** @ORM\Column(type="datetime_immutable", nullable=true) */
  203. private ?DateTimeImmutable $mobileNumberVerifiedAt = null;
  204. /**
  205. * @ORM\Column(type="string", length=64, nullable=true, unique=true, options={"fixed"=true})
  206. * @Audit\Ignore
  207. */
  208. private ?string $verifiedMobileNumberKey = null;
  209. /**
  210. * @ORM\Column(type="datetime_immutable", nullable=true)
  211. * @Audit\Ignore
  212. */
  213. private ?DateTimeImmutable $mobileEnrolmentAuthorisedUntil = null;
  214. /**
  215. * @ORM\Column(type="string", length=64, nullable=true, options={"fixed"=true})
  216. * @Audit\Ignore
  217. */
  218. private ?string $mobileEnrolmentProofHash = null;
  219. /** @ORM\Column(type="boolean", options={"default"=false}) */
  220. private bool $mobileEnrolmentRequiresSupport = false;
  221. /**
  222. * @var bool
  223. *
  224. * @ORM\Column(name="hasDocSorterAccess", type="boolean")
  225. */
  226. private $hasDocSorterAccess = false;
  227. /**
  228. * Whether a User has billing admin rights
  229. *
  230. * @var bool
  231. *
  232. * @ORM\Column(name="billingAdmin", type="boolean", options={"default"=false})
  233. */
  234. private $billingAdmin = false;
  235. /**
  236. * @var bool
  237. *
  238. * @ORM\Column(name="matterDashboardEnabled", type="boolean")
  239. */
  240. private $matterDashboardEnabled = false;
  241. /**
  242. * @var string|null
  243. *
  244. * @ORM\Column(name="userType", type="string", length=255, nullable=true)
  245. */
  246. private $userType;
  247. /**
  248. * @var string|null
  249. *
  250. * @ORM\Column(name="azureId", type="string", length=255, nullable=true)
  251. */
  252. private $azureId;
  253. /**
  254. * @var bool
  255. *
  256. * @ORM\Column(name="receiveDailyUploadNotificationEmail", type="boolean")
  257. */
  258. private $receiveDailyUploadNotificationEmail = true;
  259. /**
  260. * @var bool|null
  261. *
  262. * @ORM\Column(name="tfaEnabled", type="boolean", nullable=true)
  263. */
  264. private $tfaEnabled;
  265. /**
  266. * @var string|null
  267. *
  268. * @ORM\Column(name="tfaUserId", type="string", nullable=true)
  269. */
  270. private $tfaUserId;
  271. /**
  272. * @var int|null
  273. *
  274. * @ORM\Column(name="notificationStatus", type="integer", nullable=true)
  275. */
  276. private $notificationStatus;
  277. /**
  278. * The User's own preference for the format they would like to receive UserNotifications in
  279. *
  280. * @var int
  281. *
  282. * @ORM\Column(name="notificationFormatPreference", type="integer", options={"default"="1"})
  283. */
  284. private $notificationFormatPreference = self::NOTIFICATION_FORMAT_PREFERENCE_EMAIL;
  285. /**
  286. * @var Invitation
  287. *
  288. * @ORM\OneToOne(targetEntity="MedBrief\MSR\Entity\Invitation", inversedBy="user", cascade={"remove"})
  289. *
  290. * @ORM\JoinColumns({
  291. *
  292. * @ORM\JoinColumn(name="invitation_id", referencedColumnName="code", unique=true)
  293. * })
  294. */
  295. private $invitation;
  296. /**
  297. * @var HumanResource
  298. *
  299. * @ORM\OneToOne(targetEntity="MedBrief\MSR\Entity\HumanResource", mappedBy="user")
  300. */
  301. private $humanResource;
  302. /**
  303. * @var AnalyticsUser
  304. *
  305. * @ORM\OneToOne(targetEntity="MedBrief\MSR\Entity\Analytics\AnalyticsUser", mappedBy="user", cascade={"persist","remove"})
  306. */
  307. private $analyticsUser;
  308. /**
  309. * @var LinkedEmailAddressInvitation
  310. *
  311. * @ORM\OneToOne(targetEntity="MedBrief\MSR\Entity\LinkedEmailAddressInvitation", mappedBy="userToLink", cascade={"persist","remove"})
  312. */
  313. private $linkedEmailAddressInvitation;
  314. /**
  315. * @var DoctrineCollection
  316. *
  317. * @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\Document", mappedBy="creator", cascade={"detach"})
  318. */
  319. private $documents;
  320. /**
  321. * @var DoctrineCollection
  322. *
  323. * @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\Disc", mappedBy="creator", cascade={"detach"})
  324. */
  325. private $discs;
  326. /**
  327. * @var DoctrineCollection
  328. *
  329. * @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\Project", mappedBy="manager", cascade={"detach"})
  330. */
  331. private $managedProjects;
  332. /**
  333. * @var DoctrineCollection
  334. *
  335. * @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\RoleInvitation", mappedBy="user", cascade={"persist","remove"})
  336. */
  337. private $roleInvitations;
  338. /**
  339. * @var DoctrineCollection
  340. *
  341. * @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\LinkedEmailAddressInvitation", mappedBy="user", cascade={"persist","remove"})
  342. */
  343. private $linkedEmailAddressInvitations;
  344. /**
  345. * @var DoctrineCollection
  346. *
  347. * @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\DiscImportSession", mappedBy="creator", cascade={"all"})
  348. */
  349. private $discImportSessions;
  350. /**
  351. * @var DoctrineCollection
  352. *
  353. * @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\ProjectUser", mappedBy="user", cascade={"all"})
  354. */
  355. private $projectUsers;
  356. /**
  357. * @var DoctrineCollection
  358. *
  359. * @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\Invitation", mappedBy="creator", cascade={"persist","detach","merge","refresh"})
  360. */
  361. private $invitationsCreated;
  362. /**
  363. * @var DoctrineCollection
  364. *
  365. * @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\User", mappedBy="creator")
  366. */
  367. private $usersCreated;
  368. /**
  369. * @var DoctrineCollection
  370. *
  371. * @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\RecordsRequestDetail", mappedBy="creator")
  372. */
  373. private $recordsRequestDetails;
  374. /**
  375. * @var DoctrineCollection
  376. *
  377. * @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\ChronologyItem", mappedBy="creator")
  378. */
  379. private $chronologyItemsCreated;
  380. /**
  381. * This relates to the UserNotifications that have been sent or are queued to send to the User
  382. *
  383. * @var DoctrineCollection
  384. *
  385. * @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\UserNotification", mappedBy="recipient", cascade={"persist","remove"})
  386. */
  387. private $notifications;
  388. /**
  389. * @var DoctrineCollection
  390. *
  391. * @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\MatterNote", mappedBy="creator")
  392. */
  393. private $matterNotes;
  394. /**
  395. * @var DoctrineCollection
  396. *
  397. * @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\LinkedEmailAddress", mappedBy="user")
  398. */
  399. private $linkedEmailAddress;
  400. /**
  401. * @var DoctrineCollection
  402. *
  403. * @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\ProjectClosure", mappedBy="closedBy")
  404. */
  405. private $projectClosures;
  406. /**
  407. * @var Account
  408. *
  409. * @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\Account")
  410. *
  411. * @ORM\JoinColumns({
  412. *
  413. * @ORM\JoinColumn(name="account_id", referencedColumnName="id")
  414. * })
  415. */
  416. private $account;
  417. /**
  418. * @var ExpertAgency
  419. *
  420. * @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\ExpertAgency", inversedBy="users")
  421. *
  422. * @ORM\JoinColumns({
  423. *
  424. * @ORM\JoinColumn(name="expertAgency_id", referencedColumnName="id")
  425. * })
  426. */
  427. private $expertAgency;
  428. /**
  429. * @var User
  430. *
  431. * @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\User", inversedBy="usersCreated")
  432. *
  433. * @ORM\JoinColumns({
  434. *
  435. * @ORM\JoinColumn(name="creator_id", referencedColumnName="id", nullable=true)
  436. * })
  437. */
  438. private $creator;
  439. /**
  440. * @var DoctrineCollection
  441. *
  442. * @ORM\ManyToMany(targetEntity="MedBrief\MSR\Entity\Specialisation")
  443. *
  444. * @ORM\JoinTable(name="user_specialisation",
  445. * joinColumns={
  446. *
  447. * @ORM\JoinColumn(name="user_id", referencedColumnName="id", onDelete="CASCADE")
  448. * },
  449. * inverseJoinColumns={
  450. * @ORM\JoinColumn(name="specialisation_id", referencedColumnName="id", onDelete="CASCADE")
  451. * }
  452. * )
  453. *
  454. * @ORM\OrderBy({
  455. * "title"="ASC"
  456. * })
  457. */
  458. private $specialisations;
  459. /**
  460. * @var DoctrineCollection
  461. *
  462. * @ORM\ManyToMany(targetEntity="MedBrief\MSR\Entity\Project")
  463. *
  464. * @ORM\JoinTable(name="user_project",
  465. * joinColumns={
  466. *
  467. * @ORM\JoinColumn(name="user_id", referencedColumnName="id", onDelete="CASCADE")
  468. * },
  469. * inverseJoinColumns={
  470. * @ORM\JoinColumn(name="project_id", referencedColumnName="id", onDelete="CASCADE")
  471. * }
  472. * )
  473. */
  474. private $favouriteProjects;
  475. private $azureAccessToken;
  476. /**
  477. * @ORM\OneToMany(targetEntity=ClinicalSummary::class, mappedBy="creator")
  478. */
  479. private $clinicalSummaries;
  480. /**
  481. * Transient property to store activity timeout in minutes (not persisted to database)
  482. * Used by isActiveNow() to determine if user is currently active
  483. *
  484. * @var int
  485. */
  486. private $activityTimeoutMinutes = 45;
  487. /**
  488. * This property will track whether the 'Billed' checkbox in various modals is visible to MB Admins.
  489. *
  490. * @ORM\Column(type="boolean", options={"default": false})
  491. */
  492. private bool $accessToBilled = false;
  493. /**
  494. * @var DateTime|null
  495. *
  496. * @ORM\Column(name="legacyRadiologyViewerLastUsed", type="datetime", nullable=true)
  497. */
  498. private $legacyRadiologyViewerLastUsed;
  499. /**
  500. * Whether the user has opted in to Expert Matching
  501. *
  502. * @var bool
  503. *
  504. * @ORM\Column(name="matchOptIn", type="boolean", options={"default": false})
  505. */
  506. private bool $matchOptIn = false;
  507. /**
  508. * Whether the user has opted in to MedBrief Insights.
  509. *
  510. * @var bool
  511. *
  512. * @ORM\Column(name="insightsOptIn", type="boolean", options={"default": false})
  513. */
  514. private bool $insightsOptIn = false;
  515. public function __construct()
  516. {
  517. $this->username = Uuid::uuid4()->toString();
  518. $this->documents = new \Doctrine\Common\Collections\ArrayCollection();
  519. $this->discs = new \Doctrine\Common\Collections\ArrayCollection();
  520. $this->managedProjects = new \Doctrine\Common\Collections\ArrayCollection();
  521. $this->roleInvitations = new \Doctrine\Common\Collections\ArrayCollection();
  522. $this->linkedEmailAddressInvitations = new \Doctrine\Common\Collections\ArrayCollection();
  523. $this->discImportSessions = new \Doctrine\Common\Collections\ArrayCollection();
  524. $this->projectUsers = new \Doctrine\Common\Collections\ArrayCollection();
  525. $this->invitationsCreated = new \Doctrine\Common\Collections\ArrayCollection();
  526. $this->usersCreated = new \Doctrine\Common\Collections\ArrayCollection();
  527. $this->recordsRequestDetails = new \Doctrine\Common\Collections\ArrayCollection();
  528. $this->chronologyItemsCreated = new \Doctrine\Common\Collections\ArrayCollection();
  529. $this->notifications = new \Doctrine\Common\Collections\ArrayCollection();
  530. $this->matterNotes = new \Doctrine\Common\Collections\ArrayCollection();
  531. $this->linkedEmailAddress = new \Doctrine\Common\Collections\ArrayCollection();
  532. $this->projectClosures = new \Doctrine\Common\Collections\ArrayCollection();
  533. $this->specialisations = new \Doctrine\Common\Collections\ArrayCollection();
  534. $this->favouriteProjects = new \Doctrine\Common\Collections\ArrayCollection();
  535. $this->clinicalSummaries = new \Doctrine\Common\Collections\ArrayCollection();
  536. }
  537. /**
  538. * Returns a textual representation of this user (their full name)
  539. */
  540. public function __toString()
  541. {
  542. return $this->getFullName();
  543. }
  544. /**
  545. * @Groups({"user:list"})
  546. *
  547. * @return int|null
  548. */
  549. public function getId(): ?int
  550. {
  551. return $this->id;
  552. }
  553. /**
  554. * A visual identifier that represents this user.
  555. *
  556. * @see UserInterface
  557. */
  558. public function getUsername(): string
  559. {
  560. return (string) $this->username;
  561. }
  562. /**
  563. * @param string $username
  564. *
  565. * @return $this
  566. */
  567. public function setUsername(string $username): self
  568. {
  569. $this->username = $username;
  570. return $this;
  571. }
  572. /**
  573. * @see UserInterface
  574. */
  575. public function getRoles(): array
  576. {
  577. $roles = $this->roles;
  578. // guarantee every user at least has ROLE_USER
  579. $roles[] = 'ROLE_USER';
  580. return array_unique($roles);
  581. }
  582. /**
  583. * @param array $roles
  584. *
  585. * @return $this
  586. */
  587. public function setRoles(array $roles): self
  588. {
  589. $this->roles = $roles;
  590. return $this;
  591. }
  592. /**
  593. * @param string $role
  594. *
  595. * @return $this
  596. */
  597. public function addRole(string $role)
  598. {
  599. $this->roles[] = $role;
  600. return $this;
  601. }
  602. /**
  603. * @param string $role
  604. *
  605. * @return $this
  606. */
  607. public function removeRole(string $role)
  608. {
  609. if (($key = array_search($role, $this->roles)) !== false) {
  610. unset($this->roles[$key]);
  611. }
  612. return $this;
  613. }
  614. /**
  615. * @see UserInterface
  616. */
  617. public function getPassword(): string
  618. {
  619. return $this->password;
  620. }
  621. /**
  622. * @param string $password
  623. *
  624. * @return $this
  625. */
  626. public function setPassword(string $password): self
  627. {
  628. $this->password = $password;
  629. return $this;
  630. }
  631. /**
  632. * Returning a salt is only needed, if you are not using a modern
  633. * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  634. *
  635. * @see UserInterface
  636. */
  637. public function getSalt(): ?string
  638. {
  639. return $this->salt;
  640. }
  641. /**
  642. * Setting a salt is generally unnecessary (modern hashing algorithms), but we have implemented this so that we can
  643. * clear the salt on upgrade of a User's password.
  644. *
  645. * @param string|null $salt
  646. *
  647. * @return $this
  648. */
  649. public function setSalt(?string $salt)
  650. {
  651. $this->salt = $salt;
  652. return $this;
  653. }
  654. /**
  655. * @see UserInterface
  656. */
  657. public function eraseCredentials()
  658. {
  659. // If you store any temporary, sensitive data on the user, clear it here
  660. // $this->plainPassword = null;
  661. }
  662. /**
  663. * @return bool
  664. */
  665. public function isEnabled()
  666. {
  667. return $this->enabled;
  668. }
  669. /**
  670. * @return mixed
  671. */
  672. public function getLastLogin()
  673. {
  674. return $this->last_login;
  675. }
  676. /**
  677. * @param mixed $last_login
  678. *
  679. * @return User
  680. */
  681. public function setLastLogin($last_login)
  682. {
  683. $this->last_login = $last_login;
  684. return $this;
  685. }
  686. /**
  687. * @return string
  688. */
  689. public function getAzureId()
  690. {
  691. return $this->azureId;
  692. }
  693. /**
  694. * @param string $azureId
  695. *
  696. * @return User
  697. */
  698. public function setAzureId($azureId)
  699. {
  700. $this->azureId = $azureId;
  701. return $this;
  702. }
  703. /**
  704. * @return string
  705. */
  706. public function getAzureAccessToken()
  707. {
  708. return $this->azureAccessToken;
  709. }
  710. /**
  711. * @param mixed $azureAccessToken
  712. *
  713. * @return User
  714. */
  715. public function setAzureAccessToken($azureAccessToken)
  716. {
  717. $this->azureAccessToken = $azureAccessToken;
  718. return $this;
  719. }
  720. /**
  721. * @return string
  722. */
  723. public function getMicrosoftId()
  724. {
  725. return $this->getAzureId();
  726. }
  727. /**
  728. * @param mixed $azureId
  729. *
  730. * @return User
  731. */
  732. public function setMicrosoftId($azureId)
  733. {
  734. return $this->setAzureId($azureId);
  735. }
  736. /**
  737. * @return string
  738. */
  739. public function getMicrosoftAccessToken()
  740. {
  741. return $this->getAzureAccessToken();
  742. }
  743. /**
  744. * @param mixed $azureAccessToken
  745. *
  746. * @return User
  747. */
  748. public function setMicrosoftAccessToken($azureAccessToken)
  749. {
  750. return $this->setAzureAccessToken($azureAccessToken);
  751. }
  752. /**
  753. * @return string
  754. */
  755. public function getFullName()
  756. {
  757. $prefix = '';
  758. if ($this->getDeletedAt() !== null) {
  759. $prefix = '[REMOVED] ';
  760. }
  761. return $prefix . trim($this->getFirstName() . ' ' . $this->getLastName());
  762. }
  763. /**
  764. * @param string $first_name
  765. *
  766. * @return User
  767. */
  768. public function setFirstName($first_name)
  769. {
  770. $this->first_name = $first_name;
  771. return $this;
  772. }
  773. /**
  774. * @Groups({"user:read", "user:list", "matter_request:read", "account:read"})
  775. *
  776. * @return string
  777. */
  778. public function getFirstName()
  779. {
  780. return $this->first_name;
  781. }
  782. /**
  783. * @param string $last_name
  784. *
  785. * @return User
  786. */
  787. public function setLastName($last_name)
  788. {
  789. $this->last_name = $last_name;
  790. return $this;
  791. }
  792. /**
  793. * @Groups({"user:read", "user:list", "matter_request:read", "account:read"})
  794. *
  795. * @return string
  796. */
  797. public function getLastName()
  798. {
  799. return $this->last_name;
  800. }
  801. /**
  802. * @param DateTime $created
  803. *
  804. * @return User
  805. */
  806. public function setCreated($created)
  807. {
  808. $this->created = $created;
  809. return $this;
  810. }
  811. /**
  812. * @return DateTime
  813. */
  814. public function getCreated()
  815. {
  816. return $this->created;
  817. }
  818. /**
  819. * @param DateTime $updated
  820. *
  821. * @return User
  822. */
  823. public function setUpdated($updated)
  824. {
  825. $this->updated = $updated;
  826. return $this;
  827. }
  828. /**
  829. * @return DateTime
  830. */
  831. public function getUpdated()
  832. {
  833. return $this->updated;
  834. }
  835. /**
  836. * @param string $search_index
  837. *
  838. * @return User
  839. */
  840. public function setSearchIndex($search_index)
  841. {
  842. $this->search_index = $search_index;
  843. return $this;
  844. }
  845. /**
  846. * @return string
  847. */
  848. public function getSearchIndex()
  849. {
  850. return $this->search_index;
  851. }
  852. /**
  853. * @param Account|null $account
  854. *
  855. * @return User
  856. */
  857. public function setAccount(?Account $account = null)
  858. {
  859. $this->account = $account;
  860. return $this;
  861. }
  862. /**
  863. * @return Account
  864. */
  865. public function getAccount()
  866. {
  867. return $this->account;
  868. }
  869. /**
  870. * @param string $phoneNumber
  871. *
  872. * @return User
  873. */
  874. public function setPhoneNumber($phoneNumber)
  875. {
  876. $this->phoneNumber = $phoneNumber;
  877. return $this;
  878. }
  879. /**
  880. * @return string
  881. */
  882. public function getPhoneNumber()
  883. {
  884. return $this->phoneNumber;
  885. }
  886. /**
  887. * @param Document $documents
  888. *
  889. * @return User
  890. */
  891. public function addDocument(Document $documents)
  892. {
  893. $this->documents[] = $documents;
  894. return $this;
  895. }
  896. /**
  897. * @param Document $documents
  898. */
  899. public function removeDocument(Document $documents)
  900. {
  901. $this->documents->removeElement($documents);
  902. }
  903. /**
  904. * @return DoctrineCollection
  905. */
  906. public function getDocuments()
  907. {
  908. return $this->documents;
  909. }
  910. /**
  911. * @param Project $managedProjects
  912. *
  913. * @return User
  914. */
  915. public function addManagedProject(Project $managedProjects)
  916. {
  917. $this->managedProjects[] = $managedProjects;
  918. return $this;
  919. }
  920. /**
  921. * @param Project $managedProjects
  922. */
  923. public function removeManagedProject(Project $managedProjects)
  924. {
  925. $this->managedProjects->removeElement($managedProjects);
  926. }
  927. /**
  928. * @return DoctrineCollection
  929. */
  930. public function getManagedProjects()
  931. {
  932. return $this->managedProjects;
  933. }
  934. /**
  935. * @param Invitation|null $invitation
  936. *
  937. * @return User
  938. */
  939. public function setInvitation(?Invitation $invitation = null)
  940. {
  941. $this->invitation = $invitation;
  942. return $this;
  943. }
  944. /**
  945. * @return Invitation
  946. */
  947. public function getInvitation()
  948. {
  949. return $this->invitation;
  950. }
  951. /**
  952. * This is a validation callback function specified in our validation.yml file
  953. *
  954. * @param ExecutionContextInterface $context
  955. */
  956. public function validate(ExecutionContextInterface $context)
  957. {
  958. // this user is not valid if their email address does not match that of their invitation
  959. if (trim($this->getEmail()) != trim($this->getInvitation()->getEmail())) {
  960. $context->buildViolation('This email address does not match the one on the invitation')
  961. ->atPath('email')
  962. ->addViolation()
  963. ;
  964. }
  965. }
  966. /**
  967. * @param RoleInvitation $roleInvitations
  968. *
  969. * @return User
  970. */
  971. public function addRoleInvitation(RoleInvitation $roleInvitations)
  972. {
  973. $this->roleInvitations[] = $roleInvitations;
  974. return $this;
  975. }
  976. /**
  977. * @param RoleInvitation $roleInvitations
  978. */
  979. public function removeRoleInvitation(RoleInvitation $roleInvitations)
  980. {
  981. $this->roleInvitations->removeElement($roleInvitations);
  982. }
  983. /**
  984. * @return DoctrineCollection
  985. */
  986. public function getRoleInvitations()
  987. {
  988. return $this->roleInvitations;
  989. }
  990. /**
  991. * Checks to see if this entity has a RoleInvitation that matches the given
  992. * role. If there is one, it is returned.
  993. *
  994. * @param $role
  995. *
  996. * @return RoleInvitation|null
  997. */
  998. public function getMatchingRoleInvitation($role)
  999. {
  1000. foreach ($this->getRoleInvitations() as $roleInvitation) {
  1001. if ($role == $roleInvitation->getRole()) {
  1002. return $roleInvitation;
  1003. }
  1004. }
  1005. return null;
  1006. }
  1007. /**
  1008. * Checks to see if this entity has a RoleInvitation that is pending
  1009. * approval and matches the given role. If there is one, it is returned.
  1010. *
  1011. * @param $role
  1012. *
  1013. * @return RoleInvitation|null
  1014. */
  1015. public function getMatchingRoleInvitationPendingApproval($role)
  1016. {
  1017. foreach ($this->getRoleInvitations() as $roleInvitation) {
  1018. if ($role == $roleInvitation->getRole()
  1019. && ($roleInvitation->getStatus() == RoleInvitation::STATUS_PENDING_APPROVAL
  1020. || $roleInvitation->getStatus() == RoleInvitation::STATUS_SUPPRESSED)) {
  1021. return $roleInvitation;
  1022. }
  1023. }
  1024. return null;
  1025. }
  1026. /**
  1027. * Checks to see if this entity has a RoleInvitation that is pending one-time authentication
  1028. * and matches the given role. If there is one, it is returned.
  1029. *
  1030. * @param $role
  1031. *
  1032. * @return bool
  1033. */
  1034. public function getMatchingRoleInvitationPendingAuthentication($role)
  1035. {
  1036. foreach ($this->getRoleInvitations() as $roleInvitation) {
  1037. if ($role == $roleInvitation->getRole()
  1038. && $roleInvitation->getStatus() == RoleInvitation::STATUS_PENDING_AUTHENTICATION) {
  1039. return $roleInvitation;
  1040. }
  1041. }
  1042. return null;
  1043. }
  1044. /**
  1045. * Checks to see if this entity has an accepted RoleInvitation that
  1046. * matches the given role.
  1047. *
  1048. * @param $role
  1049. *
  1050. * @return bool
  1051. */
  1052. public function hasMatchingAcceptedRoleInvitation($role): bool
  1053. {
  1054. foreach ($this->getRoleInvitations() as $roleInvitation) {
  1055. if ($role === $roleInvitation->getRole() && $roleInvitation->getAccepted() !== null) {
  1056. return true;
  1057. }
  1058. }
  1059. return false;
  1060. }
  1061. /**
  1062. * Returns true if this user has any RoleInvitations linked directly to them
  1063. * or their Invitation that are in PENDING_APPROVAL state
  1064. *
  1065. * @return bool
  1066. */
  1067. public function hasRoleInvitationsPendingApproval()
  1068. {
  1069. $roleInvitations = $this->getPendingRoleInvitations();
  1070. return !empty($roleInvitations);
  1071. }
  1072. /**
  1073. * Returns true if this user has any RoleInvitations linked directly to them
  1074. * or their Invitation that are in PENDING_APPROVAL state
  1075. *
  1076. * @param string $role
  1077. *
  1078. * @return bool
  1079. */
  1080. public function hasMatchingRoleInvitationsPendingApproval($role): bool
  1081. {
  1082. $roleInvitations = $this->getMatchingRoleInvitationPendingApproval($role);
  1083. return !empty($roleInvitations);
  1084. }
  1085. /**
  1086. * Gets all the Pending RoleInvitations linked to this user and to their
  1087. * invitation
  1088. *
  1089. * @return array
  1090. */
  1091. public function getPendingRoleInvitations()
  1092. {
  1093. $array = [];
  1094. foreach ($this->getRoleInvitations() as $roleInvitation) {
  1095. if ($roleInvitation->getStatus() == RoleInvitation::STATUS_PENDING_APPROVAL
  1096. || $roleInvitation->getStatus() == RoleInvitation::STATUS_SUPPRESSED) {
  1097. $array[] = $roleInvitation;
  1098. }
  1099. }
  1100. if ($this->getInvitation()) {
  1101. foreach ($this->getInvitation()->getRoleInvitations() as $roleInvitation) {
  1102. if ($roleInvitation->getStatus() == RoleInvitation::STATUS_PENDING_APPROVAL
  1103. || $roleInvitation->getStatus() == RoleInvitation::STATUS_SUPPRESSED) {
  1104. $array[] = $roleInvitation;
  1105. }
  1106. }
  1107. }
  1108. return $array;
  1109. }
  1110. // @todo Should the below two be bundled in to the more accommodating functions with a "suppressed" arg?
  1111. /**
  1112. * Checks whether the User has any Role Invitations that are pending as well as not suppressed
  1113. *
  1114. * @return bool
  1115. */
  1116. public function hasUnsuppressedRoleInvitationsPendingApproval()
  1117. {
  1118. $roleInvitations = $this->getUnsuppressedRoleInvitationsPending();
  1119. return !empty($roleInvitations);
  1120. }
  1121. /**
  1122. * Grabs all the Role Invitations for this User that are pending approval and not suppressed
  1123. *
  1124. * @return array
  1125. */
  1126. public function getUnsuppressedRoleInvitationsPending()
  1127. {
  1128. $array = [];
  1129. foreach ($this->getRoleInvitations() as $roleInvitation) {
  1130. if ($roleInvitation->getStatus() == RoleInvitation::STATUS_PENDING_APPROVAL) {
  1131. $array[] = $roleInvitation;
  1132. }
  1133. }
  1134. if ($this->getInvitation()) {
  1135. foreach ($this->getInvitation()->getRoleInvitations() as $roleInvitation) {
  1136. if ($roleInvitation->getStatus() == RoleInvitation::STATUS_PENDING_APPROVAL) {
  1137. $array[] = $roleInvitation;
  1138. }
  1139. }
  1140. }
  1141. return $array;
  1142. }
  1143. /**
  1144. * Returns true if this user is a client administrator for at least one
  1145. * account. Note that this needs to match against Client Administrators and Client Super Administrators
  1146. *
  1147. * @return bool
  1148. */
  1149. public function isAccountAdministrator()
  1150. {
  1151. foreach ($this->getRoles() as $role) {
  1152. if ((stripos($role, 'ROLE_ACCOUNT_') !== false && stripos($role, '_ADMINISTRATOR') !== false)
  1153. || (stripos($role, 'ROLE_ACCOUNT_') !== false && stripos($role, '_SUPERADMINISTRATOR') !== false)) {
  1154. return true;
  1155. }
  1156. }
  1157. return false;
  1158. }
  1159. /**
  1160. * Checks whether a user is the Technical Administrator for *ANY* account
  1161. *
  1162. * @return bool
  1163. */
  1164. public function isAccountTechnicalAdmin(): bool
  1165. {
  1166. foreach ($this->getRoles() as $role) {
  1167. if (preg_match('/ROLE_ACCOUNT_\d+_TECHNICAL_ADMIN/', $role)) {
  1168. return true;
  1169. }
  1170. }
  1171. return false;
  1172. }
  1173. /**
  1174. * Checks whether a user is a sorter for *ANY* account
  1175. *
  1176. * @return bool
  1177. */
  1178. public function isAccountSorter(): bool
  1179. {
  1180. foreach ($this->getRoles() as $role) {
  1181. if (preg_match('/ROLE_ACCOUNT_\d+_SORTER/', $role)) {
  1182. return true;
  1183. }
  1184. }
  1185. return false;
  1186. }
  1187. /**
  1188. * Checks whether a user is the Technical Administrator for a specific Account (basically the same as the Voter)
  1189. *
  1190. * @param Account $account
  1191. *
  1192. * @return bool
  1193. */
  1194. public function isTechnicalAdminForSpecificAccount(Account $account): bool
  1195. {
  1196. $accountId = $account->getId();
  1197. foreach ($this->getRoles() as $role) {
  1198. if (preg_match("/ROLE_ACCOUNT_{$accountId}_TECHNICAL_ADMIN/", $role)) {
  1199. return true;
  1200. }
  1201. }
  1202. return false;
  1203. }
  1204. /**
  1205. * Returns true if this user is a client administrator for the specified Account.
  1206. * Note that this needs to match against Client Administrators and Client Super Administrators
  1207. *
  1208. * @param Account $account
  1209. *
  1210. * @return bool
  1211. */
  1212. public function isAccountAdministratorForAccount(Account $account)
  1213. {
  1214. foreach ($this->getRoles() as $role) {
  1215. if (
  1216. $role == sprintf('ROLE_ACCOUNT_%1$s_ADMINISTRATOR', $account->getId())
  1217. || $role == sprintf('ROLE_ACCOUNT_%1$s_SUPERADMINISTRATOR', $account->getId())
  1218. ) {
  1219. return true;
  1220. }
  1221. }
  1222. return false;
  1223. }
  1224. /**
  1225. * Returns true if this user is a client project manager for at least one
  1226. * account.
  1227. *
  1228. * @return bool
  1229. */
  1230. public function isAccountProjectManager()
  1231. {
  1232. foreach ($this->getRoles() as $role) {
  1233. if ((stripos($role, 'ROLE_ACCOUNT_') !== false && stripos($role, '_PROJECTMANAGER') !== false)) {
  1234. return true;
  1235. }
  1236. }
  1237. return false;
  1238. }
  1239. /**
  1240. * Returns true if this user is a client project manager for the specified Account.
  1241. *
  1242. * @param Account $account
  1243. *
  1244. * @return bool
  1245. */
  1246. public function isAccountProjectManagerForAccount(Account $account)
  1247. {
  1248. foreach ($this->getRoles() as $role) {
  1249. if ($role == sprintf('ROLE_ACCOUNT_%1$s_PROJECTMANAGER', $account->getId())) {
  1250. return true;
  1251. }
  1252. }
  1253. return false;
  1254. }
  1255. /**
  1256. * Returns true if this user is a client project manager for the specified Project.
  1257. *
  1258. * @param Project $project
  1259. *
  1260. * @return bool
  1261. */
  1262. public function isProjectManagerForSpecificProject(Project $project)
  1263. {
  1264. foreach ($this->getRoles() as $role) {
  1265. if ($role == sprintf('ROLE_PROJECT_%1$s_PROJECTMANAGER', $project->getId())) {
  1266. return true;
  1267. }
  1268. }
  1269. return false;
  1270. }
  1271. /**
  1272. * Returns true if this user is a expert agency administrator
  1273. *
  1274. * @return bool
  1275. */
  1276. public function isExpertAgencyAdministrator()
  1277. {
  1278. foreach ($this->getRoles() as $role) {
  1279. if (stripos($role, 'ROLE_EXPERTAGENCY_') !== false && stripos($role, '_ADMINISTRATOR') !== false) {
  1280. return true;
  1281. }
  1282. }
  1283. return false;
  1284. }
  1285. /**
  1286. * Returns true if this user is a project manager for at least one project
  1287. *
  1288. * @return bool
  1289. */
  1290. public function isProjectManager()
  1291. {
  1292. foreach ($this->getRoles() as $role) {
  1293. if (stripos($role, 'ROLE_PROJECT_') !== false && stripos($role, '_PROJECTMANAGER') !== false) {
  1294. return true;
  1295. }
  1296. }
  1297. return false;
  1298. }
  1299. /**
  1300. * Returns true if this user is a project scanner for at least one project
  1301. *
  1302. * @return bool
  1303. */
  1304. public function isProjectScanner(): bool
  1305. {
  1306. foreach ($this->getRoles() as $role) {
  1307. if (preg_match('/ROLE_PROJECT_\d+_SCANNER/', $role)) {
  1308. return true;
  1309. }
  1310. }
  1311. return false;
  1312. }
  1313. /**
  1314. * Returns true if this user is a project scanner downloader for at least one project
  1315. *
  1316. * @return bool
  1317. */
  1318. public function isProjectScannerDownload(): bool
  1319. {
  1320. foreach ($this->getRoles() as $role) {
  1321. if (stripos($role, 'ROLE_PROJECT_') !== false && stripos($role, '_SCANNERDOWNLOAD') !== false) {
  1322. return true;
  1323. }
  1324. }
  1325. return false;
  1326. }
  1327. /**
  1328. * Returns true if this user only has expert roles or role invitations associated with their account.
  1329. *
  1330. * @return bool
  1331. */
  1332. public function isExpertOnly()
  1333. {
  1334. if ($this->getRoles()) {
  1335. foreach ($this->getRoles() as $role) {
  1336. if ((stripos($role, 'ROLE_PROJECT_') === false || stripos($role, '_EXPERT') === false) && $role !== 'ROLE_USER') {
  1337. return false;
  1338. }
  1339. }
  1340. }
  1341. foreach ($this->getRoleInvitations() as $invitation) {
  1342. if (stripos($invitation->getRole(), 'ROLE_PROJECT_') === false || stripos($invitation->getRole(), '_EXPERT') === false) {
  1343. return false;
  1344. }
  1345. }
  1346. return true;
  1347. }
  1348. /**
  1349. * Returns true if the user only has an expert viewer role or role invitations, associated with their account.
  1350. *
  1351. * @return bool
  1352. */
  1353. public function isExpertViewerOnly()
  1354. {
  1355. if ($this->getRoles()) {
  1356. foreach ($this->getRoles() as $role) {
  1357. if ((stripos($role, 'ROLE_PROJECT_') === false || stripos($role, '_EXPERTVIEWER') === false) && $role !== 'ROLE_USER') {
  1358. return false;
  1359. }
  1360. }
  1361. }
  1362. foreach ($this->getRoleInvitations() as $invitation) {
  1363. if (stripos($invitation->getRole(), 'ROLE_PROJECT_') === false || stripos($invitation->getRole(), '_EXPERTVIEWER') === false) {
  1364. return false;
  1365. }
  1366. }
  1367. return true;
  1368. }
  1369. /**
  1370. * @param DateTime $deletedAt
  1371. *
  1372. * @return User
  1373. */
  1374. public function setDeletedAt($deletedAt)
  1375. {
  1376. $this->deletedAt = $deletedAt;
  1377. return $this;
  1378. }
  1379. /**
  1380. * @return DateTime
  1381. */
  1382. public function getDeletedAt()
  1383. {
  1384. return $this->deletedAt;
  1385. }
  1386. /**
  1387. * @param Disc $disc
  1388. *
  1389. * @return User
  1390. */
  1391. public function addDisc(Disc $disc)
  1392. {
  1393. $this->discs[] = $disc;
  1394. return $this;
  1395. }
  1396. /**
  1397. * @param Disc $disc
  1398. */
  1399. public function removeDisc(Disc $disc)
  1400. {
  1401. $this->discs->removeElement($disc);
  1402. }
  1403. /**
  1404. * @return DoctrineCollection
  1405. */
  1406. public function getDiscs()
  1407. {
  1408. return $this->discs;
  1409. }
  1410. /**
  1411. * @param DiscImportSession $discImportSession
  1412. *
  1413. * @return User
  1414. */
  1415. public function addDiscImportSession(DiscImportSession $discImportSession)
  1416. {
  1417. $this->discImportSessions[] = $discImportSession;
  1418. return $this;
  1419. }
  1420. /**
  1421. * @param DiscImportSession $discImportSession
  1422. */
  1423. public function removeDiscImportSession(DiscImportSession $discImportSession)
  1424. {
  1425. $this->discImportSessions->removeElement($discImportSession);
  1426. }
  1427. /**
  1428. * @return DoctrineCollection
  1429. */
  1430. public function getDiscImportSessions()
  1431. {
  1432. return $this->discImportSessions;
  1433. }
  1434. /**
  1435. * @param ProjectUser $projectUser
  1436. *
  1437. * @return User
  1438. */
  1439. public function addProjectUser(ProjectUser $projectUser)
  1440. {
  1441. $this->projectUsers[] = $projectUser;
  1442. return $this;
  1443. }
  1444. /**
  1445. * @param ProjectUser $projectUser
  1446. */
  1447. public function removeProjectUser(ProjectUser $projectUser)
  1448. {
  1449. $this->projectUsers->removeElement($projectUser);
  1450. }
  1451. /**
  1452. * @return DoctrineCollection
  1453. */
  1454. public function getProjectUsers()
  1455. {
  1456. return $this->projectUsers;
  1457. }
  1458. /**
  1459. * @param Invitation $invitationsCreated
  1460. *
  1461. * @return User
  1462. */
  1463. public function addInvitationsCreated(Invitation $invitationsCreated)
  1464. {
  1465. $this->invitationsCreated[] = $invitationsCreated;
  1466. return $this;
  1467. }
  1468. /**
  1469. * @param Invitation $invitationsCreated
  1470. */
  1471. public function removeInvitationsCreated(Invitation $invitationsCreated)
  1472. {
  1473. $this->invitationsCreated->removeElement($invitationsCreated);
  1474. }
  1475. /**
  1476. * @return DoctrineCollection
  1477. */
  1478. public function getInvitationsCreated()
  1479. {
  1480. return $this->invitationsCreated;
  1481. }
  1482. /**
  1483. * @param ExpertAgency|null $expertAgency
  1484. *
  1485. * @return User
  1486. */
  1487. public function setExpertAgency(?ExpertAgency $expertAgency = null)
  1488. {
  1489. $this->expertAgency = $expertAgency;
  1490. return $this;
  1491. }
  1492. /**
  1493. * @return ExpertAgency
  1494. */
  1495. public function getExpertAgency()
  1496. {
  1497. return $this->expertAgency;
  1498. }
  1499. /**
  1500. * @param DateTime $lastActivity
  1501. *
  1502. * @return User
  1503. */
  1504. public function setLastActivity($lastActivity)
  1505. {
  1506. $this->lastActivity = $lastActivity;
  1507. return $this;
  1508. }
  1509. /**
  1510. * @Groups({"user:activity"})
  1511. *
  1512. * @return DateTime
  1513. */
  1514. public function getLastActivity()
  1515. {
  1516. return $this->lastActivity;
  1517. }
  1518. /**
  1519. * @Groups({"user:activity:write"})
  1520. *
  1521. * @return User
  1522. */
  1523. public function setLastActivityToNow()
  1524. {
  1525. $this->setLastActivity(new DateTime('now'));
  1526. return $this;
  1527. }
  1528. /**
  1529. * @Groups({"user:activity"})
  1530. *
  1531. * @return bool whether the user is active or not
  1532. */
  1533. public function isActiveNow()
  1534. {
  1535. // If lastActivity is null (e.g., just logged in), treat user as active
  1536. if ($this->getLastActivity() === null) {
  1537. return true;
  1538. }
  1539. $delay = new DateTime($this->activityTimeoutMinutes . ' minutes ago');
  1540. return $this->getLastActivity() > $delay;
  1541. }
  1542. /**
  1543. * Set the activity timeout in minutes
  1544. *
  1545. * @param int $minutes
  1546. *
  1547. * @return self
  1548. */
  1549. public function setActivityTimeoutMinutes(int $minutes): self
  1550. {
  1551. $this->activityTimeoutMinutes = $minutes;
  1552. return $this;
  1553. }
  1554. /**
  1555. * Get the activity timeout in minutes
  1556. *
  1557. * @return int
  1558. */
  1559. public function getActivityTimeoutMinutes(): int
  1560. {
  1561. return $this->activityTimeoutMinutes;
  1562. }
  1563. /**
  1564. * @param User $usersCreated
  1565. *
  1566. * @return User
  1567. */
  1568. public function addUsersCreated(User $usersCreated)
  1569. {
  1570. $this->usersCreated[] = $usersCreated;
  1571. return $this;
  1572. }
  1573. /**
  1574. * @param User $usersCreated
  1575. */
  1576. public function removeUsersCreated(User $usersCreated)
  1577. {
  1578. $this->usersCreated->removeElement($usersCreated);
  1579. }
  1580. /**
  1581. * @return DoctrineCollection
  1582. */
  1583. public function getUsersCreated()
  1584. {
  1585. return $this->usersCreated;
  1586. }
  1587. /**
  1588. * @param User|null $creator
  1589. *
  1590. * @return User
  1591. */
  1592. public function setCreator(?User $creator = null)
  1593. {
  1594. $this->creator = $creator;
  1595. return $this;
  1596. }
  1597. /**
  1598. * @return User
  1599. */
  1600. public function getCreator()
  1601. {
  1602. return $this->creator;
  1603. }
  1604. /**
  1605. * @param bool $receiveDailyUploadNotificationEmail
  1606. *
  1607. * @return User
  1608. */
  1609. public function setReceiveDailyUploadNotificationEmail($receiveDailyUploadNotificationEmail)
  1610. {
  1611. $this->receiveDailyUploadNotificationEmail = $receiveDailyUploadNotificationEmail;
  1612. return $this;
  1613. }
  1614. /**
  1615. * @return bool
  1616. */
  1617. public function getReceiveDailyUploadNotificationEmail()
  1618. {
  1619. return $this->receiveDailyUploadNotificationEmail;
  1620. }
  1621. /**
  1622. * @param ChronologyItem $chronologyItemsCreated
  1623. *
  1624. * @return User
  1625. */
  1626. public function addChronologyItemsCreated(ChronologyItem $chronologyItemsCreated)
  1627. {
  1628. $this->chronologyItemsCreated[] = $chronologyItemsCreated;
  1629. return $this;
  1630. }
  1631. /**
  1632. * @param ChronologyItem $chronologyItemsCreated
  1633. */
  1634. public function removeChronologyItemsCreated(ChronologyItem $chronologyItemsCreated)
  1635. {
  1636. $this->chronologyItemsCreated->removeElement($chronologyItemsCreated);
  1637. }
  1638. /**
  1639. * @return DoctrineCollection
  1640. */
  1641. public function getChronologyItemsCreated()
  1642. {
  1643. return $this->chronologyItemsCreated;
  1644. }
  1645. /**
  1646. * @param RecordsRequestDetail $recordsRequestDetail
  1647. *
  1648. * @return User
  1649. */
  1650. public function addRecordsRequestDetail(RecordsRequestDetail $recordsRequestDetail)
  1651. {
  1652. $this->recordsRequestDetails[] = $recordsRequestDetail;
  1653. return $this;
  1654. }
  1655. /**
  1656. * @param RecordsRequestDetail $recordsRequestDetail
  1657. */
  1658. public function removeRecordsRequestDetail(RecordsRequestDetail $recordsRequestDetail)
  1659. {
  1660. $this->recordsRequestDetails->removeElement($recordsRequestDetail);
  1661. }
  1662. /**
  1663. * @return DoctrineCollection
  1664. */
  1665. public function getRecordsRequestDetails()
  1666. {
  1667. return $this->recordsRequestDetails;
  1668. }
  1669. /**
  1670. * @return bool
  1671. */
  1672. public function isAccountNonLocked()
  1673. {
  1674. return !$this->locked;
  1675. }
  1676. /**
  1677. * @return bool
  1678. */
  1679. public function isLocked()
  1680. {
  1681. return !$this->isAccountNonLocked();
  1682. }
  1683. /**
  1684. * @param $boolean
  1685. *
  1686. * @return $this
  1687. */
  1688. public function setLocked($boolean)
  1689. {
  1690. $this->locked = $boolean;
  1691. return $this;
  1692. }
  1693. /**
  1694. * @param PhoneNumber $mobileNumber
  1695. *
  1696. * @return User
  1697. */
  1698. public function setMobileNumber($mobileNumber)
  1699. {
  1700. if ($this->mobileNumberVerifiedAt !== null) {
  1701. throw new \LogicException('Use the verified mobile number change flow.');
  1702. }
  1703. $this->mobileNumber = $mobileNumber;
  1704. return $this;
  1705. }
  1706. /**
  1707. * @return PhoneNumber
  1708. */
  1709. public function getMobileNumber()
  1710. {
  1711. return $this->mobileNumber;
  1712. }
  1713. public function isTrustedDeviceEnabled(): bool
  1714. {
  1715. return $this->trustedDeviceEnabled;
  1716. }
  1717. public function setTrustedDeviceEnabled(bool $enabled): void
  1718. {
  1719. $this->trustedDeviceEnabled = $enabled;
  1720. }
  1721. public function getTrustedDeviceGeneration(): int
  1722. {
  1723. return $this->trustedDeviceGeneration;
  1724. }
  1725. public function advanceTrustedDeviceGeneration(): void
  1726. {
  1727. ++$this->trustedDeviceGeneration;
  1728. }
  1729. public function getMobileNumberVerifiedAt(): ?DateTimeImmutable
  1730. {
  1731. return $this->mobileNumberVerifiedAt;
  1732. }
  1733. public function verifyMobileNumber(PhoneNumber $number, DateTimeImmutable $at): void
  1734. {
  1735. $this->mobileNumber = $number;
  1736. $this->mobileNumberVerifiedAt = $at;
  1737. $this->verifiedMobileNumberKey = hash('sha256', PhoneNumberUtil::getInstance()->format($number, PhoneNumberFormat::E164));
  1738. $this->mobileEnrolmentAuthorisedUntil = null;
  1739. $this->mobileEnrolmentProofHash = null;
  1740. $this->mobileEnrolmentRequiresSupport = false;
  1741. }
  1742. public function getMobileEnrolmentAuthorisedUntil(): ?DateTimeImmutable
  1743. {
  1744. return $this->mobileEnrolmentAuthorisedUntil;
  1745. }
  1746. public function requireSupportForMobileEnrolment(): void
  1747. {
  1748. if ($this->mobileNumberVerifiedAt === null) {
  1749. $this->mobileEnrolmentRequiresSupport = true;
  1750. }
  1751. }
  1752. public function mobileEnrolmentRequiresSupport(): bool
  1753. {
  1754. return $this->mobileEnrolmentRequiresSupport;
  1755. }
  1756. public function authoriseMobileEnrolmentUntil(DateTimeImmutable $until, #[\SensitiveParameter] string $proof): void
  1757. {
  1758. $this->mobileNumber = null;
  1759. $this->mobileNumberVerifiedAt = null;
  1760. $this->verifiedMobileNumberKey = null;
  1761. $this->mobileEnrolmentAuthorisedUntil = $until;
  1762. $this->mobileEnrolmentProofHash = hash('sha256', $proof);
  1763. $this->mobileEnrolmentRequiresSupport = true;
  1764. }
  1765. public function consumeMobileEnrolmentProof(#[\SensitiveParameter] string $proof, DateTimeImmutable $now): bool
  1766. {
  1767. if ($this->mobileEnrolmentAuthorisedUntil === null || $this->mobileEnrolmentAuthorisedUntil <= $now
  1768. || $this->mobileEnrolmentProofHash === null || !hash_equals($this->mobileEnrolmentProofHash, hash('sha256', $proof))
  1769. ) {
  1770. return false;
  1771. }
  1772. $this->mobileEnrolmentAuthorisedUntil = null;
  1773. $this->mobileEnrolmentProofHash = null;
  1774. return true;
  1775. }
  1776. /**
  1777. * @param int $notificationStatus
  1778. *
  1779. * @return User
  1780. */
  1781. public function setNotificationStatus($notificationStatus)
  1782. {
  1783. $this->notificationStatus = $notificationStatus;
  1784. return $this;
  1785. }
  1786. /**
  1787. * @return int
  1788. */
  1789. public function getNotificationStatus()
  1790. {
  1791. return $this->notificationStatus;
  1792. }
  1793. /**
  1794. * @param int $notificationFormatPreference
  1795. *
  1796. * @return User
  1797. */
  1798. public function setNotificationFormatPreference($notificationFormatPreference)
  1799. {
  1800. $this->notificationFormatPreference = $notificationFormatPreference;
  1801. return $this;
  1802. }
  1803. /**
  1804. * @return int
  1805. */
  1806. public function getNotificationFormatPreference()
  1807. {
  1808. return $this->notificationFormatPreference;
  1809. }
  1810. /**
  1811. * @param UserNotification $notification
  1812. *
  1813. * @return User
  1814. */
  1815. public function addNotification(UserNotification $notification)
  1816. {
  1817. $this->notifications[] = $notification;
  1818. return $this;
  1819. }
  1820. /**
  1821. * @param UserNotification $notification
  1822. */
  1823. public function removeNotification(UserNotification $notification)
  1824. {
  1825. $this->notifications->removeElement($notification);
  1826. }
  1827. /**
  1828. * @return DoctrineCollection
  1829. */
  1830. public function getNotifications()
  1831. {
  1832. return $this->notifications;
  1833. }
  1834. /**
  1835. * @param bool $billingAdmin
  1836. *
  1837. * @return User
  1838. */
  1839. public function setBillingAdmin($billingAdmin)
  1840. {
  1841. $this->billingAdmin = $billingAdmin;
  1842. return $this;
  1843. }
  1844. /**
  1845. * @return bool
  1846. */
  1847. public function isBillingAdmin()
  1848. {
  1849. return $this->billingAdmin;
  1850. }
  1851. /**
  1852. * NOTE: Doctrine wants to add a ::getBillingAdmin() function but a User
  1853. * does not have a billingAdmin, but they can BE a billing admin. We will
  1854. * keep this here to appease the Doctrinosaurus.
  1855. *
  1856. * @return bool
  1857. */
  1858. public function getBillingAdmin()
  1859. {
  1860. return $this->billingAdmin;
  1861. }
  1862. /**
  1863. * @param Specialisation $specialisation
  1864. *
  1865. * @return User
  1866. */
  1867. public function addSpecialisation(Specialisation $specialisation)
  1868. {
  1869. $this->specialisations[] = $specialisation;
  1870. return $this;
  1871. }
  1872. /**
  1873. * @param Specialisation $specialisation
  1874. */
  1875. public function removeSpecialisation(Specialisation $specialisation)
  1876. {
  1877. $this->specialisations->removeElement($specialisation);
  1878. }
  1879. /**
  1880. * @return DoctrineCollection
  1881. */
  1882. public function getSpecialisations()
  1883. {
  1884. return $this->specialisations;
  1885. }
  1886. /**
  1887. * Check if this User has a particular Specialisation
  1888. *
  1889. * @param Specialisation $specialisation
  1890. *
  1891. * @return bool
  1892. */
  1893. public function hasSpecialisation(Specialisation $specialisation)
  1894. {
  1895. return $this->getSpecialisations()->contains($specialisation);
  1896. }
  1897. /**
  1898. * @param Project $favouriteProject
  1899. *
  1900. * @return User
  1901. */
  1902. public function addFavouriteProject(Project $favouriteProject)
  1903. {
  1904. $this->favouriteProjects[] = $favouriteProject;
  1905. return $this;
  1906. }
  1907. /**
  1908. * @param Project $favouriteProject
  1909. */
  1910. public function removeFavouriteProject(Project $favouriteProject)
  1911. {
  1912. $this->favouriteProjects->removeElement($favouriteProject);
  1913. }
  1914. /**
  1915. * @return DoctrineCollection
  1916. */
  1917. public function getFavouriteProjects()
  1918. {
  1919. return $this->favouriteProjects;
  1920. }
  1921. /**
  1922. * @return bool
  1923. */
  1924. public function getLocked()
  1925. {
  1926. return $this->locked;
  1927. }
  1928. /**
  1929. * @param MatterNote $matterNote
  1930. *
  1931. * @return User
  1932. */
  1933. public function addMatterNote(MatterNote $matterNote)
  1934. {
  1935. $this->matterNotes[] = $matterNote;
  1936. return $this;
  1937. }
  1938. /**
  1939. * @param MatterNote $matterNote
  1940. */
  1941. public function removeMatterNote(MatterNote $matterNote)
  1942. {
  1943. $this->matterNotes->removeElement($matterNote);
  1944. }
  1945. /**
  1946. * @return DoctrineCollection
  1947. */
  1948. public function getMatterNotes()
  1949. {
  1950. return $this->matterNotes;
  1951. }
  1952. public function isUser(?UserInterface $user = null): bool
  1953. {
  1954. return $user instanceof self && $user->id === $this->id;
  1955. }
  1956. /**
  1957. * @ORM\PrePersist
  1958. */
  1959. public function copyEmailToUsername()
  1960. {
  1961. $this->setUsername($this->getEmail());
  1962. }
  1963. /**
  1964. * Updates the Search Index field with internal data. The Search Index Field
  1965. * provides an easy way to perform a 'like' query for a generalised search.
  1966. *
  1967. * @ORM\PrePersist
  1968. *
  1969. * @ORM\PreUpdate
  1970. */
  1971. public function updateSearchIndex()
  1972. {
  1973. $searchIndex
  1974. = $this->getFullName()
  1975. . ' '
  1976. . $this->getEmail();
  1977. // Add any linked email address to the search index
  1978. /** @var LinkedEmailAddress $linkedEmailAddress */
  1979. foreach ($this->linkedEmailAddress as $linkedEmailAddress) {
  1980. $searchIndex .= ' ' . strtolower($linkedEmailAddress->getEmail());
  1981. }
  1982. $this->setSearchIndex($searchIndex);
  1983. }
  1984. /**
  1985. * @param HumanResource|null $humanResource
  1986. *
  1987. * @return User
  1988. */
  1989. public function setHumanResource(?HumanResource $humanResource = null)
  1990. {
  1991. $this->humanResource = $humanResource;
  1992. return $this;
  1993. }
  1994. /**
  1995. * @return HumanResource|null
  1996. */
  1997. public function getHumanResource()
  1998. {
  1999. return $this->humanResource;
  2000. }
  2001. /**
  2002. * @param AnalyticsUser|null $analyticsUser
  2003. *
  2004. * @return User
  2005. */
  2006. public function setAnalyticsUser(?AnalyticsUser $analyticsUser = null)
  2007. {
  2008. $this->analyticsUser = $analyticsUser;
  2009. $this->analyticsUser->setUser($this);
  2010. return $this;
  2011. }
  2012. /**
  2013. * @return AnalyticsUser|null
  2014. */
  2015. public function getAnalyticsUser()
  2016. {
  2017. return $this->analyticsUser;
  2018. }
  2019. /**
  2020. * @param LinkedEmailAddress $linkedEmailAddress
  2021. *
  2022. * @return User
  2023. */
  2024. public function addLinkedEmailAddress(LinkedEmailAddress $linkedEmailAddress)
  2025. {
  2026. $this->linkedEmailAddress[] = $linkedEmailAddress;
  2027. // Update the search index, so we include the newly linked email address
  2028. $this->updateSearchIndex();
  2029. return $this;
  2030. }
  2031. /**
  2032. * @param LinkedEmailAddress $linkedEmailAddress
  2033. *
  2034. * @return bool TRUE if this collection contained the specified element, FALSE otherwise.
  2035. */
  2036. public function removeLinkedEmailAddress(LinkedEmailAddress $linkedEmailAddress)
  2037. {
  2038. $returnValue = $this->linkedEmailAddress->removeElement($linkedEmailAddress);
  2039. // Update the search index, so we exclude the removed linked email address
  2040. $this->updateSearchIndex();
  2041. return $returnValue;
  2042. }
  2043. /**
  2044. * @return DoctrineCollection
  2045. */
  2046. public function getLinkedEmailAddress()
  2047. {
  2048. return $this->linkedEmailAddress;
  2049. }
  2050. /**
  2051. * @param string $linkedEmailAddress
  2052. *
  2053. * @return bool
  2054. */
  2055. public function hasLinkedEmailAddress(string $linkedEmailAddress): bool
  2056. {
  2057. $linkedEmailAddresses = array_map(function (LinkedEmailAddress $linkedEmailAddress) {
  2058. return $linkedEmailAddress->getEmail();
  2059. }, $this->getLinkedEmailAddress()->toArray());
  2060. if (!$linkedEmailAddresses) {
  2061. return false;
  2062. }
  2063. return in_array($linkedEmailAddress, $linkedEmailAddresses);
  2064. }
  2065. /**
  2066. * @param LinkedEmailAddressInvitation $linkedEmailAddressInvitation
  2067. *
  2068. * @return User
  2069. */
  2070. public function addLinkedEmailAddressInvitation(LinkedEmailAddressInvitation $linkedEmailAddressInvitation)
  2071. {
  2072. $this->linkedEmailAddressInvitations[] = $linkedEmailAddressInvitation;
  2073. return $this;
  2074. }
  2075. /**
  2076. * @param LinkedEmailAddressInvitation $linkedEmailAddressInvitation
  2077. *
  2078. * @return bool TRUE if this collection contained the specified element, FALSE otherwise.
  2079. */
  2080. public function removeLinkedEmailAddressInvitation(LinkedEmailAddressInvitation $linkedEmailAddressInvitation)
  2081. {
  2082. return $this->linkedEmailAddressInvitations->removeElement($linkedEmailAddressInvitation);
  2083. }
  2084. /**
  2085. * @return DoctrineCollection
  2086. */
  2087. public function getLinkedEmailAddressInvitations()
  2088. {
  2089. return $this->linkedEmailAddressInvitations;
  2090. }
  2091. /**
  2092. * @param string $linkedEmailAddress
  2093. *
  2094. * @return bool
  2095. */
  2096. public function hasMatchingLinkedEmailAddressInvitationPendingApproval(string $linkedEmailAddress): bool
  2097. {
  2098. $linkedEmailAddressInvitations = $this->getLinkedEmailAddressInvitations();
  2099. /** @var LinkedEmailAddressInvitation $linkedEmailAddressInvitation */
  2100. foreach ($linkedEmailAddressInvitations as $linkedEmailAddressInvitation) {
  2101. switch ($linkedEmailAddressInvitation->getStatus()) {
  2102. case LinkedEmailAddressInvitation::STATUS_PENDING_APPROVAL:
  2103. return $linkedEmailAddress == $linkedEmailAddressInvitation->getEmail();
  2104. case LinkedEmailAddressInvitation::STATUS_APPROVED:
  2105. case LinkedEmailAddressInvitation::STATUS_DECLINED:
  2106. default:
  2107. }
  2108. }
  2109. return false;
  2110. }
  2111. /**
  2112. * Grabs all the Role Invitations for this User that are pending approval and not suppressed
  2113. *
  2114. * @TODO this function seems inefficient, as it is basically just checking if the passed linkedEmailAddressInvitation is pending?
  2115. *
  2116. * @param LinkedEmailAddressInvitation $linkedEmailAddressInvitation
  2117. *
  2118. * @return array
  2119. */
  2120. public function getLinkedEmailAddressInvitationPending(LinkedEmailAddressInvitation $linkedEmailAddressInvitation)
  2121. {
  2122. $linkedEmailAddresses = [];
  2123. if ($linkedEmailAddressInvitation->getStatus() == LinkedEmailAddressInvitation::STATUS_PENDING_APPROVAL) {
  2124. $linkedEmailAddresses[] = $linkedEmailAddressInvitation;
  2125. }
  2126. return $linkedEmailAddresses;
  2127. }
  2128. /**
  2129. * @param LinkedEmailAddressInvitation|null $linkedEmailAddressInvitation
  2130. *
  2131. * @return User
  2132. */
  2133. public function setLinkedEmailAddressInvitation(?LinkedEmailAddressInvitation $linkedEmailAddressInvitation = null)
  2134. {
  2135. $this->linkedEmailAddressInvitation = $linkedEmailAddressInvitation;
  2136. return $this;
  2137. }
  2138. /**
  2139. * @return LinkedEmailAddressInvitation|null
  2140. */
  2141. public function getLinkedEmailAddressInvitation()
  2142. {
  2143. return $this->linkedEmailAddressInvitation;
  2144. }
  2145. /**
  2146. * @param bool $matterDashboardEnabled
  2147. *
  2148. * @return User
  2149. */
  2150. public function setMatterDashboardEnabled($matterDashboardEnabled)
  2151. {
  2152. $this->matterDashboardEnabled = $matterDashboardEnabled;
  2153. return $this;
  2154. }
  2155. /**
  2156. * @return bool
  2157. */
  2158. public function getMatterDashboardEnabled()
  2159. {
  2160. return $this->matterDashboardEnabled;
  2161. }
  2162. /**
  2163. * @param bool $hasDocSorterAccess
  2164. *
  2165. * @return User
  2166. */
  2167. public function setHasDocSorterAccess($hasDocSorterAccess)
  2168. {
  2169. $this->hasDocSorterAccess = $hasDocSorterAccess;
  2170. return $this;
  2171. }
  2172. /**
  2173. * @return bool
  2174. */
  2175. public function getHasDocSorterAccess()
  2176. {
  2177. return $this->hasDocSorterAccess;
  2178. }
  2179. /**
  2180. * Returns user type options as an array, usable as the choices for a form.
  2181. *
  2182. * @throws \Exception
  2183. *
  2184. * @return array
  2185. */
  2186. public static function getUserTypeOptions(): array
  2187. {
  2188. $matterCreationProcessOptions = self::getConstantsWithLabelsAsChoices('USER_TYPE');
  2189. return array_flip($matterCreationProcessOptions);
  2190. }
  2191. /**
  2192. * Get the value of userType
  2193. *
  2194. * @return string
  2195. */
  2196. public function getUserType()
  2197. {
  2198. return $this->userType;
  2199. }
  2200. /**
  2201. * Returns true if the userType is USER_TYPE_INTERNAL
  2202. *
  2203. * @return bool
  2204. */
  2205. public function isUserTypeInternal(): bool
  2206. {
  2207. return $this->getUserType() === self::USER_TYPE_INTERNAL;
  2208. }
  2209. /**
  2210. * @param string|null $userType
  2211. *
  2212. * @return self
  2213. */
  2214. public function setUserType(?string $userType = null)
  2215. {
  2216. $this->userType = $userType;
  2217. return $this;
  2218. }
  2219. /**
  2220. * @return DateTime
  2221. */
  2222. public function getFirstLoginDate()
  2223. {
  2224. return $this->firstLoginDate;
  2225. }
  2226. /**
  2227. * @param DateTime|null $firstLoginDate
  2228. *
  2229. * @return self
  2230. */
  2231. public function setFirstLoginDate(?DateTime $firstLoginDate = null)
  2232. {
  2233. $this->firstLoginDate = $firstLoginDate;
  2234. return $this;
  2235. }
  2236. /**
  2237. * @param ProjectClosure $projectClosure
  2238. *
  2239. * @return User
  2240. */
  2241. public function addProjectClosure(ProjectClosure $projectClosure)
  2242. {
  2243. $this->projectClosure[] = $projectClosure;
  2244. return $this;
  2245. }
  2246. /**
  2247. * @param ProjectClosure $projectClosure
  2248. *
  2249. * @return bool TRUE if this collection contained the specified element, FALSE otherwise.
  2250. */
  2251. public function removeProjectClosure(ProjectClosure $projectClosure)
  2252. {
  2253. return $this->projectClosure->removeElement($projectClosure);
  2254. }
  2255. /**
  2256. * @return DoctrineCollection
  2257. */
  2258. public function getProjectClosures()
  2259. {
  2260. return $this->projectClosures;
  2261. }
  2262. /**
  2263. * @param int $id
  2264. *
  2265. * @return User
  2266. */
  2267. public function setId(int $id): User
  2268. {
  2269. $this->id = $id;
  2270. return $this;
  2271. }
  2272. /**
  2273. * @param bool $true
  2274. *
  2275. * @return $this
  2276. */
  2277. public function setEnabled(bool $true)
  2278. {
  2279. $this->enabled = $true;
  2280. return $this;
  2281. }
  2282. /**
  2283. * @inheritDoc
  2284. */
  2285. public function isEqualTo(UserInterface $user)
  2286. {
  2287. // There are only a few attributes on a user that we should enforce a logout should they change
  2288. // If their password has changed...
  2289. if ($this->getPassword() !== $user->getPassword()) {
  2290. return false;
  2291. }
  2292. // If they've been disabled...
  2293. if ($this->isEnabled() !== $user->isEnabled()) {
  2294. return false;
  2295. }
  2296. // Check that the roles are the same, in any order. If the role is revoked while the user is logged in, it needs to log them out.
  2297. $isEqual = count($this->getRoles()) == count($user->getRoles());
  2298. if ($isEqual) {
  2299. foreach ($this->getRoles() as $role) {
  2300. $isEqual = $isEqual && in_array($role, $user->getRoles());
  2301. }
  2302. }
  2303. return $isEqual;
  2304. }
  2305. /**
  2306. * @param string $role
  2307. *
  2308. * @return bool
  2309. */
  2310. public function hasRole(string $role): bool
  2311. {
  2312. return in_array($role, $this->getRoles());
  2313. }
  2314. /**
  2315. * @return DoctrineCollection<int, ClinicalSummary>
  2316. */
  2317. public function getClinicalSummaries(): DoctrineCollection
  2318. {
  2319. return $this->clinicalSummaries;
  2320. }
  2321. /**
  2322. * @param ClinicalSummary $clinicalSummary
  2323. *
  2324. * @return self
  2325. */
  2326. public function addClinicalSummary(ClinicalSummary $clinicalSummary): self
  2327. {
  2328. if (!$this->clinicalSummaries->contains($clinicalSummary)) {
  2329. $this->clinicalSummaries[] = $clinicalSummary;
  2330. $clinicalSummary->setCreator($this);
  2331. }
  2332. return $this;
  2333. }
  2334. /**
  2335. * @param ClinicalSummary $clinicalSummary
  2336. *
  2337. * @return self
  2338. */
  2339. public function removeClinicalSummary(ClinicalSummary $clinicalSummary): self
  2340. {
  2341. if ($this->clinicalSummaries->removeElement($clinicalSummary)) {
  2342. // set the owning side to null (unless already changed)
  2343. if ($clinicalSummary->getCreator() === $this) {
  2344. $clinicalSummary->setCreator(null);
  2345. }
  2346. }
  2347. return $this;
  2348. }
  2349. /**
  2350. * Check if the user's email matches any regex pattern in the UserInternal table.
  2351. *
  2352. * @param bool $isRecursive
  2353. * @param UserInternalRepository $repository
  2354. * @param EntityManagerInterface $entityManager
  2355. *
  2356. * @return bool
  2357. */
  2358. public function isUserInternal(UserInternalRepository $repository, EntityManagerInterface $entityManager, bool $isRecursive = false): bool
  2359. {
  2360. //return true if internal user
  2361. if ($this->isUserTypeInternal()) {
  2362. return true;
  2363. }
  2364. $email = strtolower($this->getEmail());
  2365. // Get stored regex patterns from the database
  2366. $patterns = $repository->getAllPatterns();
  2367. // If the user's email matches a domain that is specified in the patterns (e.g. medbrief) then set the userType to internal.
  2368. foreach ($patterns as $pattern) {
  2369. if (preg_match('/' . $pattern . '/i', $email)) {
  2370. // Set user type to internal
  2371. $this->setUserType(self::USER_TYPE_INTERNAL);
  2372. // Persist the change to the database
  2373. $entityManager->persist($this);
  2374. $entityManager->flush();
  2375. return true;
  2376. }
  2377. }
  2378. // In case the user's email does not match we check to see if they have an admin role and avoid an infinite loop.
  2379. if (!$isRecursive) {
  2380. return $this->updateUserTypeInternal($repository, $entityManager);
  2381. }
  2382. return false;
  2383. }
  2384. /**
  2385. * Update user to internal type if they have medbrief email address and have an admin or super admin role.
  2386. *
  2387. * @param UserInternalRepository $repository
  2388. * @param EntityManagerInterface $entityManager
  2389. *
  2390. * @return bool
  2391. */
  2392. public function updateUserTypeInternal(UserInternalRepository $repository, EntityManagerInterface $entityManager): bool
  2393. {
  2394. // Check if the user is already internal
  2395. if ($this->userType === self::USER_TYPE_INTERNAL) {
  2396. return false;
  2397. }
  2398. if ($this->isUserInternal($repository, $entityManager, true) && (in_array(self::DEFAULT_ROLE_ADMIN, $this->roles) || in_array(self::DEFAULT_ROLE_SUPER_ADMIN, $this->roles))) {
  2399. $this->userType = self::USER_TYPE_INTERNAL;
  2400. $entityManager->persist($this);
  2401. $entityManager->flush();
  2402. return true;
  2403. }
  2404. return false;
  2405. }
  2406. /**
  2407. * This method tracks whether the 'Billed' checkbox is visible to MB Admins
  2408. *
  2409. * @return bool
  2410. */
  2411. public function hasAccessToBilled(): bool
  2412. {
  2413. return $this->accessToBilled;
  2414. }
  2415. /**
  2416. * This method sets whether a MB Admin can view the 'Billed' checkbox.
  2417. *
  2418. * @param bool $value
  2419. *
  2420. * @return self
  2421. */
  2422. public function setAccessToBilled(bool $value): self
  2423. {
  2424. $this->accessToBilled = $value;
  2425. return $this;
  2426. }
  2427. /**
  2428. * This method fetches the value which determines whether a MB Admin can view the 'Billed' checkbox.
  2429. *
  2430. * @return bool
  2431. */
  2432. public function getAccessToBilled(): bool
  2433. {
  2434. return $this->accessToBilled;
  2435. }
  2436. /**
  2437. * @return DateTime|null
  2438. */
  2439. public function getLegacyRadiologyViewerLastUsed()
  2440. {
  2441. return $this->legacyRadiologyViewerLastUsed;
  2442. }
  2443. /**
  2444. * @param DateTime|null $legacyRadiologyViewerLastUsed
  2445. *
  2446. * @return self
  2447. */
  2448. public function setLegacyRadiologyViewerLastUsed(?DateTime $legacyRadiologyViewerLastUsed = null): self
  2449. {
  2450. $this->legacyRadiologyViewerLastUsed = $legacyRadiologyViewerLastUsed;
  2451. return $this;
  2452. }
  2453. /**
  2454. * @return bool
  2455. */
  2456. public function getMatchOptIn(): bool
  2457. {
  2458. return $this->matchOptIn;
  2459. }
  2460. /**
  2461. * @param bool $matchOptIn
  2462. *
  2463. * @return self
  2464. */
  2465. public function setMatchOptIn(bool $matchOptIn): self
  2466. {
  2467. $this->matchOptIn = $matchOptIn;
  2468. return $this;
  2469. }
  2470. /**
  2471. * @return bool
  2472. */
  2473. public function getInsightsOptIn(): bool
  2474. {
  2475. return $this->insightsOptIn;
  2476. }
  2477. /**
  2478. * @param bool $insightsOptIn
  2479. *
  2480. * @return self
  2481. */
  2482. public function setInsightsOptIn(bool $insightsOptIn): self
  2483. {
  2484. $this->insightsOptIn = $insightsOptIn;
  2485. return $this;
  2486. }
  2487. }