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. public function __construct()
  470. {
  471. $this->username = Uuid::uuid4()->toString();
  472. $this->documents = new \Doctrine\Common\Collections\ArrayCollection();
  473. $this->discs = new \Doctrine\Common\Collections\ArrayCollection();
  474. $this->managedProjects = new \Doctrine\Common\Collections\ArrayCollection();
  475. $this->roleInvitations = new \Doctrine\Common\Collections\ArrayCollection();
  476. $this->linkedEmailAddressInvitations = new \Doctrine\Common\Collections\ArrayCollection();
  477. $this->discImportSessions = new \Doctrine\Common\Collections\ArrayCollection();
  478. $this->projectUsers = new \Doctrine\Common\Collections\ArrayCollection();
  479. $this->invitationsCreated = new \Doctrine\Common\Collections\ArrayCollection();
  480. $this->usersCreated = new \Doctrine\Common\Collections\ArrayCollection();
  481. $this->recordsRequestDetails = new \Doctrine\Common\Collections\ArrayCollection();
  482. $this->chronologyItemsCreated = new \Doctrine\Common\Collections\ArrayCollection();
  483. $this->notifications = new \Doctrine\Common\Collections\ArrayCollection();
  484. $this->matterNotes = new \Doctrine\Common\Collections\ArrayCollection();
  485. $this->linkedEmailAddress = new \Doctrine\Common\Collections\ArrayCollection();
  486. $this->projectClosures = new \Doctrine\Common\Collections\ArrayCollection();
  487. $this->specialisations = new \Doctrine\Common\Collections\ArrayCollection();
  488. $this->favouriteProjects = new \Doctrine\Common\Collections\ArrayCollection();
  489. $this->clinicalSummaries = new \Doctrine\Common\Collections\ArrayCollection();
  490. }
  491. /**
  492. * Returns a textual representation of this user (their full name)
  493. */
  494. public function __toString()
  495. {
  496. return $this->getFullName();
  497. }
  498. /**
  499. * @Groups({"user:list"})
  500. *
  501. * @return int|null
  502. */
  503. public function getId(): ?int
  504. {
  505. return $this->id;
  506. }
  507. /**
  508. * A visual identifier that represents this user.
  509. *
  510. * @see UserInterface
  511. */
  512. public function getUsername(): string
  513. {
  514. return (string) $this->username;
  515. }
  516. /**
  517. * @param string $username
  518. *
  519. * @return $this
  520. */
  521. public function setUsername(string $username): self
  522. {
  523. $this->username = $username;
  524. return $this;
  525. }
  526. /**
  527. * @see UserInterface
  528. */
  529. public function getRoles(): array
  530. {
  531. $roles = $this->roles;
  532. // guarantee every user at least has ROLE_USER
  533. $roles[] = 'ROLE_USER';
  534. return array_unique($roles);
  535. }
  536. /**
  537. * @param array $roles
  538. *
  539. * @return $this
  540. */
  541. public function setRoles(array $roles): self
  542. {
  543. $this->roles = $roles;
  544. return $this;
  545. }
  546. /**
  547. * @param string $role
  548. *
  549. * @return $this
  550. */
  551. public function addRole(string $role)
  552. {
  553. $this->roles[] = $role;
  554. return $this;
  555. }
  556. /**
  557. * @param string $role
  558. *
  559. * @return $this
  560. */
  561. public function removeRole(string $role)
  562. {
  563. if (($key = array_search($role, $this->roles)) !== false) {
  564. unset($this->roles[$key]);
  565. }
  566. return $this;
  567. }
  568. /**
  569. * @see UserInterface
  570. */
  571. public function getPassword(): string
  572. {
  573. return $this->password;
  574. }
  575. /**
  576. * @param string $password
  577. *
  578. * @return $this
  579. */
  580. public function setPassword(string $password): self
  581. {
  582. $this->password = $password;
  583. return $this;
  584. }
  585. /**
  586. * Returning a salt is only needed, if you are not using a modern
  587. * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  588. *
  589. * @see UserInterface
  590. */
  591. public function getSalt(): ?string
  592. {
  593. return $this->salt;
  594. }
  595. /**
  596. * Setting a salt is generally unnecessary (modern hashing algorithms), but we have implemented this so that we can
  597. * clear the salt on upgrade of a User's password.
  598. *
  599. * @param string|null $salt
  600. *
  601. * @return $this
  602. */
  603. public function setSalt(?string $salt)
  604. {
  605. $this->salt = $salt;
  606. return $this;
  607. }
  608. /**
  609. * @see UserInterface
  610. */
  611. public function eraseCredentials()
  612. {
  613. // If you store any temporary, sensitive data on the user, clear it here
  614. // $this->plainPassword = null;
  615. }
  616. /**
  617. * @return bool
  618. */
  619. public function isEnabled()
  620. {
  621. return $this->enabled;
  622. }
  623. /**
  624. * @return mixed
  625. */
  626. public function getLastLogin()
  627. {
  628. return $this->last_login;
  629. }
  630. /**
  631. * @param mixed $last_login
  632. *
  633. * @return User
  634. */
  635. public function setLastLogin($last_login)
  636. {
  637. $this->last_login = $last_login;
  638. return $this;
  639. }
  640. /**
  641. * @return string
  642. */
  643. public function getAzureId()
  644. {
  645. return $this->azureId;
  646. }
  647. /**
  648. * @param string $azureId
  649. *
  650. * @return User
  651. */
  652. public function setAzureId($azureId)
  653. {
  654. $this->azureId = $azureId;
  655. return $this;
  656. }
  657. /**
  658. * @return string
  659. */
  660. public function getAzureAccessToken()
  661. {
  662. return $this->azureAccessToken;
  663. }
  664. /**
  665. * @param mixed $azureAccessToken
  666. *
  667. * @return User
  668. */
  669. public function setAzureAccessToken($azureAccessToken)
  670. {
  671. $this->azureAccessToken = $azureAccessToken;
  672. return $this;
  673. }
  674. /**
  675. * @return string
  676. */
  677. public function getMicrosoftId()
  678. {
  679. return $this->getAzureId();
  680. }
  681. /**
  682. * @param mixed $azureId
  683. *
  684. * @return User
  685. */
  686. public function setMicrosoftId($azureId)
  687. {
  688. return $this->setAzureId($azureId);
  689. }
  690. /**
  691. * @return string
  692. */
  693. public function getMicrosoftAccessToken()
  694. {
  695. return $this->getAzureAccessToken();
  696. }
  697. /**
  698. * @param mixed $azureAccessToken
  699. *
  700. * @return User
  701. */
  702. public function setMicrosoftAccessToken($azureAccessToken)
  703. {
  704. return $this->setAzureAccessToken($azureAccessToken);
  705. }
  706. /**
  707. * @return string
  708. */
  709. public function getFullName()
  710. {
  711. $prefix = '';
  712. if ($this->getDeletedAt() !== null) {
  713. $prefix = '[REMOVED] ';
  714. }
  715. return $prefix . trim($this->getFirstName() . ' ' . $this->getLastName());
  716. }
  717. /**
  718. * @param string $first_name
  719. *
  720. * @return User
  721. */
  722. public function setFirstName($first_name)
  723. {
  724. $this->first_name = $first_name;
  725. return $this;
  726. }
  727. /**
  728. * @Groups({"user:read", "user:list", "matter_request:read", "account:read"})
  729. *
  730. * @return string
  731. */
  732. public function getFirstName()
  733. {
  734. return $this->first_name;
  735. }
  736. /**
  737. * @param string $last_name
  738. *
  739. * @return User
  740. */
  741. public function setLastName($last_name)
  742. {
  743. $this->last_name = $last_name;
  744. return $this;
  745. }
  746. /**
  747. * @Groups({"user:read", "user:list", "matter_request:read", "account:read"})
  748. *
  749. * @return string
  750. */
  751. public function getLastName()
  752. {
  753. return $this->last_name;
  754. }
  755. /**
  756. * @param DateTime $created
  757. *
  758. * @return User
  759. */
  760. public function setCreated($created)
  761. {
  762. $this->created = $created;
  763. return $this;
  764. }
  765. /**
  766. * @return DateTime
  767. */
  768. public function getCreated()
  769. {
  770. return $this->created;
  771. }
  772. /**
  773. * @param DateTime $updated
  774. *
  775. * @return User
  776. */
  777. public function setUpdated($updated)
  778. {
  779. $this->updated = $updated;
  780. return $this;
  781. }
  782. /**
  783. * @return DateTime
  784. */
  785. public function getUpdated()
  786. {
  787. return $this->updated;
  788. }
  789. /**
  790. * @param string $search_index
  791. *
  792. * @return User
  793. */
  794. public function setSearchIndex($search_index)
  795. {
  796. $this->search_index = $search_index;
  797. return $this;
  798. }
  799. /**
  800. * @return string
  801. */
  802. public function getSearchIndex()
  803. {
  804. return $this->search_index;
  805. }
  806. /**
  807. * @param Account|null $account
  808. *
  809. * @return User
  810. */
  811. public function setAccount(?Account $account = null)
  812. {
  813. $this->account = $account;
  814. return $this;
  815. }
  816. /**
  817. * @return Account
  818. */
  819. public function getAccount()
  820. {
  821. return $this->account;
  822. }
  823. /**
  824. * @param string $phoneNumber
  825. *
  826. * @return User
  827. */
  828. public function setPhoneNumber($phoneNumber)
  829. {
  830. $this->phoneNumber = $phoneNumber;
  831. return $this;
  832. }
  833. /**
  834. * @return string
  835. */
  836. public function getPhoneNumber()
  837. {
  838. return $this->phoneNumber;
  839. }
  840. /**
  841. * @param Document $documents
  842. *
  843. * @return User
  844. */
  845. public function addDocument(Document $documents)
  846. {
  847. $this->documents[] = $documents;
  848. return $this;
  849. }
  850. /**
  851. * @param Document $documents
  852. */
  853. public function removeDocument(Document $documents)
  854. {
  855. $this->documents->removeElement($documents);
  856. }
  857. /**
  858. * @return DoctrineCollection
  859. */
  860. public function getDocuments()
  861. {
  862. return $this->documents;
  863. }
  864. /**
  865. * @param Project $managedProjects
  866. *
  867. * @return User
  868. */
  869. public function addManagedProject(Project $managedProjects)
  870. {
  871. $this->managedProjects[] = $managedProjects;
  872. return $this;
  873. }
  874. /**
  875. * @param Project $managedProjects
  876. */
  877. public function removeManagedProject(Project $managedProjects)
  878. {
  879. $this->managedProjects->removeElement($managedProjects);
  880. }
  881. /**
  882. * @return DoctrineCollection
  883. */
  884. public function getManagedProjects()
  885. {
  886. return $this->managedProjects;
  887. }
  888. /**
  889. * @param Invitation|null $invitation
  890. *
  891. * @return User
  892. */
  893. public function setInvitation(?Invitation $invitation = null)
  894. {
  895. $this->invitation = $invitation;
  896. return $this;
  897. }
  898. /**
  899. * @return Invitation
  900. */
  901. public function getInvitation()
  902. {
  903. return $this->invitation;
  904. }
  905. /**
  906. * This is a validation callback function specified in our validation.yml file
  907. *
  908. * @param ExecutionContextInterface $context
  909. */
  910. public function validate(ExecutionContextInterface $context)
  911. {
  912. // this user is not valid if their email address does not match that of their invitation
  913. if (trim($this->getEmail()) != trim($this->getInvitation()->getEmail())) {
  914. $context->buildViolation('This email address does not match the one on the invitation')
  915. ->atPath('email')
  916. ->addViolation()
  917. ;
  918. }
  919. }
  920. /**
  921. * @param RoleInvitation $roleInvitations
  922. *
  923. * @return User
  924. */
  925. public function addRoleInvitation(RoleInvitation $roleInvitations)
  926. {
  927. $this->roleInvitations[] = $roleInvitations;
  928. return $this;
  929. }
  930. /**
  931. * @param RoleInvitation $roleInvitations
  932. */
  933. public function removeRoleInvitation(RoleInvitation $roleInvitations)
  934. {
  935. $this->roleInvitations->removeElement($roleInvitations);
  936. }
  937. /**
  938. * @return DoctrineCollection
  939. */
  940. public function getRoleInvitations()
  941. {
  942. return $this->roleInvitations;
  943. }
  944. /**
  945. * Checks to see if this entity has a RoleInvitation that matches the given
  946. * role. If there is one, it is returned.
  947. *
  948. * @param $role
  949. *
  950. * @return RoleInvitation|null
  951. */
  952. public function getMatchingRoleInvitation($role)
  953. {
  954. foreach ($this->getRoleInvitations() as $roleInvitation) {
  955. if ($role == $roleInvitation->getRole()) {
  956. return $roleInvitation;
  957. }
  958. }
  959. return null;
  960. }
  961. /**
  962. * Checks to see if this entity has a RoleInvitation that is pending
  963. * approval and matches the given role. If there is one, it is returned.
  964. *
  965. * @param $role
  966. *
  967. * @return RoleInvitation|null
  968. */
  969. public function getMatchingRoleInvitationPendingApproval($role)
  970. {
  971. foreach ($this->getRoleInvitations() as $roleInvitation) {
  972. if ($role == $roleInvitation->getRole()
  973. && ($roleInvitation->getStatus() == RoleInvitation::STATUS_PENDING_APPROVAL
  974. || $roleInvitation->getStatus() == RoleInvitation::STATUS_SUPPRESSED)) {
  975. return $roleInvitation;
  976. }
  977. }
  978. return null;
  979. }
  980. /**
  981. * Checks to see if this entity has a RoleInvitation that is pending one-time authentication
  982. * and matches the given role. If there is one, it is returned.
  983. *
  984. * @param $role
  985. *
  986. * @return bool
  987. */
  988. public function getMatchingRoleInvitationPendingAuthentication($role)
  989. {
  990. foreach ($this->getRoleInvitations() as $roleInvitation) {
  991. if ($role == $roleInvitation->getRole()
  992. && $roleInvitation->getStatus() == RoleInvitation::STATUS_PENDING_AUTHENTICATION) {
  993. return $roleInvitation;
  994. }
  995. }
  996. return null;
  997. }
  998. /**
  999. * Checks to see if this entity has an accepted RoleInvitation that
  1000. * matches the given role.
  1001. *
  1002. * @param $role
  1003. *
  1004. * @return bool
  1005. */
  1006. public function hasMatchingAcceptedRoleInvitation($role): bool
  1007. {
  1008. foreach ($this->getRoleInvitations() as $roleInvitation) {
  1009. if ($role === $roleInvitation->getRole() && $roleInvitation->getAccepted() !== null) {
  1010. return true;
  1011. }
  1012. }
  1013. return false;
  1014. }
  1015. /**
  1016. * Returns true if this user has any RoleInvitations linked directly to them
  1017. * or their Invitation that are in PENDING_APPROVAL state
  1018. *
  1019. * @return bool
  1020. */
  1021. public function hasRoleInvitationsPendingApproval()
  1022. {
  1023. $roleInvitations = $this->getPendingRoleInvitations();
  1024. return !empty($roleInvitations);
  1025. }
  1026. /**
  1027. * Returns true if this user has any RoleInvitations linked directly to them
  1028. * or their Invitation that are in PENDING_APPROVAL state
  1029. *
  1030. * @param string $role
  1031. *
  1032. * @return bool
  1033. */
  1034. public function hasMatchingRoleInvitationsPendingApproval($role): bool
  1035. {
  1036. $roleInvitations = $this->getMatchingRoleInvitationPendingApproval($role);
  1037. return !empty($roleInvitations);
  1038. }
  1039. /**
  1040. * Gets all the Pending RoleInvitations linked to this user and to their
  1041. * invitation
  1042. *
  1043. * @return array
  1044. */
  1045. public function getPendingRoleInvitations()
  1046. {
  1047. $array = [];
  1048. foreach ($this->getRoleInvitations() as $roleInvitation) {
  1049. if ($roleInvitation->getStatus() == RoleInvitation::STATUS_PENDING_APPROVAL
  1050. || $roleInvitation->getStatus() == RoleInvitation::STATUS_SUPPRESSED) {
  1051. $array[] = $roleInvitation;
  1052. }
  1053. }
  1054. if ($this->getInvitation()) {
  1055. foreach ($this->getInvitation()->getRoleInvitations() as $roleInvitation) {
  1056. if ($roleInvitation->getStatus() == RoleInvitation::STATUS_PENDING_APPROVAL
  1057. || $roleInvitation->getStatus() == RoleInvitation::STATUS_SUPPRESSED) {
  1058. $array[] = $roleInvitation;
  1059. }
  1060. }
  1061. }
  1062. return $array;
  1063. }
  1064. // @todo Should the below two be bundled in to the more accommodating functions with a "suppressed" arg?
  1065. /**
  1066. * Checks whether the User has any Role Invitations that are pending as well as not suppressed
  1067. *
  1068. * @return bool
  1069. */
  1070. public function hasUnsuppressedRoleInvitationsPendingApproval()
  1071. {
  1072. $roleInvitations = $this->getUnsuppressedRoleInvitationsPending();
  1073. return !empty($roleInvitations);
  1074. }
  1075. /**
  1076. * Grabs all the Role Invitations for this User that are pending approval and not suppressed
  1077. *
  1078. * @return array
  1079. */
  1080. public function getUnsuppressedRoleInvitationsPending()
  1081. {
  1082. $array = [];
  1083. foreach ($this->getRoleInvitations() as $roleInvitation) {
  1084. if ($roleInvitation->getStatus() == RoleInvitation::STATUS_PENDING_APPROVAL) {
  1085. $array[] = $roleInvitation;
  1086. }
  1087. }
  1088. if ($this->getInvitation()) {
  1089. foreach ($this->getInvitation()->getRoleInvitations() as $roleInvitation) {
  1090. if ($roleInvitation->getStatus() == RoleInvitation::STATUS_PENDING_APPROVAL) {
  1091. $array[] = $roleInvitation;
  1092. }
  1093. }
  1094. }
  1095. return $array;
  1096. }
  1097. /**
  1098. * Returns true if this user is a client administrator for at least one
  1099. * account. Note that this needs to match against Client Administrators and Client Super Administrators
  1100. *
  1101. * @return bool
  1102. */
  1103. public function isAccountAdministrator()
  1104. {
  1105. foreach ($this->getRoles() as $role) {
  1106. if ((stripos($role, 'ROLE_ACCOUNT_') !== false && stripos($role, '_ADMINISTRATOR') !== false)
  1107. || (stripos($role, 'ROLE_ACCOUNT_') !== false && stripos($role, '_SUPERADMINISTRATOR') !== false)) {
  1108. return true;
  1109. }
  1110. }
  1111. return false;
  1112. }
  1113. /**
  1114. * Checks whether a user is the Technical Administrator for *ANY* account
  1115. *
  1116. * @return bool
  1117. */
  1118. public function isAccountTechnicalAdmin(): bool
  1119. {
  1120. foreach ($this->getRoles() as $role) {
  1121. if (preg_match('/ROLE_ACCOUNT_\d+_TECHNICAL_ADMIN/', $role)) {
  1122. return true;
  1123. }
  1124. }
  1125. return false;
  1126. }
  1127. /**
  1128. * Checks whether a user is a sorter for *ANY* account
  1129. *
  1130. * @return bool
  1131. */
  1132. public function isAccountSorter(): bool
  1133. {
  1134. foreach ($this->getRoles() as $role) {
  1135. if (preg_match('/ROLE_ACCOUNT_\d+_SORTER/', $role)) {
  1136. return true;
  1137. }
  1138. }
  1139. return false;
  1140. }
  1141. /**
  1142. * Checks whether a user is the Technical Administrator for a specific Account (basically the same as the Voter)
  1143. *
  1144. * @param Account $account
  1145. *
  1146. * @return bool
  1147. */
  1148. public function isTechnicalAdminForSpecificAccount(Account $account): bool
  1149. {
  1150. $accountId = $account->getId();
  1151. foreach ($this->getRoles() as $role) {
  1152. if (preg_match("/ROLE_ACCOUNT_{$accountId}_TECHNICAL_ADMIN/", $role)) {
  1153. return true;
  1154. }
  1155. }
  1156. return false;
  1157. }
  1158. /**
  1159. * Returns true if this user is a client administrator for the specified Account.
  1160. * Note that this needs to match against Client Administrators and Client Super Administrators
  1161. *
  1162. * @param Account $account
  1163. *
  1164. * @return bool
  1165. */
  1166. public function isAccountAdministratorForAccount(Account $account)
  1167. {
  1168. foreach ($this->getRoles() as $role) {
  1169. if (
  1170. $role == sprintf('ROLE_ACCOUNT_%1$s_ADMINISTRATOR', $account->getId())
  1171. || $role == sprintf('ROLE_ACCOUNT_%1$s_SUPERADMINISTRATOR', $account->getId())
  1172. ) {
  1173. return true;
  1174. }
  1175. }
  1176. return false;
  1177. }
  1178. /**
  1179. * Returns true if this user is a client project manager for at least one
  1180. * account.
  1181. *
  1182. * @return bool
  1183. */
  1184. public function isAccountProjectManager()
  1185. {
  1186. foreach ($this->getRoles() as $role) {
  1187. if ((stripos($role, 'ROLE_ACCOUNT_') !== false && stripos($role, '_PROJECTMANAGER') !== false)) {
  1188. return true;
  1189. }
  1190. }
  1191. return false;
  1192. }
  1193. /**
  1194. * Returns true if this user is a client project manager for the specified Account.
  1195. *
  1196. * @param Account $account
  1197. *
  1198. * @return bool
  1199. */
  1200. public function isAccountProjectManagerForAccount(Account $account)
  1201. {
  1202. foreach ($this->getRoles() as $role) {
  1203. if ($role == sprintf('ROLE_ACCOUNT_%1$s_PROJECTMANAGER', $account->getId())) {
  1204. return true;
  1205. }
  1206. }
  1207. return false;
  1208. }
  1209. /**
  1210. * Returns true if this user is a client project manager for the specified Project.
  1211. *
  1212. * @param Project $project
  1213. *
  1214. * @return bool
  1215. */
  1216. public function isProjectManagerForSpecificProject(Project $project)
  1217. {
  1218. foreach ($this->getRoles() as $role) {
  1219. if ($role == sprintf('ROLE_PROJECT_%1$s_PROJECTMANAGER', $project->getId())) {
  1220. return true;
  1221. }
  1222. }
  1223. return false;
  1224. }
  1225. /**
  1226. * Returns true if this user is a expert agency administrator
  1227. *
  1228. * @return bool
  1229. */
  1230. public function isExpertAgencyAdministrator()
  1231. {
  1232. foreach ($this->getRoles() as $role) {
  1233. if (stripos($role, 'ROLE_EXPERTAGENCY_') !== false && stripos($role, '_ADMINISTRATOR') !== false) {
  1234. return true;
  1235. }
  1236. }
  1237. return false;
  1238. }
  1239. /**
  1240. * Returns true if this user is a project manager for at least one project
  1241. *
  1242. * @return bool
  1243. */
  1244. public function isProjectManager()
  1245. {
  1246. foreach ($this->getRoles() as $role) {
  1247. if (stripos($role, 'ROLE_PROJECT_') !== false && stripos($role, '_PROJECTMANAGER') !== false) {
  1248. return true;
  1249. }
  1250. }
  1251. return false;
  1252. }
  1253. /**
  1254. * Returns true if this user is a project scanner for at least one project
  1255. *
  1256. * @return bool
  1257. */
  1258. public function isProjectScanner(): bool
  1259. {
  1260. foreach ($this->getRoles() as $role) {
  1261. if (preg_match('/ROLE_PROJECT_\d+_SCANNER/', $role)) {
  1262. return true;
  1263. }
  1264. }
  1265. return false;
  1266. }
  1267. /**
  1268. * Returns true if this user is a project scanner downloader for at least one project
  1269. *
  1270. * @return bool
  1271. */
  1272. public function isProjectScannerDownload(): bool
  1273. {
  1274. foreach ($this->getRoles() as $role) {
  1275. if (stripos($role, 'ROLE_PROJECT_') !== false && stripos($role, '_SCANNERDOWNLOAD') !== false) {
  1276. return true;
  1277. }
  1278. }
  1279. return false;
  1280. }
  1281. /**
  1282. * Returns true if this user only has expert roles or role invitations associated with their account.
  1283. *
  1284. * @return bool
  1285. */
  1286. public function isExpertOnly()
  1287. {
  1288. if ($this->getRoles()) {
  1289. foreach ($this->getRoles() as $role) {
  1290. if ((stripos($role, 'ROLE_PROJECT_') === false || stripos($role, '_EXPERT') === false) && $role !== 'ROLE_USER') {
  1291. return false;
  1292. }
  1293. }
  1294. }
  1295. foreach ($this->getRoleInvitations() as $invitation) {
  1296. if (stripos($invitation->getRole(), 'ROLE_PROJECT_') === false || stripos($invitation->getRole(), '_EXPERT') === false) {
  1297. return false;
  1298. }
  1299. }
  1300. return true;
  1301. }
  1302. /**
  1303. * Returns true if the user only has an expert viewer role or role invitations, associated with their account.
  1304. *
  1305. * @return bool
  1306. */
  1307. public function isExpertViewerOnly()
  1308. {
  1309. if ($this->getRoles()) {
  1310. foreach ($this->getRoles() as $role) {
  1311. if ((stripos($role, 'ROLE_PROJECT_') === false || stripos($role, '_EXPERTVIEWER') === false) && $role !== 'ROLE_USER') {
  1312. return false;
  1313. }
  1314. }
  1315. }
  1316. foreach ($this->getRoleInvitations() as $invitation) {
  1317. if (stripos($invitation->getRole(), 'ROLE_PROJECT_') === false || stripos($invitation->getRole(), '_EXPERTVIEWER') === false) {
  1318. return false;
  1319. }
  1320. }
  1321. return true;
  1322. }
  1323. /**
  1324. * @param DateTime $deletedAt
  1325. *
  1326. * @return User
  1327. */
  1328. public function setDeletedAt($deletedAt)
  1329. {
  1330. $this->deletedAt = $deletedAt;
  1331. return $this;
  1332. }
  1333. /**
  1334. * @return DateTime
  1335. */
  1336. public function getDeletedAt()
  1337. {
  1338. return $this->deletedAt;
  1339. }
  1340. /**
  1341. * @param Disc $disc
  1342. *
  1343. * @return User
  1344. */
  1345. public function addDisc(Disc $disc)
  1346. {
  1347. $this->discs[] = $disc;
  1348. return $this;
  1349. }
  1350. /**
  1351. * @param Disc $disc
  1352. */
  1353. public function removeDisc(Disc $disc)
  1354. {
  1355. $this->discs->removeElement($disc);
  1356. }
  1357. /**
  1358. * @return DoctrineCollection
  1359. */
  1360. public function getDiscs()
  1361. {
  1362. return $this->discs;
  1363. }
  1364. /**
  1365. * @param DiscImportSession $discImportSession
  1366. *
  1367. * @return User
  1368. */
  1369. public function addDiscImportSession(DiscImportSession $discImportSession)
  1370. {
  1371. $this->discImportSessions[] = $discImportSession;
  1372. return $this;
  1373. }
  1374. /**
  1375. * @param DiscImportSession $discImportSession
  1376. */
  1377. public function removeDiscImportSession(DiscImportSession $discImportSession)
  1378. {
  1379. $this->discImportSessions->removeElement($discImportSession);
  1380. }
  1381. /**
  1382. * @return DoctrineCollection
  1383. */
  1384. public function getDiscImportSessions()
  1385. {
  1386. return $this->discImportSessions;
  1387. }
  1388. /**
  1389. * @param ProjectUser $projectUser
  1390. *
  1391. * @return User
  1392. */
  1393. public function addProjectUser(ProjectUser $projectUser)
  1394. {
  1395. $this->projectUsers[] = $projectUser;
  1396. return $this;
  1397. }
  1398. /**
  1399. * @param ProjectUser $projectUser
  1400. */
  1401. public function removeProjectUser(ProjectUser $projectUser)
  1402. {
  1403. $this->projectUsers->removeElement($projectUser);
  1404. }
  1405. /**
  1406. * @return DoctrineCollection
  1407. */
  1408. public function getProjectUsers()
  1409. {
  1410. return $this->projectUsers;
  1411. }
  1412. /**
  1413. * @param Invitation $invitationsCreated
  1414. *
  1415. * @return User
  1416. */
  1417. public function addInvitationsCreated(Invitation $invitationsCreated)
  1418. {
  1419. $this->invitationsCreated[] = $invitationsCreated;
  1420. return $this;
  1421. }
  1422. /**
  1423. * @param Invitation $invitationsCreated
  1424. */
  1425. public function removeInvitationsCreated(Invitation $invitationsCreated)
  1426. {
  1427. $this->invitationsCreated->removeElement($invitationsCreated);
  1428. }
  1429. /**
  1430. * @return DoctrineCollection
  1431. */
  1432. public function getInvitationsCreated()
  1433. {
  1434. return $this->invitationsCreated;
  1435. }
  1436. /**
  1437. * @param ExpertAgency|null $expertAgency
  1438. *
  1439. * @return User
  1440. */
  1441. public function setExpertAgency(?ExpertAgency $expertAgency = null)
  1442. {
  1443. $this->expertAgency = $expertAgency;
  1444. return $this;
  1445. }
  1446. /**
  1447. * @return ExpertAgency
  1448. */
  1449. public function getExpertAgency()
  1450. {
  1451. return $this->expertAgency;
  1452. }
  1453. /**
  1454. * @param DateTime $lastActivity
  1455. *
  1456. * @return User
  1457. */
  1458. public function setLastActivity($lastActivity)
  1459. {
  1460. $this->lastActivity = $lastActivity;
  1461. return $this;
  1462. }
  1463. /**
  1464. * @Groups({"user:activity"})
  1465. *
  1466. * @return DateTime
  1467. */
  1468. public function getLastActivity()
  1469. {
  1470. return $this->lastActivity;
  1471. }
  1472. /**
  1473. * @Groups({"user:activity:write"})
  1474. *
  1475. * @return User
  1476. */
  1477. public function setLastActivityToNow()
  1478. {
  1479. $this->setLastActivity(new DateTime('now'));
  1480. return $this;
  1481. }
  1482. /**
  1483. * @Groups({"user:activity"})
  1484. *
  1485. * @return bool whether the user is active or not
  1486. */
  1487. public function isActiveNow()
  1488. {
  1489. // If lastActivity is null (e.g., just logged in), treat user as active
  1490. if ($this->getLastActivity() === null) {
  1491. return true;
  1492. }
  1493. $delay = new DateTime($this->activityTimeoutMinutes . ' minutes ago');
  1494. return $this->getLastActivity() > $delay;
  1495. }
  1496. /**
  1497. * Set the activity timeout in minutes
  1498. *
  1499. * @param int $minutes
  1500. *
  1501. * @return self
  1502. */
  1503. public function setActivityTimeoutMinutes(int $minutes): self
  1504. {
  1505. $this->activityTimeoutMinutes = $minutes;
  1506. return $this;
  1507. }
  1508. /**
  1509. * Get the activity timeout in minutes
  1510. *
  1511. * @return int
  1512. */
  1513. public function getActivityTimeoutMinutes(): int
  1514. {
  1515. return $this->activityTimeoutMinutes;
  1516. }
  1517. /**
  1518. * @param User $usersCreated
  1519. *
  1520. * @return User
  1521. */
  1522. public function addUsersCreated(User $usersCreated)
  1523. {
  1524. $this->usersCreated[] = $usersCreated;
  1525. return $this;
  1526. }
  1527. /**
  1528. * @param User $usersCreated
  1529. */
  1530. public function removeUsersCreated(User $usersCreated)
  1531. {
  1532. $this->usersCreated->removeElement($usersCreated);
  1533. }
  1534. /**
  1535. * @return DoctrineCollection
  1536. */
  1537. public function getUsersCreated()
  1538. {
  1539. return $this->usersCreated;
  1540. }
  1541. /**
  1542. * @param User|null $creator
  1543. *
  1544. * @return User
  1545. */
  1546. public function setCreator(?User $creator = null)
  1547. {
  1548. $this->creator = $creator;
  1549. return $this;
  1550. }
  1551. /**
  1552. * @return User
  1553. */
  1554. public function getCreator()
  1555. {
  1556. return $this->creator;
  1557. }
  1558. /**
  1559. * @param bool $receiveDailyUploadNotificationEmail
  1560. *
  1561. * @return User
  1562. */
  1563. public function setReceiveDailyUploadNotificationEmail($receiveDailyUploadNotificationEmail)
  1564. {
  1565. $this->receiveDailyUploadNotificationEmail = $receiveDailyUploadNotificationEmail;
  1566. return $this;
  1567. }
  1568. /**
  1569. * @return bool
  1570. */
  1571. public function getReceiveDailyUploadNotificationEmail()
  1572. {
  1573. return $this->receiveDailyUploadNotificationEmail;
  1574. }
  1575. /**
  1576. * @param ChronologyItem $chronologyItemsCreated
  1577. *
  1578. * @return User
  1579. */
  1580. public function addChronologyItemsCreated(ChronologyItem $chronologyItemsCreated)
  1581. {
  1582. $this->chronologyItemsCreated[] = $chronologyItemsCreated;
  1583. return $this;
  1584. }
  1585. /**
  1586. * @param ChronologyItem $chronologyItemsCreated
  1587. */
  1588. public function removeChronologyItemsCreated(ChronologyItem $chronologyItemsCreated)
  1589. {
  1590. $this->chronologyItemsCreated->removeElement($chronologyItemsCreated);
  1591. }
  1592. /**
  1593. * @return DoctrineCollection
  1594. */
  1595. public function getChronologyItemsCreated()
  1596. {
  1597. return $this->chronologyItemsCreated;
  1598. }
  1599. /**
  1600. * @param RecordsRequestDetail $recordsRequestDetail
  1601. *
  1602. * @return User
  1603. */
  1604. public function addRecordsRequestDetail(RecordsRequestDetail $recordsRequestDetail)
  1605. {
  1606. $this->recordsRequestDetails[] = $recordsRequestDetail;
  1607. return $this;
  1608. }
  1609. /**
  1610. * @param RecordsRequestDetail $recordsRequestDetail
  1611. */
  1612. public function removeRecordsRequestDetail(RecordsRequestDetail $recordsRequestDetail)
  1613. {
  1614. $this->recordsRequestDetails->removeElement($recordsRequestDetail);
  1615. }
  1616. /**
  1617. * @return DoctrineCollection
  1618. */
  1619. public function getRecordsRequestDetails()
  1620. {
  1621. return $this->recordsRequestDetails;
  1622. }
  1623. /**
  1624. * @return bool
  1625. */
  1626. public function isAccountNonLocked()
  1627. {
  1628. return !$this->locked;
  1629. }
  1630. /**
  1631. * @return bool
  1632. */
  1633. public function isLocked()
  1634. {
  1635. return !$this->isAccountNonLocked();
  1636. }
  1637. /**
  1638. * @param $boolean
  1639. *
  1640. * @return $this
  1641. */
  1642. public function setLocked($boolean)
  1643. {
  1644. $this->locked = $boolean;
  1645. return $this;
  1646. }
  1647. /**
  1648. * @param PhoneNumber $mobileNumber
  1649. *
  1650. * @return User
  1651. */
  1652. public function setMobileNumber($mobileNumber)
  1653. {
  1654. $this->mobileNumber = $mobileNumber;
  1655. return $this;
  1656. }
  1657. /**
  1658. * @return PhoneNumber
  1659. */
  1660. public function getMobileNumber()
  1661. {
  1662. return $this->mobileNumber;
  1663. }
  1664. /**
  1665. * @param int $notificationStatus
  1666. *
  1667. * @return User
  1668. */
  1669. public function setNotificationStatus($notificationStatus)
  1670. {
  1671. $this->notificationStatus = $notificationStatus;
  1672. return $this;
  1673. }
  1674. /**
  1675. * @return int
  1676. */
  1677. public function getNotificationStatus()
  1678. {
  1679. return $this->notificationStatus;
  1680. }
  1681. /**
  1682. * @param int $notificationFormatPreference
  1683. *
  1684. * @return User
  1685. */
  1686. public function setNotificationFormatPreference($notificationFormatPreference)
  1687. {
  1688. $this->notificationFormatPreference = $notificationFormatPreference;
  1689. return $this;
  1690. }
  1691. /**
  1692. * @return int
  1693. */
  1694. public function getNotificationFormatPreference()
  1695. {
  1696. return $this->notificationFormatPreference;
  1697. }
  1698. /**
  1699. * @param UserNotification $notification
  1700. *
  1701. * @return User
  1702. */
  1703. public function addNotification(UserNotification $notification)
  1704. {
  1705. $this->notifications[] = $notification;
  1706. return $this;
  1707. }
  1708. /**
  1709. * @param UserNotification $notification
  1710. */
  1711. public function removeNotification(UserNotification $notification)
  1712. {
  1713. $this->notifications->removeElement($notification);
  1714. }
  1715. /**
  1716. * @return DoctrineCollection
  1717. */
  1718. public function getNotifications()
  1719. {
  1720. return $this->notifications;
  1721. }
  1722. /**
  1723. * @param bool $billingAdmin
  1724. *
  1725. * @return User
  1726. */
  1727. public function setBillingAdmin($billingAdmin)
  1728. {
  1729. $this->billingAdmin = $billingAdmin;
  1730. return $this;
  1731. }
  1732. /**
  1733. * @return bool
  1734. */
  1735. public function isBillingAdmin()
  1736. {
  1737. return $this->billingAdmin;
  1738. }
  1739. /**
  1740. * NOTE: Doctrine wants to add a ::getBillingAdmin() function but a User
  1741. * does not have a billingAdmin, but they can BE a billing admin. We will
  1742. * keep this here to appease the Doctrinosaurus.
  1743. *
  1744. * @return bool
  1745. */
  1746. public function getBillingAdmin()
  1747. {
  1748. return $this->billingAdmin;
  1749. }
  1750. /**
  1751. * @param Specialisation $specialisation
  1752. *
  1753. * @return User
  1754. */
  1755. public function addSpecialisation(Specialisation $specialisation)
  1756. {
  1757. $this->specialisations[] = $specialisation;
  1758. return $this;
  1759. }
  1760. /**
  1761. * @param Specialisation $specialisation
  1762. */
  1763. public function removeSpecialisation(Specialisation $specialisation)
  1764. {
  1765. $this->specialisations->removeElement($specialisation);
  1766. }
  1767. /**
  1768. * @return DoctrineCollection
  1769. */
  1770. public function getSpecialisations()
  1771. {
  1772. return $this->specialisations;
  1773. }
  1774. /**
  1775. * Check if this User has a particular Specialisation
  1776. *
  1777. * @param Specialisation $specialisation
  1778. *
  1779. * @return bool
  1780. */
  1781. public function hasSpecialisation(Specialisation $specialisation)
  1782. {
  1783. return $this->getSpecialisations()->contains($specialisation);
  1784. }
  1785. /**
  1786. * @param Project $favouriteProject
  1787. *
  1788. * @return User
  1789. */
  1790. public function addFavouriteProject(Project $favouriteProject)
  1791. {
  1792. $this->favouriteProjects[] = $favouriteProject;
  1793. return $this;
  1794. }
  1795. /**
  1796. * @param Project $favouriteProject
  1797. */
  1798. public function removeFavouriteProject(Project $favouriteProject)
  1799. {
  1800. $this->favouriteProjects->removeElement($favouriteProject);
  1801. }
  1802. /**
  1803. * @return DoctrineCollection
  1804. */
  1805. public function getFavouriteProjects()
  1806. {
  1807. return $this->favouriteProjects;
  1808. }
  1809. /**
  1810. * @return bool
  1811. */
  1812. public function getLocked()
  1813. {
  1814. return $this->locked;
  1815. }
  1816. /**
  1817. * @param MatterNote $matterNote
  1818. *
  1819. * @return User
  1820. */
  1821. public function addMatterNote(MatterNote $matterNote)
  1822. {
  1823. $this->matterNotes[] = $matterNote;
  1824. return $this;
  1825. }
  1826. /**
  1827. * @param MatterNote $matterNote
  1828. */
  1829. public function removeMatterNote(MatterNote $matterNote)
  1830. {
  1831. $this->matterNotes->removeElement($matterNote);
  1832. }
  1833. /**
  1834. * @return DoctrineCollection
  1835. */
  1836. public function getMatterNotes()
  1837. {
  1838. return $this->matterNotes;
  1839. }
  1840. public function isUser(?UserInterface $user = null): bool
  1841. {
  1842. return $user instanceof self && $user->id === $this->id;
  1843. }
  1844. /**
  1845. * @ORM\PrePersist
  1846. */
  1847. public function copyEmailToUsername()
  1848. {
  1849. $this->setUsername($this->getEmail());
  1850. }
  1851. /**
  1852. * Updates the Search Index field with internal data. The Search Index Field
  1853. * provides an easy way to perform a 'like' query for a generalised search.
  1854. *
  1855. * @ORM\PrePersist
  1856. *
  1857. * @ORM\PreUpdate
  1858. */
  1859. public function updateSearchIndex()
  1860. {
  1861. $searchIndex
  1862. = $this->getFullName()
  1863. . ' '
  1864. . $this->getEmail();
  1865. // Add any linked email address to the search index
  1866. /** @var LinkedEmailAddress $linkedEmailAddress */
  1867. foreach ($this->linkedEmailAddress as $linkedEmailAddress) {
  1868. $searchIndex .= ' ' . strtolower($linkedEmailAddress->getEmail());
  1869. }
  1870. $this->setSearchIndex($searchIndex);
  1871. }
  1872. /**
  1873. * @param HumanResource|null $humanResource
  1874. *
  1875. * @return User
  1876. */
  1877. public function setHumanResource(?HumanResource $humanResource = null)
  1878. {
  1879. $this->humanResource = $humanResource;
  1880. return $this;
  1881. }
  1882. /**
  1883. * @return HumanResource|null
  1884. */
  1885. public function getHumanResource()
  1886. {
  1887. return $this->humanResource;
  1888. }
  1889. /**
  1890. * @param AnalyticsUser|null $analyticsUser
  1891. *
  1892. * @return User
  1893. */
  1894. public function setAnalyticsUser(?AnalyticsUser $analyticsUser = null)
  1895. {
  1896. $this->analyticsUser = $analyticsUser;
  1897. $this->analyticsUser->setUser($this);
  1898. return $this;
  1899. }
  1900. /**
  1901. * @return AnalyticsUser|null
  1902. */
  1903. public function getAnalyticsUser()
  1904. {
  1905. return $this->analyticsUser;
  1906. }
  1907. /**
  1908. * @param LinkedEmailAddress $linkedEmailAddress
  1909. *
  1910. * @return User
  1911. */
  1912. public function addLinkedEmailAddress(LinkedEmailAddress $linkedEmailAddress)
  1913. {
  1914. $this->linkedEmailAddress[] = $linkedEmailAddress;
  1915. // Update the search index, so we include the newly linked email address
  1916. $this->updateSearchIndex();
  1917. return $this;
  1918. }
  1919. /**
  1920. * @param LinkedEmailAddress $linkedEmailAddress
  1921. *
  1922. * @return bool TRUE if this collection contained the specified element, FALSE otherwise.
  1923. */
  1924. public function removeLinkedEmailAddress(LinkedEmailAddress $linkedEmailAddress)
  1925. {
  1926. $returnValue = $this->linkedEmailAddress->removeElement($linkedEmailAddress);
  1927. // Update the search index, so we exclude the removed linked email address
  1928. $this->updateSearchIndex();
  1929. return $returnValue;
  1930. }
  1931. /**
  1932. * @return DoctrineCollection
  1933. */
  1934. public function getLinkedEmailAddress()
  1935. {
  1936. return $this->linkedEmailAddress;
  1937. }
  1938. /**
  1939. * @param string $linkedEmailAddress
  1940. *
  1941. * @return bool
  1942. */
  1943. public function hasLinkedEmailAddress(string $linkedEmailAddress): bool
  1944. {
  1945. $linkedEmailAddresses = array_map(function (LinkedEmailAddress $linkedEmailAddress) {
  1946. return $linkedEmailAddress->getEmail();
  1947. }, $this->getLinkedEmailAddress()->toArray());
  1948. if (!$linkedEmailAddresses) {
  1949. return false;
  1950. }
  1951. return in_array($linkedEmailAddress, $linkedEmailAddresses);
  1952. }
  1953. /**
  1954. * @param LinkedEmailAddressInvitation $linkedEmailAddressInvitation
  1955. *
  1956. * @return User
  1957. */
  1958. public function addLinkedEmailAddressInvitation(LinkedEmailAddressInvitation $linkedEmailAddressInvitation)
  1959. {
  1960. $this->linkedEmailAddressInvitations[] = $linkedEmailAddressInvitation;
  1961. return $this;
  1962. }
  1963. /**
  1964. * @param LinkedEmailAddressInvitation $linkedEmailAddressInvitation
  1965. *
  1966. * @return bool TRUE if this collection contained the specified element, FALSE otherwise.
  1967. */
  1968. public function removeLinkedEmailAddressInvitation(LinkedEmailAddressInvitation $linkedEmailAddressInvitation)
  1969. {
  1970. return $this->linkedEmailAddressInvitations->removeElement($linkedEmailAddressInvitation);
  1971. }
  1972. /**
  1973. * @return DoctrineCollection
  1974. */
  1975. public function getLinkedEmailAddressInvitations()
  1976. {
  1977. return $this->linkedEmailAddressInvitations;
  1978. }
  1979. /**
  1980. * @param string $linkedEmailAddress
  1981. *
  1982. * @return bool
  1983. */
  1984. public function hasMatchingLinkedEmailAddressInvitationPendingApproval(string $linkedEmailAddress): bool
  1985. {
  1986. $linkedEmailAddressInvitations = $this->getLinkedEmailAddressInvitations();
  1987. /** @var LinkedEmailAddressInvitation $linkedEmailAddressInvitation */
  1988. foreach ($linkedEmailAddressInvitations as $linkedEmailAddressInvitation) {
  1989. switch ($linkedEmailAddressInvitation->getStatus()) {
  1990. case LinkedEmailAddressInvitation::STATUS_PENDING_APPROVAL:
  1991. return $linkedEmailAddress == $linkedEmailAddressInvitation->getEmail();
  1992. case LinkedEmailAddressInvitation::STATUS_APPROVED:
  1993. case LinkedEmailAddressInvitation::STATUS_DECLINED:
  1994. default:
  1995. }
  1996. }
  1997. return false;
  1998. }
  1999. /**
  2000. * Grabs all the Role Invitations for this User that are pending approval and not suppressed
  2001. *
  2002. * @TODO this function seems inefficient, as it is basically just checking if the passed linkedEmailAddressInvitation is pending?
  2003. *
  2004. * @param LinkedEmailAddressInvitation $linkedEmailAddressInvitation
  2005. *
  2006. * @return array
  2007. */
  2008. public function getLinkedEmailAddressInvitationPending(LinkedEmailAddressInvitation $linkedEmailAddressInvitation)
  2009. {
  2010. $linkedEmailAddresses = [];
  2011. if ($linkedEmailAddressInvitation->getStatus() == LinkedEmailAddressInvitation::STATUS_PENDING_APPROVAL) {
  2012. $linkedEmailAddresses[] = $linkedEmailAddressInvitation;
  2013. }
  2014. return $linkedEmailAddresses;
  2015. }
  2016. /**
  2017. * @param LinkedEmailAddressInvitation|null $linkedEmailAddressInvitation
  2018. *
  2019. * @return User
  2020. */
  2021. public function setLinkedEmailAddressInvitation(?LinkedEmailAddressInvitation $linkedEmailAddressInvitation = null)
  2022. {
  2023. $this->linkedEmailAddressInvitation = $linkedEmailAddressInvitation;
  2024. return $this;
  2025. }
  2026. /**
  2027. * @return LinkedEmailAddressInvitation|null
  2028. */
  2029. public function getLinkedEmailAddressInvitation()
  2030. {
  2031. return $this->linkedEmailAddressInvitation;
  2032. }
  2033. /**
  2034. * @param bool $matterDashboardEnabled
  2035. *
  2036. * @return User
  2037. */
  2038. public function setMatterDashboardEnabled($matterDashboardEnabled)
  2039. {
  2040. $this->matterDashboardEnabled = $matterDashboardEnabled;
  2041. return $this;
  2042. }
  2043. /**
  2044. * @return bool
  2045. */
  2046. public function getMatterDashboardEnabled()
  2047. {
  2048. return $this->matterDashboardEnabled;
  2049. }
  2050. /**
  2051. * @param bool $hasDocSorterAccess
  2052. *
  2053. * @return User
  2054. */
  2055. public function setHasDocSorterAccess($hasDocSorterAccess)
  2056. {
  2057. $this->hasDocSorterAccess = $hasDocSorterAccess;
  2058. return $this;
  2059. }
  2060. /**
  2061. * @return bool
  2062. */
  2063. public function getHasDocSorterAccess()
  2064. {
  2065. return $this->hasDocSorterAccess;
  2066. }
  2067. /**
  2068. * Returns user type options as an array, usable as the choices for a form.
  2069. *
  2070. * @throws \Exception
  2071. *
  2072. * @return array
  2073. */
  2074. public static function getUserTypeOptions(): array
  2075. {
  2076. $matterCreationProcessOptions = self::getConstantsWithLabelsAsChoices('USER_TYPE');
  2077. return array_flip($matterCreationProcessOptions);
  2078. }
  2079. /**
  2080. * Get the value of userType
  2081. *
  2082. * @return string
  2083. */
  2084. public function getUserType()
  2085. {
  2086. return $this->userType;
  2087. }
  2088. /**
  2089. * Returns true if the userType is USER_TYPE_INTERNAL
  2090. *
  2091. * @return bool
  2092. */
  2093. public function isUserTypeInternal(): bool
  2094. {
  2095. return $this->getUserType() === self::USER_TYPE_INTERNAL;
  2096. }
  2097. /**
  2098. * @param string|null $userType
  2099. *
  2100. * @return self
  2101. */
  2102. public function setUserType(?string $userType = null)
  2103. {
  2104. $this->userType = $userType;
  2105. return $this;
  2106. }
  2107. /**
  2108. * @return DateTime
  2109. */
  2110. public function getFirstLoginDate()
  2111. {
  2112. return $this->firstLoginDate;
  2113. }
  2114. /**
  2115. * @param DateTime|null $firstLoginDate
  2116. *
  2117. * @return self
  2118. */
  2119. public function setFirstLoginDate(?DateTime $firstLoginDate = null)
  2120. {
  2121. $this->firstLoginDate = $firstLoginDate;
  2122. return $this;
  2123. }
  2124. /**
  2125. * @param ProjectClosure $projectClosure
  2126. *
  2127. * @return User
  2128. */
  2129. public function addProjectClosure(ProjectClosure $projectClosure)
  2130. {
  2131. $this->projectClosure[] = $projectClosure;
  2132. return $this;
  2133. }
  2134. /**
  2135. * @param ProjectClosure $projectClosure
  2136. *
  2137. * @return bool TRUE if this collection contained the specified element, FALSE otherwise.
  2138. */
  2139. public function removeProjectClosure(ProjectClosure $projectClosure)
  2140. {
  2141. return $this->projectClosure->removeElement($projectClosure);
  2142. }
  2143. /**
  2144. * @return DoctrineCollection
  2145. */
  2146. public function getProjectClosures()
  2147. {
  2148. return $this->projectClosures;
  2149. }
  2150. /**
  2151. * @param int $id
  2152. *
  2153. * @return User
  2154. */
  2155. public function setId(int $id): User
  2156. {
  2157. $this->id = $id;
  2158. return $this;
  2159. }
  2160. /**
  2161. * @param bool $true
  2162. *
  2163. * @return $this
  2164. */
  2165. public function setEnabled(bool $true)
  2166. {
  2167. $this->enabled = $true;
  2168. return $this;
  2169. }
  2170. /**
  2171. * @inheritDoc
  2172. */
  2173. public function isEqualTo(UserInterface $user)
  2174. {
  2175. // There are only a few attributes on a user that we should enforce a logout should they change
  2176. // If their password has changed...
  2177. if ($this->getPassword() !== $user->getPassword()) {
  2178. return false;
  2179. }
  2180. // If they've been disabled...
  2181. if ($this->isEnabled() !== $user->isEnabled()) {
  2182. return false;
  2183. }
  2184. // 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.
  2185. $isEqual = count($this->getRoles()) == count($user->getRoles());
  2186. if ($isEqual) {
  2187. foreach ($this->getRoles() as $role) {
  2188. $isEqual = $isEqual && in_array($role, $user->getRoles());
  2189. }
  2190. }
  2191. return $isEqual;
  2192. }
  2193. /**
  2194. * @param string $role
  2195. *
  2196. * @return bool
  2197. */
  2198. public function hasRole(string $role): bool
  2199. {
  2200. return in_array($role, $this->getRoles());
  2201. }
  2202. /**
  2203. * @return DoctrineCollection<int, ClinicalSummary>
  2204. */
  2205. public function getClinicalSummaries(): DoctrineCollection
  2206. {
  2207. return $this->clinicalSummaries;
  2208. }
  2209. /**
  2210. * @param ClinicalSummary $clinicalSummary
  2211. *
  2212. * @return self
  2213. */
  2214. public function addClinicalSummary(ClinicalSummary $clinicalSummary): self
  2215. {
  2216. if (!$this->clinicalSummaries->contains($clinicalSummary)) {
  2217. $this->clinicalSummaries[] = $clinicalSummary;
  2218. $clinicalSummary->setCreator($this);
  2219. }
  2220. return $this;
  2221. }
  2222. /**
  2223. * @param ClinicalSummary $clinicalSummary
  2224. *
  2225. * @return self
  2226. */
  2227. public function removeClinicalSummary(ClinicalSummary $clinicalSummary): self
  2228. {
  2229. if ($this->clinicalSummaries->removeElement($clinicalSummary)) {
  2230. // set the owning side to null (unless already changed)
  2231. if ($clinicalSummary->getCreator() === $this) {
  2232. $clinicalSummary->setCreator(null);
  2233. }
  2234. }
  2235. return $this;
  2236. }
  2237. /**
  2238. * Check if the user's email matches any regex pattern in the UserInternal table.
  2239. *
  2240. * @param bool $isRecursive
  2241. * @param UserInternalRepository $repository
  2242. * @param EntityManagerInterface $entityManager
  2243. *
  2244. * @return bool
  2245. */
  2246. public function isUserInternal(UserInternalRepository $repository, EntityManagerInterface $entityManager, bool $isRecursive = false): bool
  2247. {
  2248. //return true if internal user
  2249. if ($this->isUserTypeInternal()) {
  2250. return true;
  2251. }
  2252. $email = strtolower($this->getEmail());
  2253. // Get stored regex patterns from the database
  2254. $patterns = $repository->getAllPatterns();
  2255. // If the user's email matches a domain that is specified in the patterns (e.g. medbrief) then set the userType to internal.
  2256. foreach ($patterns as $pattern) {
  2257. if (preg_match('/' . $pattern . '/i', $email)) {
  2258. // Set user type to internal
  2259. $this->setUserType(self::USER_TYPE_INTERNAL);
  2260. // Persist the change to the database
  2261. $entityManager->persist($this);
  2262. $entityManager->flush();
  2263. return true;
  2264. }
  2265. }
  2266. // In case the user's email does not match we check to see if they have an admin role and avoid an infinite loop.
  2267. if (!$isRecursive) {
  2268. return $this->updateUserTypeInternal($repository, $entityManager);
  2269. }
  2270. return false;
  2271. }
  2272. /**
  2273. * Update user to internal type if they have medbrief email address and have an admin or super admin role.
  2274. *
  2275. * @param UserInternalRepository $repository
  2276. * @param EntityManagerInterface $entityManager
  2277. *
  2278. * @return bool
  2279. */
  2280. public function updateUserTypeInternal(UserInternalRepository $repository, EntityManagerInterface $entityManager): bool
  2281. {
  2282. // Check if the user is already internal
  2283. if ($this->userType === self::USER_TYPE_INTERNAL) {
  2284. return false;
  2285. }
  2286. if ($this->isUserInternal($repository, $entityManager, true) && (in_array(self::DEFAULT_ROLE_ADMIN, $this->roles) || in_array(self::DEFAULT_ROLE_SUPER_ADMIN, $this->roles))) {
  2287. $this->userType = self::USER_TYPE_INTERNAL;
  2288. $entityManager->persist($this);
  2289. $entityManager->flush();
  2290. return true;
  2291. }
  2292. return false;
  2293. }
  2294. /**
  2295. * This method tracks whether the 'Billed' checkbox is visible to MB Admins
  2296. *
  2297. * @return bool
  2298. */
  2299. public function hasAccessToBilled(): bool
  2300. {
  2301. return $this->accessToBilled;
  2302. }
  2303. /**
  2304. * This method sets whether a MB Admin can view the 'Billed' checkbox.
  2305. *
  2306. * @param bool $value
  2307. *
  2308. * @return self
  2309. */
  2310. public function setAccessToBilled(bool $value): self
  2311. {
  2312. $this->accessToBilled = $value;
  2313. return $this;
  2314. }
  2315. /**
  2316. * This method fetches the value which determines whether a MB Admin can view the 'Billed' checkbox.
  2317. *
  2318. * @return bool
  2319. */
  2320. public function getAccessToBilled(): bool
  2321. {
  2322. return $this->accessToBilled;
  2323. }
  2324. /**
  2325. * @return DateTime|null
  2326. */
  2327. public function getLegacyRadiologyViewerLastUsed()
  2328. {
  2329. return $this->legacyRadiologyViewerLastUsed;
  2330. }
  2331. /**
  2332. * @param DateTime|null $legacyRadiologyViewerLastUsed
  2333. *
  2334. * @return self
  2335. */
  2336. public function setLegacyRadiologyViewerLastUsed(?DateTime $legacyRadiologyViewerLastUsed = null): self
  2337. {
  2338. $this->legacyRadiologyViewerLastUsed = $legacyRadiologyViewerLastUsed;
  2339. return $this;
  2340. }
  2341. }