src/Entity/User.php line 50

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