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