diff --git a/migrations/Version20240110122028.php b/migrations/Version20240110122028.php new file mode 100644 index 0000000..9128728 --- /dev/null +++ b/migrations/Version20240110122028.php @@ -0,0 +1,31 @@ +addSql('ALTER TABLE feedback CHANGE destination_name destination_name VARCHAR(255) DEFAULT NULL, CHANGE assignment_date assignment_date DATE DEFAULT NULL COMMENT \'(DC2Type:date_immutable)\', CHANGE job_profile_name job_profile_name VARCHAR(255) DEFAULT NULL'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE feedback CHANGE destination_name destination_name VARCHAR(255) NOT NULL, CHANGE job_profile_name job_profile_name VARCHAR(255) NOT NULL, CHANGE assignment_date assignment_date DATE NOT NULL COMMENT \'(DC2Type:date_immutable)\''); + } +} diff --git a/src/Controller/HouseManager/Feedback/ProvideController.php b/src/Controller/HouseManager/Feedback/ProvideController.php index 5605505..87f1212 100644 --- a/src/Controller/HouseManager/Feedback/ProvideController.php +++ b/src/Controller/HouseManager/Feedback/ProvideController.php @@ -45,7 +45,7 @@ class ProvideController extends AbstractController ->getFeedbackSet() ; - $feedback = new Feedback($assignment, $user); + $feedback = Feedback::fromAssignment($assignment, $user); $form = $this->createForm(FeedbackType::class, $feedback, ['feedback_set' => $feedbackSet]); $form->handleRequest($request); diff --git a/src/Entity/Feedback.php b/src/Entity/Feedback.php index eb2e6d7..fe52191 100644 --- a/src/Entity/Feedback.php +++ b/src/Entity/Feedback.php @@ -34,14 +34,14 @@ class Feedback implements BlameableEntityInterface, TimestampableEntityInterface #[ORM\ManyToOne(inversedBy: 'feedback')] private ?Teamer $teamer = null; - #[ORM\Column(length: 255)] - private ?string $destinationName; + #[ORM\Column(length: 255, nullable: true)] + private ?string $destinationName = null; - #[ORM\Column(length: 255)] - private ?string $jobProfileName; + #[ORM\Column(length: 255, nullable: true)] + private ?string $jobProfileName = null; - #[ORM\Column(type: Types::DATE_IMMUTABLE)] - private ?\DateTimeImmutable $assignmentDate; + #[ORM\Column(type: Types::DATE_IMMUTABLE, nullable: true)] + private ?\DateTimeImmutable $assignmentDate = null; #[ORM\Column] #[Assert\Count(min: 1, minMessage: 'Bitte gib eine Bewertung ab')] @@ -57,17 +57,27 @@ class Feedback implements BlameableEntityInterface, TimestampableEntityInterface private ?string $commentInternal = null; #[ORM\Column(length: 255)] - private ?string $author = null; + private ?string $author; - public function __construct(Assignment $assignment, User $author) + public function __construct(User $author) { $this->uuid = Uuid::v4(); - $this->destinationName = $assignment->getDestination()->getProduct(); - $this->assignmentDate = $assignment->getEffectiveDateFrom(); - $this->jobProfileName = $assignment->getJobProfile()->getName(); $this->author = $author->getFullName(); } + public static function fromAssignment(Assignment $assignment, User $user): static + { + $instance = new static($user); + + $instance + ->setDestinationName($assignment->getDestination()->getProduct()) + ->setAssignmentDate($assignment->getEffectiveDateFrom()) + ->setJobProfileName($assignment->getJobProfile()->getName()) + ; + + return $instance; + } + public function getId(): ?int { return $this->id; @@ -102,18 +112,6 @@ class Feedback implements BlameableEntityInterface, TimestampableEntityInterface return $this; } - public function getDestination(): ?Destination - { - return $this->destination; - } - - public function setDestination(?Destination $destination): static - { - $this->destination = $destination; - - return $this; - } - public function getDestinationName(): ?string { return $this->destinationName;