Files
myep-team/src/Entity/Feedback.php
T

292 lines
6.6 KiB
PHP

<?php
namespace App\Entity;
use App\Entity\Traits\BlameableEntity;
use App\Entity\Traits\TimestampableEntity;
use App\Repository\FeedbackRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Uid\Uuid;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: FeedbackRepository::class)]
#[ORM\HasLifecycleCallbacks]
class Feedback implements BlameableEntityInterface, TimestampableEntityInterface
{
use BlameableEntity;
use TimestampableEntity;
public const STATUS_NEW = 'new';
public const STATUS_PUBLISHED = 'published';
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(type: 'string', length: 36, unique: true)]
private string $uuid;
#[ORM\Column(length: 32)]
private ?string $status = self::STATUS_NEW;
#[ORM\ManyToOne(inversedBy: 'feedback')]
private ?Teamer $teamer = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $destinationName = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $jobProfileName = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $hotel = null;
#[ORM\Column(length: 32, nullable: true)]
private ?string $hotelCode = null;
#[ORM\Column(nullable: true)]
private ?int $hotelBusProId = null;
#[ORM\Column(type: Types::DATE_IMMUTABLE, nullable: true)]
private ?\DateTimeImmutable $assignmentDateFrom = null;
#[ORM\Column(type: Types::DATE_IMMUTABLE, nullable: true)]
private ?\DateTimeImmutable $assignmentDateTo = null;
#[ORM\Column]
#[Assert\Count(min: 1, minMessage: 'Bitte gib eine Bewertung ab')]
private array $ratings = [];
#[ORM\Column(nullable: true)]
private ?int $averageRating = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $comment = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $commentInternal = null;
#[ORM\Column(length: 255)]
private ?string $author;
public function __construct(User $author)
{
$this->uuid = Uuid::v4();
$this->author = $author->getFullName();
}
public static function fromAssignment(Assignment $assignment, User $user): static
{
$instance = new static($user);
$destination = $assignment->getDestination();
$jobProfile = $assignment->getJobProfile();
$instance
->setAssignmentDateFrom($assignment->getEffectiveDateFrom())
->setAssignmentDateTo($assignment->getEffectiveDateTo())
->setDestinationName($destination->getProduct())
->setHotel($destination->getHotel())
->setHotelCode($destination->getHotelCode())
->setHotelBusProId($destination->getHotelBusProId())
->setJobProfileName($jobProfile->getName())
;
return $instance;
}
public function getId(): ?int
{
return $this->id;
}
public function getUuid(): string
{
return $this->uuid;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(string $status): static
{
$this->status = $status;
return $this;
}
public function getTeamer(): ?Teamer
{
return $this->teamer;
}
public function setTeamer(?Teamer $teamer): static
{
$this->teamer = $teamer;
return $this;
}
public function getDestinationName(): ?string
{
return $this->destinationName;
}
public function setDestinationName(string $destinationName): static
{
$this->destinationName = $destinationName;
return $this;
}
public function getAssignmentDateFrom(): ?\DateTimeImmutable
{
return $this->assignmentDateFrom;
}
public function setAssignmentDateFrom(\DateTimeImmutable $assignmentDateFrom): static
{
$this->assignmentDateFrom = $assignmentDateFrom;
return $this;
}
public function getAssignmentDateTo(): ?\DateTimeImmutable
{
return $this->assignmentDateTo;
}
public function setAssignmentDateTo(?\DateTimeImmutable $assignmentDateTo): static
{
$this->assignmentDateTo = $assignmentDateTo;
return $this;
}
public function getJobProfileName(): ?string
{
return $this->jobProfileName;
}
public function setJobProfileName(?string $jobProfileName): static
{
$this->jobProfileName = $jobProfileName;
return $this;
}
public function getHotel(): ?string
{
return $this->hotel;
}
public function setHotel(?string $hotel): static
{
$this->hotel = $hotel;
return $this;
}
public function getHotelCode(): ?string
{
return $this->hotelCode;
}
public function setHotelCode(?string $hotelCode): static
{
$this->hotelCode = $hotelCode;
return $this;
}
public function getHotelBusProId(): ?int
{
return $this->hotelBusProId;
}
public function setHotelBusProId(?int $hotelBusProId): static
{
$this->hotelBusProId = $hotelBusProId;
return $this;
}
public function getRatings(): array
{
return $this->ratings;
}
public function setRatings(array $ratings): static
{
$this->ratings = $ratings;
return $this;
}
public function getAverageRating(): ?int
{
return $this->averageRating;
}
#[ORM\PrePersist]
#[ORM\PreUpdate]
public function setAverageRating(): static
{
if (0 === count($this->ratings)) {
$this->averageRating = null;
return $this;
}
$sum = 0;
foreach ($this->ratings as $rating) {
$sum += $rating['mark'];
}
$this->averageRating = $sum/count($this->ratings) * 100;
return $this;
}
public function getComment(): ?string
{
return $this->comment;
}
public function setComment(?string $comment): static
{
$this->comment = $comment;
return $this;
}
public function getCommentInternal(): ?string
{
return $this->commentInternal;
}
public function setCommentInternal(?string $commentInternal): static
{
$this->commentInternal = $commentInternal;
return $this;
}
public function getAuthor(): ?string
{
return $this->author;
}
public function setAuthor(string $author): static
{
$this->author = $author;
return $this;
}
}