Use EntityManagerInterface.

This commit is contained in:
Pol Dellaiera 2021-05-06 12:34:16 +02:00
parent 7f602ffa47
commit c5940c1263
2 changed files with 18 additions and 14 deletions

View File

@ -27,6 +27,7 @@ use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\RequestStack;
use Doctrine\Persistence\ObjectManager; use Doctrine\Persistence\ObjectManager;
use Chill\MainBundle\Form\Type\Select2ChoiceType; use Chill\MainBundle\Form\Type\Select2ChoiceType;
use Doctrine\ORM\EntityManagerInterface;
/** /**
* A type to select the marital status * A type to select the marital status
@ -38,10 +39,12 @@ class Select2MaritalStatusType extends AbstractType
/** @var RequestStack */ /** @var RequestStack */
private $requestStack; private $requestStack;
/** @var ObjectManager */ /**
* @var EntityManagerInterface
*/
private $em; private $em;
public function __construct(RequestStack $requestStack,ObjectManager $em) public function __construct(RequestStack $requestStack, EntityManagerInterface $em)
{ {
$this->requestStack = $requestStack; $this->requestStack = $requestStack;
$this->em = $em; $this->em = $em;

View File

@ -21,10 +21,11 @@ namespace Chill\PersonBundle\Timeline;
use Chill\MainBundle\Timeline\TimelineProviderInterface; use Chill\MainBundle\Timeline\TimelineProviderInterface;
use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
/** /**
* Provide method to build timeline for accompanying periods * Provide method to build timeline for accompanying periods
* *
* This class is resued by TimelineAccompanyingPeriodOpening (for opening) * This class is resued by TimelineAccompanyingPeriodOpening (for opening)
* and TimelineAccompanyingPeriodClosing (for closing) * and TimelineAccompanyingPeriodClosing (for closing)
* *
@ -34,17 +35,17 @@ abstract class AbstractTimelineAccompanyingPeriod implements TimelineProviderInt
{ {
/** /**
* *
* @var EntityManager * @var EntityManagerInterface
*/ */
protected $em; protected $em;
public function __construct(EntityManager $em) public function __construct(EntityManagerInterface $em)
{ {
$this->em = $em; $this->em = $em;
} }
/** /**
* *
* {@inheritDoc} * {@inheritDoc}
*/ */
public function getEntities(array $ids) public function getEntities(array $ids)
@ -52,19 +53,19 @@ abstract class AbstractTimelineAccompanyingPeriod implements TimelineProviderInt
$periods = $this->em $periods = $this->em
->getRepository('ChillPersonBundle:AccompanyingPeriod') ->getRepository('ChillPersonBundle:AccompanyingPeriod')
->findBy(array('id' => $ids)); ->findBy(array('id' => $ids));
//set results in an associative array with id as indexes //set results in an associative array with id as indexes
$results = array(); $results = array();
foreach($periods as $period) { foreach($periods as $period) {
$results[$period->getId()] = $period; $results[$period->getId()] = $period;
} }
return $results; return $results;
} }
/** /**
* prepare fetchQuery without `WHERE` and `TYPE` clause * prepare fetchQuery without `WHERE` and `TYPE` clause
* *
* @param string $context * @param string $context
* @param array $args * @param array $args
* @return array * @return array
@ -76,15 +77,15 @@ abstract class AbstractTimelineAccompanyingPeriod implements TimelineProviderInt
throw new \LogicException('TimelineAccompanyingPeriod is not able ' throw new \LogicException('TimelineAccompanyingPeriod is not able '
. 'to render context '.$context); . 'to render context '.$context);
} }
$metadata = $this->em $metadata = $this->em
->getClassMetadata('ChillPersonBundle:AccompanyingPeriod') ->getClassMetadata('ChillPersonBundle:AccompanyingPeriod')
; ;
return array( return array(
'id' => $metadata->getColumnName('id'), 'id' => $metadata->getColumnName('id'),
'FROM' => $metadata->getTableName(), 'FROM' => $metadata->getTableName(),
'WHERE' => sprintf('%s = %d', 'WHERE' => sprintf('%s = %d',
$metadata $metadata
->getAssociationMapping('person')['joinColumns'][0]['name'], ->getAssociationMapping('person')['joinColumns'][0]['name'],
$args['person']->getId()) $args['person']->getId())
@ -93,7 +94,7 @@ abstract class AbstractTimelineAccompanyingPeriod implements TimelineProviderInt
/** /**
* return the expected response for TimelineProviderInterface::getEntityTemplate * return the expected response for TimelineProviderInterface::getEntityTemplate
* *
* @param string $template the template for rendering * @param string $template the template for rendering
* @param mixed $entity * @param mixed $entity
* @param string $context * @param string $context