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\Referral;
|
||||||
use App\Entity\StandardNote;
|
use App\Entity\StandardNote;
|
||||||
use App\Entity\User;
|
use App\Entity\User;
|
||||||
use DateTimeImmutable;
|
use App\Entity\UserCase;
|
||||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
use Doctrine\Persistence\ManagerRegistry;
|
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')
|
$query = $this->createQueryBuilder('s')
|
||||||
->join('v.referral', 'r')
|
->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) {
|
if ($params['case']) {
|
||||||
$query->andWhere('v.referral = :referral')
|
$query->andWhere('r.memberCase = :memberCase')
|
||||||
->setParameter('referral', $referral->getId()->toBinary());
|
->setParameter('memberCase', $params['case']->getId()->toBinary());
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($startDate) {
|
if ($params['referral']) {
|
||||||
$query->andWhere('v.date >= :startDate')
|
$query->andWhere('s.referral = :referral')
|
||||||
->setParameter('startDate', $startDate);
|
->setParameter('referral', $params['referral']->getId()->toBinary());
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($endDate) {
|
if ($params['startDate']) {
|
||||||
$query->andWhere('v.date <= :endDate')
|
$query->andWhere('s.date >= :startDate')
|
||||||
->setParameter('endDate', $endDate);
|
->setParameter('startDate', $params['startDate']);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $query->orderBy('v.date', 'DESC')
|
if ($params['endDate']) {
|
||||||
->addOrderBy('v.startTime', 'DESC')
|
$query->andWhere('s.date <= :endDate')
|
||||||
|
->setParameter('endDate', $params['endDate']);
|
||||||
|
}
|
||||||
|
|
||||||
|
//dd($query->getQuery()->getResult());
|
||||||
|
|
||||||
|
return $query->orderBy('s.date', 'DESC')
|
||||||
|
->addOrderBy('s.startTime', 'DESC')
|
||||||
->getQuery()
|
->getQuery()
|
||||||
->getResult()
|
->getResult()
|
||||||
;
|
;
|
||||||
|
@ -3,8 +3,10 @@
|
|||||||
namespace App\Repository;
|
namespace App\Repository;
|
||||||
|
|
||||||
use App\Entity\Referral;
|
use App\Entity\Referral;
|
||||||
|
use App\Entity\UserCase;
|
||||||
use App\Entity\User;
|
use App\Entity\User;
|
||||||
use App\Entity\VisitNote;
|
use App\Entity\VisitNote;
|
||||||
|
use App\Entity\VisitNoteMembers;
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
use Doctrine\Persistence\ManagerRegistry;
|
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')
|
$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')
|
$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')
|
$query->andWhere('v.date >= :startDate')
|
||||||
->setParameter('startDate', $startDate);
|
->setParameter('startDate', $params['startDate']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($endDate) {
|
if ($params['endDate']) {
|
||||||
$query->andWhere('v.date <= :endDate')
|
$query->andWhere('v.date <= :endDate')
|
||||||
->setParameter('endDate', $endDate);
|
->setParameter('endDate', $params['endDate']);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $query->orderBy('v.date', 'DESC')
|
return $query->orderBy('v.date', 'DESC')
|
||||||
|
Loading…
Reference in New Issue
Block a user