Files
myep-team/src/Entity/Application.php
T
2023-10-25 15:22:38 +02:00

162 lines
3.5 KiB
PHP

<?php
namespace App\Entity;
use App\Entity\Traits\TimestampableEntity;
use App\Repository\ApplicationRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Uid\Uuid;
#[ORM\Entity(repositoryClass: ApplicationRepository::class)]
class Application implements TimestampableEntityInterface
{
use TimestampableEntity;
public const STATUS_NEW = 'new';
public const STATUS_PENDING = 'pending';
public const STATUS_REJECTED = 'rejected';
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(type: 'string', length: 36, unique: true)]
private string $uuid;
#[ORM\ManyToOne(inversedBy: 'applications')]
private ?Assignment $assignment;
#[ORM\ManyToOne(inversedBy: 'applications')]
private ?Teamer $teamer;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $requests = null;
#[ORM\Column(length: 64)]
private ?string $status;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $comment = null;
#[ORM\Column]
private ?bool $commentVisible = false;
public function __construct(Assignment $assignment, Teamer $teamer)
{
$this->uuid = Uuid::v4();
$this->assignment = $assignment;
$this->teamer = $teamer;
$this->status = static::STATUS_NEW;
}
public function getId(): ?int
{
return $this->id;
}
public function getUuid(): string
{
return $this->uuid;
}
public function getAssignment(): ?Assignment
{
return $this->assignment;
}
public function setAssignment(?Assignment $assignment): static
{
$this->assignment = $assignment;
return $this;
}
public function getTeamer(): ?Teamer
{
return $this->teamer;
}
public function setTeamer(?Teamer $teamer): static
{
$this->teamer = $teamer;
return $this;
}
public function getRequests(): ?string
{
return $this->requests;
}
public function setRequests(?string $requests): static
{
$this->requests = $requests;
return $this;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(string $status): static
{
$this->status = $status;
return $this;
}
public function matchesPickup(): bool
{
if (0 === $pickupId = (int) $this->getAssignment()->getPickup()) {
return true;
}
$teamer = $this->getTeamer();
return $teamer->hasPickup($pickupId);
}
public function matchesRequiredTrainings(): bool
{
$count = 0;
$requiredTrainings = $this->getAssignment()->getJobProfile()->getRequiredTrainings();
$teamer = $this->getTeamer();
foreach ($requiredTrainings as $requiredTraining) {
if ($teamer->getTrainingAttendance($requiredTraining)) {
++$count;
}
}
return $count === $requiredTrainings->count();
}
public function getComment(): ?string
{
return $this->comment;
}
public function setComment(?string $comment): static
{
$this->comment = $comment;
return $this;
}
public function isCommentVisible(): ?bool
{
return $this->commentVisible;
}
public function setCommentVisible(bool $commentVisible): static
{
$this->commentVisible = $commentVisible;
return $this;
}
}