src/Entity/User.php line 229

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. //use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  7. use Symfony\Component\Security\Core\User\UserInterface;
  8. use Doctrine\ORM\Mapping\OrderBy;
  9. use JsonSerializable;
  10. /**
  11.  * @ORM\Entity(repositoryClass="App\Repository\UserRepository")
  12.  */
  13. class User implements UserInterfaceJsonSerializable
  14. {
  15.     /**
  16.      * @ORM\Id()
  17.      * @ORM\GeneratedValue()
  18.      * @ORM\Column(type="integer")
  19.      */
  20.     private $id;
  21.     /**
  22.      * @ORM\Column(type="string", length=255, unique=true)
  23.      */
  24.     private $email;
  25.     /**
  26.      * @ORM\Column(type="string", length=255)
  27.      */
  28.     private $firstname;
  29.     /**
  30.      * @ORM\Column(type="string", length=255)
  31.      */
  32.     private $lastname;
  33.     /**
  34.      * @ORM\Column(type="boolean")
  35.      */
  36.     private $status;
  37.     /**
  38.      * @ORM\Column(type="string", length=255, nullable=true)
  39.      */
  40.     private $telephone;
  41.     /**
  42.      * @ORM\Column(type="datetime")
  43.      */
  44.     private $created;
  45.     /**
  46.      * @ORM\Column(type="datetime", nullable=true)
  47.      */
  48.     private $activity;
  49.     /**
  50.      * @ORM\Column(type="integer", nullable=true)
  51.      */
  52.     private $section_id;
  53.     /**
  54.      * @ORM\Column(type="integer", nullable=true)
  55.      */
  56.     private $position_id;
  57.     /**
  58.      * @ORM\ManyToOne(targetEntity="App\Entity\Section", inversedBy="users")
  59.      * @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
  60.      */
  61.     private $section;
  62.     /**
  63.      * @ORM\ManyToOne(targetEntity="App\Entity\Position", inversedBy="users")
  64.      * @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
  65.      */
  66.     private $position;
  67.     /**
  68.      * @ORM\Column(type="string", length=255)
  69.      */
  70.     private $password;
  71.     /**
  72.      * @ORM\Column(type="string", length=255, unique=true)
  73.      */
  74.     private $username;
  75.     /**
  76.      * @ORM\Column(type="boolean")
  77.      */
  78.     private $admin;
  79.     /**
  80.      * @ORM\Column(type="string", length=255, nullable=true)
  81.      */
  82.     private $hash;
  83.     /**
  84.      * @ORM\Column(type="array", nullable=true)
  85.      */
  86.     private $access = [];
  87.     /**
  88.      * @ORM\OneToMany(targetEntity="App\Entity\Project", mappedBy="author")
  89.      */
  90.     private $ownedProjects;
  91.     /**
  92.      * @ORM\OneToMany(targetEntity="App\Entity\Project", mappedBy="assigned")
  93.      */
  94.     private $assignedProjects;
  95.     /**
  96.      * @ORM\OneToMany(targetEntity="App\Entity\Prognosis", mappedBy="author")
  97.      */
  98.     private $prognoses;
  99.     /**
  100.      * @ORM\OneToMany(targetEntity="App\Entity\Prognosis", mappedBy="assigned")
  101.      */
  102.     private $assignedPrognoses;
  103.     /**
  104.      * @ORM\Column(type="string", length=255, nullable=true)
  105.      */
  106.     private $theme 'default';
  107.     /**
  108.      * @ORM\OneToOne(targetEntity="App\Entity\UserTeam", mappedBy="leader", cascade={"persist", "remove"})
  109.      */
  110.     private $leader;
  111.     /**
  112.      * @ORM\ManyToOne(targetEntity="App\Entity\UserTeam", inversedBy="users")
  113.      */
  114.     private $team;
  115.     /**
  116.      * @ORM\Column(type="text", nullable=true)
  117.      */
  118.     private $bc_token;
  119.     /**
  120.      * @ORM\Column(type="datetime", nullable=true)
  121.      */
  122.     private $bc_token_expire;
  123.     /**
  124.      * @ORM\Column(type="integer", nullable=true)
  125.      */
  126.     private $bc_user_id;
  127.     /**
  128.      * @ORM\ManyToMany(targetEntity="App\Entity\KnowledgeCategory", mappedBy="users")
  129.      * @OrderBy({"ordering" = "ASC"})
  130.      */
  131.     private $knowledgeCategories;
  132.     /**
  133.      * @ORM\OneToMany(targetEntity="App\Entity\TimerEntry", mappedBy="user", orphanRemoval=true)
  134.      */
  135.     private $timerEntries;
  136.     /**
  137.      * @ORM\ManyToMany(targetEntity="App\Entity\Project", mappedBy="users")
  138.      */
  139.     private $projects;
  140.     /**
  141.      * @ORM\Column(type="integer", nullable=true)
  142.      */
  143.     private $hourValue;
  144.     /**
  145.      * @ORM\Column(type="integer", nullable=true)
  146.      */
  147.     private $daysOff;
  148.     /**
  149.      * @ORM\ManyToOne(targetEntity=User::class)
  150.      */
  151.     private $supervisor;
  152.     /**
  153.      * @ORM\OneToMany(targetEntity="App\Entity\InvoiceRequest", mappedBy="author", orphanRemoval=true)
  154.      */
  155.     private $invoiceRequests;
  156.     /**
  157.      * @ORM\Column(type="string", length=255, nullable=true)
  158.      */
  159.     private $avatar;
  160.     /**
  161.      * @ORM\Column(type="string", length=255, nullable=true)
  162.      */
  163.     private $slackUserId;
  164.     /**
  165.      * @ORM\Column(type="string", length=255, nullable=true)
  166.      */
  167.     private $color;
  168.     public function __construct()
  169.     {
  170.         $this->created = new \DateTime();
  171.         $this->ownedProjects = new ArrayCollection();
  172.         $this->assignedProjects = new ArrayCollection();
  173.         $this->prognoses = new ArrayCollection();
  174.         $this->assignedPrognoses = new ArrayCollection();
  175.         $this->knowledgeCategories = new ArrayCollection();
  176.         $this->invoiceRequests = new ArrayCollection();
  177.         $this->timerEntries = new ArrayCollection();
  178.         $this->projects = new ArrayCollection();
  179.         $this->daysOff 0;
  180.     }
  181.     public function __toString()
  182.     {
  183.         return $this->lastname " " $this->firstname;
  184.     }
  185.     public function jsonSerialize()
  186.     {
  187.         return array(
  188.             'username'=> $this->username,
  189.             'firstname' => $this->firstname,
  190.             'lastname' => $this->lastname,
  191.             'position' => (string) $this->position,
  192.             'section' => (string) $this->section,
  193.             'isAdmin' => $this->isAdmin(),
  194.             'email' => $this->email,
  195.             'telephone' => $this->telephone,
  196.             'activity' => $this->activity
  197.         );
  198.     }
  199.     public function getId(): ?int
  200.     {
  201.         return $this->id;
  202.     }
  203.     public function getEmail(): ?string
  204.     {
  205.         return $this->email;
  206.     }
  207.     public function setEmail(string $email): self
  208.     {
  209.         $this->email $email;
  210.         return $this;
  211.     }
  212.     public function getFirstname(): ?string
  213.     {
  214.         return $this->firstname;
  215.     }
  216.     public function setFirstname(string $firstname): self
  217.     {
  218.         $this->firstname $firstname;
  219.         return $this;
  220.     }
  221.     public function getLastname(): ?string
  222.     {
  223.         return $this->lastname;
  224.     }
  225.     public function setLastname(string $lastname): self
  226.     {
  227.         $this->lastname $lastname;
  228.         return $this;
  229.     }
  230.     public function getStatus(): ?bool
  231.     {
  232.         return $this->status;
  233.     }
  234.     public function getStatusName(): ?string
  235.     {
  236.         return $this->status 'Aktywny' 'Zablokowany';
  237.     }
  238.     public function setStatus(bool $status): self
  239.     {
  240.         $this->status $status;
  241.         return $this;
  242.     }
  243.     public function getTelephone(): ?string
  244.     {
  245.         return $this->telephone;
  246.     }
  247.     public function setTelephone(?string $telephone): self
  248.     {
  249.         $this->telephone $telephone;
  250.         return $this;
  251.     }
  252.     public function getCreated(): ?\DateTimeInterface
  253.     {
  254.         return $this->created;
  255.     }
  256.     public function setCreated(\DateTimeInterface $created): self
  257.     {
  258.         $this->created $created;
  259.         return $this;
  260.     }
  261.     public function getActivity(): ?\DateTimeInterface
  262.     {
  263.         return $this->activity;
  264.     }
  265.     public function setActivity(\DateTimeInterface $activity): self
  266.     {
  267.         $this->activity $activity;
  268.         return $this;
  269.     }
  270.     public function getSectionId(): ?int
  271.     {
  272.         return $this->section_id;
  273.     }
  274.     public function setSectionId(int $section_id): self
  275.     {
  276.         $this->section_id $section_id;
  277.         return $this;
  278.     }
  279.     public function getPositionId(): ?int
  280.     {
  281.         return $this->position_id;
  282.     }
  283.     public function setPositionId(int $position_id): self
  284.     {
  285.         $this->position_id $position_id;
  286.         return $this;
  287.     }
  288.     public function getSection(): ?Section
  289.     {
  290.         return $this->section;
  291.     }
  292.     public function setSection(?Section $section): self
  293.     {
  294.         $this->section $section;
  295.         return $this;
  296.     }
  297.     public function getPosition(): ?Position
  298.     {
  299.         return $this->position;
  300.     }
  301.     public function setPosition(?Position $position): self
  302.     {
  303.         $this->position $position;
  304.         return $this;
  305.     }
  306.     public function getPassword(): ?string
  307.     {
  308.         return $this->password;
  309.     }
  310.     public function setPassword(string $password): self
  311.     {
  312.         $this->password $password;
  313.         return $this;
  314.     }
  315. //SECURITY
  316.     public function isAdmin(){
  317.         return $this->admin;
  318.     }
  319.     public function getSalt()
  320.     {
  321.         // you *may* need a real salt depending on your encoder
  322.         // see section on salt below
  323.         return null;
  324.     }
  325.     public function getRoles()
  326.     {
  327.         return $this->isAdmin() ? array('ROLE_ADMIN','ROLE_USER') : ( $this->canImpersonate() ? ['ROLE_USER''ROLE_ALLOWED_TO_SWITCH'] : array('ROLE_USER'));
  328.     }
  329.     public function eraseCredentials()
  330.     {
  331.     }
  332.     /** @see \Serializable::serialize() */
  333.     public function serialize()
  334.     {
  335.         return serialize(array(
  336.             $this->id,
  337.             $this->username,
  338.             $this->password,
  339.             // see section on salt below
  340.             // $this->salt,
  341.         ));
  342.     }
  343.     /** @see \Serializable::unserialize() */
  344.     public function unserialize($serialized)
  345.     {
  346.         list (
  347.             $this->id,
  348.             $this->username,
  349.             $this->password,
  350.             // see section on salt below
  351.             // $this->salt
  352.             ) = unserialize($serialized, array('allowed_classes' => false));
  353.     }
  354.     public function getUsername(): ?string
  355.     {
  356.         return $this->username;
  357.     }
  358.     public function setUsername(string $username): self
  359.     {
  360.         $this->username $username;
  361.         return $this;
  362.     }
  363.     public function getAdmin(): ?bool
  364.     {
  365.         return $this->admin;
  366.     }
  367.     public function setAdmin(bool $admin): self
  368.     {
  369.         $this->admin $admin;
  370.         return $this;
  371.     }
  372.     public function getHash(): ?string
  373.     {
  374.         return $this->hash;
  375.     }
  376.     public function setHash(?string $hash): self
  377.     {
  378.         $this->hash $hash;
  379.         return $this;
  380.     }
  381.     //USER AUTH ITEMS
  382.     public function isEnabled(){
  383.         return $this->status == 1;
  384.     }
  385.     public function isAccountNonExpired(){
  386.         return $this->status == 1;
  387.     }
  388.     public function isAccountNonLocked(){
  389.         return $this->status <= 1;
  390.     }
  391.     public function isCredentialsNonExpired(){
  392.         return $this->status == 1;
  393.     }
  394.     public function getAccess(): ?array
  395.     {
  396.         return $this->access;
  397.     }
  398.     public function setAccess(array $access): self
  399.     {
  400.         $this->access $access;
  401.         return $this;
  402.     }
  403.     /**
  404.      * @return Collection|Project[]
  405.      */
  406.     public function getOwnedProjects(): Collection
  407.     {
  408.         return $this->ownedProjects;
  409.     }
  410.     public function addOwnedProject(Project $project): self
  411.     {
  412.         if (!$this->ownedProjects->contains($project)) {
  413.             $this->ownedProjects[] = $project;
  414.             $project->setAuthor($this);
  415.         }
  416.         return $this;
  417.     }
  418.     public function removeOwnedProject(Project $project): self
  419.     {
  420.         if ($this->ownedProjects->contains($project)) {
  421.             $this->ownedProjects->removeElement($project);
  422.             // set the owning side to null (unless already changed)
  423.             if ($project->getAuthor() === $this) {
  424.                 $project->setAuthor(null);
  425.             }
  426.         }
  427.         return $this;
  428.     }
  429.     /**
  430.      * @return Collection|Project[]
  431.      */
  432.     public function getAssignedProjects(): Collection
  433.     {
  434.         return $this->assignedProjects;
  435.     }
  436.     public function addAssignedProject(Project $assignedProject): self
  437.     {
  438.         if (!$this->assignedProjects->contains($assignedProject)) {
  439.             $this->assignedProjects[] = $assignedProject;
  440.             $assignedProject->setAssigned($this);
  441.         }
  442.         return $this;
  443.     }
  444.     public function removeAssignedProject(Project $assignedProject): self
  445.     {
  446.         if ($this->assignedProjects->contains($assignedProject)) {
  447.             $this->assignedProjects->removeElement($assignedProject);
  448.             // set the owning side to null (unless already changed)
  449.             if ($assignedProject->getAssigned() === $this) {
  450.                 $assignedProject->setAssigned(null);
  451.             }
  452.         }
  453.         return $this;
  454.     }
  455.     /**
  456.      * @return Collection|Prognosis[]
  457.      */
  458.     public function getPrognoses(): Collection
  459.     {
  460.         return $this->prognoses;
  461.     }
  462.     public function addPrognosis(Prognosis $prognosis): self
  463.     {
  464.         if (!$this->prognoses->contains($prognosis)) {
  465.             $this->prognoses[] = $prognosis;
  466.             $prognosis->setAuthor($this);
  467.         }
  468.         return $this;
  469.     }
  470.     public function removePrognosis(Prognosis $prognosis): self
  471.     {
  472.         if ($this->prognoses->contains($prognosis)) {
  473.             $this->prognoses->removeElement($prognosis);
  474.             // set the owning side to null (unless already changed)
  475.             if ($prognosis->getAuthor() === $this) {
  476.                 $prognosis->setAuthor(null);
  477.             }
  478.         }
  479.         return $this;
  480.     }
  481.     /**
  482.      * @return Collection|Prognosis[]
  483.      */
  484.     public function getAssignedPrognoses(): Collection
  485.     {
  486.         return $this->assignedPrognoses;
  487.     }
  488.     public function addAssignedPrognosis(Prognosis $assignedPrognosis): self
  489.     {
  490.         if (!$this->assignedPrognoses->contains($assignedPrognosis)) {
  491.             $this->assignedPrognoses[] = $assignedPrognosis;
  492.             $assignedPrognosis->setAssigned($this);
  493.         }
  494.         return $this;
  495.     }
  496.     public function removeAssignedPrognosis(Prognosis $assignedPrognosis): self
  497.     {
  498.         if ($this->assignedPrognoses->contains($assignedPrognosis)) {
  499.             $this->assignedPrognoses->removeElement($assignedPrognosis);
  500.             // set the owning side to null (unless already changed)
  501.             if ($assignedPrognosis->getAssigned() === $this) {
  502.                 $assignedPrognosis->setAssigned(null);
  503.             }
  504.         }
  505.         return $this;
  506.     }
  507.     public function getTheme(): ?string
  508.     {
  509.         return $this->theme;
  510.     }
  511.     public function setTheme(?string $theme): self
  512.     {
  513.         $this->theme $theme;
  514.         return $this;
  515.     }
  516.     public function getLeader(): ?UserTeam
  517.     {
  518.         return $this->leader;
  519.     }
  520.     public function setLeader(UserTeam $leader): self
  521.     {
  522.         $this->leader $leader;
  523.         // set the owning side of the relation if necessary
  524.         if ($this !== $leader->getLeader()) {
  525.             $leader->setLeader($this);
  526.         }
  527.         return $this;
  528.     }
  529.     public function getTeam(): ?UserTeam
  530.     {
  531.         return $this->team;
  532.     }
  533.     public function setTeam(?UserTeam $team): self
  534.     {
  535.         $this->team $team;
  536.         return $this;
  537.     }
  538.     public function getBcToken(): ?string
  539.     {
  540.         return $this->bc_token;
  541.     }
  542.     public function setBcToken(?string $bc_token): self
  543.     {
  544.         $this->bc_token $bc_token;
  545.         return $this;
  546.     }
  547.     public function getBcTokenExpire(): ?\DateTimeInterface
  548.     {
  549.         return $this->bc_token_expire;
  550.     }
  551.     public function setBcTokenExpire(?\DateTimeInterface $bc_token_expire): self
  552.     {
  553.         $this->bc_token_expire $bc_token_expire;
  554.         return $this;
  555.     }
  556.     public function getBcUserId(): ?int
  557.     {
  558.         return $this->bc_user_id;
  559.     }
  560.     public function setBcUserId(?int $bc_user_id): self
  561.     {
  562.         $this->bc_user_id $bc_user_id;
  563.         return $this;
  564.     }
  565.     /**
  566.      * @return Collection|KnowledgeCategory[]
  567.      */
  568.     public function getKnowledgeCategories(): Collection
  569.     {
  570.         return $this->knowledgeCategories;
  571.     }
  572.     public function addKnowledgeCategory(KnowledgeCategory $knowledgeCategory): self
  573.     {
  574.         if (!$this->knowledgeCategories->contains($knowledgeCategory)) {
  575.             $this->knowledgeCategories[] = $knowledgeCategory;
  576.             $knowledgeCategory->addUser($this);
  577.         }
  578.         return $this;
  579.     }
  580.     public function removeKnowledgeCategory(KnowledgeCategory $knowledgeCategory): self
  581.     {
  582.         if ($this->knowledgeCategories->contains($knowledgeCategory)) {
  583.             $this->knowledgeCategories->removeElement($knowledgeCategory);
  584.             $knowledgeCategory->removeUser($this);
  585.         }
  586.         return $this;
  587.     }
  588.     /**
  589.      * @return Collection|InvoiceRequest[]
  590.      */
  591.     public function getInvoiceRequests(): Collection
  592.     {
  593.         return $this->invoiceRequests;
  594.     }
  595.     public function addInvoiceRequest(InvoiceRequest $invoiceRequest): self
  596.     {
  597.         if (!$this->invoiceRequests->contains($invoiceRequest)) {
  598.             $this->invoiceRequests[] = $invoiceRequest;
  599.             $invoiceRequest->setAuthor($this);
  600.         }
  601.         return $this;
  602.     }
  603.     public function removeInvoiceRequest(InvoiceRequest $invoiceRequest): self
  604.     {
  605.         if ($this->invoiceRequests->contains($invoiceRequest)) {
  606.             $this->invoiceRequests->removeElement($invoiceRequest);
  607.             // set the owning side to null (unless already changed)
  608.             if ($invoiceRequest->getAuthor() === $this) {
  609.                 $invoiceRequest->setAuthor(null);
  610.             }
  611.         }
  612.         return $this;
  613.     }
  614.     /**
  615.      * @return Collection|TimerEntry[]
  616.      */
  617.     public function getTimerEntries(): Collection
  618.     {
  619.         return $this->timerEntries;
  620.     }
  621.     public function addTimerEntry(TimerEntry $timerEntry): self
  622.     {
  623.         if (!$this->timerEntries->contains($timerEntry)) {
  624.             $this->timerEntries[] = $timerEntry;
  625.             $timerEntry->setUser($this);
  626.         }
  627.         return $this;
  628.     }
  629.     public function removeTimerEntry(TimerEntry $timerEntry): self
  630.     {
  631.         if ($this->timerEntries->contains($timerEntry)) {
  632.             $this->timerEntries->removeElement($timerEntry);
  633.             // set the owning side to null (unless already changed)
  634.             if ($timerEntry->getUser() === $this) {
  635.                 $timerEntry->setUser(null);
  636.             }
  637.         }
  638.         return $this;
  639.     }
  640.     /**
  641.      * @return Collection|Project[]
  642.      */
  643.     public function getProjects(): Collection
  644.     {
  645.         return $this->projects;
  646.     }
  647.     public function addProject(Project $project): self
  648.     {
  649.         if (!$this->projects->contains($project)) {
  650.             $this->projects[] = $project;
  651.             $project->addUser($this);
  652.         }
  653.         return $this;
  654.     }
  655.     public function removeProject(Project $project): self
  656.     {
  657.         if ($this->projects->contains($project)) {
  658.             $this->projects->removeElement($project);
  659.             $project->removeUser($this);
  660.         }
  661.         return $this;
  662.     }
  663.     public function getHourValue(): ?int
  664.     {
  665.         return $this->hourValue;
  666.     }
  667.     public function setHourValue(?int $hourValue): self
  668.     {
  669.         $this->hourValue $hourValue;
  670.         return $this;
  671.     }
  672.     public function canTimer(){
  673. //        return false;
  674.         return $this->hourValue && $this->hourValue 0;
  675.     }
  676.     public function canImpersonate(): ?string{
  677.         return $this->getUsername() === 'm.marczyk@hypercrew.pl' 'it@hypercrew.pl' null;//wkrotce inaczej...
  678.     }
  679.     public function getDaysOff(): ?int
  680.     {
  681.         return $this->daysOff !== null $this->daysOff 0;
  682.     }
  683.     public function setDaysOff(?int $daysOff): self
  684.     {
  685.         $this->daysOff $daysOff;
  686.         return $this;
  687.     }
  688.     public function getSupervisor(): ?self
  689.     {
  690.         return $this->supervisor;
  691.     }
  692.     public function setSupervisor(?self $supervisor): self
  693.     {
  694.         $this->supervisor $supervisor;
  695.         return $this;
  696.     }
  697.     public function getAvatar(): ?string
  698.     {
  699. //        return empty($this->avatar) ? 'https://www.gravatar.com/avatar/' . md5(strtolower(trim($this->email))) : $this->avatar;
  700.         return empty($this->avatar) ? '/images/avatar.png' $this->avatar;
  701.     }
  702.     public function hasAvatar(){
  703.         return !empty($this->avatar);
  704.     }
  705.     public function setAvatar(?string $avatar): self
  706.     {
  707.         $this->avatar $avatar;
  708.         return $this;
  709.     }
  710.     public function getSlackUserId(): ?string
  711.     {
  712.         return $this->slackUserId;
  713.     }
  714.     public function setSlackUserId(?string $slackUserId): self
  715.     {
  716.         $this->slackUserId $slackUserId;
  717.         return $this;
  718.     }
  719.     public function getColor(): ?string
  720.     {
  721.         return $this->color ?: '#ec5992';
  722.     }
  723.     public function setColor(?string $color): self
  724.     {
  725.         $this->color $color;
  726.         return $this;
  727.     }
  728. }