src/Entity/Attendance.php line 34
<?phpnamespace App\Entity;use ApiPlatform\Metadata\ApiResource;use ApiPlatform\Metadata\Get;use ApiPlatform\Metadata\GetCollection;use ApiPlatform\Metadata\Post;use App\Dto\CreateAttendanceInput;use App\Kimia;use App\Repository\AttendanceRepository;use App\State\Attendance\SaveAttendanceProcessor;use App\Trait\DateTrait;use DateTimeImmutable;use DateTimeInterface;use Doctrine\DBAL\Types\Types;use Doctrine\ORM\Mapping as ORM;use Symfony\Component\Serializer\Annotation\Groups;#[ORM\Entity(repositoryClass: AttendanceRepository::class)]#[ApiResource(operations: [new GetCollection(normalizationContext: ['groups' => ['attendance:list']]),new Get(),new Post(input: CreateAttendanceInput::class,processor: SaveAttendanceProcessor::class),],normalizationContext: ['groups' => ['attendance:list', 'attendance:view']])]class Attendance{use DateTrait;const TYPE_EMPLOYEE = "EMP";const TYPE_CLIENT = "CLT";#[ORM\Id]#[ORM\GeneratedValue]#[ORM\Column]#[Groups(['attendance:list'])]private ?int $id = null;#[ORM\ManyToOne(inversedBy: 'attendances')]#[ORM\JoinColumn(nullable: true)]private ?Employee $employee = null;#[ORM\ManyToOne(inversedBy: 'attendances')]private ?Client $client = null;#[ORM\ManyToOne]#[ORM\JoinColumn(nullable: false)]private ?Establishment $establishment = null;#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]#[Groups(['attendance:list'])]private ?DateTimeInterface $arrivedAt = null;#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]#[Groups(['attendance:list'])]private ?DateTimeInterface $departedAt = null;#[ORM\Column(length: 255)]#[Groups(['attendance:list'])]private ?string $status = null;#[ORM\Column(type: Types::TEXT, nullable: true)]#[Groups(['attendance:list'])]private ?string $rapport = null;#[ORM\Column(length: 255, nullable: true)]private ?string $initiator = null;public function __construct(){if (is_null($this->createdAt)) $this->createdAt = new DateTimeImmutable();$this->updatedAt = new DateTimeImmutable();}public function getId(): ?int{return $this->id;}public function getEmployee(): ?Employee{return $this->employee;}public function setEmployee(?Employee $employee): self{$this->employee = $employee;return $this;}public function getClient(): ?Client{return $this->client;}public function setClient(?Client $client): static{$this->client = $client;return $this;}#[Groups(['attendance:list'])]public function getActor(): Employee|Client|null{if (!is_null($this->getEmployee()))return $this->getEmployee();elsereturn $this->getClient();}public function getArrivedAt(): ?DateTimeInterface{return $this->arrivedAt;}public function setArrivedAt(?DateTimeInterface $arrivedAt): self{$this->arrivedAt = $arrivedAt;return $this;}public function getDepartedAt(): ?DateTimeInterface{return $this->departedAt;}public function setDepartedAt(?DateTimeInterface $departedAt): self{$this->departedAt = $departedAt;return $this;}public function getRapport(): ?string{return $this->rapport;}public function setRapport(?string $rapport): self{$this->rapport = $rapport;return $this;}public function getStatus(): ?string{return $this->status;}public static function getStatusList(): array{return ['Absent' => Kimia::ATTENDANCE_ABSENT,'Présent' => Kimia::ATTENDANCE_PRESENT,];}public static function getStatusListForView(): array{return [Kimia::ATTENDANCE_ABSENT => "<span class='badge badge-soft-danger'>Absent</span>",Kimia::ATTENDANCE_PRESENT => "<span class='badge badge-soft-success'>Présent</span>",];}public function setStatus(string $status): self{$this->status = $status;return $this;}public function getEstablishment(): ?Establishment{return $this->establishment;}public function setEstablishment(?Establishment $establishment): self{$this->establishment = $establishment;return $this;}public function __toString(): string{return "Présence de {$this->getActor()?->getFullname()} du {$this->getCreatedAt()->format('d/m/Y')}";}public function getInitiator(): ?string{return $this->initiator;}public function setInitiator(?string $initiator): static{$this->initiator = $initiator;return $this;}}