<?php
namespace App\Entity;
use App\Repository\UserTrackingRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=UserTrackingRepository::class)
*/
class UserTracking
{
const ROLE_ADMIN = 'ROLE_ADMIN';
const ROLE_FREELANCER = 'ROLE_FREELANCER';
const ROLE_FREELANCER_ASSISTANT = 'ROLE_FREELANCER_ASSISTANT';
protected static $roleGroupName = [
self::ROLE_ADMIN => 'Admin',
self::ROLE_FREELANCER => 'Indépendant',
self::ROLE_FREELANCER_ASSISTANT => 'Assistant',
];
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="userTracking")
*/
private $user;
/**
* @ORM\Column(type="string", length=40, nullable=true)
*/
private $userRole;
/**
* @ORM\OneToMany(targetEntity=UserTrackingDetail::class, mappedBy="userTracking", orphanRemoval=true)
*/
private $details;
/**
* @ORM\Column(type="datetime")
*/
private $startedAt;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $endedAt;
/**
* @ORM\Column(type="string", length=50)
*/
private $sessionId;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $duration;
public function __construct()
{
$this->details = new ArrayCollection();
}
/**
* Représente l'entité dans le BO
* @return string
*/
public function getLabel(){
return '#' . $this->getId() . ' - ' . $this->getUser()->getFullnameAndEmail();
}
/**
* @param string $role
* @return string
*/
public static function getUserRoleName($role)
{
if (!isset(static::$roleGroupName[$role])) {
return "Unknown role group ($role)";
}
return static::$roleGroupName[$role];
}
/**
* @return array<string>
*/
public static function getAvailableUserRoles()
{
return [
self::ROLE_ADMIN,
self::ROLE_FREELANCER,
self::ROLE_FREELANCER_ASSISTANT,
];
}
public function getId(): ?int
{
return $this->id;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getUserRole(): ?string
{
return $this->userRole;
}
public function setUserRole(string $userRole): self
{
$this->userRole = $userRole;
return $this;
}
/**
* @return Collection|UserTrackingDetail[]
*/
public function getDetails(): Collection
{
return $this->details;
}
public function addDetail(UserTrackingDetail $detail): self
{
if (!$this->details->contains($detail)) {
$this->details[] = $detail;
$detail->setUserTracking($this);
}
return $this;
}
public function removeDetail(UserTrackingDetail $detail): self
{
if ($this->details->contains($detail)) {
$this->details->removeElement($detail);
// set the owning side to null (unless already changed)
if ($detail->getUserTracking() === $this) {
$detail->setUserTracking(null);
}
}
return $this;
}
public function getStartedAt(): ?\DateTimeInterface
{
return $this->startedAt;
}
public function setStartedAt(\DateTimeInterface $startedAt): self
{
$this->startedAt = $startedAt;
return $this;
}
public function getEndedAt(): ?\DateTimeInterface
{
return $this->endedAt;
}
public function setEndedAt(?\DateTimeInterface $endedAt): self
{
$this->endedAt = $endedAt;
return $this;
}
public function getSessionId(): ?string
{
return $this->sessionId;
}
public function setSessionId(string $sessionId): self
{
$this->sessionId = $sessionId;
return $this;
}
public function getDuration(): ?int
{
return $this->duration;
}
public function setDuration(?int $duration): self
{
$this->duration = $duration;
return $this;
}
}