add method to filter notes
This commit is contained in:
parent
2031165afc
commit
43bff55192
@ -5,7 +5,7 @@ namespace App\Repository;
|
||||
use App\Entity\Referral;
|
||||
use App\Entity\StandardNote;
|
||||
use App\Entity\User;
|
||||
use DateTimeImmutable;
|
||||
use App\Entity\UserCase;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
@ -31,29 +31,39 @@ class StandardNoteRepository extends ServiceEntityRepository
|
||||
;
|
||||
}
|
||||
|
||||
public function filterNotes(User $user, ?Referral $referral = null, ?DateTimeImmutable $startDate = null, ?DateTimeImmutable $endDate = null): array
|
||||
public function filterNotes(User $user, array $params = []): array
|
||||
{
|
||||
$query = $this->createQueryBuilder('v')
|
||||
->join('v.referral', 'r')
|
||||
$query = $this->createQueryBuilder('s')
|
||||
->leftJoin(Referral::class, 'r', 'WITH', 's.referral = r.id')
|
||||
->leftJoin(UserCase::class, 'uc', 'WITH', 'r.memberCase = uc.memberCase')
|
||||
->andWhere('uc.user = :user')
|
||||
->setParameter('user', $user->getId()->toBinary())
|
||||
;
|
||||
|
||||
if ($referral) {
|
||||
$query->andWhere('v.referral = :referral')
|
||||
->setParameter('referral', $referral->getId()->toBinary());
|
||||
if ($params['case']) {
|
||||
$query->andWhere('r.memberCase = :memberCase')
|
||||
->setParameter('memberCase', $params['case']->getId()->toBinary());
|
||||
}
|
||||
|
||||
if ($startDate) {
|
||||
$query->andWhere('v.date >= :startDate')
|
||||
->setParameter('startDate', $startDate);
|
||||
if ($params['referral']) {
|
||||
$query->andWhere('s.referral = :referral')
|
||||
->setParameter('referral', $params['referral']->getId()->toBinary());
|
||||
}
|
||||
|
||||
if ($endDate) {
|
||||
$query->andWhere('v.date <= :endDate')
|
||||
->setParameter('endDate', $endDate);
|
||||
if ($params['startDate']) {
|
||||
$query->andWhere('s.date >= :startDate')
|
||||
->setParameter('startDate', $params['startDate']);
|
||||
}
|
||||
|
||||
return $query->orderBy('v.date', 'DESC')
|
||||
->addOrderBy('v.startTime', 'DESC')
|
||||
if ($params['endDate']) {
|
||||
$query->andWhere('s.date <= :endDate')
|
||||
->setParameter('endDate', $params['endDate']);
|
||||
}
|
||||
|
||||
//dd($query->getQuery()->getResult());
|
||||
|
||||
return $query->orderBy('s.date', 'DESC')
|
||||
->addOrderBy('s.startTime', 'DESC')
|
||||
->getQuery()
|
||||
->getResult()
|
||||
;
|
||||
|
@ -3,8 +3,10 @@
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Referral;
|
||||
use App\Entity\UserCase;
|
||||
use App\Entity\User;
|
||||
use App\Entity\VisitNote;
|
||||
use App\Entity\VisitNoteMembers;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
@ -31,25 +33,33 @@ class VisitNoteRepository extends ServiceEntityRepository
|
||||
;
|
||||
}
|
||||
|
||||
public function filterNotes(User $user, ?Referral $referral = null, ?DateTimeImmutable $startDate = null, ?DateTimeImmutable $endDate = null): array
|
||||
public function filterNotes(User $user, array $params = []): array
|
||||
{
|
||||
$query = $this->createQueryBuilder('v')
|
||||
->join('v.referral', 'r')
|
||||
->leftJoin(Referral::class, 'r', 'WITH', 'v.referral = r.id')
|
||||
->leftJoin(UserCase::class, 'uc', 'WITH', 'r.memberCase = uc.memberCase')
|
||||
->andWhere('uc.user = :user')
|
||||
->setParameter('user', $user->getId()->toBinary())
|
||||
;
|
||||
|
||||
if ($referral) {
|
||||
if ($params['case']) {
|
||||
$query->andWhere('r.memberCase = :memberCase')
|
||||
->setParameter('memberCase', $params['case']->getId()->toBinary());
|
||||
}
|
||||
|
||||
if ($params['referral']) {
|
||||
$query->andWhere('v.referral = :referral')
|
||||
->setParameter('referral', $referral->getId()->toBinary());
|
||||
->setParameter('referral', $params['referral']->getId()->toBinary());
|
||||
}
|
||||
|
||||
if ($startDate) {
|
||||
if ($params['startDate']) {
|
||||
$query->andWhere('v.date >= :startDate')
|
||||
->setParameter('startDate', $startDate);
|
||||
->setParameter('startDate', $params['startDate']);
|
||||
}
|
||||
|
||||
if ($endDate) {
|
||||
if ($params['endDate']) {
|
||||
$query->andWhere('v.date <= :endDate')
|
||||
->setParameter('endDate', $endDate);
|
||||
->setParameter('endDate', $params['endDate']);
|
||||
}
|
||||
|
||||
return $query->orderBy('v.date', 'DESC')
|
||||
|
Loading…
Reference in New Issue
Block a user