<?php
namespace MedBrief\MSR\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use DH\Auditor\Provider\Doctrine\Auditing\Annotation as Audit;
use Doctrine\Common\Collections\Collection as DoctrineCollection;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use libphonenumber\PhoneNumber;
use MedBrief\MSR\Entity\Analytics\AnalyticsUser;
use MedBrief\MSR\Model\User\MultiFactorEnabledUser;
use MedBrief\MSR\Repository\UserInternalRepository;
use MedBrief\MSR\Repository\UserRepository;
use MedBrief\MSR\Security\AdvancedUserInterface;
use MedBrief\MSR\Traits\FilterableClassConstantsTrait;
use Ramsey\Uuid\Uuid;
use Symfony\Component\Security\Core\User\EquatableInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
/**
* @ApiResource(
* itemOperations={
* "get"={"access_control"="is_granted('READ', object)"}
* },
* attributes={
* "normalization_context"={"groups"={"user:read"}}
* }
* )
*
* @ORM\Table(name="fos_user")
*
* @ORM\Entity(repositoryClass=UserRepository::class)
*
* @ORM\HasLifecycleCallbacks
*
* @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false)
*
* @Audit\Auditable
*
* @Audit\Security(view={"ROLE_ALLOWED_TO_AUDIT"})
*/
class User extends MultiFactorEnabledUser implements AdvancedUserInterface, EquatableInterface
{
use FilterableClassConstantsTrait;
// CONSTANTS
public const NOTIFICATION_STATUS_PENDING = 1;
public const NOTIFICATION_STATUS_SENT = 2;
public const NOTIFICATION_STATUS_FAILED = 3;
public const NOTIFICATION_STATUS_UNSUBSCRIBE = 4;
public const NOTIFICATION_FORMAT_PREFERENCE_EMAIL = UserNotification::NOTIFICATION_FORMAT_EMAIL;
public const NOTIFICATION_FORMAT_PREFERENCE_SMS = UserNotification::NOTIFICATION_FORMAT_SMS;
public const NOTIFICATION_FORMAT_PREFERENCE_PUSH = UserNotification::NOTIFICATION_FORMAT_PUSH;
public const USER_TYPE_INTERNAL = 'internal';
public const USER_TYPE_INTERNAL__LABEL = 'Internal';
public const USER_TYPE_CLIENT = 'client';
public const USER_TYPE_CLIENT__LABEL = 'Client';
public const USER_TYPE_EXPERT = 'expert';
public const USER_TYPE_EXPERT__LABEL = 'Expert';
public const USER_TYPE_OTHER = 'other';
public const USER_TYPE_OTHER__LABEL = 'Other';
public const DEFAULT_ROLE_SUPER_ADMIN = 'ROLE_SUPER_ADMIN';
public const DEFAULT_ROLE_SUPER_ADMIN__LABEL = 'MedBrief Super Administrator';
public const DEFAULT_ROLE_ADMIN = 'ROLE_ADMIN';
public const DEFAULT_ROLE_ADMIN__LABEL = 'MedBrief Administrator';
// PROTECTED VARIABLES
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
*
* @ORM\Id
*
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
protected $id;
/**
* @var string
*
* @ORM\Column(name="password", type="string", length=255)
*/
protected $password;
/**
* @var string|null
*
* @ORM\Column(name="salt", type="string", length=255, nullable=true)
*/
protected $salt;
/**
* @var bool
*
* @ORM\Column(name="enabled", type="boolean")
*/
protected $enabled = false;
/**
* @var \DateTime|null
*
* @ORM\Column(name="last_login", type="datetime", nullable=true)
*/
protected $last_login;
/**
* @var array
*
* @ORM\Column(name="roles", type="array")
*/
protected $roles = [];
/**
* @var string|null
*
* @ORM\Column(name="first_name", type="string", length=255, nullable=true)
*/
protected $first_name;
/**
* @var string|null
*
* @ORM\Column(name="last_name", type="string", length=255, nullable=true)
*/
protected $last_name;
/**
* @var \DateTime
*
* @ORM\Column(name="created", type="datetime")
*
* @Gedmo\Timestampable(on="create")
*/
protected $created;
/**
* @var \DateTime
*
* @ORM\Column(name="updated", type="datetime")
*
* @Gedmo\Timestampable(on="update")
*/
protected $updated;
/**
* @var \DateTime|null
*
* @ORM\Column(name="deletedAt", type="datetime", nullable=true)
*/
protected $deletedAt;
/**
* @var string
*
* @ORM\Column(name="search_index", type="text", nullable=false)
*/
protected $search_index;
/**
* @var string|null
*
* @ORM\Column(name="phone_number", type="string", length=155, nullable=true)
*/
protected $phoneNumber;
/**
* @var \DateTime|null
*
* @ORM\Column(name="lastActivity", type="datetime", nullable=true)
*
* @Audit\Ignore
*/
protected $lastActivity;
/**
* @var \DateTime|null
*
* @ORM\Column(name="firstLoginDate", type="datetime", nullable=true)
*/
protected $firstLoginDate;
/**
* Whether the user account is locked or not
*
* @var bool|null
*
* @ORM\Column(name="locked", type="boolean", nullable=true, options={"default"=false})
*/
protected $locked = false;
/**
* @var string
*/
protected $plainPassword;
/**
* mobileNumber - Used for SMS verification.
*
* @var PhoneNumber|null
*
* @ORM\Column(name="mobileNumber", type="phone_number", nullable=true)
*/
private $mobileNumber;
/**
* @var bool
*
* @ORM\Column(name="hasDocSorterAccess", type="boolean")
*/
private $hasDocSorterAccess = false;
/**
* Whether a User has billing admin rights
*
* @var bool
*
* @ORM\Column(name="billingAdmin", type="boolean", options={"default"=false})
*/
private $billingAdmin = false;
/**
* @var bool
*
* @ORM\Column(name="matterDashboardEnabled", type="boolean")
*/
private $matterDashboardEnabled = false;
/**
* @var string|null
*
* @ORM\Column(name="userType", type="string", length=255, nullable=true)
*/
private $userType;
/**
* @var string|null
*
* @ORM\Column(name="azureId", type="string", length=255, nullable=true)
*/
private $azureId;
/**
* @var bool
*
* @ORM\Column(name="receiveDailyUploadNotificationEmail", type="boolean")
*/
private $receiveDailyUploadNotificationEmail = true;
/**
* @var bool|null
*
* @ORM\Column(name="tfaEnabled", type="boolean", nullable=true)
*/
private $tfaEnabled;
/**
* @var string|null
*
* @ORM\Column(name="tfaUserId", type="string", nullable=true)
*/
private $tfaUserId;
/**
* @var int|null
*
* @ORM\Column(name="notificationStatus", type="integer", nullable=true)
*/
private $notificationStatus;
/**
* The User's own preference for the format they would like to receive UserNotifications in
*
* @var int
*
* @ORM\Column(name="notificationFormatPreference", type="integer", options={"default"="1"})
*/
private $notificationFormatPreference = self::NOTIFICATION_FORMAT_PREFERENCE_EMAIL;
/**
* @var Invitation
*
* @ORM\OneToOne(targetEntity="MedBrief\MSR\Entity\Invitation", inversedBy="user", cascade={"remove"})
*
* @ORM\JoinColumns({
*
* @ORM\JoinColumn(name="invitation_id", referencedColumnName="code", unique=true)
* })
*/
private $invitation;
/**
* @var HumanResource
*
* @ORM\OneToOne(targetEntity="MedBrief\MSR\Entity\HumanResource", mappedBy="user")
*/
private $humanResource;
/**
* @var AnalyticsUser
*
* @ORM\OneToOne(targetEntity="MedBrief\MSR\Entity\Analytics\AnalyticsUser", mappedBy="user", cascade={"persist","remove"})
*/
private $analyticsUser;
/**
* @var LinkedEmailAddressInvitation
*
* @ORM\OneToOne(targetEntity="MedBrief\MSR\Entity\LinkedEmailAddressInvitation", mappedBy="userToLink", cascade={"persist","remove"})
*/
private $linkedEmailAddressInvitation;
/**
* @var DoctrineCollection
*
* @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\Document", mappedBy="creator", cascade={"detach"})
*/
private $documents;
/**
* @var DoctrineCollection
*
* @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\Disc", mappedBy="creator", cascade={"detach"})
*/
private $discs;
/**
* @var DoctrineCollection
*
* @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\Project", mappedBy="manager", cascade={"detach"})
*/
private $managedProjects;
/**
* @var DoctrineCollection
*
* @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\RoleInvitation", mappedBy="user", cascade={"persist","remove"})
*/
private $roleInvitations;
/**
* @var DoctrineCollection
*
* @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\LinkedEmailAddressInvitation", mappedBy="user", cascade={"persist","remove"})
*/
private $linkedEmailAddressInvitations;
/**
* @var DoctrineCollection
*
* @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\DiscImportSession", mappedBy="creator", cascade={"all"})
*/
private $discImportSessions;
/**
* @var DoctrineCollection
*
* @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\ProjectUser", mappedBy="user", cascade={"all"})
*/
private $projectUsers;
/**
* @var DoctrineCollection
*
* @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\Invitation", mappedBy="creator", cascade={"persist","detach","merge","refresh"})
*/
private $invitationsCreated;
/**
* @var DoctrineCollection
*
* @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\User", mappedBy="creator")
*/
private $usersCreated;
/**
* @var DoctrineCollection
*
* @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\RecordsRequestDetail", mappedBy="creator")
*/
private $recordsRequestDetails;
/**
* @var DoctrineCollection
*
* @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\ChronologyItem", mappedBy="creator")
*/
private $chronologyItemsCreated;
/**
* This relates to the UserNotifications that have been sent or are queued to send to the User
*
* @var DoctrineCollection
*
* @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\UserNotification", mappedBy="recipient", cascade={"persist","remove"})
*/
private $notifications;
/**
* @var DoctrineCollection
*
* @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\MatterNote", mappedBy="creator")
*/
private $matterNotes;
/**
* @var DoctrineCollection
*
* @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\LinkedEmailAddress", mappedBy="user")
*/
private $linkedEmailAddress;
/**
* @var DoctrineCollection
*
* @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\ProjectClosure", mappedBy="closedBy")
*/
private $projectClosures;
/**
* @var Account
*
* @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\Account")
*
* @ORM\JoinColumns({
*
* @ORM\JoinColumn(name="account_id", referencedColumnName="id")
* })
*/
private $account;
/**
* @var ExpertAgency
*
* @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\ExpertAgency", inversedBy="users")
*
* @ORM\JoinColumns({
*
* @ORM\JoinColumn(name="expertAgency_id", referencedColumnName="id")
* })
*/
private $expertAgency;
/**
* @var User
*
* @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\User", inversedBy="usersCreated")
*
* @ORM\JoinColumns({
*
* @ORM\JoinColumn(name="creator_id", referencedColumnName="id", nullable=true)
* })
*/
private $creator;
/**
* @var DoctrineCollection
*
* @ORM\ManyToMany(targetEntity="MedBrief\MSR\Entity\Specialisation")
*
* @ORM\JoinTable(name="user_specialisation",
* joinColumns={
*
* @ORM\JoinColumn(name="user_id", referencedColumnName="id", onDelete="CASCADE")
* },
* inverseJoinColumns={
* @ORM\JoinColumn(name="specialisation_id", referencedColumnName="id", onDelete="CASCADE")
* }
* )
*
* @ORM\OrderBy({
* "title"="ASC"
* })
*/
private $specialisations;
/**
* @var DoctrineCollection
*
* @ORM\ManyToMany(targetEntity="MedBrief\MSR\Entity\Project")
*
* @ORM\JoinTable(name="user_project",
* joinColumns={
*
* @ORM\JoinColumn(name="user_id", referencedColumnName="id", onDelete="CASCADE")
* },
* inverseJoinColumns={
* @ORM\JoinColumn(name="project_id", referencedColumnName="id", onDelete="CASCADE")
* }
* )
*/
private $favouriteProjects;
private $azureAccessToken;
/**
* @ORM\OneToMany(targetEntity=ClinicalSummary::class, mappedBy="creator")
*/
private $clinicalSummaries;
/**
* This property will track whether the 'Billed' checkbox in various modals is visible to MB Admins.
*
* @ORM\Column(type="boolean", options={"default": false})
*/
private bool $accessToBilled = false;
/**
* @var \DateTime|null
*
* @ORM\Column(name="legacyRadiologyViewerLastUsed", type="datetime", nullable=true)
*/
private $legacyRadiologyViewerLastUsed;
public function __construct()
{
$this->username = Uuid::uuid4()->toString();
$this->documents = new \Doctrine\Common\Collections\ArrayCollection();
$this->discs = new \Doctrine\Common\Collections\ArrayCollection();
$this->managedProjects = new \Doctrine\Common\Collections\ArrayCollection();
$this->roleInvitations = new \Doctrine\Common\Collections\ArrayCollection();
$this->linkedEmailAddressInvitations = new \Doctrine\Common\Collections\ArrayCollection();
$this->discImportSessions = new \Doctrine\Common\Collections\ArrayCollection();
$this->projectUsers = new \Doctrine\Common\Collections\ArrayCollection();
$this->invitationsCreated = new \Doctrine\Common\Collections\ArrayCollection();
$this->usersCreated = new \Doctrine\Common\Collections\ArrayCollection();
$this->recordsRequestDetails = new \Doctrine\Common\Collections\ArrayCollection();
$this->chronologyItemsCreated = new \Doctrine\Common\Collections\ArrayCollection();
$this->notifications = new \Doctrine\Common\Collections\ArrayCollection();
$this->matterNotes = new \Doctrine\Common\Collections\ArrayCollection();
$this->linkedEmailAddress = new \Doctrine\Common\Collections\ArrayCollection();
$this->projectClosures = new \Doctrine\Common\Collections\ArrayCollection();
$this->specialisations = new \Doctrine\Common\Collections\ArrayCollection();
$this->favouriteProjects = new \Doctrine\Common\Collections\ArrayCollection();
$this->clinicalSummaries = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Returns a textual representation of this user (their full name)
*/
public function __toString()
{
return $this->getFullName();
}
/**
* @return int|null
*/
public function getId(): ?int
{
return $this->id;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUsername(): string
{
return (string) $this->username;
}
/**
* @param string $username
*
* @return $this
*/
public function setUsername(string $username): self
{
$this->username = $username;
return $this;
}
/**
* @see UserInterface
*/
public function getRoles(): array
{
$roles = $this->roles;
// guarantee every user at least has ROLE_USER
$roles[] = 'ROLE_USER';
return array_unique($roles);
}
/**
* @param array $roles
*
* @return $this
*/
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
/**
* @param string $role
*
* @return $this
*/
public function addRole(string $role)
{
$this->roles[] = $role;
return $this;
}
/**
* @param string $role
*
* @return $this
*/
public function removeRole(string $role)
{
if (($key = array_search($role, $this->roles)) !== false) {
unset($this->roles[$key]);
}
return $this;
}
/**
* @see UserInterface
*/
public function getPassword(): string
{
return $this->password;
}
/**
* @param string $password
*
* @return $this
*/
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* Returning a salt is only needed, if you are not using a modern
* hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
*
* @see UserInterface
*/
public function getSalt(): ?string
{
return $this->salt;
}
/**
* Setting a salt is generally unnecessary (modern hashing algorithms), but we have implemented this so that we can
* clear the salt on upgrade of a User's password.
*
* @param string|null $salt
*
* @return $this
*/
public function setSalt(?string $salt)
{
$this->salt = $salt;
return $this;
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
/**
* @return bool
*/
public function isEnabled()
{
return $this->enabled;
}
/**
* @return mixed
*/
public function getLastLogin()
{
return $this->last_login;
}
/**
* @param mixed $last_login
*
* @return User
*/
public function setLastLogin($last_login)
{
$this->last_login = $last_login;
return $this;
}
/**
* @return string
*/
public function getAzureId()
{
return $this->azureId;
}
/**
* @param string $azureId
*
* @return User
*/
public function setAzureId($azureId)
{
$this->azureId = $azureId;
return $this;
}
/**
* @return string
*/
public function getAzureAccessToken()
{
return $this->azureAccessToken;
}
/**
* @param mixed $azureAccessToken
*
* @return User
*/
public function setAzureAccessToken($azureAccessToken)
{
$this->azureAccessToken = $azureAccessToken;
return $this;
}
/**
* @return string
*/
public function getMicrosoftId()
{
return $this->getAzureId();
}
/**
* @param mixed $azureId
*
* @return User
*/
public function setMicrosoftId($azureId)
{
return $this->setAzureId($azureId);
}
/**
* @return string
*/
public function getMicrosoftAccessToken()
{
return $this->getAzureAccessToken();
}
/**
* @param mixed $azureAccessToken
*
* @return User
*/
public function setMicrosoftAccessToken($azureAccessToken)
{
return $this->setAzureAccessToken($azureAccessToken);
}
/**
* @return string
*/
public function getFullName()
{
$prefix = '';
if ($this->getDeletedAt() !== null) {
$prefix = '[REMOVED] ';
}
return $prefix . trim($this->getFirstName() . ' ' . $this->getLastName());
}
/**
* @param string $first_name
*
* @return User
*/
public function setFirstName($first_name)
{
$this->first_name = $first_name;
return $this;
}
/**
* @Groups({"user:read", "matter_request:read", "account:read"})
*
* @return string
*/
public function getFirstName()
{
return $this->first_name;
}
/**
* @param string $last_name
*
* @return User
*/
public function setLastName($last_name)
{
$this->last_name = $last_name;
return $this;
}
/**
* @Groups({"user:read", "matter_request:read", "account:read"})
*
* @return string
*/
public function getLastName()
{
return $this->last_name;
}
/**
* @param \DateTime $created
*
* @return User
*/
public function setCreated($created)
{
$this->created = $created;
return $this;
}
/**
* @return \DateTime
*/
public function getCreated()
{
return $this->created;
}
/**
* @param \DateTime $updated
*
* @return User
*/
public function setUpdated($updated)
{
$this->updated = $updated;
return $this;
}
/**
* @return \DateTime
*/
public function getUpdated()
{
return $this->updated;
}
/**
* @param string $search_index
*
* @return User
*/
public function setSearchIndex($search_index)
{
$this->search_index = $search_index;
return $this;
}
/**
* @return string
*/
public function getSearchIndex()
{
return $this->search_index;
}
/**
* @param Account|null $account
*
* @return User
*/
public function setAccount(?Account $account = null)
{
$this->account = $account;
return $this;
}
/**
* @return Account
*/
public function getAccount()
{
return $this->account;
}
/**
* @param string $phoneNumber
*
* @return User
*/
public function setPhoneNumber($phoneNumber)
{
$this->phoneNumber = $phoneNumber;
return $this;
}
/**
* @return string
*/
public function getPhoneNumber()
{
return $this->phoneNumber;
}
/**
* @param Document $documents
*
* @return User
*/
public function addDocument(Document $documents)
{
$this->documents[] = $documents;
return $this;
}
/**
* @param Document $documents
*/
public function removeDocument(Document $documents)
{
$this->documents->removeElement($documents);
}
/**
* @return DoctrineCollection
*/
public function getDocuments()
{
return $this->documents;
}
/**
* @param Project $managedProjects
*
* @return User
*/
public function addManagedProject(Project $managedProjects)
{
$this->managedProjects[] = $managedProjects;
return $this;
}
/**
* @param Project $managedProjects
*/
public function removeManagedProject(Project $managedProjects)
{
$this->managedProjects->removeElement($managedProjects);
}
/**
* @return DoctrineCollection
*/
public function getManagedProjects()
{
return $this->managedProjects;
}
/**
* @param Invitation|null $invitation
*
* @return User
*/
public function setInvitation(?Invitation $invitation = null)
{
$this->invitation = $invitation;
return $this;
}
/**
* @return Invitation
*/
public function getInvitation()
{
return $this->invitation;
}
/**
* This is a validation callback function specified in our validation.yml file
*
* @param ExecutionContextInterface $context
*/
public function validate(ExecutionContextInterface $context)
{
// this user is not valid if their email address does not match that of their invitation
if (trim($this->getEmail()) != trim($this->getInvitation()->getEmail())) {
$context->buildViolation('This email address does not match the one on the invitation')
->atPath('email')
->addViolation()
;
}
}
/**
* @param RoleInvitation $roleInvitations
*
* @return User
*/
public function addRoleInvitation(RoleInvitation $roleInvitations)
{
$this->roleInvitations[] = $roleInvitations;
return $this;
}
/**
* @param RoleInvitation $roleInvitations
*/
public function removeRoleInvitation(RoleInvitation $roleInvitations)
{
$this->roleInvitations->removeElement($roleInvitations);
}
/**
* @return DoctrineCollection
*/
public function getRoleInvitations()
{
return $this->roleInvitations;
}
/**
* Checks to see if this entity has a RoleInvitation that matches the given
* role. If there is one, it is returned.
*
* @param $role
*
* @return RoleInvitation|null
*/
public function getMatchingRoleInvitation($role)
{
foreach ($this->getRoleInvitations() as $roleInvitation) {
if ($role == $roleInvitation->getRole()) {
return $roleInvitation;
}
}
return null;
}
/**
* Checks to see if this entity has a RoleInvitation that is pending
* approval and matches the given role. If there is one, it is returned.
*
* @param $role
*
* @return RoleInvitation|null
*/
public function getMatchingRoleInvitationPendingApproval($role)
{
foreach ($this->getRoleInvitations() as $roleInvitation) {
if ($role == $roleInvitation->getRole()
&& ($roleInvitation->getStatus() == RoleInvitation::STATUS_PENDING_APPROVAL
|| $roleInvitation->getStatus() == RoleInvitation::STATUS_SUPPRESSED)) {
return $roleInvitation;
}
}
return null;
}
/**
* Checks to see if this entity has a RoleInvitation that is pending one-time authentication
* and matches the given role. If there is one, it is returned.
*
* @param $role
*
* @return bool
*/
public function getMatchingRoleInvitationPendingAuthentication($role)
{
foreach ($this->getRoleInvitations() as $roleInvitation) {
if ($role == $roleInvitation->getRole()
&& $roleInvitation->getStatus() == RoleInvitation::STATUS_PENDING_AUTHENTICATION) {
return $roleInvitation;
}
}
return null;
}
/**
* Checks to see if this entity has an accepted RoleInvitation that
* matches the given role.
*
* @param $role
*
* @return bool
*/
public function hasMatchingAcceptedRoleInvitation($role): bool
{
foreach ($this->getRoleInvitations() as $roleInvitation) {
if ($role === $roleInvitation->getRole() && $roleInvitation->getAccepted() !== null) {
return true;
}
}
return false;
}
/**
* Returns true if this user has any RoleInvitations linked directly to them
* or their Invitation that are in PENDING_APPROVAL state
*
* @return bool
*/
public function hasRoleInvitationsPendingApproval()
{
$roleInvitations = $this->getPendingRoleInvitations();
return !empty($roleInvitations);
}
/**
* Returns true if this user has any RoleInvitations linked directly to them
* or their Invitation that are in PENDING_APPROVAL state
*
* @param string $role
*
* @return bool
*/
public function hasMatchingRoleInvitationsPendingApproval($role): bool
{
$roleInvitations = $this->getMatchingRoleInvitationPendingApproval($role);
return !empty($roleInvitations);
}
/**
* Gets all the Pending RoleInvitations linked to this user and to their
* invitation
*
* @return array
*/
public function getPendingRoleInvitations()
{
$array = [];
foreach ($this->getRoleInvitations() as $roleInvitation) {
if ($roleInvitation->getStatus() == RoleInvitation::STATUS_PENDING_APPROVAL
|| $roleInvitation->getStatus() == RoleInvitation::STATUS_SUPPRESSED) {
$array[] = $roleInvitation;
}
}
if ($this->getInvitation()) {
foreach ($this->getInvitation()->getRoleInvitations() as $roleInvitation) {
if ($roleInvitation->getStatus() == RoleInvitation::STATUS_PENDING_APPROVAL
|| $roleInvitation->getStatus() == RoleInvitation::STATUS_SUPPRESSED) {
$array[] = $roleInvitation;
}
}
}
return $array;
}
// @todo Should the below two be bundled in to the more accommodating functions with a "suppressed" arg?
/**
* Checks whether the User has any Role Invitations that are pending as well as not suppressed
*
* @return bool
*/
public function hasUnsuppressedRoleInvitationsPendingApproval()
{
$roleInvitations = $this->getUnsuppressedRoleInvitationsPending();
return !empty($roleInvitations);
}
/**
* Grabs all the Role Invitations for this User that are pending approval and not suppressed
*
* @return array
*/
public function getUnsuppressedRoleInvitationsPending()
{
$array = [];
foreach ($this->getRoleInvitations() as $roleInvitation) {
if ($roleInvitation->getStatus() == RoleInvitation::STATUS_PENDING_APPROVAL) {
$array[] = $roleInvitation;
}
}
if ($this->getInvitation()) {
foreach ($this->getInvitation()->getRoleInvitations() as $roleInvitation) {
if ($roleInvitation->getStatus() == RoleInvitation::STATUS_PENDING_APPROVAL) {
$array[] = $roleInvitation;
}
}
}
return $array;
}
/**
* Returns true if this user is a client administrator for at least one
* account. Note that this needs to match against Client Administrators and Client Super Administrators
*
* @return bool
*/
public function isAccountAdministrator()
{
foreach ($this->getRoles() as $role) {
if ((stripos($role, 'ROLE_ACCOUNT_') !== false && stripos($role, '_ADMINISTRATOR') !== false)
|| (stripos($role, 'ROLE_ACCOUNT_') !== false && stripos($role, '_SUPERADMINISTRATOR') !== false)) {
return true;
}
}
return false;
}
/**
* Checks whether a user is the Technical Administrator for *ANY* account
*
* @return bool
*/
public function isAccountTechnicalAdmin(): bool
{
foreach ($this->getRoles() as $role) {
if (preg_match('/ROLE_ACCOUNT_\d+_TECHNICAL_ADMIN/', $role)) {
return true;
}
}
return false;
}
/**
* Checks whether a user is a sorter for *ANY* account
*
* @return bool
*/
public function isAccountSorter(): bool
{
foreach ($this->getRoles() as $role) {
if (preg_match('/ROLE_ACCOUNT_\d+_SORTER/', $role)) {
return true;
}
}
return false;
}
/**
* Checks whether a user is the Technical Administrator for a specific Account (basically the same as the Voter)
*
* @param Account $account
*
* @return bool
*/
public function isTechnicalAdminForSpecificAccount(Account $account): bool
{
$accountId = $account->getId();
foreach ($this->getRoles() as $role) {
if (preg_match("/ROLE_ACCOUNT_{$accountId}_TECHNICAL_ADMIN/", $role)) {
return true;
}
}
return false;
}
/**
* Returns true if this user is a client administrator for the specified Account.
* Note that this needs to match against Client Administrators and Client Super Administrators
*
* @param Account $account
*
* @return bool
*/
public function isAccountAdministratorForAccount(Account $account)
{
foreach ($this->getRoles() as $role) {
if (
$role == sprintf('ROLE_ACCOUNT_%1$s_ADMINISTRATOR', $account->getId())
|| $role == sprintf('ROLE_ACCOUNT_%1$s_SUPERADMINISTRATOR', $account->getId())
) {
return true;
}
}
return false;
}
/**
* Returns true if this user is a client project manager for at least one
* account.
*
* @return bool
*/
public function isAccountProjectManager()
{
foreach ($this->getRoles() as $role) {
if ((stripos($role, 'ROLE_ACCOUNT_') !== false && stripos($role, '_PROJECTMANAGER') !== false)) {
return true;
}
}
return false;
}
/**
* Returns true if this user is a client project manager for the specified Account.
*
* @param Account $account
*
* @return bool
*/
public function isAccountProjectManagerForAccount(Account $account)
{
foreach ($this->getRoles() as $role) {
if ($role == sprintf('ROLE_ACCOUNT_%1$s_PROJECTMANAGER', $account->getId())) {
return true;
}
}
return false;
}
/**
* Returns true if this user is a client project manager for the specified Project.
*
* @param Project $project
*
* @return bool
*/
public function isProjectManagerForSpecificProject(Project $project)
{
foreach ($this->getRoles() as $role) {
if ($role == sprintf('ROLE_PROJECT_%1$s_PROJECTMANAGER', $project->getId())) {
return true;
}
}
return false;
}
/**
* Returns true if this user is a expert agency administrator
*
* @return bool
*/
public function isExpertAgencyAdministrator()
{
foreach ($this->getRoles() as $role) {
if (stripos($role, 'ROLE_EXPERTAGENCY_') !== false && stripos($role, '_ADMINISTRATOR') !== false) {
return true;
}
}
return false;
}
/**
* Returns true if this user is a project manager for at least one project
*
* @return bool
*/
public function isProjectManager()
{
foreach ($this->getRoles() as $role) {
if (stripos($role, 'ROLE_PROJECT_') !== false && stripos($role, '_PROJECTMANAGER') !== false) {
return true;
}
}
return false;
}
/**
* Returns true if this user is a project scanner for at least one project
*
* @return bool
*/
public function isProjectScanner(): bool
{
foreach ($this->getRoles() as $role) {
if (preg_match('/ROLE_PROJECT_\d+_SCANNER/', $role)) {
return true;
}
}
return false;
}
/**
* Returns true if this user is a project scanner downloader for at least one project
*
* @return bool
*/
public function isProjectScannerDownload(): bool
{
foreach ($this->getRoles() as $role) {
if (stripos($role, 'ROLE_PROJECT_') !== false && stripos($role, '_SCANNERDOWNLOAD') !== false) {
return true;
}
}
return false;
}
/**
* Returns true if this user only has expert roles or role invitations associated with their account.
*
* @return bool
*/
public function isExpertOnly()
{
if ($this->getRoles()) {
foreach ($this->getRoles() as $role) {
if ((stripos($role, 'ROLE_PROJECT_') === false || stripos($role, '_EXPERT') === false) && $role !== 'ROLE_USER') {
return false;
}
}
}
foreach ($this->getRoleInvitations() as $invitation) {
if (stripos($invitation->getRole(), 'ROLE_PROJECT_') === false || stripos($invitation->getRole(), '_EXPERT') === false) {
return false;
}
}
return true;
}
/**
* Returns true if the user only has an expert viewer role or role invitations, associated with their account.
*
* @return bool
*/
public function isExpertViewerOnly()
{
if ($this->getRoles()) {
foreach ($this->getRoles() as $role) {
if ((stripos($role, 'ROLE_PROJECT_') === false || stripos($role, '_EXPERTVIEWER') === false) && $role !== 'ROLE_USER') {
return false;
}
}
}
foreach ($this->getRoleInvitations() as $invitation) {
if (stripos($invitation->getRole(), 'ROLE_PROJECT_') === false || stripos($invitation->getRole(), '_EXPERTVIEWER') === false) {
return false;
}
}
return true;
}
/**
* @param \DateTime $deletedAt
*
* @return User
*/
public function setDeletedAt($deletedAt)
{
$this->deletedAt = $deletedAt;
return $this;
}
/**
* @return \DateTime
*/
public function getDeletedAt()
{
return $this->deletedAt;
}
/**
* @param Disc $disc
*
* @return User
*/
public function addDisc(Disc $disc)
{
$this->discs[] = $disc;
return $this;
}
/**
* @param Disc $disc
*/
public function removeDisc(Disc $disc)
{
$this->discs->removeElement($disc);
}
/**
* @return DoctrineCollection
*/
public function getDiscs()
{
return $this->discs;
}
/**
* @param DiscImportSession $discImportSession
*
* @return User
*/
public function addDiscImportSession(DiscImportSession $discImportSession)
{
$this->discImportSessions[] = $discImportSession;
return $this;
}
/**
* @param DiscImportSession $discImportSession
*/
public function removeDiscImportSession(DiscImportSession $discImportSession)
{
$this->discImportSessions->removeElement($discImportSession);
}
/**
* @return DoctrineCollection
*/
public function getDiscImportSessions()
{
return $this->discImportSessions;
}
/**
* @param ProjectUser $projectUser
*
* @return User
*/
public function addProjectUser(ProjectUser $projectUser)
{
$this->projectUsers[] = $projectUser;
return $this;
}
/**
* @param ProjectUser $projectUser
*/
public function removeProjectUser(ProjectUser $projectUser)
{
$this->projectUsers->removeElement($projectUser);
}
/**
* @return DoctrineCollection
*/
public function getProjectUsers()
{
return $this->projectUsers;
}
/**
* @param Invitation $invitationsCreated
*
* @return User
*/
public function addInvitationsCreated(Invitation $invitationsCreated)
{
$this->invitationsCreated[] = $invitationsCreated;
return $this;
}
/**
* @param Invitation $invitationsCreated
*/
public function removeInvitationsCreated(Invitation $invitationsCreated)
{
$this->invitationsCreated->removeElement($invitationsCreated);
}
/**
* @return DoctrineCollection
*/
public function getInvitationsCreated()
{
return $this->invitationsCreated;
}
/**
* @param ExpertAgency|null $expertAgency
*
* @return User
*/
public function setExpertAgency(?ExpertAgency $expertAgency = null)
{
$this->expertAgency = $expertAgency;
return $this;
}
/**
* @return ExpertAgency
*/
public function getExpertAgency()
{
return $this->expertAgency;
}
/**
* @param \DateTime $lastActivity
*
* @return User
*/
public function setLastActivity($lastActivity)
{
$this->lastActivity = $lastActivity;
return $this;
}
/**
* @return \DateTime
*/
public function getLastActivity()
{
return $this->lastActivity;
}
/**
* @return bool whether the user is active or not
*/
public function isActiveNow()
{
$delay = new \DateTime('2 minutes ago');
return $this->getlastActivity() > $delay;
}
/**
* @param User $usersCreated
*
* @return User
*/
public function addUsersCreated(User $usersCreated)
{
$this->usersCreated[] = $usersCreated;
return $this;
}
/**
* @param User $usersCreated
*/
public function removeUsersCreated(User $usersCreated)
{
$this->usersCreated->removeElement($usersCreated);
}
/**
* @return DoctrineCollection
*/
public function getUsersCreated()
{
return $this->usersCreated;
}
/**
* @param User|null $creator
*
* @return User
*/
public function setCreator(?User $creator = null)
{
$this->creator = $creator;
return $this;
}
/**
* @return User
*/
public function getCreator()
{
return $this->creator;
}
/**
* @param bool $receiveDailyUploadNotificationEmail
*
* @return User
*/
public function setReceiveDailyUploadNotificationEmail($receiveDailyUploadNotificationEmail)
{
$this->receiveDailyUploadNotificationEmail = $receiveDailyUploadNotificationEmail;
return $this;
}
/**
* @return bool
*/
public function getReceiveDailyUploadNotificationEmail()
{
return $this->receiveDailyUploadNotificationEmail;
}
/**
* @param ChronologyItem $chronologyItemsCreated
*
* @return User
*/
public function addChronologyItemsCreated(ChronologyItem $chronologyItemsCreated)
{
$this->chronologyItemsCreated[] = $chronologyItemsCreated;
return $this;
}
/**
* @param ChronologyItem $chronologyItemsCreated
*/
public function removeChronologyItemsCreated(ChronologyItem $chronologyItemsCreated)
{
$this->chronologyItemsCreated->removeElement($chronologyItemsCreated);
}
/**
* @return DoctrineCollection
*/
public function getChronologyItemsCreated()
{
return $this->chronologyItemsCreated;
}
/**
* @param RecordsRequestDetail $recordsRequestDetail
*
* @return User
*/
public function addRecordsRequestDetail(RecordsRequestDetail $recordsRequestDetail)
{
$this->recordsRequestDetails[] = $recordsRequestDetail;
return $this;
}
/**
* @param RecordsRequestDetail $recordsRequestDetail
*/
public function removeRecordsRequestDetail(RecordsRequestDetail $recordsRequestDetail)
{
$this->recordsRequestDetails->removeElement($recordsRequestDetail);
}
/**
* @return DoctrineCollection
*/
public function getRecordsRequestDetails()
{
return $this->recordsRequestDetails;
}
/**
* @return bool
*/
public function isAccountNonLocked()
{
return !$this->locked;
}
/**
* @return bool
*/
public function isLocked()
{
return !$this->isAccountNonLocked();
}
/**
* @param $boolean
*
* @return $this
*/
public function setLocked($boolean)
{
$this->locked = $boolean;
return $this;
}
/**
* @param PhoneNumber $mobileNumber
*
* @return User
*/
public function setMobileNumber($mobileNumber)
{
$this->mobileNumber = $mobileNumber;
return $this;
}
/**
* @return PhoneNumber
*/
public function getMobileNumber()
{
return $this->mobileNumber;
}
/**
* @param int $notificationStatus
*
* @return User
*/
public function setNotificationStatus($notificationStatus)
{
$this->notificationStatus = $notificationStatus;
return $this;
}
/**
* @return int
*/
public function getNotificationStatus()
{
return $this->notificationStatus;
}
/**
* @param int $notificationFormatPreference
*
* @return User
*/
public function setNotificationFormatPreference($notificationFormatPreference)
{
$this->notificationFormatPreference = $notificationFormatPreference;
return $this;
}
/**
* @return int
*/
public function getNotificationFormatPreference()
{
return $this->notificationFormatPreference;
}
/**
* @param UserNotification $notification
*
* @return User
*/
public function addNotification(UserNotification $notification)
{
$this->notifications[] = $notification;
return $this;
}
/**
* @param UserNotification $notification
*/
public function removeNotification(UserNotification $notification)
{
$this->notifications->removeElement($notification);
}
/**
* @return DoctrineCollection
*/
public function getNotifications()
{
return $this->notifications;
}
/**
* @param bool $billingAdmin
*
* @return User
*/
public function setBillingAdmin($billingAdmin)
{
$this->billingAdmin = $billingAdmin;
return $this;
}
/**
* @return bool
*/
public function isBillingAdmin()
{
return $this->billingAdmin;
}
/**
* NOTE: Doctrine wants to add a ::getBillingAdmin() function but a User
* does not have a billingAdmin, but they can BE a billing admin. We will
* keep this here to appease the Doctrinosaurus.
*
* @return bool
*/
public function getBillingAdmin()
{
return $this->billingAdmin;
}
/**
* @param Specialisation $specialisation
*
* @return User
*/
public function addSpecialisation(Specialisation $specialisation)
{
$this->specialisations[] = $specialisation;
return $this;
}
/**
* @param Specialisation $specialisation
*/
public function removeSpecialisation(Specialisation $specialisation)
{
$this->specialisations->removeElement($specialisation);
}
/**
* @return DoctrineCollection
*/
public function getSpecialisations()
{
return $this->specialisations;
}
/**
* Check if this User has a particular Specialisation
*
* @param Specialisation $specialisation
*
* @return bool
*/
public function hasSpecialisation(Specialisation $specialisation)
{
return $this->getSpecialisations()->contains($specialisation);
}
/**
* @param Project $favouriteProject
*
* @return User
*/
public function addFavouriteProject(Project $favouriteProject)
{
$this->favouriteProjects[] = $favouriteProject;
return $this;
}
/**
* @param Project $favouriteProject
*/
public function removeFavouriteProject(Project $favouriteProject)
{
$this->favouriteProjects->removeElement($favouriteProject);
}
/**
* @return DoctrineCollection
*/
public function getFavouriteProjects()
{
return $this->favouriteProjects;
}
/**
* @return bool
*/
public function getLocked()
{
return $this->locked;
}
/**
* @param MatterNote $matterNote
*
* @return User
*/
public function addMatterNote(MatterNote $matterNote)
{
$this->matterNotes[] = $matterNote;
return $this;
}
/**
* @param MatterNote $matterNote
*/
public function removeMatterNote(MatterNote $matterNote)
{
$this->matterNotes->removeElement($matterNote);
}
/**
* @return DoctrineCollection
*/
public function getMatterNotes()
{
return $this->matterNotes;
}
public function isUser(?UserInterface $user = null): bool
{
return $user instanceof self && $user->id === $this->id;
}
/**
* @ORM\PrePersist
*/
public function copyEmailToUsername()
{
$this->setUsername($this->getEmail());
}
/**
* Updates the Search Index field with internal data. The Search Index Field
* provides an easy way to perform a 'like' query for a generalised search.
*
* @ORM\PrePersist
*
* @ORM\PreUpdate
*/
public function updateSearchIndex()
{
$searchIndex
= $this->getFullName()
. ' '
. $this->getEmail();
// Add any linked email address to the search index
/** @var LinkedEmailAddress $linkedEmailAddress */
foreach ($this->linkedEmailAddress as $linkedEmailAddress) {
$searchIndex .= ' ' . strtolower($linkedEmailAddress->getEmail());
}
$this->setSearchIndex($searchIndex);
}
/**
* @param HumanResource|null $humanResource
*
* @return User
*/
public function setHumanResource(?HumanResource $humanResource = null)
{
$this->humanResource = $humanResource;
return $this;
}
/**
* @return HumanResource|null
*/
public function getHumanResource()
{
return $this->humanResource;
}
/**
* @param AnalyticsUser|null $analyticsUser
*
* @return User
*/
public function setAnalyticsUser(?AnalyticsUser $analyticsUser = null)
{
$this->analyticsUser = $analyticsUser;
$this->analyticsUser->setUser($this);
return $this;
}
/**
* @return AnalyticsUser|null
*/
public function getAnalyticsUser()
{
return $this->analyticsUser;
}
/**
* @param LinkedEmailAddress $linkedEmailAddress
*
* @return User
*/
public function addLinkedEmailAddress(LinkedEmailAddress $linkedEmailAddress)
{
$this->linkedEmailAddress[] = $linkedEmailAddress;
// Update the search index, so we include the newly linked email address
$this->updateSearchIndex();
return $this;
}
/**
* @param LinkedEmailAddress $linkedEmailAddress
*
* @return bool TRUE if this collection contained the specified element, FALSE otherwise.
*/
public function removeLinkedEmailAddress(LinkedEmailAddress $linkedEmailAddress)
{
$returnValue = $this->linkedEmailAddress->removeElement($linkedEmailAddress);
// Update the search index, so we exclude the removed linked email address
$this->updateSearchIndex();
return $returnValue;
}
/**
* @return DoctrineCollection
*/
public function getLinkedEmailAddress()
{
return $this->linkedEmailAddress;
}
/**
* @param string $linkedEmailAddress
*
* @return bool
*/
public function hasLinkedEmailAddress(string $linkedEmailAddress): bool
{
$linkedEmailAddresses = array_map(function (LinkedEmailAddress $linkedEmailAddress) {
return $linkedEmailAddress->getEmail();
}, $this->getLinkedEmailAddress()->toArray());
if (!$linkedEmailAddresses) {
return false;
}
return in_array($linkedEmailAddress, $linkedEmailAddresses);
}
/**
* @param LinkedEmailAddressInvitation $linkedEmailAddressInvitation
*
* @return User
*/
public function addLinkedEmailAddressInvitation(LinkedEmailAddressInvitation $linkedEmailAddressInvitation)
{
$this->linkedEmailAddressInvitations[] = $linkedEmailAddressInvitation;
return $this;
}
/**
* @param LinkedEmailAddressInvitation $linkedEmailAddressInvitation
*
* @return bool TRUE if this collection contained the specified element, FALSE otherwise.
*/
public function removeLinkedEmailAddressInvitation(LinkedEmailAddressInvitation $linkedEmailAddressInvitation)
{
return $this->linkedEmailAddressInvitations->removeElement($linkedEmailAddressInvitation);
}
/**
* @return DoctrineCollection
*/
public function getLinkedEmailAddressInvitations()
{
return $this->linkedEmailAddressInvitations;
}
/**
* @param string $linkedEmailAddress
*
* @return bool
*/
public function hasMatchingLinkedEmailAddressInvitationPendingApproval(string $linkedEmailAddress): bool
{
$linkedEmailAddressInvitations = $this->getLinkedEmailAddressInvitations();
/** @var LinkedEmailAddressInvitation $linkedEmailAddressInvitation */
foreach ($linkedEmailAddressInvitations as $linkedEmailAddressInvitation) {
switch ($linkedEmailAddressInvitation->getStatus()) {
case LinkedEmailAddressInvitation::STATUS_PENDING_APPROVAL:
return $linkedEmailAddress == $linkedEmailAddressInvitation->getEmail();
case LinkedEmailAddressInvitation::STATUS_APPROVED:
case LinkedEmailAddressInvitation::STATUS_DECLINED:
default:
}
}
return false;
}
/**
* Grabs all the Role Invitations for this User that are pending approval and not suppressed
*
* @TODO this function seems inefficient, as it is basically just checking if the passed linkedEmailAddressInvitation is pending?
*
* @param LinkedEmailAddressInvitation $linkedEmailAddressInvitation
*
* @return array
*/
public function getLinkedEmailAddressInvitationPending(LinkedEmailAddressInvitation $linkedEmailAddressInvitation)
{
$linkedEmailAddresses = [];
if ($linkedEmailAddressInvitation->getStatus() == LinkedEmailAddressInvitation::STATUS_PENDING_APPROVAL) {
$linkedEmailAddresses[] = $linkedEmailAddressInvitation;
}
return $linkedEmailAddresses;
}
/**
* @param LinkedEmailAddressInvitation|null $linkedEmailAddressInvitation
*
* @return User
*/
public function setLinkedEmailAddressInvitation(?LinkedEmailAddressInvitation $linkedEmailAddressInvitation = null)
{
$this->linkedEmailAddressInvitation = $linkedEmailAddressInvitation;
return $this;
}
/**
* @return LinkedEmailAddressInvitation|null
*/
public function getLinkedEmailAddressInvitation()
{
return $this->linkedEmailAddressInvitation;
}
/**
* @param bool $matterDashboardEnabled
*
* @return User
*/
public function setMatterDashboardEnabled($matterDashboardEnabled)
{
$this->matterDashboardEnabled = $matterDashboardEnabled;
return $this;
}
/**
* @return bool
*/
public function getMatterDashboardEnabled()
{
return $this->matterDashboardEnabled;
}
/**
* @param bool $hasDocSorterAccess
*
* @return User
*/
public function setHasDocSorterAccess($hasDocSorterAccess)
{
$this->hasDocSorterAccess = $hasDocSorterAccess;
return $this;
}
/**
* @return bool
*/
public function getHasDocSorterAccess()
{
return $this->hasDocSorterAccess;
}
/**
* Returns user type options as an array, usable as the choices for a form.
*
* @throws \Exception
*
* @return array
*/
public static function getUserTypeOptions(): array
{
$matterCreationProcessOptions = self::getConstantsWithLabelsAsChoices('USER_TYPE');
return array_flip($matterCreationProcessOptions);
}
/**
* Get the value of userType
*
* @return string
*/
public function getUserType()
{
return $this->userType;
}
/**
* Returns true if the userType is USER_TYPE_INTERNAL
*
* @return bool
*/
public function isUserTypeInternal(): bool
{
return $this->getUserType() === self::USER_TYPE_INTERNAL;
}
/**
* @param string|null $userType
*
* @return self
*/
public function setUserType(?string $userType = null)
{
$this->userType = $userType;
return $this;
}
/**
* @return \DateTime
*/
public function getFirstLoginDate()
{
return $this->firstLoginDate;
}
/**
* @param \DateTime|null $firstLoginDate
*
* @return self
*/
public function setFirstLoginDate(?\DateTime $firstLoginDate = null)
{
$this->firstLoginDate = $firstLoginDate;
return $this;
}
/**
* @param ProjectClosure $projectClosure
*
* @return User
*/
public function addProjectClosure(ProjectClosure $projectClosure)
{
$this->projectClosure[] = $projectClosure;
return $this;
}
/**
* @param ProjectClosure $projectClosure
*
* @return bool TRUE if this collection contained the specified element, FALSE otherwise.
*/
public function removeProjectClosure(ProjectClosure $projectClosure)
{
return $this->projectClosure->removeElement($projectClosure);
}
/**
* @return DoctrineCollection
*/
public function getProjectClosures()
{
return $this->projectClosures;
}
/**
* @param int $id
*
* @return User
*/
public function setId(int $id): User
{
$this->id = $id;
return $this;
}
/**
* @param bool $true
*
* @return $this
*/
public function setEnabled(bool $true)
{
$this->enabled = $true;
return $this;
}
/**
* @inheritDoc
*/
public function isEqualTo(UserInterface $user)
{
// There are only a few attributes on a user that we should enforce a logout should they change
// If their password has changed...
if ($this->getPassword() !== $user->getPassword()) {
return false;
}
// If they've been disabled...
if ($this->isEnabled() !== $user->isEnabled()) {
return false;
}
// 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.
$isEqual = count($this->getRoles()) == count($user->getRoles());
if ($isEqual) {
foreach ($this->getRoles() as $role) {
$isEqual = $isEqual && in_array($role, $user->getRoles());
}
}
return $isEqual;
}
/**
* @param string $role
*
* @return bool
*/
public function hasRole(string $role): bool
{
return in_array($role, $this->getRoles());
}
/**
* @return DoctrineCollection<int, ClinicalSummary>
*/
public function getClinicalSummaries(): DoctrineCollection
{
return $this->clinicalSummaries;
}
/**
* @param ClinicalSummary $clinicalSummary
*
* @return self
*/
public function addClinicalSummary(ClinicalSummary $clinicalSummary): self
{
if (!$this->clinicalSummaries->contains($clinicalSummary)) {
$this->clinicalSummaries[] = $clinicalSummary;
$clinicalSummary->setCreator($this);
}
return $this;
}
/**
* @param ClinicalSummary $clinicalSummary
*
* @return self
*/
public function removeClinicalSummary(ClinicalSummary $clinicalSummary): self
{
if ($this->clinicalSummaries->removeElement($clinicalSummary)) {
// set the owning side to null (unless already changed)
if ($clinicalSummary->getCreator() === $this) {
$clinicalSummary->setCreator(null);
}
}
return $this;
}
/**
* Check if the user's email matches any regex pattern in the UserInternal table.
*
* @param bool $isRecursive
* @param UserInternalRepository $repository
* @param EntityManagerInterface $entityManager
*
* @return bool
*/
public function isUserInternal(UserInternalRepository $repository, EntityManagerInterface $entityManager, bool $isRecursive = false): bool
{
//return true if internal user
if ($this->isUserTypeInternal()) {
return true;
}
$email = strtolower($this->getEmail());
// Get stored regex patterns from the database
$patterns = $repository->getAllPatterns();
// If the user's email matches a domain that is specified in the patterns (e.g. medbrief) then set the userType to internal.
foreach ($patterns as $pattern) {
if (preg_match('/' . $pattern . '/i', $email)) {
// Set user type to internal
$this->setUserType(self::USER_TYPE_INTERNAL);
// Persist the change to the database
$entityManager->persist($this);
$entityManager->flush();
return true;
}
}
// In case the user's email does not match we check to see if they have an admin role and avoid an infinite loop.
if (!$isRecursive) {
return $this->updateUserTypeInternal($repository, $entityManager);
}
return false;
}
/**
* Update user to internal type if they have medbrief email address and have an admin or super admin role.
*
* @param UserInternalRepository $repository
* @param EntityManagerInterface $entityManager
*
* @return bool
*/
public function updateUserTypeInternal(UserInternalRepository $repository, EntityManagerInterface $entityManager): bool
{
// Check if the user is already internal
if ($this->userType === self::USER_TYPE_INTERNAL) {
return false;
}
if ($this->isUserInternal($repository, $entityManager, true) && (in_array(self::DEFAULT_ROLE_ADMIN, $this->roles) || in_array(self::DEFAULT_ROLE_SUPER_ADMIN, $this->roles))) {
$this->userType = self::USER_TYPE_INTERNAL;
$entityManager->persist($this);
$entityManager->flush();
return true;
}
return false;
}
/**
* This method tracks whether the 'Billed' checkbox is visible to MB Admins
*
* @return bool
*/
public function hasAccessToBilled(): bool
{
return $this->accessToBilled;
}
/**
* This method sets whether a MB Admin can view the 'Billed' checkbox.
*
* @param bool $value
*
* @return self
*/
public function setAccessToBilled(bool $value): self
{
$this->accessToBilled = $value;
return $this;
}
/**
* This method fetches the value which determines whether a MB Admin can view the 'Billed' checkbox.
*
* @return bool
*/
public function getAccessToBilled(): bool
{
return $this->accessToBilled;
}
/**
* @return \DateTime|null
*/
public function getLegacyRadiologyViewerLastUsed()
{
return $this->legacyRadiologyViewerLastUsed;
}
/**
* @param \DateTime|null $legacyRadiologyViewerLastUsed
*
* @return self
*/
public function setLegacyRadiologyViewerLastUsed(?\DateTime $legacyRadiologyViewerLastUsed = null): self
{
$this->legacyRadiologyViewerLastUsed = $legacyRadiologyViewerLastUsed;
return $this;
}
}