|
|
|
@ -1,21 +1,23 @@ |
|
|
|
|
<?php |
|
|
|
|
namespace vierbergenlars\AuthserverTosBundle\EventListener; |
|
|
|
|
|
|
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
|
|
|
|
use Admin\AdminEvents; |
|
|
|
|
use Admin\Event\FilterListEvent; |
|
|
|
|
use App\Entity\User; |
|
|
|
|
use Doctrine\Common\Collections\Criteria; |
|
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
|
|
|
use Registration\RegistrationEvents; |
|
|
|
|
use Registration\Event\RegistrationFormEvent; |
|
|
|
|
use Registration\Event\RegistrationHandleEvent; |
|
|
|
|
use Symfony\Component\Form\Extension\Core\Type\CheckboxType; |
|
|
|
|
use Symfony\Component\Validator\Constraints\IsTrue; |
|
|
|
|
use vierbergenlars\AuthserverTosBundle\Entity\UserTos; |
|
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
|
|
|
use App\Entity\User; |
|
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
|
|
|
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; |
|
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
|
|
|
|
use Symfony\Component\HttpKernel\KernelEvents; |
|
|
|
|
use Symfony\Component\HttpKernel\Event\GetResponseEvent; |
|
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
|
|
|
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; |
|
|
|
|
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; |
|
|
|
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; |
|
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
|
|
|
|
use vierbergenlars\AuthserverTosBundle\Entity\UserTos; |
|
|
|
|
use vierbergenlars\AuthserverTosBundle\Form\AcceptTosType; |
|
|
|
|
|
|
|
|
|
class TosListener implements EventSubscriberInterface |
|
|
|
@ -45,7 +47,7 @@ class TosListener implements EventSubscriberInterface |
|
|
|
|
|
|
|
|
|
public static function getSubscribedEvents() |
|
|
|
|
{ |
|
|
|
|
return [ |
|
|
|
|
$handlers = [ |
|
|
|
|
RegistrationEvents::BUILD_FORM => [ |
|
|
|
|
'onBuildForm', |
|
|
|
|
-200 |
|
|
|
@ -56,6 +58,22 @@ class TosListener implements EventSubscriberInterface |
|
|
|
|
], |
|
|
|
|
KernelEvents::REQUEST => 'onKernelRequest' |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
if (class_exists(AdminEvents::class) && defined(AdminEvents::class . '::FILTER_LIST')) { |
|
|
|
|
$handlers[AdminEvents::FILTER_LIST] = [ |
|
|
|
|
[ |
|
|
|
|
'onFilterListCreateForm', |
|
|
|
|
10 |
|
|
|
|
], |
|
|
|
|
[ |
|
|
|
|
'onFilterListFilter', |
|
|
|
|
-10 |
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $handlers; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function __construct($terms, $tosVersion, EntityManagerInterface $em, TokenStorageInterface $tokenStorage, UrlGeneratorInterface $urlGenerator) |
|
|
|
@ -119,4 +137,39 @@ class TosListener implements EventSubscriberInterface |
|
|
|
|
$event->setResponse($response); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function onFilterListCreateForm(FilterListEvent $event) |
|
|
|
|
{ |
|
|
|
|
$event->getSearchFormBuilder()->add('tos_accepted', ChoiceType::class, [ |
|
|
|
|
'choices' => [ |
|
|
|
|
'Yes' => '1', |
|
|
|
|
'No' => '0' |
|
|
|
|
], |
|
|
|
|
'expanded' => true, |
|
|
|
|
'required' => false |
|
|
|
|
]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function onFilterListFilter(FilterListEvent $event) |
|
|
|
|
{ |
|
|
|
|
$field = $event->getSearchForm()->get('tos_accepted'); |
|
|
|
|
if ($field->isEmpty() || $field->getData() === null) |
|
|
|
|
return; |
|
|
|
|
$toses = $this->em->createQueryBuilder() |
|
|
|
|
->select('t') |
|
|
|
|
->from(UserTos::class, 't') |
|
|
|
|
->where('t.acceptedVersion >= :currentVersion') |
|
|
|
|
->setParameter('currentVersion', $this->tosVersion) |
|
|
|
|
->groupBy('t.user') |
|
|
|
|
->getQuery() |
|
|
|
|
->getArrayResult(); |
|
|
|
|
|
|
|
|
|
$userIds = array_map(function ($tos) { |
|
|
|
|
return $tos['user_id']; |
|
|
|
|
}, $toses); |
|
|
|
|
|
|
|
|
|
$expr = $field->getData() === "1" ? Criteria::expr()->in('id', $userIds) : Criteria::expr()->notIn('id', $userIds); |
|
|
|
|
|
|
|
|
|
$event->addFilter('tos_accepted', $expr); |
|
|
|
|
} |
|
|
|
|
} |