fix error with getInt() and inject PaginatorFactory service in EventController

This commit is contained in:
Tchama 2020-08-04 12:23:10 +02:00
parent d4948b176f
commit 7730f732ed
4 changed files with 18 additions and 13 deletions

View File

@ -24,6 +24,7 @@ namespace Chill\EventBundle\Controller;
use Chill\EventBundle\Entity\Participation; use Chill\EventBundle\Entity\Participation;
use Chill\EventBundle\Form\Type\PickEventType; use Chill\EventBundle\Form\Type\PickEventType;
use Chill\MainBundle\Pagination\PaginatorFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Csv; use PhpOffice\PhpSpreadsheet\Writer\Csv;
use PhpOffice\PhpSpreadsheet\Writer\Ods; use PhpOffice\PhpSpreadsheet\Writer\Ods;
@ -77,6 +78,11 @@ class EventController extends Controller
*/ */
protected $translator; protected $translator;
/**
* @var PaginatorFactory
*/
protected $paginator;
/** /**
* EventController constructor. * EventController constructor.
* *
@ -84,18 +90,21 @@ class EventController extends Controller
* @param AuthorizationHelper $authorizationHelper * @param AuthorizationHelper $authorizationHelper
* @param FormFactoryInterface $formFactoryInterface * @param FormFactoryInterface $formFactoryInterface
* @param TranslatorInterface $translator * @param TranslatorInterface $translator
* @param PaginatorFactory $paginator
*/ */
public function __construct( public function __construct(
EventDispatcherInterface $eventDispatcher, EventDispatcherInterface $eventDispatcher,
AuthorizationHelper $authorizationHelper, AuthorizationHelper $authorizationHelper,
FormFactoryInterface $formFactoryInterface, FormFactoryInterface $formFactoryInterface,
TranslatorInterface $translator TranslatorInterface $translator,
PaginatorFactory $paginator
) )
{ {
$this->eventDispatcher = $eventDispatcher; $this->eventDispatcher = $eventDispatcher;
$this->authorizationHelper = $authorizationHelper; $this->authorizationHelper = $authorizationHelper;
$this->formFactoryInterface = $formFactoryInterface; $this->formFactoryInterface = $formFactoryInterface;
$this->translator = $translator; $this->translator = $translator;
$this->paginator = $paginator;
} }
@ -388,11 +397,7 @@ class EventController extends Controller
$total = $em->getRepository('ChillEventBundle:Participation')->countByPerson($person_id); $total = $em->getRepository('ChillEventBundle:Participation')->countByPerson($person_id);
/** $paginator = $this->paginator->create($total);
* @var $paginatorFactory \Chill\MainBundle\Pagination\PaginatorFactory
*/
$paginatorFactory = $this->get('chill_main.paginator_factory');
$paginator = $paginatorFactory->create($total);
$participations = $em->getRepository('ChillEventBundle:Participation')->findByPersonInCircle( $participations = $em->getRepository('ChillEventBundle:Participation')->findByPersonInCircle(
$person_id, $person_id,

View File

@ -369,7 +369,8 @@ class ParticipationController extends Controller
. "the object manager using the method ".__METHOD__); . "the object manager using the method ".__METHOD__);
} }
$event_id = $request->query->getInt('event_id', null); $event_id = $request->query->getInt('event_id', 0); // sf4 check:
// prevent error: `Argument 2 passed to ::getInt() must be of the type int, null given`
if ($event_id !== NULL) { if ($event_id !== NULL) {
$event = $em->getRepository('ChillEventBundle:Event') $event = $em->getRepository('ChillEventBundle:Event')
@ -388,9 +389,9 @@ class ParticipationController extends Controller
// this script should be able to handle multiple, so we translate // this script should be able to handle multiple, so we translate
// single person_id in an array // single person_id in an array
$persons_ids = $request->query->has('person_id') ? $persons_ids = $request->query->has('person_id') ?
array($request->query->getInt('person_id', null)): [$request->query->getInt('person_id', 0)] // sf4 check:
explode(',', $request->query->get('persons_ids')) // prevent error: `Argument 2 passed to ::getInt() must be of the type int, null given`
; : explode(',', $request->query->get('persons_ids'));
$participations = array(); $participations = array();
foreach($persons_ids as $person_id) { foreach($persons_ids as $person_id) {

View File

@ -1,4 +1,2 @@
services: services:
Chill\EventBundle\:
resource: '../../*'
exclude: '../../{Entity,Resources/migrations,Resources/test}'

View File

@ -6,5 +6,6 @@ services:
$authorizationHelper: '@Chill\MainBundle\Security\Authorization\AuthorizationHelper' $authorizationHelper: '@Chill\MainBundle\Security\Authorization\AuthorizationHelper'
$formFactoryInterface: '@Symfony\Component\Form\FormFactoryInterface' $formFactoryInterface: '@Symfony\Component\Form\FormFactoryInterface'
$translator: '@Symfony\Component\Translation\TranslatorInterface' $translator: '@Symfony\Component\Translation\TranslatorInterface'
$paginator: '@chill_main.paginator_factory'
public: true public: true