src/Entity/UserTracking.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserTrackingRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Entity(repositoryClass=UserTrackingRepository::class)
  9.  */
  10. class UserTracking
  11. {
  12.     const ROLE_ADMIN 'ROLE_ADMIN';
  13.     const ROLE_FREELANCER 'ROLE_FREELANCER';
  14.     const ROLE_FREELANCER_ASSISTANT 'ROLE_FREELANCER_ASSISTANT';
  15.     protected static $roleGroupName = [
  16.         self::ROLE_ADMIN => 'Admin',
  17.         self::ROLE_FREELANCER => 'Indépendant',
  18.         self::ROLE_FREELANCER_ASSISTANT => 'Assistant',
  19.     ];
  20.     /**
  21.      * @ORM\Id()
  22.      * @ORM\GeneratedValue()
  23.      * @ORM\Column(type="integer")
  24.      */
  25.     private $id;
  26.     /**
  27.      * @ORM\ManyToOne(targetEntity=User::class, inversedBy="userTracking")
  28.      */
  29.     private $user;
  30.     /**
  31.      * @ORM\Column(type="string", length=40, nullable=true)
  32.      */
  33.     private $userRole;
  34.     /**
  35.      * @ORM\OneToMany(targetEntity=UserTrackingDetail::class, mappedBy="userTracking", orphanRemoval=true)
  36.      */
  37.     private $details;
  38.     /**
  39.      * @ORM\Column(type="datetime")
  40.      */
  41.     private $startedAt;
  42.     /**
  43.      * @ORM\Column(type="datetime", nullable=true)
  44.      */
  45.     private $endedAt;
  46.     /**
  47.      * @ORM\Column(type="string", length=50)
  48.      */
  49.     private $sessionId;
  50.     /**
  51.      * @ORM\Column(type="integer", nullable=true)
  52.      */
  53.     private $duration;
  54.     public function __construct()
  55.     {
  56.         $this->details = new ArrayCollection();
  57.     }
  58.     /**
  59.      * Représente l'entité dans le BO
  60.      * @return string
  61.      */
  62.     public function getLabel(){
  63.         return '#' $this->getId() . ' - ' $this->getUser()->getFullnameAndEmail();
  64.     }
  65.     /**
  66.      * @param string $role
  67.      * @return string
  68.      */
  69.     public static function getUserRoleName($role)
  70.     {
  71.         if (!isset(static::$roleGroupName[$role])) {
  72.             return "Unknown role group ($role)";
  73.         }
  74.         return static::$roleGroupName[$role];
  75.     }
  76.     /**
  77.      * @return array<string>
  78.      */
  79.     public static function getAvailableUserRoles()
  80.     {
  81.         return [
  82.             self::ROLE_ADMIN,
  83.             self::ROLE_FREELANCER,
  84.             self::ROLE_FREELANCER_ASSISTANT,
  85.         ];
  86.     }
  87.     public function getId(): ?int
  88.     {
  89.         return $this->id;
  90.     }
  91.     public function getUser(): ?User
  92.     {
  93.         return $this->user;
  94.     }
  95.     public function setUser(?User $user): self
  96.     {
  97.         $this->user $user;
  98.         return $this;
  99.     }
  100.     public function getUserRole(): ?string
  101.     {
  102.         return $this->userRole;
  103.     }
  104.     public function setUserRole(string $userRole): self
  105.     {
  106.         $this->userRole $userRole;
  107.         return $this;
  108.     }
  109.     /**
  110.      * @return Collection|UserTrackingDetail[]
  111.      */
  112.     public function getDetails(): Collection
  113.     {
  114.         return $this->details;
  115.     }
  116.     public function addDetail(UserTrackingDetail $detail): self
  117.     {
  118.         if (!$this->details->contains($detail)) {
  119.             $this->details[] = $detail;
  120.             $detail->setUserTracking($this);
  121.         }
  122.         return $this;
  123.     }
  124.     public function removeDetail(UserTrackingDetail $detail): self
  125.     {
  126.         if ($this->details->contains($detail)) {
  127.             $this->details->removeElement($detail);
  128.             // set the owning side to null (unless already changed)
  129.             if ($detail->getUserTracking() === $this) {
  130.                 $detail->setUserTracking(null);
  131.             }
  132.         }
  133.         return $this;
  134.     }
  135.     public function getStartedAt(): ?\DateTimeInterface
  136.     {
  137.         return $this->startedAt;
  138.     }
  139.     public function setStartedAt(\DateTimeInterface $startedAt): self
  140.     {
  141.         $this->startedAt $startedAt;
  142.         return $this;
  143.     }
  144.     public function getEndedAt(): ?\DateTimeInterface
  145.     {
  146.         return $this->endedAt;
  147.     }
  148.     public function setEndedAt(?\DateTimeInterface $endedAt): self
  149.     {
  150.         $this->endedAt $endedAt;
  151.         return $this;
  152.     }
  153.     public function getSessionId(): ?string
  154.     {
  155.         return $this->sessionId;
  156.     }
  157.     public function setSessionId(string $sessionId): self
  158.     {
  159.         $this->sessionId $sessionId;
  160.         return $this;
  161.     }
  162.     public function getDuration(): ?int
  163.     {
  164.         return $this->duration;
  165.     }
  166.     public function setDuration(?int $duration): self
  167.     {
  168.         $this->duration $duration;
  169.         return $this;
  170.     }
  171. }