|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Repository; |
|
4
|
|
|
|
|
5
|
|
|
use App\Entity\Section; |
|
6
|
|
|
use App\Entity\Student; |
|
7
|
|
|
use App\Entity\Tuition; |
|
8
|
|
|
use App\Entity\TuitionGrade; |
|
9
|
|
|
use App\Entity\TuitionGradeCategory; |
|
10
|
|
|
use Doctrine\ORM\QueryBuilder; |
|
11
|
|
|
|
|
12
|
|
|
class TuitionGradeRepository extends AbstractTransactionalRepository implements TuitionGradeRepositoryInterface { |
|
13
|
|
|
|
|
14
|
|
|
private function createDefaultQueryBuilder(): QueryBuilder { |
|
15
|
|
|
return $this->em->createQueryBuilder() |
|
16
|
|
|
->select(['g', 't', 's', 'c']) |
|
17
|
|
|
->from(TuitionGrade::class, 'g') |
|
18
|
|
|
->leftJoin('g.category', 'c') |
|
19
|
|
|
->leftJoin('g.student', 's') |
|
20
|
|
|
->leftJoin('g.tuition', 't'); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function findAllByTuition(Tuition $tuition): array { |
|
24
|
|
|
return $this->createDefaultQueryBuilder() |
|
|
|
|
|
|
25
|
|
|
->where('t.id = :tuition') |
|
26
|
|
|
->setParameter('tuition', $tuition->getId()) |
|
27
|
|
|
->getQuery() |
|
28
|
|
|
->getResult(); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function findAllByStudent(Student $student, Section $section): array { |
|
32
|
|
|
return $this->createDefaultQueryBuilder() |
|
|
|
|
|
|
33
|
|
|
->leftJoin('t.section', 'sec') |
|
34
|
|
|
->where('s.id = :student') |
|
35
|
|
|
->andWhere('sec.id = :section') |
|
36
|
|
|
->setParameter('student', $student->getId()) |
|
37
|
|
|
->setParameter('section', $section->getId()) |
|
38
|
|
|
->getQuery() |
|
39
|
|
|
->getResult(); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function countByTuitionGradeCategory(TuitionGradeCategory $category): int { |
|
43
|
|
|
return $this->em->createQueryBuilder() |
|
44
|
|
|
->select('COUNT(DISTINCT g.id)') |
|
45
|
|
|
->from(TuitionGrade::class, 'g') |
|
46
|
|
|
->leftJoin('g.category', 'c') |
|
47
|
|
|
->where('c.id = :category') |
|
48
|
|
|
->setParameter('category', $category->getId()) |
|
49
|
|
|
->getQuery() |
|
50
|
|
|
->getSingleScalarResult(); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function persist(TuitionGrade $grade): void { |
|
54
|
|
|
$this->em->persist($grade); |
|
55
|
|
|
$this->flushIfNotInTransaction(); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function removeForSection(Section $section): int { |
|
59
|
|
|
$qb = $this->em->createQueryBuilder() |
|
60
|
|
|
->delete(TuitionGrade::class, 'g'); |
|
61
|
|
|
|
|
62
|
|
|
$qbInner = $this->em->createQueryBuilder() |
|
63
|
|
|
->select('tInner.id') |
|
64
|
|
|
->from(Tuition::class, 'tInner') |
|
65
|
|
|
->where('tInner.section = :section'); |
|
66
|
|
|
|
|
67
|
|
|
$qb->where($qb->expr()->in('g.tuition', $qbInner->getDQL())) |
|
68
|
|
|
->setParameter('section', $section->getId()); |
|
69
|
|
|
|
|
70
|
|
|
return $qb->getQuery()->execute(); |
|
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
} |