mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-25 09:03:48 +00:00
Feature: Add filters on activity list
This commit is contained in:
@@ -18,11 +18,16 @@ use Chill\ActivityBundle\Repository\ActivityACLAwareRepositoryInterface;
|
||||
use Chill\ActivityBundle\Repository\ActivityRepository;
|
||||
use Chill\ActivityBundle\Repository\ActivityTypeCategoryRepository;
|
||||
use Chill\ActivityBundle\Repository\ActivityTypeRepositoryInterface;
|
||||
use Chill\ActivityBundle\Repository\ActivityUserJobRepository;
|
||||
use Chill\ActivityBundle\Security\Authorization\ActivityVoter;
|
||||
use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable;
|
||||
use Chill\MainBundle\Entity\UserJob;
|
||||
use Chill\MainBundle\Repository\LocationRepository;
|
||||
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
||||
use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface;
|
||||
use Chill\MainBundle\Templating\Listing\FilterOrderHelper;
|
||||
use Chill\MainBundle\Templating\Listing\FilterOrderHelperFactoryInterface;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Privacy\PrivacyEvent;
|
||||
@@ -47,68 +52,25 @@ use function array_key_exists;
|
||||
|
||||
final class ActivityController extends AbstractController
|
||||
{
|
||||
private AccompanyingPeriodRepository $accompanyingPeriodRepository;
|
||||
|
||||
private ActivityACLAwareRepositoryInterface $activityACLAwareRepository;
|
||||
|
||||
private ActivityRepository $activityRepository;
|
||||
|
||||
private ActivityTypeCategoryRepository $activityTypeCategoryRepository;
|
||||
|
||||
private ActivityTypeRepositoryInterface $activityTypeRepository;
|
||||
|
||||
private CenterResolverManagerInterface $centerResolver;
|
||||
|
||||
private EntityManagerInterface $entityManager;
|
||||
|
||||
private EventDispatcherInterface $eventDispatcher;
|
||||
|
||||
private LocationRepository $locationRepository;
|
||||
|
||||
private LoggerInterface $logger;
|
||||
|
||||
private PersonRepository $personRepository;
|
||||
|
||||
private SerializerInterface $serializer;
|
||||
|
||||
private ThirdPartyRepository $thirdPartyRepository;
|
||||
|
||||
private TranslatorInterface $translator;
|
||||
|
||||
private UserRepositoryInterface $userRepository;
|
||||
|
||||
public function __construct(
|
||||
ActivityACLAwareRepositoryInterface $activityACLAwareRepository,
|
||||
ActivityTypeRepositoryInterface $activityTypeRepository,
|
||||
ActivityTypeCategoryRepository $activityTypeCategoryRepository,
|
||||
PersonRepository $personRepository,
|
||||
ThirdPartyRepository $thirdPartyRepository,
|
||||
LocationRepository $locationRepository,
|
||||
ActivityRepository $activityRepository,
|
||||
AccompanyingPeriodRepository $accompanyingPeriodRepository,
|
||||
EntityManagerInterface $entityManager,
|
||||
EventDispatcherInterface $eventDispatcher,
|
||||
LoggerInterface $logger,
|
||||
SerializerInterface $serializer,
|
||||
UserRepositoryInterface $userRepository,
|
||||
CenterResolverManagerInterface $centerResolver,
|
||||
TranslatorInterface $translator
|
||||
private readonly ActivityACLAwareRepositoryInterface $activityACLAwareRepository,
|
||||
private readonly ActivityTypeRepositoryInterface $activityTypeRepository,
|
||||
private readonly ActivityTypeCategoryRepository $activityTypeCategoryRepository,
|
||||
private readonly PersonRepository $personRepository,
|
||||
private readonly ThirdPartyRepository $thirdPartyRepository,
|
||||
private readonly LocationRepository $locationRepository,
|
||||
private readonly ActivityRepository $activityRepository,
|
||||
private readonly AccompanyingPeriodRepository $accompanyingPeriodRepository,
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly EventDispatcherInterface $eventDispatcher,
|
||||
private readonly LoggerInterface $logger,
|
||||
private readonly SerializerInterface $serializer,
|
||||
private readonly UserRepositoryInterface $userRepository,
|
||||
private readonly CenterResolverManagerInterface $centerResolver,
|
||||
private readonly TranslatorInterface $translator,
|
||||
private readonly FilterOrderHelperFactoryInterface $filterOrderHelperFactory,
|
||||
private readonly TranslatableStringHelperInterface $translatableStringHelper,
|
||||
) {
|
||||
$this->activityACLAwareRepository = $activityACLAwareRepository;
|
||||
$this->activityTypeRepository = $activityTypeRepository;
|
||||
$this->activityTypeCategoryRepository = $activityTypeCategoryRepository;
|
||||
$this->personRepository = $personRepository;
|
||||
$this->thirdPartyRepository = $thirdPartyRepository;
|
||||
$this->locationRepository = $locationRepository;
|
||||
$this->activityRepository = $activityRepository;
|
||||
$this->accompanyingPeriodRepository = $accompanyingPeriodRepository;
|
||||
$this->entityManager = $entityManager;
|
||||
$this->eventDispatcher = $eventDispatcher;
|
||||
$this->logger = $logger;
|
||||
$this->serializer = $serializer;
|
||||
$this->userRepository = $userRepository;
|
||||
$this->centerResolver = $centerResolver;
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -292,11 +254,27 @@ final class ActivityController extends AbstractController
|
||||
// TODO: add pagination
|
||||
|
||||
[$person, $accompanyingPeriod] = $this->getEntity($request);
|
||||
$filter = $this->buildFilterOrder($person ?? $accompanyingPeriod);
|
||||
|
||||
$filterArgs = [
|
||||
'my_activities' => $filter->getSingleCheckboxData('my_activities'),
|
||||
'types' => $filter->getEntityChoiceData('activity_types'),
|
||||
'jobs' => $filter->getEntityChoiceData('jobs'),
|
||||
'before' => $filter->getDateRangeData('activity_date')['to'],
|
||||
'after' => $filter->getDateRangeData('activity_date')['from'],
|
||||
];
|
||||
|
||||
if ($person instanceof Person) {
|
||||
$this->denyAccessUnlessGranted(ActivityVoter::SEE, $person);
|
||||
$activities = $this->activityACLAwareRepository
|
||||
->findByPerson($person, ActivityVoter::SEE, 0, null, ['date' => 'DESC', 'id' => 'DESC']);
|
||||
->findByPerson(
|
||||
$person,
|
||||
ActivityVoter::SEE,
|
||||
0,
|
||||
null,
|
||||
['date' => 'DESC', 'id' => 'DESC'],
|
||||
$filterArgs
|
||||
);
|
||||
|
||||
$event = new PrivacyEvent($person, [
|
||||
'element_class' => Activity::class,
|
||||
@@ -309,7 +287,14 @@ final class ActivityController extends AbstractController
|
||||
$this->denyAccessUnlessGranted(ActivityVoter::SEE, $accompanyingPeriod);
|
||||
|
||||
$activities = $this->activityACLAwareRepository
|
||||
->findByAccompanyingPeriod($accompanyingPeriod, ActivityVoter::SEE, 0, null, ['date' => 'DESC', 'id' => 'DESC']);
|
||||
->findByAccompanyingPeriod(
|
||||
$accompanyingPeriod,
|
||||
ActivityVoter::SEE,
|
||||
0,
|
||||
null,
|
||||
['date' => 'DESC', 'id' => 'DESC'],
|
||||
$filterArgs
|
||||
);
|
||||
|
||||
$view = 'ChillActivityBundle:Activity:listAccompanyingCourse.html.twig';
|
||||
}
|
||||
@@ -320,10 +305,39 @@ final class ActivityController extends AbstractController
|
||||
'activities' => $activities,
|
||||
'person' => $person,
|
||||
'accompanyingCourse' => $accompanyingPeriod,
|
||||
'filter' => $filter,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
private function buildFilterOrder(AccompanyingPeriod|Person $associated): FilterOrderHelper
|
||||
{
|
||||
|
||||
$filterBuilder = $this->filterOrderHelperFactory->create(self::class);
|
||||
$types = $this->activityACLAwareRepository->findActivityTypeByAssociated($associated);
|
||||
$jobs = $this->activityACLAwareRepository->findUserJobByAssociated($associated);
|
||||
|
||||
$filterBuilder
|
||||
->addDateRange('activity_date', 'activity.date')
|
||||
->addSingleCheckbox('my_activities', 'activity_filter.My activities')
|
||||
->addEntityChoice('activity_types', 'activity_filter.Types', \Chill\ActivityBundle\Entity\ActivityType::class, $types, [
|
||||
'choice_label' => function (\Chill\ActivityBundle\Entity\ActivityType $activityType) {
|
||||
$text = match ($activityType->hasCategory()) {
|
||||
true => $this->translatableStringHelper->localize($activityType->getCategory()->getName()) . ' > ',
|
||||
false => '',
|
||||
};
|
||||
|
||||
return $text . $this->translatableStringHelper->localize($activityType->getName());
|
||||
}
|
||||
])
|
||||
->addEntityChoice('jobs', 'activity_filter.Jobs', UserJob::class, $jobs, [
|
||||
'choice_label' => fn (UserJob $u) => $this->translatableStringHelper->localize($u->getLabel())
|
||||
])
|
||||
;
|
||||
|
||||
return $filterBuilder->build();
|
||||
}
|
||||
|
||||
public function newAction(Request $request): Response
|
||||
{
|
||||
$view = null;
|
||||
|
Reference in New Issue
Block a user