-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectRepository.php
More file actions
122 lines (101 loc) · 3.8 KB
/
ProjectRepository.php
File metadata and controls
122 lines (101 loc) · 3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
namespace App\Repository;
use App\Entity\Project;
use App\Entity\ServiceAgreement;
use App\Model\Invoices\ProjectFilterData;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\QueryBuilder;
use Doctrine\Persistence\ManagerRegistry;
use Knp\Component\Pager\Pagination\PaginationInterface;
use Knp\Component\Pager\PaginatorInterface;
/**
* @extends ServiceEntityRepository<Project>
*
* @method Project|null find($id, $lockMode = null, $lockVersion = null)
* @method Project|null findOneBy(array $criteria, array $orderBy = null)
* @method findAll()
* @method findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class ProjectRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry, private readonly PaginatorInterface $paginator)
{
parent::__construct($registry, Project::class);
}
public function save(Project $entity, bool $flush = false): void
{
$this->getEntityManager()->persist($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
public function remove(Project $entity, bool $flush = false): void
{
$this->getEntityManager()->remove($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
public function getIncluded(): QueryBuilder
{
$qb = $this->createQueryBuilder('project');
$qb
->where($qb->expr()->eq('project.include', true))
->orderBy('project.name', 'ASC');
return $qb;
}
public function getFilteredPagination(ProjectFilterData $projectFilterData, int $page = 1): PaginationInterface
{
$qb = $this->createQueryBuilder('project');
if (!is_null($projectFilterData->include)) {
$qb->andWhere(
$projectFilterData->include
? 'project.include = TRUE'
: 'project.include = FALSE OR project.include IS NULL'
);
}
if (!is_null($projectFilterData->isBillable)) {
$qb->andWhere(
$projectFilterData->isBillable
? 'project.isBillable = TRUE'
: 'project.isBillable = FALSE OR project.isBillable IS NULL'
);
}
if (!is_null($projectFilterData->name)) {
$name = $projectFilterData->name;
$qb->andWhere('project.name LIKE :name')->setParameter('name', "%$name%");
}
if (!is_null($projectFilterData->key)) {
$key = $projectFilterData->key;
$qb->andWhere('project.projectTrackerKey LIKE :key')->setParameter('key', "%$key%");
}
return $this->paginator->paginate(
$qb,
$page,
10,
['defaultSortFieldName' => 'project.id', 'defaultSortDirection' => 'asc']
);
}
public function getProjectTrackerIdsByDataProviders(array $dataProviders)
{
$qb = $this->createQueryBuilder('project');
$qb
->select('project.projectTrackerId')
->where($qb->expr()->eq('project.include', true))
->where($qb->expr()->in('project.dataProvider', ':dataProviders'))
->setParameter('dataProviders', $dataProviders)
->orderBy('project.projectTrackerId', 'ASC');
return $qb->getQuery()->getSingleColumnResult();
}
public function getProjectIdsWithCybersecurityAgreement(): array
{
$result = $this->_em->createQueryBuilder()
->select('DISTINCT p.id')
->from(ServiceAgreement::class, 'sa')
->innerJoin('sa.project', 'p')
->where('sa.cybersecurityAgreement IS NOT NULL')
->getQuery()
->getScalarResult();
return array_column($result, 'id');
}
}