mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-02 22:17:45 +00:00
FEATURE [repository] add parameters for filter data - typing error still for userjob
This commit is contained in:
parent
8d6cd0cf63
commit
08df1c4ac8
@ -312,18 +312,39 @@ final class ActivityController extends AbstractController
|
||||
|
||||
$view = 'ChillActivityBundle:Activity:listPerson.html.twig';
|
||||
} elseif ($accompanyingPeriod instanceof AccompanyingPeriod) {
|
||||
|
||||
$this->denyAccessUnlessGranted(ActivityVoter::SEE, $accompanyingPeriod);
|
||||
|
||||
$data = $form->getData();
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
dump($data['types']->getValues());
|
||||
$activities = $this->activityACLAwareRepository
|
||||
->findByAccompanyingPeriod(
|
||||
$accompanyingPeriod,
|
||||
ActivityVoter::SEE,
|
||||
0,
|
||||
$data['dateTo'],
|
||||
$data['dateFrom'],
|
||||
$data['jobs']->getValues(),
|
||||
$data['types']->getValues(),
|
||||
null,
|
||||
['date' => 'DESC', 'id' => 'DESC']
|
||||
);
|
||||
}
|
||||
|
||||
$activities = $this->activityACLAwareRepository
|
||||
->findByAccompanyingPeriod($accompanyingPeriod, ActivityVoter::SEE, 0, null, ['date' => 'DESC', 'id' => 'DESC']);
|
||||
|
||||
$view = 'ChillActivityBundle:Activity:listAccompanyingCourse.html.twig';
|
||||
->findByAccompanyingPeriod(
|
||||
$accompanyingPeriod,
|
||||
ActivityVoter::SEE,
|
||||
0,
|
||||
null,
|
||||
null,
|
||||
[],
|
||||
[],
|
||||
null,
|
||||
['date' => 'DESC', 'id' => 'DESC']
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
$view = 'ChillActivityBundle:Activity:listAccompanyingCourse.html.twig';
|
||||
|
||||
return $this->render(
|
||||
$view,
|
||||
|
@ -22,14 +22,15 @@ use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||
use Chill\MainBundle\Security\Resolver\CenterResolverDispatcherInterface;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use DateTime;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\AbstractQuery;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\Query\ResultSetMappingBuilder;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||
|
||||
use Symfony\Component\Security\Core\Role\Role;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
|
||||
use function count;
|
||||
use function in_array;
|
||||
|
||||
@ -63,8 +64,17 @@ final class ActivityACLAwareRepository implements ActivityACLAwareRepositoryInte
|
||||
$this->security = $security;
|
||||
}
|
||||
|
||||
public function findByAccompanyingPeriod(AccompanyingPeriod $period, string $role, ?int $start = 0, ?int $limit = 1000, ?array $orderBy = []): array
|
||||
{
|
||||
public function findByAccompanyingPeriod(
|
||||
AccompanyingPeriod $period,
|
||||
string $role,
|
||||
?int $start = 0,
|
||||
?DateTime $before = null,
|
||||
?DateTime $after = null,
|
||||
?array $userJob = [],
|
||||
?array $activityTypes = [],
|
||||
?int $limit = 1000,
|
||||
?array $orderBy = []
|
||||
): array {
|
||||
$user = $this->security->getUser();
|
||||
$center = $this->centerResolverDispatcher->resolveCenter($period);
|
||||
|
||||
@ -76,7 +86,7 @@ final class ActivityACLAwareRepository implements ActivityACLAwareRepositoryInte
|
||||
->getReachableCircles($user, $role, $center);
|
||||
|
||||
return $this->em->getRepository(Activity::class)
|
||||
->findByAccompanyingPeriod($period, $scopes, true, $limit, $start, $orderBy);
|
||||
->findByAccompanyingPeriod($period, $scopes, true, $before, $after, $userJob, $activityTypes, $limit, $start, $orderBy);
|
||||
}
|
||||
|
||||
public function findByAccompanyingPeriodSimplified(AccompanyingPeriod $period, ?int $limit = 1000): array
|
||||
|
@ -11,15 +11,27 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\ActivityBundle\Repository;
|
||||
|
||||
use Chill\ActivityBundle\Entity\Activity;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use DateTime;
|
||||
|
||||
interface ActivityACLAwareRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @return Activity[]|array
|
||||
*/
|
||||
public function findByAccompanyingPeriod(AccompanyingPeriod $period, string $role, ?int $start = 0, ?int $limit = 1000, ?array $orderBy = []): array;
|
||||
public function findByAccompanyingPeriod(
|
||||
AccompanyingPeriod $period,
|
||||
string $role,
|
||||
?int $start = 0,
|
||||
?DateTime $before = null,
|
||||
?DateTime $after = null,
|
||||
?array $userJob = [],
|
||||
?array $activityTypes = [],
|
||||
?int $limit = 1000,
|
||||
?array $orderBy = []
|
||||
): array;
|
||||
|
||||
/**
|
||||
* Return a list of activities, simplified as array (not object).
|
||||
|
@ -16,10 +16,12 @@ use Chill\ActivityBundle\Entity\ActivityType;
|
||||
use Chill\MainBundle\Entity\UserJob;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use DateTime;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use function count;
|
||||
|
||||
/**
|
||||
* @method Activity|null find($id, $lockMode = null, $lockVersion = null)
|
||||
@ -42,8 +44,18 @@ class ActivityRepository extends ServiceEntityRepository
|
||||
*
|
||||
* @return Activity[]
|
||||
*/
|
||||
public function findByAccompanyingPeriod(AccompanyingPeriod $period, array $scopes, ?bool $allowNullScope = false, ?int $limit = 100, ?int $offset = 0, array $orderBy = ['date' => 'desc']): array
|
||||
{
|
||||
public function findByAccompanyingPeriod(
|
||||
AccompanyingPeriod $period,
|
||||
array $scopes,
|
||||
?bool $allowNullScope = false,
|
||||
?DateTime $before = null,
|
||||
?DateTime $after = null,
|
||||
?array $userJob = [],
|
||||
array $activityTypes = [],
|
||||
?int $limit = 100,
|
||||
?int $offset = 0,
|
||||
array $orderBy = ['date' => 'desc']
|
||||
): array {
|
||||
$qb = $this->createQueryBuilder('a');
|
||||
$qb->select('a');
|
||||
|
||||
@ -68,12 +80,41 @@ class ActivityRepository extends ServiceEntityRepository
|
||||
)
|
||||
->setParameter('period', $period);
|
||||
|
||||
// Add filter parameters to query if any
|
||||
if ($before) {
|
||||
$qb->andWhere(
|
||||
$qb->expr()->lt('a.date', ':before')
|
||||
);
|
||||
$qb->setParameter('before', $before);
|
||||
}
|
||||
|
||||
if ($after) {
|
||||
$qb->andWhere(
|
||||
$qb->expr()->lt('a.date', ':after')
|
||||
);
|
||||
$qb->setParameter('after', $after);
|
||||
}
|
||||
|
||||
if (count($activityTypes) > 0) {
|
||||
$qb->andWhere(
|
||||
$qb->expr()->in('a.activityType', ':activityTypes')
|
||||
);
|
||||
$qb->setParameter('activityTypes', $activityTypes);
|
||||
}
|
||||
|
||||
/*if (null !== $userJob) {
|
||||
$qb->innerJoin()
|
||||
}*/
|
||||
|
||||
foreach ($orderBy as $k => $dir) {
|
||||
$qb->addOrderBy('a.' . $k, $dir);
|
||||
}
|
||||
|
||||
$qb->setMaxResults($limit)->setFirstResult($offset);
|
||||
|
||||
dump($qb->getQuery());
|
||||
dump($qb->getQuery()->getResult());
|
||||
|
||||
return $qb->getQuery()->getResult();
|
||||
}
|
||||
|
||||
@ -106,15 +147,10 @@ class ActivityRepository extends ServiceEntityRepository
|
||||
}
|
||||
|
||||
/**
|
||||
* @param QueryBuilder $qb
|
||||
* @param array|UserJob $jobs
|
||||
* @param array|ActivityType $types
|
||||
* @param \DateTime $dateFrom
|
||||
* @param \DateTime $dateTo
|
||||
* @param bool $onlyMe
|
||||
* @return QueryBuilder
|
||||
*/
|
||||
private function addQueryFilters(QueryBuilder $qb, array $jobs, array $types, \DateTime $dateFrom, \DateTime $dateTo, bool $onlyMe): QueryBuilder
|
||||
private function addQueryFilters(QueryBuilder $qb, array $jobs, array $types, DateTime $dateFrom, DateTime $dateTo, bool $onlyMe): QueryBuilder
|
||||
{
|
||||
if (0 < count($jobs)) {
|
||||
$qb->join('a.user', 'u');
|
||||
@ -127,8 +163,7 @@ class ActivityRepository extends ServiceEntityRepository
|
||||
->setParameter('types', $types);
|
||||
}
|
||||
|
||||
if (null !== $dateFrom && null !== $dateTo)
|
||||
{
|
||||
if (null !== $dateFrom && null !== $dateTo) {
|
||||
$qb->andWhere($qb->expr()->between(
|
||||
'a.date',
|
||||
':date_from',
|
||||
|
Loading…
x
Reference in New Issue
Block a user