WIP: Implement feedback functionality

This commit is contained in:
Björn Fromme committed 2023-11-03 09:20:48 +01:00
1 parent d024e11f8f
commit d016ee043a
12 files changed
+123 -73

No files matched your search

@@ -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);
-34
View File
@@ -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<int, Feedback>
*/
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;
}
}
+15
View File
@@ -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;
}
}
-16
View File
@@ -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;
+8 -6
View File
@@ -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;
}
+1
View File
@@ -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()
+1 -1
View File
@@ -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,
+1 -1
View File
@@ -50,7 +50,7 @@ class JobProfileType extends AbstractType
'label' => 'Feedback-Vorlage',
'class' => FeedbackSet::class,
'choice_label' => 'name',
'placeholder' => 'Kein Feedback',
'placeholder' => '',
])
;
}
+36
View File
@@ -0,0 +1,36 @@
<?php
namespace App\Security\Voter;
use App\Entity\FeedbackSet;
use App\Repository\JobProfileRepository;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
class FeedbackSetVoter extends Voter
{
public const DELETE = 'DELETE';
public function __construct(private readonly JobProfileRepository $jobProfileRepository)
{
}
protected function supports(string $attribute, mixed $subject): bool
{
return $subject instanceof FeedbackSet && static::DELETE === $attribute;
}
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
{
/** @var FeedbackSet $feedbackSet */
$feedbackSet = $subject;
// Feedback sets may only be deleted when not in use
$result = $this
->jobProfileRepository
->findOneBy(['feedbackSet' => $feedbackSet])
;
return null === $result;
}
}