myCRM/src/Filter/ProjectTaskProjectFilter.php
olli 8a132d2fb9 feat: Implement ProjectTask module with full CRUD functionality
- 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.
2025-11-14 17:12:40 +01:00

58 lines
1.7 KiB
PHP

<?php
namespace App\Filter;
use ApiPlatform\Doctrine\Orm\Filter\AbstractFilter;
use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface;
use ApiPlatform\Metadata\Operation;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\PropertyInfo\Type;
final class ProjectTaskProjectFilter extends AbstractFilter
{
protected function filterProperty(
string $property,
$value,
QueryBuilder $queryBuilder,
QueryNameGeneratorInterface $queryNameGenerator,
string $resourceClass,
?Operation $operation = null,
array $context = []
): void {
if ($property !== 'hasProject') {
return;
}
$alias = $queryBuilder->getRootAliases()[0];
// Convert string 'true'/'false' to boolean
$hasProject = filter_var($value, FILTER_VALIDATE_BOOLEAN);
if ($hasProject) {
// Filter for tasks WITH project
$queryBuilder->andWhere(sprintf('%s.project IS NOT NULL', $alias));
} else {
// Filter for tasks WITHOUT project
$queryBuilder->andWhere(sprintf('%s.project IS NULL', $alias));
}
}
public function getDescription(string $resourceClass): array
{
return [
'hasProject' => [
'property' => 'hasProject',
'type' => Type::BUILTIN_TYPE_BOOL,
'required' => false,
'description' => 'Filter tasks by project existence (true = with project, false = without project)',
'openapi' => [
'example' => 'true',
'allowReserved' => false,
'allowEmptyValue' => true,
'explode' => false,
],
],
];
}
}