* feat: start project reviews entity * feat: add review areas entity * feat: add review comments entity * fix: code styles improvements by php-cs-fixer * feat: expose project review resources in the API * feat: add timestampt to review resources * feat: add SQL migration * fix: update ProjectReview API docs and operations * feat: refactor ProjectsListener to dedicated project status listener * fix: make default review area risk high * feat: add ReviewService for creating default project reviews * fix: renamed timestampt entity traits * fix: update doctrine migration * feat: test for release date to be set greater than today's start * feat: add test for project campaign review * fix: update person and organization patch validations * fix: test if review entity is truly persisted * fix: bad start statuses in project tests * fix: ProjectStatusListener not persisting side effect data * fix: centralize project status change side-effects processing in ProjectService * fix: small review persistence tweaks * feat: allow only concerned users to see and edit review areas * feat: apply validations and security for concerned users to review comments
125 lines
2.7 KiB
PHP
125 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Entity\Project;
|
|
|
|
use App\Entity\DateCreatedTrait;
|
|
use App\Entity\DateUpdatedTrait;
|
|
use App\Entity\User\User;
|
|
use App\Mapping\Provider\EntityMapProvider;
|
|
use App\Repository\Project\ReviewRepository;
|
|
use AutoMapper\Attribute\MapProvider;
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
use Doctrine\Common\Collections\Collection;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
use Symfony\Component\Security\Core\User\UserInterface;
|
|
|
|
#[MapProvider(EntityMapProvider::class)]
|
|
#[ORM\Entity(repositoryClass: ReviewRepository::class)]
|
|
class Review
|
|
{
|
|
use DateCreatedTrait;
|
|
use DateUpdatedTrait;
|
|
|
|
#[ORM\Id]
|
|
#[ORM\GeneratedValue]
|
|
#[ORM\Column]
|
|
private ?int $id = null;
|
|
|
|
#[ORM\ManyToOne(inversedBy: 'reviews')]
|
|
#[ORM\JoinColumn(nullable: false)]
|
|
private ?Project $project = null;
|
|
|
|
#[ORM\ManyToOne]
|
|
private ?User $reviewer = null;
|
|
|
|
#[ORM\Column(enumType: ReviewType::class)]
|
|
private ?ReviewType $type = null;
|
|
|
|
/**
|
|
* @var Collection<int, ReviewArea>
|
|
*/
|
|
#[ORM\OneToMany(targetEntity: ReviewArea::class, mappedBy: 'review', cascade: ['persist'])]
|
|
private Collection $areas;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->areas = new ArrayCollection();
|
|
}
|
|
|
|
public function getId(): ?int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function getProject(): ?Project
|
|
{
|
|
return $this->project;
|
|
}
|
|
|
|
public function setProject(?Project $project): static
|
|
{
|
|
$this->project = $project;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getReviewer(): ?User
|
|
{
|
|
return $this->reviewer;
|
|
}
|
|
|
|
public function isReviewedBy(UserInterface $user): bool
|
|
{
|
|
return $this->reviewer?->getUserIdentifier() === $user->getUserIdentifier();
|
|
}
|
|
|
|
public function setReviewer(?User $reviewer): static
|
|
{
|
|
$this->reviewer = $reviewer;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getType(): ?ReviewType
|
|
{
|
|
return $this->type;
|
|
}
|
|
|
|
public function setType(ReviewType $type): static
|
|
{
|
|
$this->type = $type;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return Collection<int, ReviewArea>
|
|
*/
|
|
public function getAreas(): Collection
|
|
{
|
|
return $this->areas;
|
|
}
|
|
|
|
public function addArea(ReviewArea $area): static
|
|
{
|
|
if (!$this->areas->contains($area)) {
|
|
$this->areas->add($area);
|
|
$area->setReview($this);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function removeArea(ReviewArea $area): static
|
|
{
|
|
if ($this->areas->removeElement($area)) {
|
|
// set the owning side to null (unless already changed)
|
|
if ($area->getReview() === $this) {
|
|
$area->setReview(null);
|
|
}
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
}
|