src/Entity/User.php line 16
<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
#[ORM\Table(name:"til_user")]
#[ORM\Entity(repositoryClass:"App\Repository\UserRepository")]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
public function __toString(){
return $this->getSurname().' '.$this->getName();
}
public function displayFullNameAndAccountType(){
return $this->getSurname().' '.$this->getName().' ('.$this->getAccountType()->__toString().')';
}
public function getCanViewPermissionCategory($categorySlug){
foreach($this->permissions as $jt){
if($jt->getPermission()->getCategory()->getSlug() == $categorySlug){
if($jt->getValue() != "")
return true;
}
}
return false;
}
public function getCanViewPermission($permissionSlug){
foreach($this->permissions as $jt){
if($jt->getPermission()->getSlug() == $permissionSlug){
if($jt->getValue() != "")
return true;
else
return false;
}
}
return false;
}
public function getCanEditPermission($permissionSlug){
foreach($this->permissions as $jt){
if($jt->getPermission()->getSlug() == $permissionSlug){
if($jt->getValue() == "rw")
return true;
else
return false;
}
}
return false;
}
public function getPermissionType($permissionSlug){
foreach($this->permissions as $jt){
if($jt->getPermission()->getSlug() == $permissionSlug)
return $jt->getValue();
}
return "";
}
public function getUnreadNotifications(){
$count = 0;
foreach($this->getNotifications() as $n){
if($n->isPersonal() && !$n->isRead())
$count++;
}
return $count;
}
public function printPdfName(){
return $this->surname.' '.substr($this->name, 0, 1);
}
public function getHasProvince($facilityProvince){
if($this->getAccountType()->getSlug() == "kam"){
foreach ($this->coveredProvinces as $province){
if($province->getId() == $facilityProvince)
return true;
}
}
return false;
}
public function getSellName(){
if($this->getAccountType()->getSlug() == "kam" && $this->getName() != "Tillomed")
return $this->surname. ' ' .$this->name;
elseif($this->getAccountType()->getSlug() == "kam" && $this->getName() == "Tillomed")
return "Vacant";
else
return "Customer Service";
}
public function getIsEligible($feature){
switch($feature){
case 'alarmBtn':
if($this->getAccountType()->getSlug() == 'supervisor_mario'
|| strpos($this->getAccountType()->getSlug(), "commercial") !== false
|| $this->getAccountType()->getSlug() == 'kam'
|| $this->getAccountType()->getSlug() == 'administration')
return true;
}
return false;
}
public function getActualOdometer($month, $year){
foreach($this->refundYears as $ry){
if($ry->getValue() == $year){
foreach($ry->getRefundMonths() as $rm){
if($rm->getValue() == $month)
return $rm->getEndMonthOdometer();
}
}
}
return 0;
}
public function getActualKmPlusMinus($month, $year){
$odometer = $this->getActualOdometer($month, $year);
foreach($this->refundYears as $ry){
foreach($ry->getRefundMonths() as $rm){
return $odometer - $l->getStartKm() - ($rm->getValue()*$l->getKmMonth());
}
}
foreach($this->leasings as $l){
}
return 0;
}
public function getCurrentBudgetKamPercentage($date){
$year = $date->format("Y");
if($date->format("m") < 4)
$year--;
foreach($this->budgetKams as $bk){
if($bk->getBudgetTotal()->getYear() == $year)
return $bk->getPercentage();
}
return "0";
}
public function getUnclosedPresenceMonth(){
$months = array();
foreach($this->presenceYears as $py){
foreach($py->getPresenceMonths() as $pm){
if($pm->getStatus() < 2){
array_push($months, $pm);
}
}
}
return $months;
}
public function getMonthPresenceStats($month, $year, $startDate, $endDate, $filterType){
$presence = 0;
$rol = 0;
$holiday = 0;
$transfer = 0;
$permission = 0;
$illness = 0;
$meeting = 0;
$congress = 0;
foreach($this->presenceYears as $py){
if($filterType == "progressive"){
if($month < 4 && ($py->getValue() == $year || $py->getValue() == $year - 1)){
foreach($py->getPresenceMonths() as $pm){
if(($py->getValue() == $year && $pm->getValue() <= $month) || ($py->getValue() == $year - 1 && $pm->getValue() >= 4)){
foreach($pm->getPresenceDays() as $pd){
if($pd->getJobHours() > 0)
$presence++;
$rol += $pd->getRol();
$holiday += $pd->getHoliday();
$transfer += $pd->getIsTransfer();
$permission += $pd->getPermission();
$illness += $pd->getIllness();
$meeting += $pd->getIsMeeting();
$congress += $pd->getIsCongress();
}
}
}
}
elseif($month >= 4 && $py->getValue() == $year){
foreach($py->getPresenceMonths() as $pm){
if($pm->getValue() >= 4 && $pm->getValue() <= $month){
foreach($pm->getPresenceDays() as $pd){
if($pd->getJobHours() > 0)
$presence++;
$rol += $pd->getRol();
$holiday += $pd->getHoliday();
$transfer += $pd->getIsTransfer();
$permission += $pd->getPermission();
$illness += $pd->getIllness();
$meeting += $pd->getIsMeeting();
$congress += $pd->getIsCongress();
}
}
}
}
}
elseif($filterType == "monthly"){
if($py->getValue() == $year){
foreach($py->getPresenceMonths() as $pm){
if($pm->getValue() == $month){
foreach($pm->getPresenceDays() as $pd){
if($pd->getJobHours() > 0)
$presence++;
$rol += $pd->getRol();
$holiday += $pd->getHoliday();
$transfer += $pd->getIsTransfer();
$permission += $pd->getPermission();
$illness += $pd->getIllness();
$meeting += $pd->getIsMeeting();
$congress += $pd->getIsCongress();
}
}
}
}
}
else{
if($py->getValue() >= $startDate->format("Y") and $py->getValue() <= $endDate->format("Y")){
foreach($py->getPresenceMonths() as $pm){
foreach($pm->getPresenceDays() as $pd){
if($pd->getDate()->format("Ymd") >= $startDate->format("Ymd") && $pd->getDate()->format("Ymd") <= $endDate->format("Ymd")){
if($pd->getJobHours() > 0)
$presence++;
$rol += $pd->getRol();
$holiday += $pd->getHoliday();
$transfer += $pd->getIsTransfer();
$permission += $pd->getPermission();
$illness += $pd->getIllness();
$meeting += $pd->getIsMeeting();
$congress += $pd->getIsCongress();
}
}
}
}
}
}
return array($presence, $rol, $holiday, $transfer, $permission, $illness, $meeting, $congress);
}
public function getMonthRefundStats($month, $year, $filterType){
$types = array();
foreach($this->refundYears as $ry){
if($filterType == "progressive"){
if($month < 4 && ($ry->getValue() == $year || $ry->getValue() == $year - 1)){
foreach($ry->getRefundMonths() as $rm){
if(($ry->getValue() == $year && $rm->getValue() <= $month) || ($ry->getValue() == $year - 1 && $rm->getValue() >= 4)){
foreach($rm->getRefundDays() as $rd){
foreach($rd->getRefunds() as $r){
$index = $r->getRefundType()->getId();
if(array_key_exists($index, $types))
$types[$index] += $r->getValue();
else
$types[$index] = $r->getValue();
}
}
}
}
}
elseif($month >= 4 && $ry->getValue() == $year){
foreach($ry->getRefundMonths() as $rm){
if($rm->getValue() >= 4 && $rm->getValue() <= $month){
foreach($rm->getRefundDays() as $rd){
foreach($rd->getRefunds() as $r){
$index = $r->getRefundType()->getId();
if(array_key_exists($index, $types))
$types[$index] += $r->getValue();
else
$types[$index] = $r->getValue();
}
}
}
}
}
}
else{
if($ry->getValue() == $year){
foreach($ry->getRefundMonths() as $rm){
if($rm->getValue() == $month){
foreach($rm->getRefundDays() as $rd){
foreach($rd->getRefunds() as $r){
$index = $r->getRefundType()->getId();
if(array_key_exists($index, $types))
$types[$index] += $r->getValue();
else
$types[$index] = $r->getValue();
}
}
}
}
}
}
}
return $types;
}
#[ORM\Column(name:"id", type:"bigint")]
#[ORM\Id]
#[ORM\GeneratedValue(strategy:"AUTO")]
private ?string $id;
#[ORM\Column(name:"email", type:"string", length:191, unique:true, nullable:true)]
private ?string $email;
#[ORM\Column(name:"name", type:"string", length:191)]
private ?string $name;
#[ORM\Column(name:"surname", type:"string", length:191)]
private ?string $surname;
#[ORM\Column(name:"password", type:"string", length:191, nullable:true)]
private ?string $password;
#[ORM\Column(name:"directory_path", type:"string", length:191)]
private ?string $directoryPath;
#[ORM\Column(name:"one_time_code", type:"string", length:191, nullable:true)]
private ?string $oneTimeCode;
#[ORM\Column(name:"role", type:"string", length:191)]
private ?string $role = 'ROLE_USER';
#[ORM\Column(name:"expiration_one_time_code", type:"datetime", nullable:true)]
private ?\DateTimeInterface $expirationOneTimeCode;
#[ORM\Column(name:"office_hours", type:"text", nullable:true)]
private ?string $officeHours;
#[ORM\Column(name:"is_active", type:"boolean")]
private ?bool $active = false;
#[ORM\Column(name:"is_admin_active", type:"boolean")]
private ?bool $adminActive = true;
#[ORM\Column(name:"is_email_notification_active", type:"boolean")]
private ?bool $emailNotificationActive = false;
#[ORM\Column(name:"is_alert_read", type:"boolean")]
private ?bool $alertRead = false;
#[ORM\Column(name:"is_gdpr_sent", type:"boolean")]
private ?bool $gdprSent = false;
// ONE TO ONE
#[ORM\OneToOne(targetEntity:"App\Entity\UserPrivacy", mappedBy:"user", cascade:['remove', 'persist'])]
private $privacy;
#[ORM\OneToOne(targetEntity:"App\Entity\UserProfile", mappedBy:"user", cascade:['remove', 'persist'])]
private $profile;
#[ORM\OneToOne(targetEntity:"App\Entity\Employee", mappedBy:"user")]
private $employee;
// MANY TO ONE
#[ORM\ManyToOne(targetEntity:"App\Entity\UserAccountType", inversedBy:"users")]
#[ORM\JoinColumn(name:"account_type_id", referencedColumnName:"id")]
private $accountType;
// ONE TO MANY
#[ORM\OneToMany(targetEntity:'App\Entity\Document', mappedBy:'owner')]
private $uploads;
#[ORM\OneToMany(targetEntity:'App\Entity\Document', mappedBy:'user')]
private $documents;
#[ORM\OneToMany(targetEntity:'App\Entity\Notification', mappedBy:'user')]
private $notifications;
#[ORM\OneToMany(targetEntity:'App\Entity\Log', mappedBy:'user')]
private $logs;
#[ORM\OneToMany(targetEntity:'App\Entity\JoinTableUserTest', mappedBy:'user')]
private $tests;
#[ORM\OneToMany(targetEntity:'App\Entity\TestCode', mappedBy:'user')]
private $codes;
#[ORM\OneToMany(targetEntity:'App\Entity\TestAnswer', mappedBy:'user')]
private $answers;
#[ORM\OneToMany(targetEntity:'App\Entity\JoinTableUserPermission', mappedBy:'user')]
private $permissions;
public function __construct()
{
$this->uploads = new ArrayCollection();
$this->documents = new ArrayCollection();
$this->notifications = new ArrayCollection();
$this->logs = new ArrayCollection();
$this->departments = new ArrayCollection();
$this->tests = new ArrayCollection();
$this->codes = new ArrayCollection();
$this->answers = new ArrayCollection();
$this->permissions = new ArrayCollection();
}
/**
* @inheritdoc
*/
public function getRoles(): array
{
switch($this->role){
case 'ROLE_ADMIN': return array('ROLE_ADMIN');
case 'ROLE_USER': return array('ROLE_USER');
}
}
public function getSalt(): ?string
{
return null;
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
}
public function getUserIdentifier(): string
{
return (string) $this->email;
}
public function getUsername(): string
{
return null;
}
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
public function getId(): ?string
{
return $this->id;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(?string $email): static
{
$this->email = $email;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
public function getSurname(): ?string
{
return $this->surname;
}
public function setSurname(string $surname): static
{
$this->surname = $surname;
return $this;
}
public function getDirectoryPath(): ?string
{
return $this->directoryPath;
}
public function setDirectoryPath(string $directoryPath): static
{
$this->directoryPath = $directoryPath;
return $this;
}
public function getOneTimeCode(): ?string
{
return $this->oneTimeCode;
}
public function setOneTimeCode(?string $oneTimeCode): static
{
$this->oneTimeCode = $oneTimeCode;
return $this;
}
public function getRole(): ?string
{
return $this->role;
}
public function setRole(string $role): static
{
$this->role = $role;
return $this;
}
public function getExpirationOneTimeCode(): ?\DateTimeInterface
{
return $this->expirationOneTimeCode;
}
public function setExpirationOneTimeCode(?\DateTimeInterface $expirationOneTimeCode): static
{
$this->expirationOneTimeCode = $expirationOneTimeCode;
return $this;
}
public function getOfficeHours(): ?string
{
return $this->officeHours;
}
public function setOfficeHours(?string $officeHours): static
{
$this->officeHours = $officeHours;
return $this;
}
public function isActive(): ?bool
{
return $this->active;
}
public function setActive(bool $active): static
{
$this->active = $active;
return $this;
}
public function isAdminActive(): ?bool
{
return $this->adminActive;
}
public function setAdminActive(bool $adminActive): static
{
$this->adminActive = $adminActive;
return $this;
}
public function isEmailNotificationActive(): ?bool
{
return $this->emailNotificationActive;
}
public function setEmailNotificationActive(bool $emailNotificationActive): static
{
$this->emailNotificationActive = $emailNotificationActive;
return $this;
}
public function isAlertRead(): ?bool
{
return $this->alertRead;
}
public function setAlertRead(bool $alertRead): static
{
$this->alertRead = $alertRead;
return $this;
}
public function isGdprSent(): ?bool
{
return $this->gdprSent;
}
public function setGdprSent(bool $gdprSent): static
{
$this->gdprSent = $gdprSent;
return $this;
}
public function getPrivacy(): ?UserPrivacy
{
return $this->privacy;
}
public function setPrivacy(?UserPrivacy $privacy): static
{
// unset the owning side of the relation if necessary
if ($privacy === null && $this->privacy !== null) {
$this->privacy->setUser(null);
}
// set the owning side of the relation if necessary
if ($privacy !== null && $privacy->getUser() !== $this) {
$privacy->setUser($this);
}
$this->privacy = $privacy;
return $this;
}
public function getProfile(): ?UserProfile
{
return $this->profile;
}
public function setProfile(?UserProfile $profile): static
{
// unset the owning side of the relation if necessary
if ($profile === null && $this->profile !== null) {
$this->profile->setUser(null);
}
// set the owning side of the relation if necessary
if ($profile !== null && $profile->getUser() !== $this) {
$profile->setUser($this);
}
$this->profile = $profile;
return $this;
}
public function getEmployee(): ?Employee
{
return $this->employee;
}
public function setEmployee(?Employee $employee): static
{
// unset the owning side of the relation if necessary
if ($employee === null && $this->employee !== null) {
$this->employee->setUser(null);
}
// set the owning side of the relation if necessary
if ($employee !== null && $employee->getUser() !== $this) {
$employee->setUser($this);
}
$this->employee = $employee;
return $this;
}
public function getAccountType(): ?UserAccountType
{
return $this->accountType;
}
public function setAccountType(?UserAccountType $accountType): static
{
$this->accountType = $accountType;
return $this;
}
/**
* @return Collection<int, Document>
*/
public function getUploads(): Collection
{
return $this->uploads;
}
public function addUpload(Document $upload): static
{
if (!$this->uploads->contains($upload)) {
$this->uploads->add($upload);
$upload->setOwner($this);
}
return $this;
}
public function removeUpload(Document $upload): static
{
if ($this->uploads->removeElement($upload)) {
// set the owning side to null (unless already changed)
if ($upload->getOwner() === $this) {
$upload->setOwner(null);
}
}
return $this;
}
/**
* @return Collection<int, Document>
*/
public function getDocuments(): Collection
{
return $this->documents;
}
public function addDocument(Document $document): static
{
if (!$this->documents->contains($document)) {
$this->documents->add($document);
$document->setUser($this);
}
return $this;
}
public function removeDocument(Document $document): static
{
if ($this->documents->removeElement($document)) {
// set the owning side to null (unless already changed)
if ($document->getUser() === $this) {
$document->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Notification>
*/
public function getNotifications(): Collection
{
return $this->notifications;
}
public function addNotification(Notification $notification): static
{
if (!$this->notifications->contains($notification)) {
$this->notifications->add($notification);
$notification->setUser($this);
}
return $this;
}
public function removeNotification(Notification $notification): static
{
if ($this->notifications->removeElement($notification)) {
// set the owning side to null (unless already changed)
if ($notification->getUser() === $this) {
$notification->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Log>
*/
public function getLogs(): Collection
{
return $this->logs;
}
public function addLog(Log $log): static
{
if (!$this->logs->contains($log)) {
$this->logs->add($log);
$log->setUser($this);
}
return $this;
}
public function removeLog(Log $log): static
{
if ($this->logs->removeElement($log)) {
// set the owning side to null (unless already changed)
if ($log->getUser() === $this) {
$log->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, HospitalDepartmentReferent>
*/
public function getDepartments(): Collection
{
return $this->departments;
}
public function addDepartment(HospitalDepartmentReferent $department): static
{
if (!$this->departments->contains($department)) {
$this->departments->add($department);
$department->setUser($this);
}
return $this;
}
public function removeDepartment(HospitalDepartmentReferent $department): static
{
if ($this->departments->removeElement($department)) {
// set the owning side to null (unless already changed)
if ($department->getUser() === $this) {
$department->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, JoinTableUserTest>
*/
public function getTests(): Collection
{
return $this->tests;
}
public function addTest(JoinTableUserTest $test): static
{
if (!$this->tests->contains($test)) {
$this->tests->add($test);
$test->setUser($this);
}
return $this;
}
public function removeTest(JoinTableUserTest $test): static
{
if ($this->tests->removeElement($test)) {
// set the owning side to null (unless already changed)
if ($test->getUser() === $this) {
$test->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, TestCode>
*/
public function getCodes(): Collection
{
return $this->codes;
}
public function addCode(TestCode $code): static
{
if (!$this->codes->contains($code)) {
$this->codes->add($code);
$code->setUser($this);
}
return $this;
}
public function removeCode(TestCode $code): static
{
if ($this->codes->removeElement($code)) {
// set the owning side to null (unless already changed)
if ($code->getUser() === $this) {
$code->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, TestAnswer>
*/
public function getAnswers(): Collection
{
return $this->answers;
}
public function addAnswer(TestAnswer $answer): static
{
if (!$this->answers->contains($answer)) {
$this->answers->add($answer);
$answer->setUser($this);
}
return $this;
}
public function removeAnswer(TestAnswer $answer): static
{
if ($this->answers->removeElement($answer)) {
// set the owning side to null (unless already changed)
if ($answer->getUser() === $this) {
$answer->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, JoinTableUserPermission>
*/
public function getPermissions(): Collection
{
return $this->permissions;
}
public function addPermission(JoinTableUserPermission $permission): static
{
if (!$this->permissions->contains($permission)) {
$this->permissions->add($permission);
$permission->setUser($this);
}
return $this;
}
public function removePermission(JoinTableUserPermission $permission): static
{
if ($this->permissions->removeElement($permission)) {
// set the owning side to null (unless already changed)
if ($permission->getUser() === $this) {
$permission->setUser(null);
}
}
return $this;
}
}