From d016ee043a4f41ba74f25cb5ef72de97ca6dc0b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Fri, 3 Nov 2023 09:20:48 +0100 Subject: [PATCH] WIP: Implement feedback functionality --- migrations/Version20231103081749.php | 43 +++++++++++++++++++ .../System/FeedbackSet/DeleteController.php | 1 + src/Entity/Assignment.php | 34 --------------- src/Entity/Disposition.php | 15 +++++++ src/Entity/Feedback.php | 16 ------- src/Entity/FeedbackSet.php | 14 +++--- src/Entity/JobProfile.php | 1 + src/Form/FeedbackSetType.php | 2 +- src/Form/JobProfileType.php | 2 +- src/Security/Voter/FeedbackSetVoter.php | 36 ++++++++++++++++ .../admin/system/feedback_set/_form.html.twig | 8 ++-- .../admin/system/feedback_set/index.html.twig | 24 ++++++----- 12 files changed, 123 insertions(+), 73 deletions(-) create mode 100644 migrations/Version20231103081749.php create mode 100644 src/Security/Voter/FeedbackSetVoter.php diff --git a/migrations/Version20231103081749.php b/migrations/Version20231103081749.php new file mode 100644 index 0000000..a6c9a68 --- /dev/null +++ b/migrations/Version20231103081749.php @@ -0,0 +1,43 @@ +addSql('ALTER TABLE disposition ADD feedback_id INT DEFAULT NULL'); + $this->addSql('ALTER TABLE disposition ADD CONSTRAINT FK_4C58BF60D249A887 FOREIGN KEY (feedback_id) REFERENCES feedback (id)'); + $this->addSql('CREATE UNIQUE INDEX UNIQ_4C58BF60D249A887 ON disposition (feedback_id)'); + $this->addSql('ALTER TABLE feedback DROP FOREIGN KEY FK_D2294458D19302F8'); + $this->addSql('DROP INDEX IDX_D2294458D19302F8 ON feedback'); + $this->addSql('ALTER TABLE feedback DROP assignment_id'); + $this->addSql('ALTER TABLE feedback_set ADD created_by VARCHAR(255) DEFAULT NULL, ADD updated_by VARCHAR(255) DEFAULT NULL, CHANGE items ratings JSON NOT NULL COMMENT \'(DC2Type:json)\''); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE disposition DROP FOREIGN KEY FK_4C58BF60D249A887'); + $this->addSql('DROP INDEX UNIQ_4C58BF60D249A887 ON disposition'); + $this->addSql('ALTER TABLE disposition DROP feedback_id'); + $this->addSql('ALTER TABLE feedback ADD assignment_id INT DEFAULT NULL'); + $this->addSql('ALTER TABLE feedback ADD CONSTRAINT FK_D2294458D19302F8 FOREIGN KEY (assignment_id) REFERENCES assignment (id) ON DELETE SET NULL'); + $this->addSql('CREATE INDEX IDX_D2294458D19302F8 ON feedback (assignment_id)'); + $this->addSql('ALTER TABLE feedback_set DROP created_by, DROP updated_by, CHANGE ratings items JSON NOT NULL COMMENT \'(DC2Type:json)\''); + } +} diff --git a/src/Controller/Admin/System/FeedbackSet/DeleteController.php b/src/Controller/Admin/System/FeedbackSet/DeleteController.php index 9796eba..4010ab6 100644 --- a/src/Controller/Admin/System/FeedbackSet/DeleteController.php +++ b/src/Controller/Admin/System/FeedbackSet/DeleteController.php @@ -20,6 +20,7 @@ class DeleteController extends AbstractController #[Route('/admin/system/feedback-set/delete/{id}', name: 'app_admin_system_feedback_set_delete', methods: ['POST'])] #[IsGranted('ROLE_ADMIN')] + #[IsGranted('DELETE', subject: 'feedbackSet')] public function index(FeedbackSet $feedbackSet): Response { $this->entityManager->remove($feedbackSet); diff --git a/src/Entity/Assignment.php b/src/Entity/Assignment.php index d681cd4..eb42e98 100644 --- a/src/Entity/Assignment.php +++ b/src/Entity/Assignment.php @@ -84,9 +84,6 @@ class Assignment implements BlameableEntityInterface, TimestampableEntityInterfa #[ORM\ManyToOne] private ?User $owner = null; - #[ORM\OneToMany(mappedBy: 'assignment', targetEntity: Feedback::class)] - private Collection $feedbacks; - public function __construct() { $this->uuid = Uuid::v4(); @@ -96,7 +93,6 @@ class Assignment implements BlameableEntityInterface, TimestampableEntityInterfa $this->teamers = new ArrayCollection(); $this->benefits = "Anreise im E&P Reisebus\nUnterkunft\nVerpflegung\nSkipass\n"; $this->documents = new ArrayCollection(); - $this->feedbacks = new ArrayCollection(); } public static function duplicate(Assignment $assignment): static @@ -440,34 +436,4 @@ class Assignment implements BlameableEntityInterface, TimestampableEntityInterfa return $this; } - - /** - * @return Collection - */ - public function getFeedbacks(): Collection - { - return $this->feedbacks; - } - - public function addFeedback(Feedback $feedback): static - { - if (!$this->feedbacks->contains($feedback)) { - $this->feedbacks->add($feedback); - $feedback->setAssignment($this); - } - - return $this; - } - - public function removeFeedback(Feedback $feedback): static - { - if ($this->feedbacks->removeElement($feedback)) { - // set the owning side to null (unless already changed) - if ($feedback->getAssignment() === $this) { - $feedback->setAssignment(null); - } - } - - return $this; - } } diff --git a/src/Entity/Disposition.php b/src/Entity/Disposition.php index 1f01974..b74cdd2 100644 --- a/src/Entity/Disposition.php +++ b/src/Entity/Disposition.php @@ -48,6 +48,9 @@ class Disposition implements BlameableEntityInterface, TimestampableEntityInterf #[ORM\OneToMany(mappedBy: 'disposition', targetEntity: Upload::class, cascade: ['persist', 'remove'])] private Collection $documents; + #[ORM\OneToOne(cascade: ['persist', 'remove'])] + private ?Feedback $feedback = null; + public function __construct(Application $application) { $this->uuid = Uuid::v4(); @@ -155,4 +158,16 @@ class Disposition implements BlameableEntityInterface, TimestampableEntityInterf return $this; } + + public function getFeedback(): ?Feedback + { + return $this->feedback; + } + + public function setFeedback(?Feedback $feedback): static + { + $this->feedback = $feedback; + + return $this; + } } diff --git a/src/Entity/Feedback.php b/src/Entity/Feedback.php index 0ff6e71..3ccbae8 100644 --- a/src/Entity/Feedback.php +++ b/src/Entity/Feedback.php @@ -26,10 +26,6 @@ class Feedback implements BlameableEntityInterface, TimestampableEntityInterface #[ORM\ManyToOne(inversedBy: 'feedback')] private ?Teamer $teamer = null; - #[ORM\ManyToOne(inversedBy: 'feedbacks')] - #[ORM\JoinColumn(onDelete: 'SET NULL')] - private ?Assignment $assignment = null; - #[ORM\Column(length: 255)] private ?string $assignmentDestination = null; @@ -66,18 +62,6 @@ class Feedback implements BlameableEntityInterface, TimestampableEntityInterface return $this; } - public function getAssignment(): ?Assignment - { - return $this->assignment; - } - - public function setAssignment(?Assignment $assignment): static - { - $this->assignment = $assignment; - - return $this; - } - public function getAssignmentDestination(): ?string { return $this->assignmentDestination; diff --git a/src/Entity/FeedbackSet.php b/src/Entity/FeedbackSet.php index 536d9f0..f181001 100644 --- a/src/Entity/FeedbackSet.php +++ b/src/Entity/FeedbackSet.php @@ -2,14 +2,16 @@ namespace App\Entity; +use App\Entity\Traits\BlameableEntity; use App\Entity\Traits\TimestampableEntity; use App\Repository\FeedbackSetRepository; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Constraints as Assert; #[ORM\Entity(repositoryClass: FeedbackSetRepository::class)] -class FeedbackSet implements TimestampableEntityInterface +class FeedbackSet implements BlameableEntityInterface, TimestampableEntityInterface { + use BlameableEntity; use TimestampableEntity; #[ORM\Id] @@ -23,7 +25,7 @@ class FeedbackSet implements TimestampableEntityInterface #[ORM\Column] #[Assert\Count(min: 1, minMessage: 'Bitte füge mindestens eine Bewertung hinzu')] - private array $items = []; + private array $ratings = []; public function getId(): ?int { @@ -42,14 +44,14 @@ class FeedbackSet implements TimestampableEntityInterface return $this; } - public function getItems(): array + public function getRatings(): array { - return $this->items; + return $this->ratings; } - public function setItems(array $items): static + public function setRatings(array $ratings): static { - $this->items = $items; + $this->ratings = $ratings; return $this; } diff --git a/src/Entity/JobProfile.php b/src/Entity/JobProfile.php index d178525..0346003 100644 --- a/src/Entity/JobProfile.php +++ b/src/Entity/JobProfile.php @@ -40,6 +40,7 @@ class JobProfile implements BlameableEntityInterface, TimestampableEntityInterfa #[ORM\ManyToOne] #[ORM\JoinColumn(onDelete: 'SET NULL')] + #[Assert\NotNull(message: 'Bitte ordne eine Feedback-Vorlage zu')] private ?FeedbackSet $feedbackSet = null; public function __construct() diff --git a/src/Form/FeedbackSetType.php b/src/Form/FeedbackSetType.php index 5c57bbb..f8449fc 100644 --- a/src/Form/FeedbackSetType.php +++ b/src/Form/FeedbackSetType.php @@ -17,7 +17,7 @@ class FeedbackSetType extends AbstractType ->add('name', TextType::class, [ 'label' => 'Bezeichnung', ]) - ->add('items', CollectionType::class, [ + ->add('ratings', CollectionType::class, [ 'label' => 'Bewertungen', 'entry_type' => TextType::class, 'allow_add' => true, diff --git a/src/Form/JobProfileType.php b/src/Form/JobProfileType.php index af6fdc1..f91775f 100644 --- a/src/Form/JobProfileType.php +++ b/src/Form/JobProfileType.php @@ -50,7 +50,7 @@ class JobProfileType extends AbstractType 'label' => 'Feedback-Vorlage', 'class' => FeedbackSet::class, 'choice_label' => 'name', - 'placeholder' => 'Kein Feedback', + 'placeholder' => '', ]) ; } diff --git a/src/Security/Voter/FeedbackSetVoter.php b/src/Security/Voter/FeedbackSetVoter.php new file mode 100644 index 0000000..1166e78 --- /dev/null +++ b/src/Security/Voter/FeedbackSetVoter.php @@ -0,0 +1,36 @@ +jobProfileRepository + ->findOneBy(['feedbackSet' => $feedbackSet]) + ; + + return null === $result; + } +} \ No newline at end of file diff --git a/templates/admin/system/feedback_set/_form.html.twig b/templates/admin/system/feedback_set/_form.html.twig index 19b3a9b..12a6efb 100644 --- a/templates/admin/system/feedback_set/_form.html.twig +++ b/templates/admin/system/feedback_set/_form.html.twig @@ -13,13 +13,13 @@ {{ form_start(form) }}
{{ form_row(form.name) }} -
+

Bewertungen

- {% do form.items.setRendered %} - {%- for item in form.items -%}{{- _self.collectionRow(item) -}}{%- endfor -%} + {% do form.ratings.setRendered %} + {%- for item in form.ratings -%}{{- _self.collectionRow(item) -}}{%- endfor -%}
- {{ form_errors(form.items) }} + {{ form_errors(form.ratings) }}
diff --git a/templates/admin/system/feedback_set/index.html.twig b/templates/admin/system/feedback_set/index.html.twig index 99f48a5..d1461f0 100644 --- a/templates/admin/system/feedback_set/index.html.twig +++ b/templates/admin/system/feedback_set/index.html.twig @@ -27,20 +27,22 @@ {{ feedbackSet.name }} - {{ feedbackSet.items|length }} + {{ feedbackSet.ratings|length }}
- + {% if is_granted('DELETE', feedbackSet) %} + + {% endif %} {{ icon('edit') }}