- Added ProjectTask entity with fields for name, description, budget, hour contingent, hourly rate, and total price. - Created ProjectTaskRepository with methods for querying tasks by project and user access. - Implemented ProjectTaskVoter for fine-grained access control based on user roles and project membership. - Developed ProjectTaskSecurityListener to enforce permission checks during task creation. - Introduced custom ProjectTaskProjectFilter for filtering tasks based on project existence. - Integrated ProjectTask management in the frontend with Vue.js components, including CRUD operations and filtering capabilities. - Added API endpoints for ProjectTask with appropriate security measures. - Created migration for project_tasks table in the database. - Updated documentation to reflect new module features and usage.
238 lines
6.7 KiB
PHP
238 lines
6.7 KiB
PHP
<?php
|
|
|
|
namespace App\Entity;
|
|
|
|
use ApiPlatform\Metadata\ApiResource;
|
|
use ApiPlatform\Metadata\ApiFilter;
|
|
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
|
|
use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
|
|
use App\Filter\ProjectTaskProjectFilter;
|
|
use ApiPlatform\Metadata\Get;
|
|
use ApiPlatform\Metadata\GetCollection;
|
|
use ApiPlatform\Metadata\Post;
|
|
use ApiPlatform\Metadata\Put;
|
|
use ApiPlatform\Metadata\Delete;
|
|
use App\Entity\Interface\ModuleAwareInterface;
|
|
use App\Repository\ProjectTaskRepository;
|
|
use Doctrine\DBAL\Types\Types;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
use Symfony\Component\Serializer\Annotation\Groups;
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
|
|
|
#[ORM\Entity(repositoryClass: ProjectTaskRepository::class)]
|
|
#[ORM\Table(name: 'project_tasks')]
|
|
#[ApiResource(
|
|
operations: [
|
|
new GetCollection(
|
|
security: "is_granted('VIEW', 'project_tasks')",
|
|
stateless: false
|
|
),
|
|
new Get(
|
|
security: "is_granted('VIEW', object)",
|
|
stateless: false
|
|
),
|
|
new Post(
|
|
security: "is_granted('CREATE', 'project_tasks')",
|
|
stateless: false
|
|
),
|
|
new Put(
|
|
security: "is_granted('EDIT', object)",
|
|
stateless: false
|
|
),
|
|
new Delete(
|
|
security: "is_granted('DELETE', object)",
|
|
stateless: false
|
|
)
|
|
],
|
|
paginationClientItemsPerPage: true,
|
|
paginationItemsPerPage: 30,
|
|
paginationMaximumItemsPerPage: 5000,
|
|
normalizationContext: ['groups' => ['project_task:read']],
|
|
denormalizationContext: ['groups' => ['project_task:write']],
|
|
order: ['createdAt' => 'DESC']
|
|
)]
|
|
#[ApiFilter(SearchFilter::class, properties: ['name' => 'partial', 'project.name' => 'partial'])]
|
|
#[ApiFilter(DateFilter::class, properties: ['createdAt', 'updatedAt'])]
|
|
#[ApiFilter(ProjectTaskProjectFilter::class)]
|
|
class ProjectTask implements ModuleAwareInterface
|
|
{
|
|
#[ORM\Id]
|
|
#[ORM\GeneratedValue]
|
|
#[ORM\Column]
|
|
#[Groups(['project_task:read'])]
|
|
private ?int $id = null;
|
|
|
|
#[ORM\Column(length: 255)]
|
|
#[Groups(['project_task:read', 'project_task:write'])]
|
|
#[Assert\NotBlank(message: 'Der Name der Tätigkeit darf nicht leer sein')]
|
|
#[Assert\Length(max: 255)]
|
|
private ?string $name = null;
|
|
|
|
#[ORM\Column(type: Types::TEXT, nullable: true)]
|
|
#[Groups(['project_task:read', 'project_task:write'])]
|
|
private ?string $description = null;
|
|
|
|
#[ORM\ManyToOne(targetEntity: Project::class)]
|
|
#[ORM\JoinColumn(nullable: true, onDelete: 'CASCADE')]
|
|
#[Groups(['project_task:read', 'project_task:write'])]
|
|
private ?Project $project = null;
|
|
|
|
#[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 2, nullable: true)]
|
|
#[Groups(['project_task:read', 'project_task:write'])]
|
|
#[Assert\PositiveOrZero(message: 'Das Budget muss positiv sein')]
|
|
private ?string $budget = null;
|
|
|
|
#[ORM\Column(type: Types::DECIMAL, precision: 8, scale: 2, nullable: true)]
|
|
#[Groups(['project_task:read', 'project_task:write'])]
|
|
#[Assert\PositiveOrZero(message: 'Das Stundenkontingent muss positiv sein')]
|
|
private ?string $hourContingent = null;
|
|
|
|
#[ORM\Column(type: Types::DECIMAL, precision: 8, scale: 2, nullable: true)]
|
|
#[Groups(['project_task:read', 'project_task:write'])]
|
|
#[Assert\PositiveOrZero(message: 'Der Stundensatz muss positiv sein')]
|
|
private ?string $hourlyRate = null;
|
|
|
|
#[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 2, nullable: true)]
|
|
#[Groups(['project_task:read', 'project_task:write'])]
|
|
#[Assert\PositiveOrZero(message: 'Der Gesamtpreis muss positiv sein')]
|
|
private ?string $totalPrice = null;
|
|
|
|
#[ORM\Column]
|
|
#[Groups(['project_task:read'])]
|
|
private ?\DateTimeImmutable $createdAt = null;
|
|
|
|
#[ORM\Column(nullable: true)]
|
|
#[Groups(['project_task:read'])]
|
|
private ?\DateTimeImmutable $updatedAt = null;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->createdAt = new \DateTimeImmutable();
|
|
}
|
|
|
|
public function getId(): ?int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function getName(): ?string
|
|
{
|
|
return $this->name;
|
|
}
|
|
|
|
public function setName(string $name): static
|
|
{
|
|
$this->name = $name;
|
|
$this->updatedAt = new \DateTimeImmutable();
|
|
return $this;
|
|
}
|
|
|
|
public function getDescription(): ?string
|
|
{
|
|
return $this->description;
|
|
}
|
|
|
|
public function setDescription(?string $description): static
|
|
{
|
|
$this->description = $description;
|
|
$this->updatedAt = new \DateTimeImmutable();
|
|
return $this;
|
|
}
|
|
|
|
public function getProject(): ?Project
|
|
{
|
|
return $this->project;
|
|
}
|
|
|
|
public function setProject(?Project $project): static
|
|
{
|
|
$this->project = $project;
|
|
$this->updatedAt = new \DateTimeImmutable();
|
|
return $this;
|
|
}
|
|
|
|
public function getBudget(): ?string
|
|
{
|
|
return $this->budget;
|
|
}
|
|
|
|
public function setBudget(?string $budget): static
|
|
{
|
|
$this->budget = $budget;
|
|
$this->updatedAt = new \DateTimeImmutable();
|
|
return $this;
|
|
}
|
|
|
|
public function getHourContingent(): ?string
|
|
{
|
|
return $this->hourContingent;
|
|
}
|
|
|
|
public function setHourContingent(?string $hourContingent): static
|
|
{
|
|
$this->hourContingent = $hourContingent;
|
|
$this->updatedAt = new \DateTimeImmutable();
|
|
return $this;
|
|
}
|
|
|
|
public function getHourlyRate(): ?string
|
|
{
|
|
return $this->hourlyRate;
|
|
}
|
|
|
|
public function setHourlyRate(?string $hourlyRate): static
|
|
{
|
|
$this->hourlyRate = $hourlyRate;
|
|
$this->updatedAt = new \DateTimeImmutable();
|
|
return $this;
|
|
}
|
|
|
|
public function getTotalPrice(): ?string
|
|
{
|
|
return $this->totalPrice;
|
|
}
|
|
|
|
public function setTotalPrice(?string $totalPrice): static
|
|
{
|
|
$this->totalPrice = $totalPrice;
|
|
$this->updatedAt = new \DateTimeImmutable();
|
|
return $this;
|
|
}
|
|
|
|
public function getCreatedAt(): ?\DateTimeImmutable
|
|
{
|
|
return $this->createdAt;
|
|
}
|
|
|
|
public function setCreatedAt(\DateTimeImmutable $createdAt): static
|
|
{
|
|
$this->createdAt = $createdAt;
|
|
return $this;
|
|
}
|
|
|
|
public function getUpdatedAt(): ?\DateTimeImmutable
|
|
{
|
|
return $this->updatedAt;
|
|
}
|
|
|
|
public function setUpdatedAt(?\DateTimeImmutable $updatedAt): static
|
|
{
|
|
$this->updatedAt = $updatedAt;
|
|
return $this;
|
|
}
|
|
|
|
public function __toString(): string
|
|
{
|
|
return $this->name ?? '';
|
|
}
|
|
|
|
/**
|
|
* Returns the module code this entity belongs to.
|
|
* Required by ModuleVoter for permission checks.
|
|
*/
|
|
public function getModuleName(): string
|
|
{
|
|
return 'project_tasks';
|
|
}
|
|
}
|