fix event bundle stuffs

- adapt event templates
- event bundle: fix deprecated deps injections
- fix error with n=0 not iterated into querybuilder with centers loop
This commit is contained in:
2023-04-24 14:44:26 +02:00
parent 01f2697b8d
commit 8fd9010ea5
8 changed files with 47 additions and 43 deletions

View File

@@ -12,13 +12,14 @@ declare(strict_types=1);
namespace Chill\EventBundle\Search;
use Chill\EventBundle\Entity\Event;
use Chill\EventBundle\Repository\EventRepository;
use Chill\MainBundle\Pagination\PaginatorFactory;
use Chill\MainBundle\Search\AbstractSearch;
use Chill\MainBundle\Search\SearchInterface;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Templating\EngineInterface as TemplatingEngine;
use function count;
@@ -40,15 +41,17 @@ class EventSearch extends AbstractSearch
{
public const NAME = 'event_regular';
private $security;
/**
* @var EntityRepository
* @var EventRepository
*/
private $er;
/**
* @var AuthorizationHelper
*/
private $helper;
private $authorizationHelper;
/**
* @var PaginatorFactory
@@ -60,21 +63,16 @@ class EventSearch extends AbstractSearch
*/
private $templating;
/**
* @var \Chill\MainBundle\Entity\User
*/
private $user;
public function __construct(
TokenStorageInterface $tokenStorage,
EntityRepository $eventRepository,
Security $security,
EventRepository $eventRepository,
AuthorizationHelper $authorizationHelper,
TemplatingEngine $templating,
PaginatorFactory $paginatorFactory
) {
$this->user = $tokenStorage->getToken()->getUser();
$this->security = $security;
$this->er = $eventRepository;
$this->helper = $authorizationHelper;
$this->authorizationHelper = $authorizationHelper;
$this->templating = $templating;
$this->paginationFactory = $paginatorFactory;
}
@@ -101,7 +99,7 @@ class EventSearch extends AbstractSearch
if ('html' === $format) {
return $this->templating->render(
'ChillEventBundle:Event:list.html.twig',
'@ChillEvent/Event/list.html.twig',
[
'events' => $this->search($terms, $start, $limit, $options),
'pattern' => $this->recomposePattern($terms, $this->getAvailableTerms(), $terms['_domain']),
@@ -140,8 +138,10 @@ class EventSearch extends AbstractSearch
protected function composeQuery(QueryBuilder &$qb, $terms)
{
// add security clauses
$reachableCenters = $this->helper
->getReachableCenters($this->user, 'CHILL_EVENT_SEE');
$reachableCenters = $this->authorizationHelper->getReachableCenters(
$this->security->getUser(),
'CHILL_EVENT_SEE'
);
if (count($reachableCenters) === 0) {
// add a clause to block all events
@@ -152,8 +152,9 @@ class EventSearch extends AbstractSearch
$orWhere = $qb->expr()->orX();
foreach ($reachableCenters as $center) {
$circles = $this->helper->getReachableScopes(
$this->user,
$n = $n+1;
$circles = $this->authorizationHelper->getReachableScopes(
$this->security->getUser(),
'CHILL_EVENT_SEE',
$center
);